Sync missing files (lean, preprints, history.md); remove stale build artifacts (part 9)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- lean/OAI/Probability/ThorpRouting/Casimir/InputTree.leanAdded+869
- lean/OAI/Probability/ThorpRouting/Casimir/InsertionPerm.leanAdded+891
- lean/OAI/Probability/ThorpRouting/Casimir/Main.leanAdded+971
- lean/OAI/Probability/ThorpRouting/Casimir/Model.leanAdded+335
- lean/OAI/Probability/ThorpRouting/Casimir/ModifiedReverseCoins.leanAdded+761
- lean/OAI/Probability/ThorpRouting/Casimir/ModifiedRoutingMoment.leanAdded+856
- lean/OAI/Probability/ThorpRouting/Casimir/PairAssembleEquiv.leanAdded+835
- lean/OAI/Probability/ThorpRouting/Casimir/PalindromeFamilyCost.leanAdded+880
- lean/OAI/Probability/ThorpRouting/Casimir/ParallelFollow.leanAdded+883
- lean/OAI/Probability/ThorpRouting/Casimir/PriorPaths.leanAdded+882
- lean/OAI/Probability/ThorpRouting/Casimir/RotationMeeting.leanAdded+881
- lean/OAI/Probability/ThorpRouting/Casimir/SandwichShuffle.leanAdded+874
- lean/OAI/Probability/ThorpRouting/Casimir/Shapes.leanAdded+882
- lean/OAI/Probability/ThorpRouting/Casimir/Site.leanAdded+851
- lean/OAI/Probability/ThorpRouting/Casimir/TailShapes.leanAdded+894
- lean/OAI/Probability/ThorpRouting/Casimir/TypedSet.leanAdded+871
- lean/OAI/Probability/ThorpRouting/Casimir/ZeroExtend.leanAdded+878
- lean/OAI/Probability/ThorpRouting/Contact/AlternatingPerm.leanAdded+900
- lean/OAI/Probability/ThorpRouting/Contact/AssignmentSlots.leanAdded+834
- lean/OAI/Probability/ThorpRouting/Contact/BenesCoins.leanAdded+882
- lean/OAI/Probability/ThorpRouting/Contact/BlockProduct.leanAdded+894
- lean/OAI/Probability/ThorpRouting/Contact/Coins.leanAdded+767
- lean/OAI/Probability/ThorpRouting/Contact/ExposedCoins.leanAdded+860
- lean/OAI/Probability/ThorpRouting/Contact/HeightDecay.leanAdded+863
- lean/OAI/Probability/ThorpRouting/Contact/InputTree.leanAdded+884
- lean/OAI/Probability/ThorpRouting/Contact/Main.leanAdded
- lean/OAI/Probability/ThorpRouting/Contact/Model.leanAdded
- lean/OAI/Probability/ThorpRouting/Contact/ModifiedReverseEquiv.leanAdded
- lean/OAI/Probability/ThorpRouting/Contact/ModifiedRoutingMoment.leanAdded
- lean/OAI/Probability/ThorpRouting/Contact/ModifiedStageEquiv.leanAdded
- lean/OAI/Probability/ThorpRouting/Contact/ParallelFollow.leanAdded
- lean/OAI/Probability/ThorpRouting/Contact/ParallelFreshPre.leanAdded
- lean/OAI/Probability/ThorpRouting/Contact/PriorPaths.leanAdded
- lean/OAI/Probability/ThorpRouting/Contact/Representative.leanAdded
- lean/OAI/Probability/ThorpRouting/Contact/RotationMeeting.leanAdded
- lean/OAI/Probability/ThorpRouting/Contact/ShapePartitionEquiv.leanAdded
- lean/OAI/Probability/ThorpRouting/Dense/AssignmentSlots.leanAdded
- lean/OAI/Probability/ThorpRouting/Dense/Coins.leanAdded
- lean/OAI/Probability/ThorpRouting/Dense/ColoredEmbedding.leanAdded
- lean/OAI/Probability/ThorpRouting/Dense/CutoffMass.leanAdded
- lean/OAI/Probability/ThorpRouting/Dense/ExposedCoins.leanAdded
- lean/OAI/Probability/ThorpRouting/Dense/Main.leanAdded
- lean/OAI/Probability/ThorpRouting/Dense/Model.leanAdded
- lean/OAI/Probability/ThorpRouting/Dense/PalindromeFamilyCost.leanAdded
- lean/OAI/Probability/ThorpRouting/Dense/ParallelFollow.leanAdded
- lean/OAI/Probability/ThorpRouting/Dense/PriorPaths.leanAdded
- lean/OAI/Probability/ThorpRouting/Dense/ProjectCycle.leanAdded
- lean/OAI/Probability/ThorpRouting/Dense/RotationCharge.leanAdded
- lean/OAI/Probability/ThorpRouting/Dense/SingleSlotsEquiv.leanAdded
- lean/OAI/Probability/ThorpRouting/Harmonic/AlternatingPerm.leanAdded
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869import Mathlib
import OAI.Probability.ThorpRouting.Casimir.PalindromeFamilyCost
namespace OAI
namespace ThorpNine.Casimir
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.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891import Mathlib
import OAI.Probability.ThorpRouting.Casimir.ZeroExtend
namespace OAI
namespace ThorpNine.Casimir
namespace Thorp.DimensionEstimates
open scoped BigOperators Classical
section
open Filter
lemma chosenTuple_density_bound (N j : ℕ) (hj : 0<j) (hx : 1≤(N:ℝ)/j)
(hhalf : ((N:ℝ)/j)^(nearPower-1)≤1/2) (C : ℝ) (hC : 0≤C) :
C*(chosenTuple N j:ℝ)*((chosenTuple N j:ℝ)/N)^(1/512:ℝ) ≤
C*2^(1+(1/512:ℝ))*(j:ℝ)*((N:ℝ)/j)^(-tailPower) := by
let x : ℝ := (N:ℝ)/j
have hjp : (0:ℝ)<j := by exact_mod_cast hj
have hxp : 0<x := lt_of_lt_of_le zero_lt_one hx
have hNp : (0:ℝ)<N := by
have : (0:ℝ)<(N:ℝ)/j := hxp
exact (div_pos_iff.mp this).resolve_right (by intro h; exact (not_lt_of_ge hjp.le) h.2) |>.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<nearPower)).eventually
(eventually_ge_atTop (2:ℝ))
have hhalf : ∀ᶠ x : ℝ in atTop, x^(nearPower-1)≤1/2 := by
have h := (tendsto_rpow_neg_atTop (by norm_num [nearPower] : 0<1-nearPower)).eventually
(gt_mem_nhds (by norm_num : (0:ℝ)<1/2))
filter_upwards [h] with x hx
simpa only [neg_sub] using hx.le
have hdec : Tendsto (fun x : ℝ => 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<tailPower)))
have hd := hdec.eventually (gt_mem_nhds (by norm_num [nearFraction] : (0:ℝ)<nearFraction/4000))
filter_upwards [eventually_ge_atTop (2:ℝ),hpow,hhalf,
Real.tendsto_log_atTop.eventually (eventually_ge_atTop (8*Real.log 2/nearPower)),
Real.tendsto_log_atTop.eventually (eventually_ge_atTop (4*Real.log 2+2)),hd] with x hx hp hh hl hl' hd
exact ⟨hx,hp,hh,hl,hl',hd.le⟩
theorem exists_near_cutoff (C : ℝ) (hC : 0≤C) :
∃ X : ℝ, 2≤X ∧ ∀ (N j D m : ℕ), 0<j → X≤(N:ℝ)/j →
N.choose j≤D*2^j →
D * (chosenTuple N j).choose j ≤ m * N.choose j →
j≤chosenTuple N j ∧ chosenTuple N j≤N ∧
nearFraction*Real.log D≤Real.log m ∧
C*(chosenTuple N j:ℝ)*((chosenTuple N j:ℝ)/N)^(1/512:ℝ)≤Real.log m/4000 ∧
(1/2:ℝ)*Real.log N≤Real.log D ∧ (j:ℝ)≤Real.log D := by
obtain ⟨X,hX⟩ := eventually_atTop.mp (near_conditions_eventually C)
refine ⟨max 2 X,le_max_left _ _,?_⟩
intro N j D m hj hNx hD hfoot
have hc := hX ((N:ℝ)/j) ((le_max_right _ _).trans hNx)
have hjp : (0:ℝ)<j := by exact_mod_cast hj
have hN : 2*j≤N := by exact_mod_cast (le_div_iff₀ hjp).mp hc.1
have hk := chosenTuple_bounds N j hj (by linarith [hc.1]) hc.2.2.1
have hm := chosenTuple_log_footprint N j D m hj hN hD hc.2.1 hc.2.2.2.1 hfoot
have hd := near_row_log_uniform N j D hj hN hD hc.2.2.2.2.1
refine ⟨hk.1,hk.2.1,hm,?_,hd⟩
apply (chosenTuple_density_bound N j hj (by linarith [hc.1]) hc.2.2.1 C hC).trans
have hh := mul_le_mul_of_nonneg_right hc.2.2.2.2.2 hjp.le
dsimp [nearFraction] at hm ⊢
dsimp [nearFraction] at hh
nlinarith [hd.2]
end
lemma amplification_numerical (m u : ℝ) (hm : 1 ≤ m) (hu : u ≤ Real.log m/4000) :
Real.exp u*(Real.exp (Real.log m/2))^(-(1/1000:ℝ))+
Real.sqrt (Real.exp (Real.log m/2)/m) ≤ 2*Real.exp (-Real.log m/4000) := by
have hmp : 0 < m := lt_of_lt_of_le zero_lt_one hm
have hl : 0≤Real.log m := Real.log_nonneg hm
have he : Real.exp (Real.log m/2)/m=Real.exp (-Real.log m/2) := by
calc
_ = Real.exp (Real.log m/2)/Real.exp (Real.log m) := by rw [Real.exp_log hmp]
_ = _ := by rw [←Real.exp_sub]; congr 1; ring
have hs : Real.sqrt (Real.exp (-Real.log m/2))=Real.exp (-Real.log m/4) := by
rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp]
congr 1
ring
rw [Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp,←Real.exp_add,he,hs]
have h₁ : u+(Real.log m/2)*(-(1/1000:ℝ))≤ -Real.log m/4000 := by linarith
have h₂ : -Real.log m/4≤ -Real.log m/4000 := by linarith
linarith [Real.exp_le_exp.mpr h₁,Real.exp_le_exp.mpr h₂]
lemma amplification_absorb (x : ℝ) (hx : 8000*Real.log 2≤x) :
2*Real.exp (-x/4000)≤Real.exp (-x/8000) := by
rw [show (2:ℝ)=Real.exp (Real.log 2) by rw [Real.exp_log (by norm_num)],←Real.exp_add]
exact Real.exp_le_exp.mpr (by linarith)
lemma amplification_decay (m u : ℝ) (hm : 1 ≤ m) (hu : u ≤ Real.log m/4000)
(hl : 8000*Real.log 2≤Real.log m) :
Real.exp u*(Real.exp (Real.log m/2))^(-(1/1000:ℝ))+
Real.sqrt (Real.exp (Real.log m/2)/m) ≤ Real.exp (-Real.log m/8000) :=
(amplification_numerical m u hm hu).trans (amplification_absorb _ hl)
end Thorp.DimensionEstimates
namespace Thorp.UnitaryFinite
open scoped BigOperators Classical
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V]
omit [FiniteDimensional ℂ V] in
lemma full_tuple_fixed (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) :
fixedSpace tupleAction (Function.Embedding.refl (Card d)) ρ=⊤ := by
apply Submodule.eq_top_iff'.mpr
intro v g hg
have he : g=1 := by
apply Equiv.ext
intro x
exact congrArg (fun f : Card d ↪ Card d => 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<Fintype.card ι)
(ρ : Representation ℂ (Equiv.Perm (Card d)) V) [Representation.IsIrreducible ρ]
(hρ : IsUnitary ρ) (hm : 0<Module.finrank ℂ (fixedSpace tupleAction f ρ))
(z : ℝ) (hz : 0<z) :
‖sampleOperator ρ (palindromePerm d)‖ ≤
Real.exp (densityConstant*Fintype.card ι*((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ))*
z^(-(1/1000:ℝ))+Real.sqrt (z/(Module.finrank ℂ (fixedSpace tupleAction f ρ):ℝ)) := by
apply sampleOperator_amplification tupleAction f (tupleAction_transitive f) ρ hρ
(palindromePerm d) _ _ (1/1000) z _ (by norm_num) hz (by positivity) _ hm
· intro e f
simp only [tupleAction_kernel]
exact palindrome_kernel_symmetric d e f
· intro e
simp only [tupleAction_kernel]
exact PairRouting.tupleProbability_row_sum _ e
· intro e
simp only [tupleAction_kernel]
exact palindrome_row_moment_bound d e hk
theorem modified_irrep_amplification (L r : ℕ) (E : Finset (Card r))
(ρ : Representation ℂ (Equiv.Perm (Card (L+r))) V) [Representation.IsIrreducible ρ]
(hρ : IsUnitary ρ) (hm : 0<Module.finrank ℂ V)
(u z : ℝ) (hz : 0<z)
(hM : ∀ e : Card (L+r) ↪ Card (L+r), modifiedRowMoment L r E e (1/1000)≤Real.exp u) :
‖sampleOperator ρ (modifiedPerm L r E)‖ ≤
Real.exp u*z^(-(1/1000:ℝ))+Real.sqrt (z/(Module.finrank ℂ V:ℝ)) := by
let f := Function.Embedding.refl (Card (L+r))
have h := sampleOperator_amplification tupleAction f (tupleAction_transitive f) ρ hρ
(modifiedPerm L r E) (fun e f => 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<t := by linarith
have hε : 0<ε := lt_min hε₀ (lt_min (by norm_num) (by positivity))
refine ⟨ε,hε,min_le_left _ _,(min_le_right _ _).trans_lt ((min_le_left _ _).trans_lt (by norm_num)),t,htp.le,?_⟩
have hsmall : ε≤κ/(2*t) := (min_le_right _ _).trans (min_le_right _ _)
have hm := (le_div_iff₀ (by positivity : (0:ℝ)<2*t)).mp hsmall
linarith
end
open Filter
lemma log_error_eventually (a : ℝ) (ha : 0<a) :
∀ᶠ N : ℕ in atTop, 2*Real.log N+1≤(a/2)*(N:ℝ) := by
have h := (tendsto_natCast_atTop_atTop (R := ℝ)).eventually
(Real.isLittleO_log_id_atTop.bound (by linarith : 0<a/8))
have hg := (tendsto_natCast_atTop_atTop (R := ℝ)).eventually (eventually_ge_atTop (4/a))
filter_upwards [h,hg,eventually_ge_atTop 1] with N h hg hN
have hn : (1:ℝ)≤N := by exact_mod_cast hN
simp only [Real.norm_eq_abs,abs_of_nonneg (Real.log_nonneg hn),id_eq,abs_of_nonneg (by positivity : (0:ℝ)≤N)] at h
have hh : 4≤(N:ℝ)*a := (div_le_iff₀ ha).mp hg
linarith
end Thorp.DimensionEstimates
namespace Thorp.Specht
open scoped BigOperators Classical
open DimensionEstimates Filter
theorem medium_dimension (δ : ℝ) (hδ : 0<δ) (hδ2 : δ≤1/2) :
∃ h : ℝ, 0<h ∧ ∀ᶠ N : ℕ in atTop, ∀ μ : YoungDiagram, μ.card=N →
δ*(N:ℝ)≤N-μ.rowLen 0 → (μ.colLen 0:ℝ)≤(N:ℝ)/2 →
h*(N:ℝ)≤Real.log (Module.finrank ℂ (space μ)) := by
let a := min ((3/2:ℝ)*Real.log 2-1) (entropyGap*δ)
have ha : 0<a := by
apply lt_min
· nlinarith [Real.log_two_gt_d9]
· exact mul_pos entropyGap_pos hδ
refine ⟨a/2,by positivity,?_⟩
filter_upwards [log_error_eventually a ha,eventually_ge_atTop 1] with N hN hn
intro μ hμ hr hc
have hp : 0<μ.card := by omega
have hh := medium_dimension_raw μ hp δ hδ hδ2 (by simpa only [hμ] using hr) (by simpa only [hμ] using hc)
rw [hμ] at hh
change a*(N:ℝ)-2*Real.log N-1≤_ at hh
linarith
end Thorp.Specht
namespace Thorp
open scoped BigOperators Classical
lemma insertNth_castSucc_snoc {α : Type*} {d : ℕ} (i : Fin (d+1)) (b a : α) (y : Fin d → α) :
Fin.insertNth i.castSucc b (Fin.snoc (α := fun _ => α) 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<k)
(hm : 0<Module.finrank ℂ (fixedSpace (V := hilbertSpace μ) tupleAction f (relabelledUnitary μ e))) :
‖sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) (palindromePerm d)‖ ≤
Real.exp (densityConstant*(k:ℝ)*((k:ℝ)/(2:ℝ)^d)^(1/512:ℝ))*
(Real.exp (Real.log (Module.finrank ℂ (fixedSpace (V := hilbertSpace μ) tupleAction f (relabelledUnitary μ e)))/2))^(-(1/1000:ℝ))+
Real.sqrt ((Real.exp (Real.log (Module.finrank ℂ (fixedSpace (V := hilbertSpace μ) tupleAction f (relabelledUnitary μ e)))/2))/
(Module.finrank ℂ (fixedSpace (V := hilbertSpace μ) tupleAction f (relabelledUnitary μ e)):���)) := by
let := relabelledUnitary_irreducible μ e
let : NormedAddCommGroup (hilbertSpace μ) := inferInstance
let : InnerProductSpace ℂ (hilbertSpace μ) := inferInstance
let : FiniteDimensional ℂ (hilbertSpace μ) := inferInstance
have aux := @palindrome_irrep_amplification (hilbertSpace μ) _ _ _ d (Fin k) _ f
(by simpa only [Fintype.card_fin] using hk) (relabelledUnitary μ e) inferInstance
(relabelledUnitary_unitary μ e) hm
(Real.exp (Real.log (Module.finrank ℂ (fixedSpace (V := hilbertSpace μ) tupleAction f (relabelledUnitary μ e)))/2))
(Real.exp_pos _)
simpa only [Fintype.card_fin] using aux
theorem near_row_spectral :
∃ X : ℝ, 2 ≤ X ∧ ∀ (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ),
0 < μ.card-μ.rowLen 0 → X ≤ (μ.card:ℝ)/(μ.card-μ.rowLen 0:ℕ) →
32768000 * Real.log 2 ≤ (1/2:ℝ) * Real.log μ.card →
‖sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) (palindromePerm d)‖ ≤
Real.exp (-(nearFraction/8000) * Real.log (Module.finrank ℂ (space μ))) ∧
(1/2:ℝ) * Real.log μ.card ≤ Real.log (Module.finrank ℂ (space μ)) ∧
(μ.card-μ.rowLen 0:ℕ) ≤ Real.log (Module.finrank ℂ (space μ)) := by
obtain ⟨X,hX,h⟩ := near_numerical_cutoff
refine ⟨X,hX,?_⟩
intro d μ e hj hx hlarge
let j := μ.card-μ.rowLen 0
let D := Module.finrank ℂ (space μ)
have hcard : μ.card=2^d := by rw [←card_cell,←Fintype.card_congr e,card_positions]
obtain ⟨k,hjk,hk,hnum⟩ := h μ.card j D hj hx (choose_tail_le_dimension μ)
obtain ⟨f⟩ := Function.Embedding.nonempty_of_card_le
(show Fintype.card (Fin k) ≤ Fintype.card (Card d) by simpa only [Fintype.card_fin,card_positions,←hcard] using hk)
let m := Module.finrank ℂ (fixedSpace (V := hilbertSpace μ) tupleAction f (relabelledUnitary μ e))
have hfoot : D * k.choose j ≤ m * μ.card.choose j := by
simpa only [Fintype.card_fin,finrank_hilbertSpace] using relabelled_tuple_dimension μ e f
have hm : 0 < m := by
have hc := Nat.choose_pos hjk
have hd := dimension_pos μ
by_contra hn
have hz : m=0 := by omega
rw [hz,zero_mul] at hfoot
exact (Nat.mul_pos hd hc).not_ge hfoot
obtain ⟨hlm,hden,hlog,hjlog⟩ := hnum m hfoot
have ha := near_row_amplification d μ e f (hj.trans_le hjk) hm
have hcardR : (μ.card:ℝ)=(2:ℝ)^d := by exact_mod_cast hcard
rw [←hcardR] at ha
have hl : 8000 * Real.log 2 ≤ Real.log m := by
dsimp [nearFraction] at hlm
linarith
have hn := amplification_decay (m:ℝ) (densityConstant * k * ((k:ℝ)/μ.card)^(1/512:ℝ))
(by exact_mod_cast hm) hden hl
refine ⟨ha.trans (hn.trans ?_),hlog,hjlog⟩
apply Real.exp_le_exp.mpr
dsimp [D] at hlm
linarith
end Thorp.Specht
namespace Thorp.UnitaryFinite
open scoped BigOperators Classical
open DimensionEstimates
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V]
theorem full_palindrome_decay (d : ℕ)
(ρ : Representation ℂ (Equiv.Perm (Card d)) V) [Representation.IsIrreducible ρ]
(hρ : IsUnitary ρ) (hm : 0<Module.finrank ℂ V)
(hden : densityConstant*(2:ℝ)^d≤Real.log (Module.finrank ℂ V)/4000)
(hl : 8000*Real.log 2≤Real.log (Module.finrank ℂ V)) :
‖sampleOperator ρ (palindromePerm d)‖≤Real.exp (-Real.log (Module.finrank ℂ V)/8000) := by
have h := palindrome_irrep_amplification d (Function.Embedding.refl (Card d))
(Fintype.card_pos) ρ hρ (by simpa only [full_tuple_finrank] using hm)
(Real.exp (Real.log (Module.finrank ℂ V)/2)) (Real.exp_pos _)
simp only [full_tuple_finrank,card_positions,Nat.cast_pow,Nat.cast_ofNat,
div_self (by positivity : (2:ℝ)^d≠0),Real.one_rpow,mul_one] at h
exact h.trans (amplification_decay _ _ (by exact_mod_cast hm) hden hl)
theorem full_modified_decay (L r : ℕ) (E : Finset (Card r))
(ρ : Representation ℂ (Equiv.Perm (Card (L+r))) V) [Representation.IsIrreducible ρ]
(hρ : IsUnitary ρ) (hm : 0<Module.finrank ℂ V) (u : ℝ)
(hM : ∀ e : Card (L+r) ↪ Card (L+r), modifiedRowMoment L r E e (1/1000)≤Real.exp u)
(hden : u≤Real.log (Module.finrank ℂ V)/4000)
(hl : 8000*Real.log 2≤Real.log (Module.finrank ℂ V)) :
‖sampleOperator ρ (modifiedPerm L r E)‖≤Real.exp (-Real.log (Module.finrank ℂ V)/8000) := by
exact (modified_irrep_amplification L r E ρ hρ hm u
(Real.exp (Real.log (Module.finrank ℂ V)/2)) (Real.exp_pos _) hM).trans
(amplification_decay _ _ (by exact_mod_cast hm) hden hl)
lemma palindrome_exception_cards (r L : ℕ)
(ρ : Representation ℂ (Equiv.Perm (Card (L+r))) V) (hρ : IsUnitary ρ) (n : ℕ) :
‖sampleOperator ρ (palindromePerm (L+r))‖ ≤
(blockGap L)^n+∑ E : Finset (Card r), if E.card<n then
‖sampleOperator ρ (modifiedPerm L r E)‖ else 0 := by
let σ := ρ.comp (splitPerm r L).symm.toMonoidHom
have he : σ.comp (splitPerm r L).toMonoidHom=ρ := by
ext g v
change ρ ((splitPerm r L).symm ((splitPerm r L) g)) v=ρ g v
rw [MulEquiv.symm_apply_apply]
have h := palindrome_exception_bound r L σ (unitary_comp ρ hρ _) n
simpa only [he] using h
end Thorp.UnitaryFinite
namespace Thorp.DimensionEstimates
open scoped BigOperators Classical
open Filter
lemma medium_parameters (h : ℝ) (hh : 0<h) :
∃ L : ℕ, 0<L ∧ ∃ ε t : ℝ, 0<ε ∧ ε<1/2 ∧ 0≤t ∧
t*ε+Real.log (1+Real.exp (-t))≤h*(2:ℝ)^L/16000 ∧
∀ᶠ r : ℕ in 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 ((h/4000)*(2:ℝ)^(L+r)) := by
obtain ⟨L,hL,ε₀,hε₀,_,hM⟩ := modified_arbitrarily_small_rate (h/4000) (by positivity)
obtain ⟨ε,hε,hεle,hεhalf,t,ht,hcount⟩ := exists_small_set_rate
(h*(2:ℝ)^L/16000) ε₀ (by positivity) hε₀
refine ⟨L,hL,ε,t,hε,hεhalf,ht,hcount,?_⟩
filter_upwards [hM] with r hM
intro E hE e
exact hM E (hE.le.trans (mul_le_mul_of_nonneg_right hεle (by positivity))) e
lemma geometric_ceil_bound (θ ε : ℝ) (hθ : 0<θ) (hθ1 : θ<1) (M : ℕ) :
θ^⌈ε*M⌉₊≤Real.exp (Real.log θ*ε*M) := by
conv_lhs => 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<Module.finrank ℂ V)
(hd : h*(2:ℝ)^(L+r)≤Real.log (Module.finrank ℂ V))
(hl : 8000*Real.log 2≤Real.log (Module.finrank ℂ V))
(hM : ∀ (E : Finset (Card r)), (E.card:ℝ)<ε*(2:ℝ)^r →
∀ e : Card (L+r) ↪ Card (L+r),
modifiedRowMoment L r E e (1/1000)≤Real.exp ((h/4000)*(2:ℝ)^(L+r))) :
‖sampleOperator ρ (palindromePerm (L+r))‖≤
Real.exp (Real.log (blockGap L)*ε*(2:ℝ)^r)+Real.exp (-h*(2:ℝ)^(L+r)/16000) := by
have hmE (E : Finset (Card r)) (hE : E.card<⌈ε*(2:ℝ)^r⌉₊) :
‖sampleOperator ρ (modifiedPerm L r E)‖≤Real.exp (-h*(2:ℝ)^(L+r)/8000) := by
apply (full_modified_decay L r E ρ hρ hm ((h/4000)*(2:ℝ)^(L+r))
(hM E (Nat.lt_ceil.mp hE)) (by linarith) hl).trans
apply Real.exp_le_exp.mpr
linarith
have hs : (∑ E : Finset (Card r), if E.card<⌈ε*(2:ℝ)^r⌉₊ then
‖sampleOperator ρ (modifiedPerm L r E)‖ else 0) ≤
Real.exp (-h*(2:ℝ)^(L+r)/16000) := by
calc
_ ≤ (∑ E : Finset (Card r), if E.card<⌈ε*(2:ℝ)^r⌉₊ then (1:ℝ) else 0)*
Real.exp (-h*(2:ℝ)^(L+r)/8000) := by
rw [Finset.sum_mul]
apply Finset.sum_le_sum
intro E _
split_ifs with hE
· simpa only [one_mul] using hmE E hE
· simp
_ ≤ Real.exp ((t*ε+Real.log (1+Real.exp (-t)))*(2:ℝ)^r)*
Real.exp (-h*(2:ℝ)^(L+r)/8000) := by
apply mul_le_mul_of_nonneg_right _ (Real.exp_pos _).le
simpa only [card_positions,Nat.cast_pow,Nat.cast_ofNat] using
small_sets_ceil_bound (ι := Card r) ε t ht
_ ≤ _ := by
rw [←Real.exp_add]
apply Real.exp_le_exp.mpr
have hh := mul_le_mul_of_nonneg_right hcount (by positivity : (0:ℝ)≤(2:ℝ)^r)
rw [pow_add]
nlinarith
apply (palindrome_exception_cards r L ρ hρ ⌈ε*(2:ℝ)^r⌉₊).trans
apply add_le_add _ hs
simpa only [Nat.cast_pow,Nat.cast_ofNat] using
geometric_ceil_bound (blockGap L) ε (blockGap_pos L) (blockGap_lt_one L) (2^r)
end Thorp.UnitaryFinite
end ThorpNine.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971import Mathlib
import OAI.Probability.ThorpRouting.Casimir.Site
namespace OAI
namespace ThorpNine.Casimir
namespace Thorp.CasimirBounds
open scoped BigOperators Classical
theorem palindrome_cost_mgf_coarse (d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/32) :
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 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.CasimirBounds
namespace Thorp.CasimirBounds
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:ℝ)<k := by exact_mod_cast Nat.pos_of_ne_zero h
have hlog : 0 ≤ Real.log ((n:ℝ)/k) := Real.log_nonneg ((one_le_div hkp).mpr (by exact_mod_cast hk))
dsimp [levelScale]
nlinarith
lemma choose_le_exp_levelScale (n k : ℕ) (hn : 0<n) (hk : k≤n) :
(n.choose k:ℝ) ≤ Real.exp (levelScale n k) := by
by_cases h : k=0
· simp [h,levelScale]
have hkp : 0<k := Nat.pos_of_ne_zero h
have hh := DimensionEstimates.log_choose_upper n k hn hk
have hf := DimensionEstimates.log_factorial_lower k hkp
have he : Real.log ((n:ℝ)/k) = Real.log n-Real.log k :=
Real.log_div (by positivity) (by positivity)
have hl : Real.log (n.choose k:ℝ) ≤ levelScale n k := by
dsimp [levelScale]
rw [he]
linarith
rw [←Real.exp_log (by exact_mod_cast Nat.choose_pos hk : (0:ℝ)<n.choose k)]
exact Real.exp_le_exp.mpr hl
lemma trace_bound (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) :
(Module.finrank ℂ (Specht.space μ):ℝ)*traceMoment d μ e 65 ≤
Real.exp ((1+64*(1+heightDecay 1))*levelScale (2^d) (μ.card-μ.rowLen 0)) := by
let k := μ.card-μ.rowLen 0
have hn : μ.card=2^d := by
rw [←Specht.card_cell,←Fintype.card_congr e,card_positions]
have hk : k≤2^d := by dsimp [k]; omega
let x₀ : Fin k ↪ Card d := (Fin.castLEEmb (show k≤Fintype.card (Card d) by simpa [card_positions] using hk)).trans
(Fintype.equivFin (Card d)).symm.toEmbedding
let m := Module.finrank ℂ (fixedSpace (V := Specht.hilbertSpace μ) tupleAction x₀
(Specht.relabelledUnitary μ e))
have hd : (Module.finrank ℂ (Specht.space μ):ℝ) ≤ (m:ℝ)*((2^d).choose k:ℝ) := by
have hh := Specht.relabelled_tuple_dimension μ e x₀
simp only [Fintype.card_fin] at hh
change Module.finrank ℂ (Specht.hilbertSpace μ) * k.choose k ≤ m * μ.card.choose k at hh
rw [Nat.choose_self,mul_one,Specht.finrank_hilbertSpace,hn] at hh
exact_mod_cast hh
have hm := fixed_trace_bound d k μ e x₀
by_cases ht : 0≤traceMoment d μ e 65
· calc
_ ≤ ((m:ℝ)*((2^d).choose k:ℝ))*traceMoment d μ e 65 :=
mul_le_mul_of_nonneg_right hd ht
_ = ((2^d).choose k:ℝ)*((m:ℝ)*traceMoment d μ e 65) := by ring
_ ≤ ((2^d).choose k:ℝ)*Real.exp ((64*(1+heightDecay 1))*k) :=
mul_le_mul_of_nonneg_left hm (Nat.cast_nonneg _)
_ ≤ Real.exp (levelScale (2^d) k)*Real.exp ((64*(1+heightDecay 1))*levelScale (2^d) k) := by
apply mul_le_mul (choose_le_exp_levelScale _ _ (by positivity) hk) _ (by positivity) (Real.exp_nonneg _)
apply Real.exp_le_exp.mpr
exact mul_le_mul_of_nonneg_left (levelScale_ge _ _ hk) (by linarith [heightDecay_nonneg 1])
_ = _ := by rw [←Real.exp_add]; congr 1; ring
· exact (mul_nonpos_of_nonneg_of_nonpos (Nat.cast_nonneg _) (le_of_not_ge ht)).trans (Real.exp_nonneg _)
end Thorp.CasimirBounds
namespace Thorp.CasimirBounds
open scoped BigOperators Classical
open Filter UnitaryFinite DimensionEstimates
lemma levelScale_le (n k : ℕ) (hn : 0<n) (_ : k≤n) : levelScale n k ≤ n := by
by_cases hz : k=0
· simp [hz,levelScale]
have hkp : (0:ℝ)<k := by exact_mod_cast Nat.pos_of_ne_zero hz
have hnp : (0:ℝ)<n := by exact_mod_cast hn
have hh := Real.log_le_sub_one_of_pos (div_pos hnp hkp)
have hm := mul_le_mul_of_nonneg_left hh hkp.le
have he : (k:ℝ)*((n:ℝ)/k)=n := mul_div_cancel₀ _ (ne_of_gt hkp)
dsimp [levelScale]
nlinarith
lemma nontrivial_uniform_zero (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ)
(hk : 0<μ.card-μ.rowLen 0) :
uniformOperator (V:=Specht.hilbertSpace μ) (Specht.relabelledUnitary μ e)=0 := by
apply ContinuousLinearMap.ext
intro v
apply SparseContact.point_relabelled_fixed_zero μ e ∅ (by simpa using hk)
intro g _
have he := congrArg (fun A : Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ => 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:ℝ)<k := by exact_mod_cast hk
have hratio : (16:ℝ)≤(2^d:ℕ)/k := (le_div_iff₀ hkp).mpr (by linarith)
have hlog : 4*Real.log 2 ≤ Real.log ((2^d:ℕ)/k) := by
have ht := Real.log_le_log (by norm_num : (0:ℝ)<16) hratio
rw [show (16:ℝ)=2^(4:ℕ) by norm_num,Real.log_pow] at ht
simpa using ht
have hlog2 : (1/2:ℝ)≤Real.log 2 := by linarith [Real.log_two_gt_d9]
have hL : levelScale (2^d) k ≤ 3*Real.log (Module.finrank ℂ (Specht.space μ)) := by
dsimp [levelScale]
nlinarith
have hη := mul_le_mul_of_nonneg_right (min_le_left (1/3:ℝ) h) hΛ
nlinarith
· have hdim := hd μ hμ (by rw [←hμ,←hr]; change (1/16:ℝ)*(μ.card:ℝ)≤(k:ℝ); rw [hμ]; linarith)
(by simpa only [←hμ] using hc)
have hL := levelScale_le (2^d) k (by positivity) hkn
have ht := mul_le_mul_of_nonneg_left hL hh.le
have hη := mul_le_mul_of_nonneg_right (min_le_right (1/3:ℝ) h) hΛ
nlinarith
lemma eventual_level_contraction :
∃ a : ℝ, 0<a ∧ ∀ᶠ d : ℕ in atTop,
∀ (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ), 0<μ.card-μ.rowLen 0 →
‖K d μ e‖ ≤ Real.exp (-a*levelScale (2^d) (μ.card-μ.rowLen 0)) := by
obtain ⟨a,h,ha,hh,hsp⟩ := Specht.spectral_regimes
obtain ⟨η,hη,hdim⟩ := eventual_level_dimension
refine ⟨a*η,mul_pos ha hη,?_⟩
filter_upwards [hsp,hdim,eventually_ge_atTop 1] with d hs hd hd1
intro μ e hk
by_cases ht : (μ.card:ℝ)/2 < μ.colLen 0
· have hz := Specht.palindrome_tall_zero_general d (by omega) μ e ht
change K d μ e=0 at hz
rw [hz,@norm_zero (Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ) _]
exact (Real.exp_pos _).le
· have hc := le_of_not_gt ht
have hμ : μ.card=2^d := by rw [←Specht.card_cell,←Fintype.card_congr e,card_positions]
apply (hs μ e hk hc).1.trans
apply Real.exp_le_exp.mpr
have hh := mul_le_mul_of_nonneg_left (hd μ hμ hk hc) ha.le
nlinarith
lemma finite_positive_lower (f : ℕ → ℝ) (D : ℕ) (hf : ∀ d<D,0<f d) :
∃ b : ℝ, 0<b ∧ ∀ d<D,b≤f d := by
induction D with
| zero => 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<a ∧ ∀ (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ),
0<μ.card-μ.rowLen 0 →
‖K d μ e‖ ≤ Real.exp (-a*levelScale (2^d) (μ.card-μ.rowLen 0)) := by
obtain ⟨a,ha,he⟩ := eventual_level_contraction
obtain ⟨D,hD⟩ := eventually_atTop.mp he
let f (d : ℕ) : ℝ := -Real.log (blockGap d)/(2:ℝ)^d
have hf (d : ℕ) : 0<f d := by
have hl := Real.log_neg (blockGap_pos d) (blockGap_lt_one d)
exact div_pos (neg_pos.mpr hl) (by positivity)
obtain ⟨b,hb,hbD⟩ := finite_positive_lower f D (fun d _ => 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.CasimirBounds
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:ℝ)<Module.finrank ℂ (space μ.1) := by exact_mod_cast dimension_pos μ.1
calc
_ ≤ (Module.finrank ℂ (space μ.1):ℝ)^2*
(Real.exp (-a*Real.log (Module.finrank ℂ (space μ.1))))^C :=
mul_le_mul_of_nonneg_left (hp.trans hkpow) (sq_nonneg _)
_ = Real.exp ((2-a*C)*Real.log (Module.finrank ℂ (space μ.1))) := by
rw [←Real.exp_log hDp,←Real.exp_nat_mul,←Real.exp_nat_mul,←Real.exp_add,Real.log_exp]
congr 1
ring
_ ≤ _ := Real.exp_le_exp.mpr (by nlinarith)
lemma card_fourier_tall (d C : ℕ) (hd : 0<d) (hC : 0<C) (μ : Shapes (2^d))
(hc : (μ.1.card:ℝ)/2<(μ.1.colLen 0:ℝ)) :
sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d (C*d))-uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ)=0 := by
let : NormedAddCommGroup (hilbertSpace μ.1) := inferInstance
let : InnerProductSpace ℂ (hilbertSpace μ.1) := inferInstance
let : FiniteDimensional ℂ (hilbertSpace μ.1) := inferInstance
have hk : sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (palindromePerm d)=0 :=
palindrome_tall_zero_general d hd μ.1 (cardLabels d μ) hc
have hu : uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ)=0 :=
uniform_zero_of_sample_norm_lt_one _ (palindromePerm d) (by rw [hk,norm_zero]; norm_num)
rw [hu,sub_zero]
apply norm_eq_zero.mp
have hp := physical_power_bound d C hC (cardRepresentation d μ) (cardRepresentation_unitary d μ)
rw [hk,norm_zero,zero_pow (by omega : C≠0)] at hp
nlinarith [norm_nonneg (sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d (C*d)))]
lemma card_fourier_full_row (d t : ℕ) (μ : Shapes (2^d)) (hj : μ.1.card-μ.1.rowLen 0=0) :
sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d t)-uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ)=0 := by
have hr : μ.1.rowLen 0=μ.1.card := by have := rowLen_zero_le_card μ.1; omega
have ht (p : Equiv.Perm (Card d)) : cardRepresentation d μ p=1 :=
relabelled_full_row μ.1 hr (cardLabels d μ) p
rw [sampleOperator_trivial _ ht,uniformOperator_trivial _ ht,sub_self]
end
lemma half_geom_sum (n : ℕ) : (∑ j∈Finset.range n,(1/2:ℝ)^j)≤2 := by
have he : (∑ j∈Finset.range n,(1/2:ℝ)^j)=2*(1-(1/2:ℝ)^n) := by
induction n with
| zero => 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<N) (hs : 4≤ s)
(hL : 0≤L) (hl : (1/2:ℝ)*Real.log N≤L) (hj : (j:ℝ)≤L) :
Real.exp (-s*L)≤(1/(N:ℝ))*(1/4:ℝ)^j := by
have hlog : Real.log (4:ℝ)≤2 := by
have h2 : Real.log (2:ℝ)<1 := by
have ht := Real.log_lt_sub_one_of_pos (by norm_num : (0:ℝ)<2) (by norm_num : (2:ℝ)≠1)
norm_num at ht
exact ht
have he : Real.log (4:ℝ)=2*Real.log 2 := by rw [show (4:ℝ)=2^2 by norm_num,Real.log_pow]; norm_num
linarith
have hnR : (0:ℝ)<N := by exact_mod_cast hN
calc
_ ≤ Real.exp (-(Real.log N+(j:ℝ)*Real.log 4)) := Real.exp_le_exp.mpr (by
have hb := mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg j : (0:ℝ)≤j)
nlinarith)
_ = _ := by
rw [neg_add,Real.exp_add,Real.exp_neg,Real.exp_log hnR,one_div]
congr 1
rw [show -((j:ℝ)*Real.log (4:ℝ))=(j:ℝ)*(-Real.log 4) by ring,
Real.exp_nat_mul,Real.exp_neg,Real.exp_log (by norm_num : (0:ℝ)<4)]
norm_num
lemma shapes_medium_sum (N : ℕ) (h s : ℝ) (hsh : 2≤ s*h) :
(Fintype.card (Shapes N):ℝ)*Real.exp (-s*h*N)≤Real.exp (-(N:ℝ)) := by
have hc : (Fintype.card (Shapes N):ℝ)≤(2:ℝ)^N := by exact_mod_cast shapes_count N
have hl : Real.log (2:ℝ)≤1 := by
have := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2)
norm_num at this ⊢
exact this
calc
_ ≤ (2:ℝ)^N*Real.exp (-s*h*N) := mul_le_mul_of_nonneg_right hc (Real.exp_pos _).le
_ = Real.exp ((Real.log 2-s*h)*N) := by
rw [←Real.exp_log (by norm_num : (0:ℝ)<2),←Real.exp_nat_mul,←Real.exp_add,Real.log_exp]
congr 1
ring
_ ≤ _ := Real.exp_le_exp.mpr (by
have hb := mul_le_mul_of_nonneg_right (show Real.log 2-s*h≤-1 by linarith) (Nat.cast_nonneg N : (0:ℝ)≤N)
linarith)
end Thorp.Specht
namespace Thorp
open scoped BigOperators Classical
section
open UnitaryFinite Specht DimensionEstimates Filter
lemma sampleLaw_run (d t : ℕ) : sampleLaw (run d t)=law d t := by
classical
funext g
unfold sampleLaw finiteMean law
rw [Fintype.card_subtype]
apply congrArg (fun z : ℝ => 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<C ∧ ∀ᶠ d : ℕ in atTop,
distance d (C*d)^2≤2/(2:ℝ)^d+Real.exp (-(2:ℝ)^d) := by
obtain ⟨a,h,ha,hh,hreg⟩ := spectral_regimes
let s := max 4 (2/h)
have hs4 : 4≤ s := le_max_left _ _
have hs : 0≤ s := by dsimp [s]; positivity
have hsh : 2≤ s*h := by
have hc := le_max_right (4:ℝ) (2/h)
exact (div_le_iff₀ hh).mp hc
obtain ⟨C,hC₀⟩ := exists_nat_ge ((s+2)/a)
have hC : s+2≤a*C := by
have hC := (div_le_iff₀ ha).mp hC₀
nlinarith
have hCp : 0<C := by
by_contra hn
have hz : C=0 := by omega
rw [hz,Nat.cast_zero,mul_zero] at hC
linarith
refine ⟨C,hCp,?_⟩
filter_upwards [hreg,eventually_gt_atTop 0] with d hd hdp
have hbound (μ : Shapes (2^d)) :
(Module.finrank ℂ (hilbertSpace μ.1):ℝ)^2*
‖sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d (C*d))-
uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ)‖^2≤
(1/(2:ℝ)^d)*(1/4:ℝ)^(μ.1.card-μ.1.rowLen 0)+Real.exp (-s*h*(2:ℝ)^d) := by
let : NormedAddCommGroup (hilbertSpace μ.1) := inferInstance
let : InnerProductSpace ℂ (hilbertSpace μ.1) := inferInstance
let : FiniteDimensional ℂ (hilbertSpace μ.1) := inferInstance
have hr : 0≤(1/(2:ℝ)^d)*(1/4:ℝ)^(μ.1.card-μ.1.rowLen 0) := by positivity
by_cases hj : μ.1.card-μ.1.rowLen 0=0
· rw [card_fourier_full_row d (C*d) μ hj,norm_zero,zero_pow (by norm_num : 2≠0),mul_zero]
positivity
by_cases hc : (μ.1.colLen 0:ℝ)≤(μ.1.card:ℝ)/2
· obtain ⟨hK,hD,halt⟩ := hd μ.1 (cardLabels d μ) (by omega) hc
have ht := card_fourier_decay d C μ a s ha hs hC hD hK
apply ht.trans
rcases halt with ⟨hlog,hjlog⟩ | hlog
· have hnear := near_shape_term μ.1.card (μ.1.card-μ.1.rowLen 0)
(Real.log (Module.finrank ℂ (space μ.1))) s
(by rw [μ.2]; positivity) hs4 (by linarith) hlog hjlog
rw [μ.2,Nat.cast_pow,Nat.cast_ofNat] at hnear
rw [μ.2]
exact hnear.trans (le_add_of_nonneg_right (Real.exp_pos _).le)
· apply le_trans (b := Real.exp (-s*h*(2:ℝ)^d)) _ (le_add_of_nonneg_left hr)
apply Real.exp_le_exp.mpr
nlinarith
· rw [card_fourier_tall d C hdp hCp μ (lt_of_not_ge hc),norm_zero,
zero_pow (by norm_num : 2≠0),mul_zero]
positivity
calc
_ ≤ ∑ μ : Shapes (2^d),(Module.finrank ℂ (hilbertSpace μ.1):ℝ)^2*
‖sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d (C*d))-
uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ)‖^2 := physical_fourier_bound d (C*d)
_ ≤ ∑ μ : Shapes (2^d),((1/(2:ℝ)^d)*(1/4:ℝ)^(μ.1.card-μ.1.rowLen 0)+
Real.exp (-s*h*(2:ℝ)^d)) := Finset.sum_le_sum (fun μ _ => 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<C ∧
Tendsto (fun d : ℕ => 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.CasimirBounds
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.CasimirBounds
end ThorpNine.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335import Mathlib
namespace OAI
namespace ThorpNine.Casimir
namespace Thorp
open scoped BigOperators
open Filter
abbrev Card (d : ℕ) := Fin d → Bool
def Coins : ℕ → Type
| 0 => Unit
| d + 1 => Card d → Bool
instance (d : ℕ) : Fintype (Coins d) := by
cases d <;> dsimp [Coins] <;> infer_instance
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 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) : ℝ)
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
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))
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.CasimirBounds
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)
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 Thorp.CasimirBounds
end ThorpNine.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761import Mathlib
import OAI.Probability.ThorpRouting.Casimir.ModifiedRoutingMoment
namespace OAI
namespace ThorpNine.Casimir
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.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856import Mathlib
import OAI.Probability.ThorpRouting.Casimir.InputTree
namespace OAI
namespace ThorpNine.Casimir
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.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835import Mathlib
import OAI.Probability.ThorpRouting.Casimir.BlockProduct
namespace OAI
namespace ThorpNine.Casimir
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<n then
‖B*coarse (centralProjection ρ) (centralProjection_commute ρ) E*B.adjoint‖ else 0 := by
have hB : ‖B.adjoint‖≤1 := by
rw [ContinuousLinearMap.adjoint.norm_map]
exact hB0
have h := blocks_exception_bound (centralProjection ρ) (centralProjection_commute ρ)
(fun b => 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<n then
‖sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (modifiedPerm L r E)‖ else 0 := by
rw [sampleOperator_palindrome_stage r L ρ hρ]
rw [sampleOperator_parallel ρ (fun _ => 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<z) (hM0 : 0≤M)
(hM : ∀ x, finiteMean (fun y => ((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<z) (hM0 : 0≤M)
(hM : ∀ x, finiteMean (fun y => ((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.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880import Mathlib
import OAI.Probability.ThorpRouting.Casimir.CutoffMass
namespace OAI
namespace ThorpNine.Casimir
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^2)]
_ ≤ _ := Real.exp_le_exp.mpr (by
have hh := mul_le_mul_of_nonneg_left hlog2 (Nat.cast_nonneg (Fintype.card ι) : (0:ℝ)≤_)
nlinarith [Nat.cast_nonneg (α:=ℝ) (Fintype.card ι)])
have hhigh := palindrome_high_full_mgf 1 d d (by decide) e (q^2) hq2 hlog2
have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => 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.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883import Mathlib
import OAI.Probability.ThorpRouting.Casimir.PriorPaths
namespace OAI
namespace ThorpNine.Casimir
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.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882import Mathlib
import OAI.Probability.ThorpRouting.Casimir.AssignmentSlots
namespace OAI
namespace ThorpNine.Casimir
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.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881import Mathlib
import OAI.Probability.ThorpRouting.Casimir.ExposedCoins
namespace OAI
namespace ThorpNine.Casimir
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.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874import Mathlib
import OAI.Probability.ThorpRouting.Casimir.AlternatingPerm
namespace OAI
namespace ThorpNine.Casimir
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
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.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882import Mathlib
import OAI.Probability.ThorpRouting.Casimir.ModifiedReverseCoins
namespace OAI
namespace ThorpNine.Casimir
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<n) : n ≤ 2^(n-1) := by
obtain ⟨n,rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn.ne'
simp only [Nat.add_one_sub_one]
induction n with
| zero => 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.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851import Mathlib
import OAI.Probability.ThorpRouting.Casimir.TailShapes
namespace OAI
namespace ThorpNine.Casimir
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
def tailDiagram (μ : YoungDiagram) : YoungDiagram :=
YoungDiagram.ofRowLens μ.rowLens.tail μ.rowLens_sorted.pairwise.tail.sortedGE
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:ℝ)<n.factorial) hb
lemma log_normalization_le (N l : ℕ) (hN : 0 < N) (hl : l ≤ N) :
Real.log ((N:ℝ)^l/(N.descFactorial l:ℝ)) ≤ 2*l := by
have hNp : (0:ℝ)<N := by exact_mod_cast hN
have hMp : (0:ℝ)<N.descFactorial l := by exact_mod_cast Nat.descFactorial_pos.mpr hl
rw [Real.log_div (by positivity) hMp.ne',Real.log_pow]
by_cases hlow : 2*l ≤ N
· have hhalf : (N:ℝ)/2 ≤ (N+1-l:ℕ) := by
have hNat : N ≤ 2*(N+1-l) := by omega
exact (div_le_iff₀ (by norm_num : (0:ℝ)<2)).mpr (by simpa only [mul_comm] using (show (N:ℝ) ≤ 2*(N+1-l:ℕ) by exact_mod_cast hNat))
have hb : ((N:ℝ)/2)^l ≤ (N.descFactorial l:ℝ) := by
apply (pow_le_pow_left₀ (by positivity) hhalf l).trans
exact_mod_cast Nat.pow_sub_le_descFactorial N l
have hh := Real.log_le_log (pow_pos (by positivity : (0:ℝ)<(N:ℝ)/2) l) hb
rw [Real.log_pow,Real.log_div hNp.ne' (by norm_num)] at hh
have ht : Real.log (2:ℝ) ≤ 1 := by simpa only [show (2:ℝ)-1=1 by norm_num] using Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2)
nlinarith [(show (0:ℝ) ≤ l by positivity)]
· have he : (N.descFactorial l:ℝ)*(Nat.factorial (N-l):ℝ) = N.factorial := by
have he := Nat.factorial_mul_descFactorial hl
exact_mod_cast (by simpa only [mul_comm] using he : N.descFactorial l * (N-l).factorial = N.factorial)
have hh := congrArg Real.log he
rw [Real.log_mul hMp.ne' (by positivity)] at hh
have hfull := log_factorial_lower (show 1 ≤ N by omega)
have hrem := log_factorial_le_power (N-l) N (Nat.sub_le _ _) hN
rw [Nat.cast_sub hl] at hrem
have hNle : (N:ℝ) ≤ 2*l := by exact_mod_cast (by omega : N ≤ 2*l)
linarith
lemma normalized_moment_identity {X : Type*} [Fintype X] [Nonempty X]
(f : X → ℝ) (hf : ∀ x, 0 ≤ f x) {N : ℝ} (hN : 0 < N) (p : ℝ) :
N⁻¹*(∑ x, (N*f x)^p) =
(N/(Fintype.card X:ℝ))^(p-1) * finiteMean (fun x => ((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<p) hpq
have hb : Real.exp ((l:ℝ)*(1+heightDecay 1)) ≤ Real.exp ((3+heightDecay 1)*l) := by
apply Real.exp_le_exp.mpr
nlinarith [(show (0:ℝ) ≤ l by positivity)]
have hs (y) : reflectedKernel d l order rev y x = reflectedKernel d l order rev x y := (reflected_symm_both d l order rev).apply _ _
have hpow : (((2:ℝ)^d)^l)⁻¹ * (∑ y, ((((2:ℝ)^d)^l)*H x y)^p) ≤
Real.exp ((3+heightDecay 1)*l) := by
rw [normalized_moment_identity (fun y => 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.CasimirBounds
open scoped BigOperators Classical
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.CasimirBounds
end ThorpNine.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894import Mathlib
import OAI.Probability.ThorpRouting.Casimir.InsertionPerm
namespace OAI
namespace ThorpNine.Casimir
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<x) (hb : ∀ x∈b, 0<x) (ht : a.tail=b.tail) (hs : a.sum=b.sum) : a=b := by
cases a with
| nil =>
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<d) (μ : YoungDiagram) (e : Card d ≃ Cell μ)
(hj : (μ.card:ℝ)/2<(μ.colLen 0:ℝ)) :
sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) (palindromePerm d)=0 := by
obtain ⟨r,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : d≠0)
apply palindrome_tall_zero r μ e
have hc : μ.card=2^(r+1) := by rw [←card_cell,←Fintype.card_congr e,card_positions]
rw [hc,Nat.cast_pow,Nat.cast_ofNat,pow_succ] at hj
have hh : (2:ℝ)^r<(μ.colLen 0:ℝ) := by linarith
exact_mod_cast hh
end Thorp.Specht
namespace Thorp.DimensionEstimates
open Filter
lemma twopow_tendsto : Tendsto (fun d : ℕ => (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<c) (B : ℝ) :
∀ᶠ d : ℕ in atTop, B≤c*(2:ℝ)^d := by
filter_upwards [twopow_tendsto.eventually (eventually_ge_atTop (B/c))] with d hd
exact (div_le_iff₀ hc).mp hd |>.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<h) :
∃ a : ℝ, 0<a ∧ ∀ᶠ d : ℕ in atTop, ∀ (μ : YoungDiagram) (e : Card d ≃ Cell μ),
h*(2:ℝ)^d≤Real.log (Module.finrank ℂ (space μ)) →
‖sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) (palindromePerm d)‖ ≤
Real.exp (-a*Real.log (Module.finrank ℂ (space μ))) := by
obtain ⟨L,hL,ε,t,hε,_,ht,hcount,hM⟩ := medium_parameters h hh
obtain ⟨R,hR⟩ := eventually_atTop.mp hM
let A := 4000*densityConstant+1
have hA : 0<A := by dsimp [A]; have := densityConstant_pos; positivity
let β := min (-Real.log (blockGap L)*ε/(2:ℝ)^L) (h/16000)
have hβ : 0<β := by
apply lt_min
· exact div_pos (mul_pos (neg_pos.mpr (Real.log_neg (blockGap_pos L) (blockGap_lt_one L))) hε) (by positivity)
· positivity
let a := min (1/8000:ℝ) (β/(2*A))
have ha : 0<a := lt_min (by norm_num) (div_pos hβ (by positivity))
refine ⟨a,ha,?_⟩
filter_upwards [eventually_ge_atTop (L+R),twopow_mul_eventually h hh (8000*Real.log 2),
twopow_mul_eventually (β/2) (by positivity) (Real.log 2)] with d hd hl hb
intro μ e hdim
let : NormedAddCommGroup (hilbertSpace μ) := inferInstance
let : InnerProductSpace ℂ (hilbertSpace μ) := inferInstance
let : FiniteDimensional ℂ (hilbertSpace μ) := inferInstance
let := relabelledUnitary_irreducible μ e
have hpos : 0<Module.finrank ℂ (hilbertSpace μ) := by rw [finrank_hilbertSpace]; exact dimension_pos μ
have hlarge : 8000*Real.log 2≤Real.log (Module.finrank ℂ (hilbertSpace μ)) := by rw [finrank_hilbertSpace]; exact hl.trans hdim
have hlog : 0≤Real.log (Module.finrank ℂ (space μ)) := (by positivity : (0:ℝ)≤h*(2:ℝ)^d).trans hdim
by_cases hhigh : A*(2:ℝ)^d≤Real.log (Module.finrank ℂ (space μ))
· have hden : densityConstant*(2:ℝ)^d≤Real.log (Module.finrank ℂ (hilbertSpace μ))/4000 := by
rw [finrank_hilbertSpace]
dsimp [A] at hhigh
nlinarith [pow_pos (by norm_num : (0:ℝ)<2) d]
have hspec := @full_palindrome_decay (hilbertSpace μ) _ _ _ d (relabelledUnitary μ e)
inferInstance (relabelledUnitary_unitary μ e) hpos hden hlarge
rw [finrank_hilbertSpace] at hspec
apply hspec.trans (Real.exp_le_exp.mpr ?_)
have := min_le_left (1/8000:ℝ) (β/(2*A))
nlinarith
· obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le (show L≤d by omega)
have hr : R≤r := by omega
have hdim' : h*(2:ℝ)^(L+r)≤Real.log (Module.finrank ℂ (hilbertSpace μ)) := by rwa [finrank_hilbertSpace]
have hs := @medium_exception_decay (hilbertSpace μ) _ _ _ L r h ε t ht hcount
(relabelledUnitary μ e) inferInstance (relabelledUnitary_unitary μ e) hpos hdim' hlarge (hR r hr)
have hb1 : Real.log (blockGap L)*ε*(2:ℝ)^r≤-β*(2:ℝ)^(L+r) := by
have hb0 := min_le_left (-Real.log (blockGap L)*ε/(2:ℝ)^L) (h/16000)
have hp := (le_div_iff₀ (by positivity : (0:ℝ)<(2:ℝ)^L)).mp hb0
have hp := mul_le_mul_of_nonneg_right hp (by positivity : (0:ℝ)≤(2:ℝ)^r)
rw [pow_add]
dsimp [β]
nlinarith
have hb2 : -h*(2:ℝ)^(L+r)/16000≤-β*(2:ℝ)^(L+r) := by
have hp := mul_le_mul_of_nonneg_right (min_le_right (-Real.log (blockGap L)*ε/(2:ℝ)^L) (h/16000))
(by positivity : (0:ℝ)≤(2:ℝ)^(L+r))
dsimp [β]
linarith
apply hs.trans ((add_le_add (Real.exp_le_exp.mpr hb1) (Real.exp_le_exp.mpr hb2)).trans ?_)
apply (exp_two_absorb β ((2:ℝ)^(L+r)) (by nlinarith)).trans
apply Real.exp_le_exp.mpr
have hdmax := le_of_not_ge hhigh
have hp := mul_le_mul_of_nonneg_left hdmax (by positivity : 0≤β/(2*A))
have he : β/(2*A)*(A*(2:ℝ)^(L+r))=β*(2:ℝ)^(L+r)/2 := by field_simp
rw [he] at hp
have hba := mul_le_mul_of_nonneg_right (min_le_right (1/8000:ℝ) (β/(2*A))) hlog
dsimp [a] at *
linarith
theorem spectral_regimes :
∃ a h : ℝ, 0<a ∧ 0<h ∧ ∀ᶠ d : ℕ in atTop,
∀ (μ : YoungDiagram) (e : Card d ≃ Cell μ), 0<μ.card-μ.rowLen 0 →
(μ.colLen 0:ℝ)≤(μ.card:ℝ)/2 →
‖sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) (palindromePerm d)‖≤
Real.exp (-a*Real.log (Module.finrank ℂ (space μ))) ∧
1≤Real.log (Module.finrank ℂ (space μ)) ∧
(((1/2:ℝ)*Real.log μ.card≤Real.log (Module.finrank ℂ (space μ)) ∧
(μ.card-μ.rowLen 0:ℕ)≤Real.log (Module.finrank ℂ (space μ))) ∨
h*(2:ℝ)^d≤Real.log (Module.finrank ℂ (space μ))) := by
obtain ⟨X,hX,hnear⟩ := near_row_spectral
have hXpos : 0<X := by linarith
have hδ : 0<(1:ℝ)/X := by positivity
have hδ2 : (1:ℝ)/X≤1/2 := (div_le_iff₀ hXpos).mpr (by linarith)
obtain ⟨h,hh,hmedium⟩ := medium_dimension (1/X) hδ hδ2
obtain ⟨a₀,ha₀,hlarge⟩ := exponential_dimension_spectral h hh
let a := min (nearFraction/8000) a₀
have ha : 0<a := lt_min (by norm_num [nearFraction]) ha₀
refine ⟨a,h,ha,hh,?_⟩
have hl := (Real.tendsto_log_atTop.comp twopow_tendsto).eventually
(eventually_ge_atTop (2*max (32768000*Real.log 2) 1))
filter_upwards [hlarge,twopow_nat_tendsto.eventually hmedium,hl,
twopow_mul_eventually h hh 1] with d hspec hdim hlog h1
intro μ e hj hc
simp only [Function.comp_apply] at hlog
have hcard : μ.card=2^d := by rw [←card_cell,←Fintype.card_congr e,card_positions]
have hcardR : (μ.card:ℝ)=(2:ℝ)^d := by exact_mod_cast hcard
have hμlog : max (32768000*Real.log 2) 1≤(1/2:ℝ)*Real.log μ.card := by rw [hcardR]; linarith
by_cases hx : X≤(μ.card:ℝ)/(μ.card-μ.rowLen 0:ℕ)
· obtain ⟨hs,hl,hjD⟩ := hnear d μ e hj hx ((le_max_left _ _).trans hμlog)
have h1D : 1≤Real.log (Module.finrank ℂ (space μ)) := ((le_max_right _ _).trans hμlog).trans hl
refine ⟨hs.trans (Real.exp_le_exp.mpr ?_),h1D,Or.inl ⟨hl,hjD⟩⟩
have hp := mul_le_mul_of_nonneg_right (min_le_left (nearFraction/8000) a₀) (by linarith : 0≤Real.log (Module.finrank ℂ (space μ)))
dsimp [a]
linarith
· have htail : (1/X)*(μ.card:ℝ)≤(μ.card:ℝ)-μ.rowLen 0 := by
have hjR : (0:ℝ)<(μ.card-μ.rowLen 0:ℕ) := by exact_mod_cast hj
have hh := (div_lt_iff₀ hjR).mp (lt_of_not_ge hx)
have hs : ((μ.card-μ.rowLen 0:ℕ):ℝ)=(μ.card:ℝ)-μ.rowLen 0 := by
rw [Nat.cast_sub (rowLen_zero_le_card μ)]
rw [hs] at hh
have hd : (μ.card:ℝ)/X≤(μ.card:ℝ)-μ.rowLen 0 :=
(div_le_iff₀ hXpos).mpr (by nlinarith)
convert hd using 1; ring
have hdim' : h*(2:ℝ)^d≤Real.log (Module.finrank ℂ (space μ)) := by
simpa only [Nat.cast_pow,Nat.cast_ofNat] using
hdim μ hcard (by simpa only [hcard] using htail) (by simpa only [hcard] using hc)
have h1D := h1.trans hdim'
refine ⟨(hspec μ e hdim').trans (Real.exp_le_exp.mpr ?_),h1D,Or.inr hdim'⟩
have hp := mul_le_mul_of_nonneg_right (min_le_right (nearFraction/8000) a₀) (by linarith : 0≤Real.log (Module.finrank ℂ (space μ)))
dsimp [a]
linarith
end Thorp.Specht
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))
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]
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 ι] [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)
end Thorp.StrongSmoothing
end ThorpNine.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871import Mathlib
import OAI.Probability.ThorpRouting.Casimir.PairAssembleEquiv
namespace OAI
namespace ThorpNine.Casimir
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
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]
end Thorp.SparseContact
end ThorpNine.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878import Mathlib
import OAI.Probability.ThorpRouting.Casimir.TypedSet
namespace OAI
namespace ThorpNine.Casimir
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
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 ω))
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.DimensionEstimates
open scoped BigOperators
lemma log_factorial_upper_binary (n : ℕ) (hn : 0<n) :
Real.log (n.factorial:ℝ) ≤ (n:ℝ)*Real.log n-Real.log 2*((n:ℝ)-1) := by
induction n, hn using Nat.le_induction with
| base => norm_num
| succ n hn ih =>
have hn0 : (0:ℝ)<n := by exact_mod_cast hn
have hb : (2:ℝ) ≤ (1+(n:ℝ)⁻¹)^n := by
have h := one_add_mul_le_pow (by have := inv_nonneg.mpr hn0.le; linarith : (-2:ℝ)≤(n:ℝ)⁻¹) n
norm_num [mul_inv_cancel₀ hn0.ne'] at h ⊢
exact h
have hl := Real.log_le_log (by norm_num : (0:ℝ)<2) hb
rw [Real.log_pow] at hl
have hs : Real.log (1+(n:ℝ)⁻¹)=Real.log ((n:ℝ)+1)-Real.log n := by
rw [←Real.log_div (by positivity) hn0.ne']
congr 1
field_simp
rw [hs] at hl
rw [Nat.factorial_succ,Nat.cast_mul,Real.log_mul (by positivity) (by positivity),Nat.cast_add,Nat.cast_one]
nlinarith
lemma log_factorial_lower (n : ℕ) (hn : 0<n) :
(n:ℝ)*Real.log n-n+1 ≤ Real.log (n.factorial:ℝ) := by
induction n, hn using Nat.le_induction with
| base => norm_num
| succ n hn ih =>
have hn0 : (0:ℝ)<n := by exact_mod_cast hn
have hl := Real.log_le_sub_one_of_pos (show 0<((n:ℝ)+1)/n by positivity)
rw [Real.log_div (by positivity) hn0.ne'] at hl
have hh := mul_le_mul_of_nonneg_left hl hn0.le
have he : (n:ℝ)*(((n:ℝ)+1)/n-1)=1 := by field_simp; ring
rw [he] at hh
rw [Nat.factorial_succ,Nat.cast_mul,Real.log_mul (by positivity) (by positivity),Nat.cast_add,Nat.cast_one]
nlinarith
lemma log_factorial_upper (n : ℕ) (hn : 0<n) :
Real.log (n.factorial:ℝ) ≤ (n:ℝ)*Real.log n-n+Real.log n+1 := by
induction n, hn using Nat.le_induction with
| base => norm_num
| succ n hn ih =>
have hn0 : (0:ℝ)<n := by exact_mod_cast hn
have hl := Real.one_sub_inv_le_log_of_pos (show 0<((n:ℝ)+1)/n by positivity)
rw [Real.log_div (by positivity) hn0.ne'] at hl
have hh := mul_le_mul_of_nonneg_left hl (show 0≤(n:ℝ)+1 by positivity)
have he : ((n:ℝ)+1)*(1-(((n:ℝ)+1)/n)⁻¹)=1 := by field_simp; ring
rw [he] at hh
rw [Nat.factorial_succ,Nat.cast_mul,Real.log_mul (by positivity) (by positivity),Nat.cast_add,Nat.cast_one]
nlinarith
variable {X I J : Type*} [Fintype X] [Fintype I] [Fintype J]
open scoped Classical
noncomputable def fiberWeight (f : X → I) (i : I) : ℝ := Fintype.card {x // f x=i}
omit [Fintype I] in
lemma fiberWeight_nonneg (f : X → I) (i : I) : 0≤fiberWeight f i := Nat.cast_nonneg _
omit [Fintype I] in
lemma fiberWeight_pos (f : X → I) (x : X) : 0<fiberWeight f (f x) := by
let : Nonempty {y // f y=f x} := ⟨⟨x,rfl⟩⟩
exact Nat.cast_pos.mpr Fintype.card_pos
lemma fiber_sum (f : X → I) (u : I → ℝ) :
∑ x, u (f x)=∑ i, fiberWeight f i*u i := by
rw [←Equiv.sum_comp (Equiv.sigmaFiberEquiv f)]
simp only [Equiv.sigmaFiberEquiv_apply,Fintype.sum_sigma]
apply Finset.sum_congr rfl
intro i _
calc
(∑ x : {x // f x=i}, u (f x)) = ∑ _x : {x // f x=i}, u i :=
Finset.sum_congr rfl (fun x _ => 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:ℝ)<Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos
have hprod : ∑ x, fiberWeight f (f x)*fiberWeight g (g x) ≤ (Fintype.card X:ℝ)^2 := by
calc
_ ≤ ∑ p : I × J, fiberWeight f p.1*fiberWeight g p.2 := by
calc
_ = ∑ p ∈ Finset.univ.image (fun x => (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<fiberWeight f (f x)*fiberWeight g (g x)/(Fintype.card X:ℝ) from
div_pos (mul_pos (fiberWeight_pos f x) (fiberWeight_pos g x)) hN)
have hs := Finset.sum_le_sum (s := Finset.univ) (fun x _ => 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<D := by
by_contra h
have : D=0 := by omega
simp [this] at hD
exact (Nat.factorial_pos _).ne' hD
have hf := log_fiber_factorials f
have hg := log_fiber_factorials g
have hi := incidence_entropy f g hinj
have hlo := log_factorial_lower (Fintype.card X) Fintype.card_pos
have hlog := Real.log_le_log (by positivity : (0:ℝ)<(Fintype.card X).factorial)
(show ((Fintype.card X).factorial:ℝ) ≤ D *
(∏ i, (Fintype.card {x // f x=i}).factorial) *
(∏ j, (Fintype.card {x // g x=j}).factorial) by exact_mod_cast hD)
rw [Real.log_mul (by positivity) (by positivity),
Real.log_mul (by positivity) (by positivity)] at hlog
nlinarith
lemma scaled_binEntropy (N j : ℝ) (hN : 0<N) (hj : 0<j) (hjN : j<N) :
N*Real.binEntropy (j/N)=N*Real.log N-j*Real.log j-(N-j)*Real.log (N-j) := by
have hsub : 0<N-j := sub_pos.mpr hjN
have he : 1-j/N=(N-j)/N := by field_simp
unfold Real.binEntropy
rw [he,Real.log_inv,Real.log_inv,Real.log_div hj.ne' hN.ne',
Real.log_div hsub.ne' hN.ne']
field_simp
ring
lemma log_choose_lower_entropy (N j : ℕ) (hj : 0<j) (hjN : j<N) :
(N:ℝ)*Real.binEntropy ((j:ℝ)/N)-2*Real.log N-1 ≤ Real.log (N.choose j:ℝ) := by
have hN : 0<N := lt_trans hj hjN
have ht : 0<N-j := Nat.sub_pos_of_lt hjN
have hj0 : (0:ℝ)<j := by exact_mod_cast hj
have hN0 : (0:ℝ)<N := by exact_mod_cast hN
have hjN0 : (j:ℝ)<N := by exact_mod_cast hjN
have hchoose : (0:ℝ)<N.choose j := by exact_mod_cast Nat.choose_pos hjN.le
have hfac := congrArg (fun n : ℕ => 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<entropyGap := by
unfold entropyGap
exact div_pos (Real.log_pos (by norm_num)) (by norm_num)
lemma entropyGap_eq : entropyGap=(5*Real.log 2-3*Real.log 3)/3 := by
unfold entropyGap
rw [Real.log_div (by norm_num) (by norm_num),show (32:ℝ)=2^5 by norm_num,
show (27:ℝ)=3^3 by norm_num,Real.log_pow,Real.log_pow]
norm_num
lemma binEntropy_tail_lower (q : ℝ) (hq : 0≤q) (hq' : q≤3/4) :
q*Real.log 2+entropyGap*q ≤ Real.binEntropy q := by
have hc := Real.strictConcave_binEntropy.concaveOn.2
(show (0:ℝ)∈Set.Icc 0 1 by constructor <;> 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<j) (hjN : j<N)
(hfrac : (j:ℝ)≤(3/4:ℝ)*N) (hD : N.choose j≤D*2^j) :
entropyGap*(j:ℝ)-2*Real.log N-1 ≤ Real.log D := by
have hpos : 0<N.choose j := Nat.choose_pos hjN.le
have hd : 0<D := by nlinarith [Nat.zero_le (2^j)]
have hN : (0:ℝ)<N := by exact_mod_cast lt_trans hj hjN
have hm := Real.log_le_log (by exact_mod_cast hpos : (0:ℝ)<N.choose j)
(show (N.choose j:ℝ)≤D*2^j by exact_mod_cast hD)
rw [Real.log_mul (by positivity) (by positivity),Real.log_pow] at hm
have he := binEntropy_tail_lower ((j:ℝ)/N) (by positivity)
((div_le_iff₀ hN).mpr hfrac)
have hel := mul_le_mul_of_nonneg_left he hN.le
have hbin := log_choose_lower_entropy N j hj hjN
have heq : (N:ℝ)*((j:ℝ)/N*Real.log 2+entropyGap*((j:ℝ)/N))=
(j:ℝ)*Real.log 2+entropyGap*j := by field_simp
rw [heq] at hel
linarith
lemma balanced_dimension_coefficient_pos : 0<(3/2:ℝ)*Real.log 2-1 := by
linarith [Real.log_two_gt_d9]
lemma log_choose_upper (N j : ℕ) (hN : 0<N) (hj : j≤N) :
Real.log (N.choose j:ℝ) ≤ (j:ℝ)*Real.log N-Real.log (j.factorial:ℝ) := by
have hh := Real.log_le_log (by exact_mod_cast Nat.choose_pos hj : (0:ℝ)<N.choose j)
(Nat.choose_le_pow_div j N : (N.choose j:ℝ)≤(N:ℝ)^j/(j.factorial:ℝ))
rw [Real.log_div (by positivity : (N:ℝ)^j≠0) (by positivity : (j.factorial:ℝ)≠0),Real.log_pow] at hh
exact hh
lemma log_choose_lower (N j : ℕ) (hj : j≤N) :
(j:ℝ)*Real.log (N+1-j:ℕ)-Real.log (j.factorial:ℝ) ≤ Real.log (N.choose j:ℝ) := by
have hp : 0<N+1-j := by omega
have hh := Real.log_le_log (by positivity : (0:ℝ)<((N+1-j:ℕ):ℝ)^j/(j.factorial:ℝ))
(Nat.pow_le_choose j N : (((N+1-j:ℕ):ℝ)^j)/(j.factorial:ℝ)≤N.choose j)
rw [Real.log_div (by positivity : (((N+1-j:ℕ):ℝ)^j)≠0) (by positivity : (j.factorial:ℝ)≠0),Real.log_pow] at hh
exact hh
lemma footprint_log_bound (N k j D m : ℕ) (hN : 0<N) (hk : j≤k) (hj : j≤N)
(hD : 0<D) (hfoot : D * k.choose j ≤ m * N.choose j) :
Real.log D-(j:ℝ)*(Real.log N-Real.log (k+1-j:ℕ)) ≤ Real.log m := by
have hkpos := Nat.choose_pos hk
have hprod : 0<D*k.choose j := Nat.mul_pos hD hkpos
have hm : 0 < m := by
by_contra h
have he : m=0 := by omega
simp only [he,zero_mul] at hfoot
omega
have hh := Real.log_le_log (by exact_mod_cast hprod : (0:ℝ)<D*k.choose j)
(show (D:ℝ)*k.choose j≤ m*N.choose j by exact_mod_cast hfoot)
rw [Real.log_mul (by positivity) (by exact_mod_cast hkpos.ne'),
Real.log_mul (by positivity) (by exact_mod_cast (Nat.choose_pos hj).ne')] at hh
have hlo := log_choose_lower k j hk
have hup := log_choose_upper N j hN hj
nlinarith
lemma log_factorial_le_mul_log (j : ℕ) (_hj : 0<j) :
Real.log (j.factorial:ℝ)≤(j:ℝ)*Real.log j := by
have h := Real.log_le_log (by positivity : (0:ℝ)<j.factorial)
(show (j.factorial:ℝ)≤(j:ℝ)^j by exact_mod_cast Nat.factorial_le_pow j)
simpa only [Real.log_pow] using h
lemma near_row_log_dimension (N j D : ℕ) (hj : 0<j) (hsmall : 2*j≤N)
(hD : N.choose j≤D*2^j) :
(j:ℝ)*(Real.log ((N:ℝ)/j)-2*Real.log 2) ≤ Real.log D := by
have hjN : j≤N := by omega
have hN : 0<N := by omega
have hNp : (0:ℝ)<N := by exact_mod_cast hN
have hjp : (0:ℝ)<j := by exact_mod_cast hj
have hn : 0<N+1-j := by omega
have hnreal : (N:ℝ)/2≤(N+1-j:ℕ) := by
rw [Nat.cast_sub (by omega : j≤N+1),Nat.cast_add,Nat.cast_one]
have hc : 2*(j:ℝ)≤N := by exact_mod_cast hsmall
linarith
have hDpos : 0<D := by
have hc := Nat.choose_pos hjN
by_contra h
have he : D=0 := by omega
simp only [he,zero_mul] at hD
omega
have hm := Real.log_le_log (by exact_mod_cast Nat.choose_pos hjN : (0:ℝ)<N.choose j)
(show (N.choose j:ℝ)≤D*2^j by exact_mod_cast hD)
rw [Real.log_mul (by positivity) (by positivity),Real.log_pow] at hm
have hl := Real.log_le_log (by positivity : (0:ℝ)<(N:ℝ)/2) hnreal
rw [Real.log_div hNp.ne' (by norm_num)] at hl
have hh := log_choose_lower N j hjN
have hf := log_factorial_le_mul_log j hj
rw [Real.log_div hNp.ne' hjp.ne']
nlinarith
open Filter
noncomputable def nearPower : ℝ := 1/2048
noncomputable def nearFraction : ℝ := 1/4096
noncomputable def tailPower : ℝ := 1535/1048576
noncomputable def chosenTuple (N j : ℕ) : ℕ :=
⌈(j:ℝ)*((N:ℝ)/j)^nearPower⌉₊
lemma chosenTuple_bounds (N j : ℕ) (hj : 0<j) (hx : 1≤(N:ℝ)/j)
(hhalf : ((N:ℝ)/j)^(nearPower-1)≤1/2) :
j≤chosenTuple N j ∧ chosenTuple N j≤N ∧
(chosenTuple N j:ℝ)≤2*j*((N:ℝ)/j)^nearPower := by
let x : ℝ := (N:ℝ)/j
have hjp : (0:ℝ)<j := by exact_mod_cast hj
have hj1 : (1:ℝ)≤j := by exact_mod_cast hj
have hxp : 0<x := lt_of_lt_of_le zero_lt_one hx
have hpow : 1≤x^nearPower := Real.one_le_rpow hx (by norm_num [nearPower])
have hceil : (j:ℝ)*x^nearPower≤chosenTuple N j := Nat.le_ceil _
have hceil' : (chosenTuple N j:ℝ)<(j:ℝ)*x^nearPower+1 := Nat.ceil_lt_add_one (by positivity)
have he : (j:ℝ)*x=N := by dsimp [x]; field_simp
have hh : x^nearPower≤x/2 := by
rw [Real.rpow_sub hxp,Real.rpow_one] at hhalf
nlinarith [(div_le_iff₀ hxp).mp hhalf]
constructor
· exact_mod_cast (le_mul_of_one_le_right hjp.le hpow).trans hceil
constructor
· apply Nat.ceil_le.mpr
change (j:ℝ)*x^nearPower≤N
nlinarith
· change (chosenTuple N j:ℝ)≤2*(j:ℝ)*x^nearPower
nlinarith
lemma chosenTuple_tail_lower (N j : ℕ) (hj : 0<j)
(hx : 2≤((N:ℝ)/j)^nearPower) :
(j:ℝ)*((N:ℝ)/j)^nearPower/2 ≤ (chosenTuple N j+1-j:ℕ) := by
have hjp : (0:ℝ)<j := by exact_mod_cast hj
have hc : (j:ℝ)*((N:ℝ)/j)^nearPower≤chosenTuple N j := Nat.le_ceil _
have hjk : j≤chosenTuple N j := by exact_mod_cast (by nlinarith : (j:ℝ)≤chosenTuple N j)
rw [Nat.cast_sub (by omega : j≤chosenTuple N j+1),Nat.cast_add,Nat.cast_one]
nlinarith
lemma chosenTuple_log_footprint (N j D m : ℕ) (hj : 0<j)
(hN : 2*j≤N) (hD : N.choose j≤D*2^j)
(hx : 2≤((N:ℝ)/j)^nearPower)
(hlog : 8*Real.log 2/nearPower≤Real.log ((N:ℝ)/j))
(hfoot : D * (chosenTuple N j).choose j ≤ m * N.choose j) :
nearFraction*Real.log D≤Real.log m := by
let x : ℝ := (N:ℝ)/j
have hjp : (0:ℝ)<j := by exact_mod_cast hj
have hNp : (0:ℝ)<N := by exact_mod_cast (by omega : 0<N)
have hxp : 0<x := by dsimp [x]; positivity
have hdpos : 0<D := by
have hc := Nat.choose_pos (show j≤N by omega)
by_contra h
have hz : D=0 := by omega
simp only [hz,zero_mul] at hD
omega
have htail := chosenTuple_tail_lower N j hj hx
have hjk : j≤chosenTuple N j := by
have hc : (j:ℝ)*x^nearPower≤chosenTuple N j := Nat.le_ceil _
exact_mod_cast (by nlinarith : (j:ℝ)≤chosenTuple N j)
have hh := footprint_log_bound N (chosenTuple N j) j D m (by omega) hjk (by omega) hdpos hfoot
have htlog := Real.log_le_log (by positivity : (0:ℝ)<(j:ℝ)*x^nearPower/2) htail
rw [Real.log_div (by positivity) (by norm_num),Real.log_mul hjp.ne' (by positivity),Real.log_rpow hxp] at htlog
have hxlog : Real.log x=Real.log N-Real.log j := Real.log_div hNp.ne' hjp.ne'
have hdim := near_row_log_dimension N j D hj hN hD
change (j:ℝ)*(Real.log x-2*Real.log 2)≤Real.log D at hdim
have hh' : Real.log D-(j:ℝ)*((1-nearPower)*Real.log x+Real.log 2)≤Real.log m := by
have hm := mul_le_mul_of_nonneg_left htlog hjp.le
rw [hxlog] at hm
nlinarith
have hlg : (3-nearPower)*Real.log 2≤nearFraction*Real.log x := by
dsimp [nearPower,nearFraction] at hlog ⊢
have := Real.log_pos (by norm_num : (1:ℝ)<2)
linarith
have hlg' := mul_le_mul_of_nonneg_left hlg hjp.le
dsimp [nearPower,nearFraction] at hh' hlg' ⊢
nlinarith
lemma near_row_log_uniform (N j D : ℕ) (hj : 0<j) (hN : 2*j≤N)
(hD : N.choose j≤D*2^j) (hlog : 4*Real.log 2+2≤Real.log ((N:ℝ)/j)) :
(1/2:ℝ)*Real.log N≤Real.log D ∧ (j:ℝ)≤Real.log D := by
have hjp : (0:ℝ)<j := by exact_mod_cast hj
have hj1 : (1:ℝ)≤j := by exact_mod_cast hj
have hNp : (0:ℝ)<N := by exact_mod_cast (by omega : 0<N)
have hd := near_row_log_dimension N j D hj hN hD
have hjlog := Real.log_le_sub_one_of_pos hjp
have hl2 : 0≤Real.log 2 := Real.log_nonneg (by norm_num)
have hi : 1≤Real.log ((N:ℝ)/j) := by linarith
have he : Real.log N=Real.log j+Real.log ((N:ℝ)/j) := by rw [Real.log_div hNp.ne' hjp.ne']; ring
constructor
· rw [he]
nlinarith
· nlinarith
end Thorp.DimensionEstimates
end ThorpNine.Casimir
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900import Mathlib
import OAI.Probability.ThorpRouting.Contact.ParallelFollow
namespace OAI
namespace ThorpNine.Contact
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.Contact
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834import Mathlib
import OAI.Probability.ThorpRouting.Contact.RotationMeeting
namespace OAI
namespace ThorpNine.Contact
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.Contact
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882import Mathlib
import OAI.Probability.ThorpRouting.Contact.AlternatingPerm
namespace OAI
namespace ThorpNine.Contact
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.Contact
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894import Mathlib
import OAI.Probability.ThorpRouting.Contact.Representative
namespace OAI
namespace ThorpNine.Contact
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<n then ‖B.adjoint*coarse P hcomm E*B‖ else 0 := by
let T : Finset ι → V →L[ℂ] V := sector P hcomm Finset.univ
have hsum : ∑ E,T E=1 := by
simpa only [Finset.powerset_univ] using sector_sum P hcomm Finset.univ
have hbound := resolution_exception_bound T (coarse P hcomm)
(fun E => 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<n)
(θ^n) (pow_nonneg hθ _) (by
intro E hE
have hEn : n≤E.card := by simpa using hE
exact (blocks_sector_norm P hcomm hP A hA hAP hn θ hθ hgap E).trans
(pow_le_pow_of_le_one hθ hθ1 hEn))
simpa only [Finset.sum_filter] using hbound
end Thorp.CommutingBlocks
namespace Thorp.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 Ξ]
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ρ]
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.Contact
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767import Mathlib
import OAI.Probability.ThorpRouting.Contact.Model
namespace OAI
namespace ThorpNine.Contact
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 index hindex => ite_eq_left (h hindex))).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.Contact
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860import Mathlib
import OAI.Probability.ThorpRouting.Contact.Coins
namespace OAI
namespace ThorpNine.Contact
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.Contact
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863import Mathlib
import OAI.Probability.ThorpRouting.Contact.ParallelFreshPre
namespace OAI
namespace ThorpNine.Contact
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^2)]
_ ≤ _ := Real.exp_le_exp.mpr (by
have hh := mul_le_mul_of_nonneg_left hlog2 (Nat.cast_nonneg (Fintype.card ι) : (0:ℝ)≤_)
nlinarith [Nat.cast_nonneg (α:=ℝ) (Fintype.card ι)])
have hhigh := palindrome_high_full_mgf 1 d d (by decide) e (q^2) hq2 hlog2
have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => 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.Contact
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884import Mathlib
import OAI.Probability.ThorpRouting.Contact.HeightDecay
namespace OAI
namespace ThorpNine.Contact
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.Contact
end OAIlean/OAI/Probability/ThorpRouting/Casimir/InputTree.leanAdded+869
lean/OAI/Probability/ThorpRouting/Casimir/InsertionPerm.leanAdded+891
lean/OAI/Probability/ThorpRouting/Casimir/Main.leanAdded+971
lean/OAI/Probability/ThorpRouting/Casimir/Model.leanAdded+335
lean/OAI/Probability/ThorpRouting/Casimir/ModifiedReverseCoins.leanAdded+761
lean/OAI/Probability/ThorpRouting/Casimir/ModifiedRoutingMoment.leanAdded+856
lean/OAI/Probability/ThorpRouting/Casimir/PairAssembleEquiv.leanAdded+835
lean/OAI/Probability/ThorpRouting/Casimir/PalindromeFamilyCost.leanAdded+880
lean/OAI/Probability/ThorpRouting/Casimir/ParallelFollow.leanAdded+883
lean/OAI/Probability/ThorpRouting/Casimir/PriorPaths.leanAdded+882
lean/OAI/Probability/ThorpRouting/Casimir/RotationMeeting.leanAdded+881
lean/OAI/Probability/ThorpRouting/Casimir/SandwichShuffle.leanAdded+874
lean/OAI/Probability/ThorpRouting/Casimir/Shapes.leanAdded+882
lean/OAI/Probability/ThorpRouting/Casimir/Site.leanAdded+851
lean/OAI/Probability/ThorpRouting/Casimir/TailShapes.leanAdded+894
lean/OAI/Probability/ThorpRouting/Casimir/TypedSet.leanAdded+871
lean/OAI/Probability/ThorpRouting/Casimir/ZeroExtend.leanAdded+878
lean/OAI/Probability/ThorpRouting/Contact/AlternatingPerm.leanAdded+900
lean/OAI/Probability/ThorpRouting/Contact/AssignmentSlots.leanAdded+834
lean/OAI/Probability/ThorpRouting/Contact/BenesCoins.leanAdded+882
lean/OAI/Probability/ThorpRouting/Contact/BlockProduct.leanAdded+894
lean/OAI/Probability/ThorpRouting/Contact/Coins.leanAdded+767
lean/OAI/Probability/ThorpRouting/Contact/ExposedCoins.leanAdded+860
lean/OAI/Probability/ThorpRouting/Contact/HeightDecay.leanAdded+863
lean/OAI/Probability/ThorpRouting/Contact/InputTree.leanAdded+884
lean/OAI/Probability/ThorpRouting/Contact/Main.leanAdded
lean/OAI/Probability/ThorpRouting/Contact/Model.leanAdded
lean/OAI/Probability/ThorpRouting/Contact/ModifiedReverseEquiv.leanAdded
lean/OAI/Probability/ThorpRouting/Contact/ModifiedRoutingMoment.leanAdded
lean/OAI/Probability/ThorpRouting/Contact/ModifiedStageEquiv.leanAdded
lean/OAI/Probability/ThorpRouting/Contact/ParallelFollow.leanAdded
lean/OAI/Probability/ThorpRouting/Contact/ParallelFreshPre.leanAdded
lean/OAI/Probability/ThorpRouting/Contact/PriorPaths.leanAdded
lean/OAI/Probability/ThorpRouting/Contact/Representative.leanAdded
lean/OAI/Probability/ThorpRouting/Contact/RotationMeeting.leanAdded
lean/OAI/Probability/ThorpRouting/Contact/ShapePartitionEquiv.leanAdded
lean/OAI/Probability/ThorpRouting/Dense/AssignmentSlots.leanAdded
lean/OAI/Probability/ThorpRouting/Dense/Coins.leanAdded
lean/OAI/Probability/ThorpRouting/Dense/ColoredEmbedding.leanAdded
lean/OAI/Probability/ThorpRouting/Dense/CutoffMass.leanAdded
lean/OAI/Probability/ThorpRouting/Dense/ExposedCoins.leanAdded
lean/OAI/Probability/ThorpRouting/Dense/Main.leanAdded
lean/OAI/Probability/ThorpRouting/Dense/Model.leanAdded
lean/OAI/Probability/ThorpRouting/Dense/PalindromeFamilyCost.leanAdded
lean/OAI/Probability/ThorpRouting/Dense/ParallelFollow.leanAdded
lean/OAI/Probability/ThorpRouting/Dense/PriorPaths.leanAdded
lean/OAI/Probability/ThorpRouting/Dense/ProjectCycle.leanAdded
lean/OAI/Probability/ThorpRouting/Dense/RotationCharge.leanAdded
lean/OAI/Probability/ThorpRouting/Dense/SingleSlotsEquiv.leanAdded
lean/OAI/Probability/ThorpRouting/Harmonic/AlternatingPerm.leanAdded