diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/AdaptiveProjectionBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/AdaptiveProjectionBounds.lean index edb6c23a9370ff957233d6031082a9eb5a5ed76f..e8599131d683d6aefe00292ffd9d64967723d0eb 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/AdaptiveProjectionBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/AdaptiveProjectionBounds.lean @@ -1,124 +1,124 @@ -import OAI.Combinatorics.HadwigerCounterexample.KeyProjectionBounds - -namespace OAI - -/-! # Adaptive Projection Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix -open scoped BigOperators Topology -open Template -namespace StatusAnalysis -variable {p:Shape} {n N K M r z s0:ℕ} {q:Format} {d e:Rates} {b:Bool} - -private theorem avg_side_bounds {A : Type} [Fintype A] (w : Wgt A) (hw:IsLaw w) - (b:Bool) (f : Wgt A) (F:A×A→ℝ) (h:∀ i,F i≤f (onSide i b)) : - avg (pairW w w) F≤avg w f := by - apply (avg_mono (pairW_law hw hw).nz h).trans - cases b - · rw [pairW_avg] - simp [onSide,hw.avg_const] - rw [pairW_avg]; simp only [onSide,ite_true,hw.avg_const]; rfl - -namespace Quill -variable (w:Quill p q d b) - (m:Mixer p n) (t:Tagging p (Messenger q)) (φ:Messenger q→F) - (u:LeafMixture p n N) (Y:Silhouette p N r) - -set_option maxHeartbeats 1200000 in -theorem oneTrestle (omega_:Wgt u.T) (hv:IsLaw omega_) (s:u.T→ Charts p n d) - (μ:u.T→Wgt (UnitType p n N)) (hμ:∀ i,IsLaw (μ i)) - (P : Keys (p:=p) t N→ Fin z) (F:u.T×u.T → UnitType p n N→Prop) - (hF : ∀ i o,F i o→PreparationParameters.frameSide p m o) - (hw:∀ i,IsLaw (w.policies t φ n i)) (hν:IsLaw (lawNu p N t φ)) - (ε v A B:ℝ) (he:0≤ε) - (ha:∀ i:Fin z, - pr (mixW omega_ μ) (w.flunk t φ Y (fun x=>ind (P x=i)) m v ε) ≤ A) - (hh: pr (mixW omega_ μ) (fun x=>¬ w.matchesArea t φ Y x v)≤B) : - let L (i:u.T×u.T):=onSide i b - avg (pairW omega_ omega_) (fun i=>varOne (mapW (w.displayMass t φ (μ (L i)) (F i) m (s (L i)) Y) P) - (mapW (w.sales t φ (μ (L i)) (F i) m (s (L i))) P)) ≤ z*(ε+2*(A+B)) := by - classical - intro L - let Q (i:u.T×u.T) (x:Fin z):= - |mapW (w.displayMass t φ (μ (L i)) (F i) m (s (L i)) Y) P x- - mapW (w.sales t φ (μ (L i)) (F i) m (s (L i))) P x| - let V:= pairW omega_ omega_ - have h (x : Fin z) : - avg V (fun i=>Q i x) ≤ ε+ 2*(A+B) := by - let H k:= P k=x - let R:= w.flunk t φ Y (fun i=>ind (H i)) m v ε - let Z (i:UnitType p n N):= ¬ w.matchesArea t φ Y i v - let S o:=R o∨ Z o - have heq (i): Q i x≤ ε+2*pr (μ (L i)) S := by - refine w.display_test t φ (μ (L i)) (F i) m (s (L i)) Y H (hμ _) hw hν S he - (fun y hy hz=> ?_) - by_cases hf :Z y - · exact Or.inr hf - exact Or.inl ⟨hF _ _ hy,not_not.mp hf,s (L i),hz⟩ - let U:=mixW omega_ μ - have hu : IsLaw U:=mixW_law hv hμ - have hm (o) : avg omega_ (fun i=>pr (μ i) o)= pr U o := (mixW_avg ..).symm - apply (avg_side_bounds omega_ hv b (fun i=>ε+2*pr (μ i) S) _ heq).trans - rw [avg_add,avg_mul',hm,hv.avg_const] - exact add_le_add_right (mul_le_mul_of_nonneg_left ((pr_or_le hu.nz).trans - (add_le_add (ha _) hh)) (by norm_num)) _ - change avg V (fun x=> ∑ i,Q x i) ≤ _ - rw [avg_sum]; exact (Finset.sum_le_sum fun i _=> h i).trans_eq (by simp; ring) -end Quill - -open Station PreparationParameters -namespace Station -variable {w:LeafMixture p n N} (t:Station p n N K w) - (x:Typus p q d e) (m:Mixer p n) (k: Fin (2^deckMax p K)) - (μ:Wgt (UnitType p n N)) (Y:Silhouette p N r) - -theorem gauzed_area (Y:Silhouette p N r) (w : Quill p q d b) - (t: Tagging p (Messenger q)) (u : Messenger q → F) - (h:w.moral t u) (δ:ℝ) - {K : ℕ} {m:Mixer p n} {ε v:ℝ} (he:ε≤v) - (o : UnitType p n N) (hc:gauze p ε δ Y m K o) : - w.matchesArea t u Y o v := by - intro i; have heq := w.allure_apt t u h i - exact ((hc _ (w.allure t u i)).1 heq).trans he - -set_option maxHeartbeats 1200000 in -theorem projectSum (P : Keys (p:=p) x.t N→Fin z) - (h :apart w.T) (hm:IsLaw μ) (hw :∀ i∈w.T,0¬gauze p τ δ Y m K i)≤B) - (hx : ∀ i:Fin z,pr (w.sap μ) (x.qA.flunk x.t x.z Y (fun y=>ind (P y=i)) m v ε)≤B) - (hy : ∀ i:Fin z,pr (w.sap μ) (x.qB.flunk x.t x.z Y (fun y=>ind (P y=i)) m v' ε)≤B) : - t.due x m μ k Y P≤2*(z*(ε+2*(B+B))) := by - classical - obtain ⟨hp,hq⟩:=rebuild hm.nz h hw hs - let A (i:w.T):=partW μ i.val - let u:=portionW μ w.T - have hQ : w.sap μ=mixW u A :=hq - let V:=pairW u u; have hA i:IsLaw (A i):=on_law hm.nz (hw i.val i.property) - have hL : avg V (fun i=> taxLeft t x m μ k Y P i.1 i.2) ≤ z*(ε+2*(B+B)) := by - refine x.qA.oneTrestle m x.t x.z w Y u hp (fun i=>t.cAxes i d) A hA P - (fun i=> t.frontPage x m i.1 i.2 k) (fun i o h => h.2.2.1) ha hν ε v B B he - (fun i=>by rw [←hQ]; exact hx i) ?_ - rw [←hQ]; apply (pr_mono (LeafMixture.sapLaw hs hm).nz ?_).trans hh - exact fun i hi h=> hi (gauzed_area _ _ _ _ hf.2.1 δ ht.1 i h) - have hR : avg V (fun i=> taxRight t x m μ k Y P i.1 i.2) ≤ z*(ε+2*(B+B)) := by - refine x.qB.oneTrestle m x.t x.z w Y u hp (fun i=>t.cAxes i e) A hA P - (fun i=> t.backPage x m i.1 i.2 k) (fun i o h => h.2.2.1) hb hν ε v' B B he - (fun i=>by rw [←hQ]; exact hy i) ?_ - rw [←hQ]; apply (pr_mono (LeafMixture.sapLaw hs hm).nz ?_).trans hh - exact fun i hi h=>hi (gauzed_area _ _ _ _ hf.2.2.1 δ ht.2 i h) - unfold due; rw [avg_add,two_mul] - exact add_le_add hL hR - -end Station -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.KeyProjectionBounds + +namespace OAI + +/-! # Adaptive Projection Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix +open scoped BigOperators Topology +open Template +namespace StatusAnalysis +variable {p:Shape} {n N K M r z s0:ℕ} {q:Format} {d e:Rates} {b:Bool} + +private theorem avg_side_bounds {A : Type} [Fintype A] (w : Wgt A) (hw:IsLaw w) + (b:Bool) (f : Wgt A) (F:A×A→ℝ) (h:∀ i,F i≤f (onSide i b)) : + avg (pairW w w) F≤avg w f := by + apply (avg_mono (pairW_law hw hw).nz h).trans + cases b + · rw [pairW_avg] + simp [onSide,hw.avg_const] + rw [pairW_avg]; simp only [onSide,ite_true,hw.avg_const]; rfl + +namespace Quill +variable (w:Quill p q d b) + (m:Mixer p n) (t:Tagging p (Messenger q)) (φ:Messenger q→F) + (u:LeafMixture p n N) (Y:Silhouette p N r) + +set_option maxHeartbeats 1200000 in +theorem oneTrestle (omega_:Wgt u.T) (hv:IsLaw omega_) (s:u.T→ Charts p n d) + (μ:u.T→Wgt (UnitType p n N)) (hμ:∀ i,IsLaw (μ i)) + (P : Keys (p:=p) t N→ Fin z) (F:u.T×u.T → UnitType p n N→Prop) + (hF : ∀ i o,F i o→PreparationParameters.frameSide p m o) + (hw:∀ i,IsLaw (w.policies t φ n i)) (hν:IsLaw (lawNu p N t φ)) + (ε v A B:ℝ) (he:0≤ε) + (ha:∀ i:Fin z, + pr (mixW omega_ μ) (w.flunk t φ Y (fun x=>ind (P x=i)) m v ε) ≤ A) + (hh: pr (mixW omega_ μ) (fun x=>¬ w.matchesArea t φ Y x v)≤B) : + let L (i:u.T×u.T):=onSide i b + avg (pairW omega_ omega_) (fun i=>varOne (mapW (w.displayMass t φ (μ (L i)) (F i) m (s (L i)) Y) P) + (mapW (w.sales t φ (μ (L i)) (F i) m (s (L i))) P)) ≤ z*(ε+2*(A+B)) := by + classical + intro L + let Q (i:u.T×u.T) (x:Fin z):= + |mapW (w.displayMass t φ (μ (L i)) (F i) m (s (L i)) Y) P x- + mapW (w.sales t φ (μ (L i)) (F i) m (s (L i))) P x| + let V:= pairW omega_ omega_ + have h (x : Fin z) : + avg V (fun i=>Q i x) ≤ ε+ 2*(A+B) := by + let H k:= P k=x + let R:= w.flunk t φ Y (fun i=>ind (H i)) m v ε + let Z (i:UnitType p n N):= ¬ w.matchesArea t φ Y i v + let S o:=R o∨ Z o + have heq (i): Q i x≤ ε+2*pr (μ (L i)) S := by + refine w.display_test t φ (μ (L i)) (F i) m (s (L i)) Y H (hμ _) hw hν S he + (fun y hy hz=> ?_) + by_cases hf :Z y + · exact Or.inr hf + exact Or.inl ⟨hF _ _ hy,not_not.mp hf,s (L i),hz⟩ + let U:=mixW omega_ μ + have hu : IsLaw U:=mixW_law hv hμ + have hm (o) : avg omega_ (fun i=>pr (μ i) o)= pr U o := (mixW_avg ..).symm + apply (avg_side_bounds omega_ hv b (fun i=>ε+2*pr (μ i) S) _ heq).trans + rw [avg_add,avg_mul',hm,hv.avg_const] + exact add_le_add_right (mul_le_mul_of_nonneg_left ((pr_or_le hu.nz).trans + (add_le_add (ha _) hh)) (by norm_num)) _ + change avg V (fun x=> ∑ i,Q x i) ≤ _ + rw [avg_sum]; exact (Finset.sum_le_sum fun i _=> h i).trans_eq (by simp; ring) +end Quill + +open Station PreparationParameters +namespace Station +variable {w:LeafMixture p n N} (t:Station p n N K w) + (x:Typus p q d e) (m:Mixer p n) (k: Fin (2^deckMax p K)) + (μ:Wgt (UnitType p n N)) (Y:Silhouette p N r) + +theorem gauzed_area (Y:Silhouette p N r) (w : Quill p q d b) + (t: Tagging p (Messenger q)) (u : Messenger q → F) + (h:w.moral t u) (δ:ℝ) + {K : ℕ} {m:Mixer p n} {ε v:ℝ} (he:ε≤v) + (o : UnitType p n N) (hc:gauze p ε δ Y m K o) : + w.matchesArea t u Y o v := by + intro i; have heq := w.allure_apt t u h i + exact ((hc _ (w.allure t u i)).1 heq).trans he + +set_option maxHeartbeats 1200000 in +theorem projectSum (P : Keys (p:=p) x.t N→Fin z) + (h :apart w.T) (hm:IsLaw μ) (hw :∀ i∈w.T,0¬gauze p τ δ Y m K i)≤B) + (hx : ∀ i:Fin z,pr (w.sap μ) (x.qA.flunk x.t x.z Y (fun y=>ind (P y=i)) m v ε)≤B) + (hy : ∀ i:Fin z,pr (w.sap μ) (x.qB.flunk x.t x.z Y (fun y=>ind (P y=i)) m v' ε)≤B) : + t.due x m μ k Y P≤2*(z*(ε+2*(B+B))) := by + classical + obtain ⟨hp,hq⟩:=rebuild hm.nz h hw hs + let A (i:w.T):=partW μ i.val + let u:=portionW μ w.T + have hQ : w.sap μ=mixW u A :=hq + let V:=pairW u u; have hA i:IsLaw (A i):=on_law hm.nz (hw i.val i.property) + have hL : avg V (fun i=> taxLeft t x m μ k Y P i.1 i.2) ≤ z*(ε+2*(B+B)) := by + refine x.qA.oneTrestle m x.t x.z w Y u hp (fun i=>t.cAxes i d) A hA P + (fun i=> t.frontPage x m i.1 i.2 k) (fun i o h => h.2.2.1) ha hν ε v B B he + (fun i=>by rw [←hQ]; exact hx i) ?_ + rw [←hQ]; apply (pr_mono (LeafMixture.sapLaw hs hm).nz ?_).trans hh + exact fun i hi h=> hi (gauzed_area _ _ _ _ hf.2.1 δ ht.1 i h) + have hR : avg V (fun i=> taxRight t x m μ k Y P i.1 i.2) ≤ z*(ε+2*(B+B)) := by + refine x.qB.oneTrestle m x.t x.z w Y u hp (fun i=>t.cAxes i e) A hA P + (fun i=> t.backPage x m i.1 i.2 k) (fun i o h => h.2.2.1) hb hν ε v' B B he + (fun i=>by rw [←hQ]; exact hy i) ?_ + rw [←hQ]; apply (pr_mono (LeafMixture.sapLaw hs hm).nz ?_).trans hh + exact fun i hi h=>hi (gauzed_area _ _ _ _ hf.2.2.1 δ ht.2 i h) + unfold due; rw [avg_add,two_mul] + exact add_le_add hL hR + +end Station +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/AdaptiveRecordBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/AdaptiveRecordBounds.lean index 07822b153a27a20844b552c69447d1ef36eb330d..baa87fa861abd6593c96679794cbc923d511aa42 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/AdaptiveRecordBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/AdaptiveRecordBounds.lean @@ -1,102 +1,102 @@ -import OAI.Combinatorics.HadwigerCounterexample.IndependentTestWitnesses - -namespace OAI - -/-! # Adaptive Record Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Function Finset -open scoped BigOperators -variable {p : Shape} {n N r : ℕ} {T : Cov p N} - -def quest (p : Shape) (r k n N : ℕ) (H ε : ℝ) := - ∀ x : ℕ,x≤2*r → - bp ((x:ℝ)*N)*bp (0.51*k*N)*(H*heatRate p n N ε x k)≤bp (-0.2*N) - -namespace Bazaar -variable (s : Bazaar p n r T) - -set_option maxHeartbeats 800000 in -private theorem probe_event {w : Wgt (UnitType p n N)} {Δ} - (hw : IsLaw w) (h : s.opened Δ w) - (S : Party) (j : Bool) (hi : S j=1) {k : ℕ} - {q : Place p→ℕ} (R : DTuple (p:=p) q N) (F : Catalog p T r q) - (hq : ctot p q=k) (hr : ∀ M Z,(↑(F M Z).card:ℝ) ≤ bp (0.51*k*N)) - (m : Mixer p n) {ε H : ℝ} (he₀ : initCap p N m ε) (hH : 0≤H) (hZ : quest p r k n N H ε) - (hg : ∀ x,w x≤H*pairW (raw m N) (raw m N) x) - (hT : num (Atlas p r T) ≤ bp (0.002*N)) : - pr w (fun x => s.atList S j R F x ∧ glimpse p x j R) ≤ bp (-0.1*N) := by - classical - let P (M : Atlas p r T) (z : Batch M N) (v : DTuple (p:=p) q N) := - fun x => basisFrom p (x : UnitType p n N) j z ∧ glimpse p x j R ∧ thermal p x S R=v - let L (M : Atlas p r T) (x) := standard M ∧ ∃ z,∃ v∈ F M z,P M z v x - have he x : w x≠0 → s.atList S j R F x ∧ glimpse p x j R → - ∃ M,L M x := by - rintro hx ⟨hx',hy⟩ - exact ⟨s.ix x,(h x hx).1,s.bag (s.ix x) j x, thermal p x S R,hx', - ((h x hx).2 j).1,hy,rfl⟩ - have ht (M : Atlas p r T) : pr w (L M) ≤ bp (-0.2*N) := by - by_cases hu : standard M - · let x := cells M - have hb (z : Batch M N) : - pr w (fun y => ∃ v∈F M z,P M z v y) ≤ bp (0.51*k*N)*(H*heatRate p n N ε x k) := by - have ha v : pr w (P M z v) ≤ H*heatRate p n N ε x k := by - rw [← hq]; exact (pr_cap hg _).trans - (mul_le_mul_of_nonneg_left (heat_rate _ S hi R v z m he₀) hH) - refine (pr_union_le hw.nz (F M z) (P M z)).trans ((Finset.sum_le_sum fun v _ => ha v).trans ?_) - rw [Finset.sum_const,nsmul_eq_mul] - apply mul_le_mul_of_nonneg_right (hr M z) - unfold heatRate - exact mul_nonneg hH (mul_nonneg (bp_pos _).le (bp_pos _).le) - simp only [L,hu,true_and] - refine (pr_exists_le hw.nz (fun z y => ∃ v∈F M z,P M z v y)).trans - ((Finset.sum_le_sum (fun z _ => hb z)).trans ?_) - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,card_space] - rw [show dim (Batch M N)=x*N from tuple_dim.trans (Nat.mul_comm ..), - Nat.cast_mul, ← mul_assoc] - exact hZ x hu.2.1 - simp only [L,hu,false_and,pr_false] - exact (bp_pos _).le - refine ((pr_on_mono hw.nz he).trans (pr_exists_le hw.nz L)).trans - ((Finset.sum_le_sum fun i _ => ht i).trans ?_) - rw [Finset.sum_const,nsmul_eq_mul] - apply (mul_le_mul_of_nonneg_right hT (bp_pos _).le).trans - rw [←bp_add] - apply bp_le; linarith [(Nat.cast_nonneg N : 0≤(N:ℝ))] - -set_option maxHeartbeats 600000 in -theorem frequent_sparse {w : Wgt (UnitType p n N)} {Δ} - (hw : IsLaw w) (h : s.opened Δ w) - (S : Party) (j : Bool) (hi : S j=1) - (k d : ℕ) (hh : k ≤ d) (l : ℝ) (hl : 0< l) - (hC : ∀ C : Cov p N,cdim p C≤d → pr w (fun x => offsetCov (s.ix x) ≤ C) ≤ l) - (hb : ∀ A M Z,(↑(s.bids w S j A M Z).card:ℝ) ≤ bp (0.51*N)) - (m : Mixer p n) {ε H L : ℝ} (hN : 2*num (Full p n)-N≤ -1) - (he : initCap p N m ε) - (hH : 0≤H) (hZ : quest p r k n N H ε) - (hg : ∀ x,w x≤H*pairW (raw m N) (raw m N) x) - (hL : 0 ≤ L) (hv : bySide p w m L) - (hT : num (Atlas p r T) ≤ bp (0.002*N)) - (hk : glimpsesBill p k L+bp (-0.1*N) s.frequent w S j (s.ix x.1) (s.ix x.2) x.2) ≤5*l := by - classical - by_contra! hr - obtain ⟨q,R,F,hq,hR,hF,hx⟩ := s.shooting hw S j k d hh l hl hr.le hC hb - have hp := s.probe_event hw h S j hi R F hq hF m he hH hZ hg hT - have hq' z : q z≤ k := hq ▸ Finset.single_le_sum (fun i _ => Nat.zero_le (q i)) - (Finset.mem_univ z) - have hu := glimpse_failure m hL hv hw.sub j hN R k hR hq' - let T := fun (x : UnitType p n N) => glimpse p x j R - let V := s.atList S j R F - have hh' x : V x → ¬T x ∨ (V x ∧ T x) := fun h => by by_cases ht:T x <;> simp [ht,h] - exact not_lt_of_ge - (hx.trans ((pr_mono hw.nz hh').trans ((pr_or_le hw.nz).trans (add_le_add hu hp)))) hk - -end Bazaar - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.IndependentTestWitnesses + +namespace OAI + +/-! # Adaptive Record Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Function Finset +open scoped BigOperators +variable {p : Shape} {n N r : ℕ} {T : Cov p N} + +def quest (p : Shape) (r k n N : ℕ) (H ε : ℝ) := + ∀ x : ℕ,x≤2*r → + bp ((x:ℝ)*N)*bp (0.51*k*N)*(H*heatRate p n N ε x k)≤bp (-0.2*N) + +namespace Bazaar +variable (s : Bazaar p n r T) + +set_option maxHeartbeats 800000 in +private theorem probe_event {w : Wgt (UnitType p n N)} {Δ} + (hw : IsLaw w) (h : s.opened Δ w) + (S : Party) (j : Bool) (hi : S j=1) {k : ℕ} + {q : Place p→ℕ} (R : DTuple (p:=p) q N) (F : Catalog p T r q) + (hq : ctot p q=k) (hr : ∀ M Z,(↑(F M Z).card:ℝ) ≤ bp (0.51*k*N)) + (m : Mixer p n) {ε H : ℝ} (he₀ : initCap p N m ε) (hH : 0≤H) (hZ : quest p r k n N H ε) + (hg : ∀ x,w x≤H*pairW (raw m N) (raw m N) x) + (hT : num (Atlas p r T) ≤ bp (0.002*N)) : + pr w (fun x => s.atList S j R F x ∧ glimpse p x j R) ≤ bp (-0.1*N) := by + classical + let P (M : Atlas p r T) (z : Batch M N) (v : DTuple (p:=p) q N) := + fun x => basisFrom p (x : UnitType p n N) j z ∧ glimpse p x j R ∧ thermal p x S R=v + let L (M : Atlas p r T) (x) := standard M ∧ ∃ z,∃ v∈ F M z,P M z v x + have he x : w x≠0 → s.atList S j R F x ∧ glimpse p x j R → + ∃ M,L M x := by + rintro hx ⟨hx',hy⟩ + exact ⟨s.ix x,(h x hx).1,s.bag (s.ix x) j x, thermal p x S R,hx', + ((h x hx).2 j).1,hy,rfl⟩ + have ht (M : Atlas p r T) : pr w (L M) ≤ bp (-0.2*N) := by + by_cases hu : standard M + · let x := cells M + have hb (z : Batch M N) : + pr w (fun y => ∃ v∈F M z,P M z v y) ≤ bp (0.51*k*N)*(H*heatRate p n N ε x k) := by + have ha v : pr w (P M z v) ≤ H*heatRate p n N ε x k := by + rw [← hq]; exact (pr_cap hg _).trans + (mul_le_mul_of_nonneg_left (heat_rate _ S hi R v z m he₀) hH) + refine (pr_union_le hw.nz (F M z) (P M z)).trans ((Finset.sum_le_sum fun v _ => ha v).trans ?_) + rw [Finset.sum_const,nsmul_eq_mul] + apply mul_le_mul_of_nonneg_right (hr M z) + unfold heatRate + exact mul_nonneg hH (mul_nonneg (bp_pos _).le (bp_pos _).le) + simp only [L,hu,true_and] + refine (pr_exists_le hw.nz (fun z y => ∃ v∈F M z,P M z v y)).trans + ((Finset.sum_le_sum (fun z _ => hb z)).trans ?_) + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,card_space] + rw [show dim (Batch M N)=x*N from tuple_dim.trans (Nat.mul_comm ..), + Nat.cast_mul, ← mul_assoc] + exact hZ x hu.2.1 + simp only [L,hu,false_and,pr_false] + exact (bp_pos _).le + refine ((pr_on_mono hw.nz he).trans (pr_exists_le hw.nz L)).trans + ((Finset.sum_le_sum fun i _ => ht i).trans ?_) + rw [Finset.sum_const,nsmul_eq_mul] + apply (mul_le_mul_of_nonneg_right hT (bp_pos _).le).trans + rw [←bp_add] + apply bp_le; linarith [(Nat.cast_nonneg N : 0≤(N:ℝ))] + +set_option maxHeartbeats 600000 in +theorem frequent_sparse {w : Wgt (UnitType p n N)} {Δ} + (hw : IsLaw w) (h : s.opened Δ w) + (S : Party) (j : Bool) (hi : S j=1) + (k d : ℕ) (hh : k ≤ d) (l : ℝ) (hl : 0< l) + (hC : ∀ C : Cov p N,cdim p C≤d → pr w (fun x => offsetCov (s.ix x) ≤ C) ≤ l) + (hb : ∀ A M Z,(↑(s.bids w S j A M Z).card:ℝ) ≤ bp (0.51*N)) + (m : Mixer p n) {ε H L : ℝ} (hN : 2*num (Full p n)-N≤ -1) + (he : initCap p N m ε) + (hH : 0≤H) (hZ : quest p r k n N H ε) + (hg : ∀ x,w x≤H*pairW (raw m N) (raw m N) x) + (hL : 0 ≤ L) (hv : bySide p w m L) + (hT : num (Atlas p r T) ≤ bp (0.002*N)) + (hk : glimpsesBill p k L+bp (-0.1*N) s.frequent w S j (s.ix x.1) (s.ix x.2) x.2) ≤5*l := by + classical + by_contra! hr + obtain ⟨q,R,F,hq,hR,hF,hx⟩ := s.shooting hw S j k d hh l hl hr.le hC hb + have hp := s.probe_event hw h S j hi R F hq hF m he hH hZ hg hT + have hq' z : q z≤ k := hq ▸ Finset.single_le_sum (fun i _ => Nat.zero_le (q i)) + (Finset.mem_univ z) + have hu := glimpse_failure m hL hv hw.sub j hN R k hR hq' + let T := fun (x : UnitType p n N) => glimpse p x j R + let V := s.atList S j R F + have hh' x : V x → ¬T x ∨ (V x ∧ T x) := fun h => by by_cases ht:T x <;> simp [ht,h] + exact not_lt_of_ge + (hx.trans ((pr_mono hw.nz hh').trans ((pr_or_le hw.nz).trans (add_le_add hu hp)))) hk + +end Bazaar + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/AdditionalProbeBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/AdditionalProbeBounds.lean index 6356dd20285670b74b97f060bf674f0971e1d220..a96f2eaf7a28f5716b476f374b3e114668b0fba9 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/AdditionalProbeBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/AdditionalProbeBounds.lean @@ -1,171 +1,171 @@ -import OAI.Combinatorics.HadwigerCounterexample.SingletonPhaseTests - -namespace OAI - -/-! # Additional Probe Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module Submodule Function Finset -open scoped BigOperators -variable {I J K : Type} [Fintype I] [Fintype J] [Fintype K] - -private def moreMatrix {r : ℕ} (A : Mat I (Fin r)) (v : Vec I) : Mat I (Fin (r+1)) := - Matrix.of (fun i => Fin.cons (v i) (A i)) - -omit [Fintype I] in -private theorem moreMatrix_act {r : ℕ} (A : Mat I (Fin r)) (v : Vec I) - (x : Vec (Fin (r+1))) : - moreMatrix A v *ᵥ x=x 0 • v + A *ᵥ (fun i => x i.succ) := by - funext i; simp only [Matrix.mulVec,dotProduct,moreMatrix,Matrix.of_apply, - Fin.sum_univ_succ,Pi.add_apply,Pi.smul_apply,smul_eq_mul,Fin.cons_zero,Fin.cons_succ] - congr 1; exact mul_comm _ _ - -omit [Fintype I] in -private theorem moreMatrix_inj {r : ℕ} (A : Mat I (Fin r)) (v : Vec I) - (ha : Injective A.mulVec) (h : v∉colSp A) : - Injective (moreMatrix A v).mulVec := by - rw [← Matrix.coe_mulVecLin,← LinearMap.ker_eq_bot, Matrix.ker_mulVecLin_eq_bot_iff] - intro x hx - rw [moreMatrix_act] at hx - let b (i : Fin r) := x i.succ - rcases bit_cases (x 0) with he|he - · have hh : b=0 := by - apply ha - rw [he,zero_smul,zero_add] at hx - exact hx.trans (Matrix.mulVec_zero _).symm - funext i - refine Fin.cases he (fun k => ?_) i - exact congr_fun hh k - · rw [he,one_smul] at hx - have heq : v=A *ᵥ b := add_right_cancel (hx.trans (char_two _).symm) - exact (h ⟨b,heq.symm⟩).elim - -omit [Fintype J] in -private theorem moreMatrix_mul {r} (B : Mat J I) (A : Mat I (Fin r)) (v) : - B*moreMatrix A v=moreMatrix (B*A) (B *ᵥ v) := by - ext i j - refine Fin.cases ?_ (fun j => ?_) j - · rfl - simp only [moreMatrix,Matrix.mul_apply,Matrix.of_apply,Fin.cons_succ] - -variable {p : Shape} {n N r : ℕ} {T : Cov p N} -variable {q : Place p → ℕ} - -private def growFmt (q : Place p→ℕ) (z : Place p) := fun i => - q i+(if i=z then 1 else 0) - -private theorem grow_sum (q : Place p→ℕ) (z : Place p) : - ctot p (growFmt (p:=p) q z)=ctot p q+1 := by simp [growFmt,ctot,Finset.sum_add_distrib] - -private def growing (A : DTuple (p:=p) q N) (z : Place p) (v : Vec (Fin N)) : - DTuple (p:=p) (growFmt (p:=p) q z) N := fun i => by - change Mat (Fin N) (Fin (q i+ if i=z then 1 else 0)) - by_cases h : i=z - · rw [ite_eq_left h]; exact moreMatrix (A i) v - rw [ite_eq_right h]; exact A i - -private theorem castMat_inj {r n m : ℕ} (e : r=n) - (A : Mat (Fin m) (Fin r)) (h : Injective A.mulVec) : - Injective (cast (show Mat (Fin m) (Fin r)=Mat (Fin m) (Fin n) from congrArg (fun t => Mat (Fin m) (Fin t)) e) A).mulVec := by - subst n - exact h -private theorem castMat_prod {r n m : ℕ} (e : r=n) - (A : Mat (Fin m) (Fin r)) (B : Mat (Fin m) (Fin m)) : - B*(cast (show Mat (Fin m) (Fin r)=Mat (Fin m) (Fin n) from congrArg (fun t => Mat (Fin m) (Fin t)) e) A) = - cast (show Mat (Fin m) (Fin r)=Mat (Fin m) (Fin n) from congrArg (fun t => Mat (Fin m) (Fin t)) e) (B*A) := by - subst n; rfl - -private theorem growth_inj (A : DTuple (p:=p) q N) (z : Place p) (v : Vec (Fin N)) - (hv : v∉colSp (A z)) (h : ∀ i, Injective (A i).mulVec) : - ∀ i,Injective (growing A z v i).mulVec := by - intro i - by_cases he : i=z - · subst i - simp [growing,growFmt] - apply castMat_inj _ (moreMatrix (A z) v) (moreMatrix_inj (A z) v (h z) hv) - simp - simp [growing,growFmt,he] - apply castMat_inj _ (A i) (h i) - simp [he] - -private theorem growth_value (A : DTuple (p:=p) q N) (z : Place p) (v : Vec (Fin N)) - (x : UnitType p n N) (S : Party) : - thermal p x S (growing A z v)=growing (thermal p x S A) z (heat p x S z *ᵥ v) := by - funext i - by_cases he : i=z - · subst i - simp [thermal,growing,growFmt] - rw [←moreMatrix_mul] - apply castMat_prod - simp - simp [thermal,growing,growFmt,he] - apply castMat_prod - simp [he] - -theorem column_observe (A : DTuple (p:=p) q N) (z : Place p) (j : Fin (q z)) - (x : UnitType p n N) (S : Party) : - heat p x S z *ᵥ (A z).col j=(thermal p x S A z).col j := rfl - -namespace Bazaar -variable (s : Bazaar p n r T) - -abbrev Catalog (p : Shape) {N} (T : Cov p N) (r : ℕ) (q : Place p→ℕ) := - (M : Atlas p r T) → Batch M N → Finset (DTuple (p:=p) q N) - -def atList (s : Bazaar p n r T) (S : Party) (j : Bool) - (A : DTuple (p:=p) q N) (F : Catalog p T r q) (x : UnitType p n N) := - let M := s.ix x - thermal p x S A∈ F M (s.bag M j x) - -def probed (p : Shape) {N} {q : Place p→ℕ} (A : DTuple (p:=p) q N) : Cov p N := - fun z => colSp (A z) - -theorem extend_probe (w : Wgt (UnitType p n N)) (S : Party) (j : Bool) {k : ℕ} - (A : DTuple (p:=p) q N) (hq : ctot p q=k) - (h : ∀ i, Injective (A i).mulVec) - (F : Catalog p T r q) (hF : ∀ M Z,(↑(F M Z).card:ℝ) ≤ bp (0.51*k*N)) - (G : Atlas p r T) (hg : ¬ offsetCov G ≤ probed p A) - (hb : ∀ M Z,(↑(s.bids w S j G M Z).card:ℝ) ≤ bp (0.51*N)) : - ∃ (q : Place p→ℕ) (A' : DTuple (p:=p) q N) - (F' : Catalog p T r q), ctot p q=k+1 ∧ - (∀ i, Injective (A' i).mulVec) ∧ - (∀ M Z,(↑(F' M Z).card:ℝ) ≤ bp (0.51*(k+1)*N)) ∧ - ∀ x,s.atList S j A F x → s.frequent w S j G (s.ix x) x → - s.atList S j A' F' x := by - classical - obtain ⟨z,i,hg⟩ : - ∃ (z : Place p) (i : Fin (breadth G z)),(src G z).col i∉colSp (A z) := by - by_contra! hh - apply hg - intro z - change colSp (src G z) ≤ _ - rw [colSp,range_mulVecLin] - exact Submodule.span_le.mpr (Set.range_subset_iff.mpr (hh z)) - let q' := growFmt (p:=p) q z - let v := (src G z).col i - let f (M Z) : Finset (DTuple (p:=p) q' N) := - ((F M Z) ×ˢ (s.bids w S j G M Z)).image - (fun a => growing a.1 z ((a.2 z).col i)) - refine ⟨q',growing A z v, f,(grow_sum q z).trans (by rw [hq]), - growth_inj A z v hg h,fun M Z => ?_,fun x hx hi => ?_⟩ - · have he := bp_pos (0.51*(k:ℝ)*N) - have h1 : - (↑(f M Z).card:ℝ) ≤ (↑(F M Z).card:ℝ)*(↑(s.bids w S j G M Z).card:ℝ) := by - exact_mod_cast (show (f M Z).card ≤ _*_ from - Finset.card_image_le.trans_eq (Finset.card_product ..)) - apply (h1.trans (mul_le_mul (hF M Z) (hb M Z) (Nat.cast_nonneg _) he.le)).trans_eq - rw [←bp_add]; congr 1; ring - · rw [atList,growth_value] - - refine Finset.mem_image.mpr ⟨(thermal p x S A,thermal p x S (src G)),?_,?_⟩ - · exact Finset.mem_product.mpr ⟨hx,(s.bids_mem ..).mp hi⟩ - · change growing _ _ _ = _ - rw [show heat p x S z *ᵥ v=_ from column_observe (src G) z i x S] - -end Bazaar -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SingletonPhaseTests + +namespace OAI + +/-! # Additional Probe Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module Submodule Function Finset +open scoped BigOperators +variable {I J K : Type} [Fintype I] [Fintype J] [Fintype K] + +private def moreMatrix {r : ℕ} (A : Mat I (Fin r)) (v : Vec I) : Mat I (Fin (r+1)) := + Matrix.of (fun i => Fin.cons (v i) (A i)) + +omit [Fintype I] in +private theorem moreMatrix_act {r : ℕ} (A : Mat I (Fin r)) (v : Vec I) + (x : Vec (Fin (r+1))) : + moreMatrix A v *ᵥ x=x 0 • v + A *ᵥ (fun i => x i.succ) := by + funext i; simp only [Matrix.mulVec,dotProduct,moreMatrix,Matrix.of_apply, + Fin.sum_univ_succ,Pi.add_apply,Pi.smul_apply,smul_eq_mul,Fin.cons_zero,Fin.cons_succ] + congr 1; exact mul_comm _ _ + +omit [Fintype I] in +private theorem moreMatrix_inj {r : ℕ} (A : Mat I (Fin r)) (v : Vec I) + (ha : Injective A.mulVec) (h : v∉colSp A) : + Injective (moreMatrix A v).mulVec := by + rw [← Matrix.coe_mulVecLin,← LinearMap.ker_eq_bot, Matrix.ker_mulVecLin_eq_bot_iff] + intro x hx + rw [moreMatrix_act] at hx + let b (i : Fin r) := x i.succ + rcases bit_cases (x 0) with he|he + · have hh : b=0 := by + apply ha + rw [he,zero_smul,zero_add] at hx + exact hx.trans (Matrix.mulVec_zero _).symm + funext i + refine Fin.cases he (fun k => ?_) i + exact congr_fun hh k + · rw [he,one_smul] at hx + have heq : v=A *ᵥ b := add_right_cancel (hx.trans (char_two _).symm) + exact (h ⟨b,heq.symm⟩).elim + +omit [Fintype J] in +private theorem moreMatrix_mul {r} (B : Mat J I) (A : Mat I (Fin r)) (v) : + B*moreMatrix A v=moreMatrix (B*A) (B *ᵥ v) := by + ext i j + refine Fin.cases ?_ (fun j => ?_) j + · rfl + simp only [moreMatrix,Matrix.mul_apply,Matrix.of_apply,Fin.cons_succ] + +variable {p : Shape} {n N r : ℕ} {T : Cov p N} +variable {q : Place p → ℕ} + +private def growFmt (q : Place p→ℕ) (z : Place p) := fun i => + q i+(if i=z then 1 else 0) + +private theorem grow_sum (q : Place p→ℕ) (z : Place p) : + ctot p (growFmt (p:=p) q z)=ctot p q+1 := by simp [growFmt,ctot,Finset.sum_add_distrib] + +private def growing (A : DTuple (p:=p) q N) (z : Place p) (v : Vec (Fin N)) : + DTuple (p:=p) (growFmt (p:=p) q z) N := fun i => by + change Mat (Fin N) (Fin (q i+ if i=z then 1 else 0)) + by_cases h : i=z + · rw [ite_eq_left h]; exact moreMatrix (A i) v + rw [ite_eq_right h]; exact A i + +private theorem castMat_inj {r n m : ℕ} (e : r=n) + (A : Mat (Fin m) (Fin r)) (h : Injective A.mulVec) : + Injective (cast (show Mat (Fin m) (Fin r)=Mat (Fin m) (Fin n) from congrArg (fun t => Mat (Fin m) (Fin t)) e) A).mulVec := by + subst n + exact h +private theorem castMat_prod {r n m : ℕ} (e : r=n) + (A : Mat (Fin m) (Fin r)) (B : Mat (Fin m) (Fin m)) : + B*(cast (show Mat (Fin m) (Fin r)=Mat (Fin m) (Fin n) from congrArg (fun t => Mat (Fin m) (Fin t)) e) A) = + cast (show Mat (Fin m) (Fin r)=Mat (Fin m) (Fin n) from congrArg (fun t => Mat (Fin m) (Fin t)) e) (B*A) := by + subst n; rfl + +private theorem growth_inj (A : DTuple (p:=p) q N) (z : Place p) (v : Vec (Fin N)) + (hv : v∉colSp (A z)) (h : ∀ i, Injective (A i).mulVec) : + ∀ i,Injective (growing A z v i).mulVec := by + intro i + by_cases he : i=z + · subst i + simp [growing,growFmt] + apply castMat_inj _ (moreMatrix (A z) v) (moreMatrix_inj (A z) v (h z) hv) + simp + simp [growing,growFmt,he] + apply castMat_inj _ (A i) (h i) + simp [he] + +private theorem growth_value (A : DTuple (p:=p) q N) (z : Place p) (v : Vec (Fin N)) + (x : UnitType p n N) (S : Party) : + thermal p x S (growing A z v)=growing (thermal p x S A) z (heat p x S z *ᵥ v) := by + funext i + by_cases he : i=z + · subst i + simp [thermal,growing,growFmt] + rw [←moreMatrix_mul] + apply castMat_prod + simp + simp [thermal,growing,growFmt,he] + apply castMat_prod + simp [he] + +theorem column_observe (A : DTuple (p:=p) q N) (z : Place p) (j : Fin (q z)) + (x : UnitType p n N) (S : Party) : + heat p x S z *ᵥ (A z).col j=(thermal p x S A z).col j := rfl + +namespace Bazaar +variable (s : Bazaar p n r T) + +abbrev Catalog (p : Shape) {N} (T : Cov p N) (r : ℕ) (q : Place p→ℕ) := + (M : Atlas p r T) → Batch M N → Finset (DTuple (p:=p) q N) + +def atList (s : Bazaar p n r T) (S : Party) (j : Bool) + (A : DTuple (p:=p) q N) (F : Catalog p T r q) (x : UnitType p n N) := + let M := s.ix x + thermal p x S A∈ F M (s.bag M j x) + +def probed (p : Shape) {N} {q : Place p→ℕ} (A : DTuple (p:=p) q N) : Cov p N := + fun z => colSp (A z) + +theorem extend_probe (w : Wgt (UnitType p n N)) (S : Party) (j : Bool) {k : ℕ} + (A : DTuple (p:=p) q N) (hq : ctot p q=k) + (h : ∀ i, Injective (A i).mulVec) + (F : Catalog p T r q) (hF : ∀ M Z,(↑(F M Z).card:ℝ) ≤ bp (0.51*k*N)) + (G : Atlas p r T) (hg : ¬ offsetCov G ≤ probed p A) + (hb : ∀ M Z,(↑(s.bids w S j G M Z).card:ℝ) ≤ bp (0.51*N)) : + ∃ (q : Place p→ℕ) (A' : DTuple (p:=p) q N) + (F' : Catalog p T r q), ctot p q=k+1 ∧ + (∀ i, Injective (A' i).mulVec) ∧ + (∀ M Z,(↑(F' M Z).card:ℝ) ≤ bp (0.51*(k+1)*N)) ∧ + ∀ x,s.atList S j A F x → s.frequent w S j G (s.ix x) x → + s.atList S j A' F' x := by + classical + obtain ⟨z,i,hg⟩ : + ∃ (z : Place p) (i : Fin (breadth G z)),(src G z).col i∉colSp (A z) := by + by_contra! hh + apply hg + intro z + change colSp (src G z) ≤ _ + rw [colSp,range_mulVecLin] + exact Submodule.span_le.mpr (Set.range_subset_iff.mpr (hh z)) + let q' := growFmt (p:=p) q z + let v := (src G z).col i + let f (M Z) : Finset (DTuple (p:=p) q' N) := + ((F M Z) ×ˢ (s.bids w S j G M Z)).image + (fun a => growing a.1 z ((a.2 z).col i)) + refine ⟨q',growing A z v, f,(grow_sum q z).trans (by rw [hq]), + growth_inj A z v hg h,fun M Z => ?_,fun x hx hi => ?_⟩ + · have he := bp_pos (0.51*(k:ℝ)*N) + have h1 : + (↑(f M Z).card:ℝ) ≤ (↑(F M Z).card:ℝ)*(↑(s.bids w S j G M Z).card:ℝ) := by + exact_mod_cast (show (f M Z).card ≤ _*_ from + Finset.card_image_le.trans_eq (Finset.card_product ..)) + apply (h1.trans (mul_le_mul (hF M Z) (hb M Z) (Nat.cast_nonneg _) he.le)).trans_eq + rw [←bp_add]; congr 1; ring + · rw [atList,growth_value] + + refine Finset.mem_image.mpr ⟨(thermal p x S A,thermal p x S (src G)),?_,?_⟩ + · exact Finset.mem_product.mpr ⟨hx,(s.bids_mem ..).mp hi⟩ + · change growing _ _ _ = _ + rw [show heat p x S z *ᵥ v=_ from column_observe (src G) z i x S] + +end Bazaar +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/AffineFrames.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/AffineFrames.lean index 4187a4c91de231a65eb669fe350fd517fc44ebc0..37ecbdfd2fc114669b0831767595d2a0c5a701e5 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/AffineFrames.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/AffineFrames.lean @@ -1,195 +1,195 @@ -import OAI.Combinatorics.HadwigerCounterexample.QuadraticTesters -import OAI.Combinatorics.HadwigerCounterexample.SampledGraphs -import Mathlib.Data.Matrix.ColumnRowPartitioned - -namespace OAI - -/-! # Affine Frames -/ - -noncomputable section -namespace HadwigerCounterexample - -open Matrix -open scoped BigOperators - -structure Mixer (p : Shape) (n : ℕ) where - mixL : Fin p.J → Comp p.g → Comp p.g → Moment p n - mixR : Fin p.J → Comp p.g → Comp p.g → Moment p n - mixM : Fin p.b → Mat (Fin n) (Fin n) - -abbrev Pdual (p : Shape) (n : ℕ) := Profile p n →ₗ[F] F - -def linTensor {V : Type} [AddCommGroup V] [Module F V] (a b : V →ₗ[F] F) : V →ₗ[F] V →ₗ[F] F := - a.smulRight b - -theorem linTensor_val {V : Type} [AddCommGroup V] [Module F V] (a b : V →ₗ[F] F) - (x y : V) : linTensor a b x y = a x * b y := rfl - -variable {p : Shape} {n N : ℕ} - -def T0 (p : Shape) (n : ℕ) : Profile p n →ₗ[F] Pdual p n := - linTensor (role p n) (role p n) + - ∑ i : Tag p.g, (linTensor (roleT p n i) (sharedT p n i) + - linTensor (sharedT p n i) (roleT p n i)) - -theorem T0_val (x y : Profile p n) : T0 p n x y = - role p n x * role p n y + - ∑ i : Tag p.g, (roleT p n i x * sharedT p n i y + sharedT p n i x * roleT p n i y) := by - simp only [T0,LinearMap.add_apply,LinearMap.sum_apply,linTensor_val] - -def B1 (m : Mixer p n) : Profile p n →ₗ[F] Pdual p n where - toFun x := { - toFun := fun y => ∑ j, ∑ e, ∑ f, - mpair (x e) (liftM (m.mixL j e f) (m.mixR j e f) (y f)) - map_add' y z := by simp only [Pi.add_apply,map_add, Finset.sum_add_distrib] - map_smul' b y := by simp only [Pi.smul_apply,map_smul,RingHom.id_apply,smul_eq_mul, - Finset.mul_sum] } - map_add' x y := LinearMap.ext fun z => by - simp only [LinearMap.coe_mk,AddHom.coe_mk,LinearMap.add_apply, - Pi.add_apply,mpair_add, Finset.sum_add_distrib] - map_smul' b x := LinearMap.ext fun z => by - simp only [LinearMap.coe_mk,AddHom.coe_mk,LinearMap.smul_apply,RingHom.id_apply, - Pi.smul_apply,mpair_smul,smul_eq_mul, Finset.mul_sum] - -def Tmix (m : Mixer p n) := B1 m + LinearMap.flip (B1 m) -def Tsym (m : Mixer p n) := T0 p n + Tmix m - -theorem Tsym_val (m : Mixer p n) (x y : Profile p n) : - Tsym m x y = T0 p n x y + (B1 m x y + B1 m y x) := by - change (T0 p n + (B1 m + _)) x y = _ - simp - -theorem T_swap (m : Mixer p n) (x y : Profile p n) : Tsym m x y = Tsym m y x := by - simp only [Tsym_val,T0_val] - refine congrArg₂ (· + ·) (congrArg₂ (· + ·) (mul_comm _ _) - (Finset.sum_congr rfl fun i _ => ?_)) (add_comm _ _) - rw [mul_comm (roleT p n i x),mul_comm (sharedT p n i x),add_comm] - -theorem T_diag (m : Mixer p n) (x : Profile p n) : Tsym m x x = role p n x := by - have h (a b : F) : a*b+b*a=0 := by rw [mul_comm b a,char_two] - simp only [Tsym_val,T0_val,char_two,h,Finset.sum_const_zero,add_zero,bit_sq] - -def grad (m : Mixer p n) (x : Profile p n) := role p n + Tsym m x -theorem grad_val (m : Mixer p n) (x y : Profile p n) : - grad m x y = role p n y + Tsym m x y := rfl - -abbrev Full (p : Shape) (n : ℕ) := Row p n ⊕ Fin p.h -abbrev RawFrame (I J : Type) := Mat J I × Mat J I -abbrev Oframe (p : Shape) (n N : ℕ) := RawFrame (Full p n) (Fin N) -abbrev Orient (p : Shape) (n N : ℕ) := Comp p.g → Oframe p n N - -def primary {I J E : Type} (M : Mat E (I ⊕ J)) : Mat E I := M.submatrix id Sum.inl -def channel {I J E : Type} (M : Mat E (I ⊕ J)) : Mat E J := M.submatrix id Sum.inr - -theorem fromCols_frame {I J E : Type} (M : Mat E (I ⊕ J)) : - fromCols (primary M) (channel M) = M := by ext i j; rcases j with i|j <;> rfl - -theorem primary_inj {I J E : Type} [Fintype I] [Fintype J] - {M : Mat E (I ⊕ J)} (h : Function.Injective M.mulVec) : - Function.Injective (primary M).mulVec := by - intro a b hab - let v (x : Vec I) := Sum.elim x (fun _ : J => (0:F)) - have he (x : Vec I) : M *ᵥ v x = primary M *ᵥ x := by - conv_lhs => rw [← fromCols_frame M] - unfold v; rw [fromCols_mulVec_sumElim] - change _ + (channel M *ᵥ 0) = _ - rw [Matrix.mulVec_zero,add_zero] - have hh : v a = v b := h (by rw [he,he]; exact hab) - exact funext fun i => congr_fun hh (.inl i) - -def valid (M : Moment p n) (o : Oframe p n N) : Prop := - Function.Injective o.1.mulVec ∧ Function.Injective o.2.mulVec ∧ - (primary o.1)ᵀ * primary o.2 = M ∧ (channel o.1)ᵀ * primary o.2 = 0 ∧ - (primary o.1)ᵀ * channel o.2 = 0 - -def frameLaw (m : Mixer p n) (o : Orient p n N) := - ∀ e, valid (selfM p n m.mixM) (o e) - -abbrev Ambient (p : Shape) (N : ℕ) := Comp p.g → Mat (Fin N) (Fin N) - -def Uembed (o : Orient p n N) : Profile p n →ₗ[F] Ambient p N where - toFun x e := liftM (primary (o e).1) (primary (o e).2) (x e) - map_add' x y := by funext e; simp only [Pi.add_apply,map_add] - map_smul' a x := by funext e; simp only [Pi.smul_apply,map_smul,RingHom.id_apply] - -def ufun (o : Orient p n N) : Ambient p N →ₗ[F] F where - toFun x := ∑ e, mpair (channel (o e).2 * (channel (o e).1)ᵀ) (x e) - map_add' x y := by simp only [Pi.add_apply,map_add, Finset.sum_add_distrib] - map_smul' a x := by simp only [Pi.smul_apply,map_smul,RingHom.id_apply, - smul_eq_mul,Finset.mul_sum] - -theorem Uembed_inj {m : Mixer p n} {o : Orient p n N} (h : frameLaw m o) : - Function.Injective (Uembed o) := by - intro x y e - exact funext fun i => - liftM_inj (primary_inj (h i).1) (primary_inj (h i).2.1) (congr_fun e i) - -theorem ufun_self {m : Mixer p n} {o : Orient p n N} (h : frameLaw m o) (x : Profile p n) : - ufun o (Uembed o x) = 0 := by - simp only [ufun,Uembed,LinearMap.coe_mk,AddHom.coe_mk] - refine Finset.sum_eq_zero fun i _ => ?_ - rw [mpair_liftM,liftM_def,← Matrix.mul_assoc,(h i).2.2.2.2,Matrix.zero_mul, - Matrix.zero_mul,mpair_comm,map_zero] - -/-- Witnesses v,w are in the cut-profile space. The gradients agree over that -*whole* space. -/ -def hole (m : Mixer p n) (x y : Orient p n N) := - frameLaw m x ∧ frameLaw m y ∧ ∃ v w : Profile p n, - v ∈ Xspace p n ∧ w ∈ Xspace p n ∧ - Uembed x v = Uembed y w ∧ - (∀ i ∈ Xspace p n, ufun y (Uembed x i) = grad m v i) ∧ - (∀ i ∈ Xspace p n, ufun x (Uembed y i) = grad m w i) ∧ - role p n v + role p n w = 1 - -theorem hole_sym {m : Mixer p n} {x y : Orient p n N} (h : hole m x y) : hole m y x := by - obtain ⟨hx,hy,v,w,hv,hw,e,h,g,p⟩ := h - exact ⟨hy,hx,w,v,hw,hv,e.symm,g,h,(add_comm _ _).trans p⟩ - -theorem not_hole_self (m : Mixer p n) (x : Orient p n N) : ¬hole m x x := by - rintro ⟨hx,_,v,w,_,_,e,_,_,hp⟩ - rw [Uembed_inj hx e,char_two] at hp - exact zero_ne_one hp - -theorem hole_triangle {m : Mixer p n} {x y z : Orient p n N} - (h1 : hole m x y) (h2 : hole m y z) : ¬ hole m x z := by - intro h3 - obtain ⟨_,_,a,b,ha,hb,hab,u1,u2,p1⟩ := h1 - obtain ⟨_,_,c,d,hc,hd,hcd,u3,u4,p2⟩ := h2 - obtain ⟨_,_,e,f,he,hf,hef,u5,u6,p3⟩ := h3 - have hx : grad m b c = grad m f d := by rw [←u2 _ hc, ←u6 _ hd,hcd] - have hy : grad m a e = grad m d f := by rw [←u1 _ he, ←u4 _ hf,hef] - have hz : grad m e a = grad m c b := by rw [←u5 _ ha, ←u3 _ hb,hab] - simp only [grad_val] at hx hy hz - let A := role p n - have hw (x y : F) (h : x=y) : x+y=0 := by rw [h,char_two] - have hp : (A a+A b)+(A c+A d)+(A e+A f)=0 := by - let H := Tsym m - change A _ + H _ _ = A _ + H _ _ at hx hy hz - calc (A a+A b)+(A c+A d)+(A e+A f) - _ = ((A c+H b c)+(A d+H f d)) + - ((A e+H a e)+(A f+H d f)) + - ((A a+H e a)+(A b+H c b)) := by - have h (x y) : H x y+H y x=0 := hw _ _ (T_swap m _ _) - symm - calc ((A c+H b c)+(A d+H f d)) + - ((A e+H a e)+(A f+H d f)) + - ((A a+H e a)+(A b+H c b)) - _ = ((A a+A b)+(A c+A d)+(A e+A f)) + (H b c+H c b) + - (H f d+H d f)+(H a e+H e a) := by ac_rfl - _ = _ := by simp only [h,add_zero] - _ = 0 := by rw [hw _ _ hx, hw _ _ hy, hw _ _ hz]; simp - unfold A at hp - rw [p1,p2,p3,char_two,zero_add] at hp - exact one_ne_zero hp - -def rawHoles (m : Mixer p n) : Holes (Orient p n N) where - rel := hole m - sym := hole_sym - irr := not_hole_self m - ntri := hole_triangle - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.QuadraticTesters +import OAI.Combinatorics.HadwigerCounterexample.SampledGraphs +import Mathlib.Data.Matrix.ColumnRowPartitioned + +namespace OAI + +/-! # Affine Frames -/ + +noncomputable section +namespace HadwigerCounterexample + +open Matrix +open scoped BigOperators + +structure Mixer (p : Shape) (n : ℕ) where + mixL : Fin p.J → Comp p.g → Comp p.g → Moment p n + mixR : Fin p.J → Comp p.g → Comp p.g → Moment p n + mixM : Fin p.b → Mat (Fin n) (Fin n) + +abbrev Pdual (p : Shape) (n : ℕ) := Profile p n →ₗ[F] F + +def linTensor {V : Type} [AddCommGroup V] [Module F V] (a b : V →ₗ[F] F) : V →ₗ[F] V →ₗ[F] F := + a.smulRight b + +theorem linTensor_val {V : Type} [AddCommGroup V] [Module F V] (a b : V →ₗ[F] F) + (x y : V) : linTensor a b x y = a x * b y := rfl + +variable {p : Shape} {n N : ℕ} + +def T0 (p : Shape) (n : ℕ) : Profile p n →ₗ[F] Pdual p n := + linTensor (role p n) (role p n) + + ∑ i : Tag p.g, (linTensor (roleT p n i) (sharedT p n i) + + linTensor (sharedT p n i) (roleT p n i)) + +theorem T0_val (x y : Profile p n) : T0 p n x y = + role p n x * role p n y + + ∑ i : Tag p.g, (roleT p n i x * sharedT p n i y + sharedT p n i x * roleT p n i y) := by + simp only [T0,LinearMap.add_apply,LinearMap.sum_apply,linTensor_val] + +def B1 (m : Mixer p n) : Profile p n →ₗ[F] Pdual p n where + toFun x := { + toFun := fun y => ∑ j, ∑ e, ∑ f, + mpair (x e) (liftM (m.mixL j e f) (m.mixR j e f) (y f)) + map_add' y z := by simp only [Pi.add_apply,map_add, Finset.sum_add_distrib] + map_smul' b y := by simp only [Pi.smul_apply,map_smul,RingHom.id_apply,smul_eq_mul, + Finset.mul_sum] } + map_add' x y := LinearMap.ext fun z => by + simp only [LinearMap.coe_mk,AddHom.coe_mk,LinearMap.add_apply, + Pi.add_apply,mpair_add, Finset.sum_add_distrib] + map_smul' b x := LinearMap.ext fun z => by + simp only [LinearMap.coe_mk,AddHom.coe_mk,LinearMap.smul_apply,RingHom.id_apply, + Pi.smul_apply,mpair_smul,smul_eq_mul, Finset.mul_sum] + +def Tmix (m : Mixer p n) := B1 m + LinearMap.flip (B1 m) +def Tsym (m : Mixer p n) := T0 p n + Tmix m + +theorem Tsym_val (m : Mixer p n) (x y : Profile p n) : + Tsym m x y = T0 p n x y + (B1 m x y + B1 m y x) := by + change (T0 p n + (B1 m + _)) x y = _ + simp + +theorem T_swap (m : Mixer p n) (x y : Profile p n) : Tsym m x y = Tsym m y x := by + simp only [Tsym_val,T0_val] + refine congrArg₂ (· + ·) (congrArg₂ (· + ·) (mul_comm _ _) + (Finset.sum_congr rfl fun i _ => ?_)) (add_comm _ _) + rw [mul_comm (roleT p n i x),mul_comm (sharedT p n i x),add_comm] + +theorem T_diag (m : Mixer p n) (x : Profile p n) : Tsym m x x = role p n x := by + have h (a b : F) : a*b+b*a=0 := by rw [mul_comm b a,char_two] + simp only [Tsym_val,T0_val,char_two,h,Finset.sum_const_zero,add_zero,bit_sq] + +def grad (m : Mixer p n) (x : Profile p n) := role p n + Tsym m x +theorem grad_val (m : Mixer p n) (x y : Profile p n) : + grad m x y = role p n y + Tsym m x y := rfl + +abbrev Full (p : Shape) (n : ℕ) := Row p n ⊕ Fin p.h +abbrev RawFrame (I J : Type) := Mat J I × Mat J I +abbrev Oframe (p : Shape) (n N : ℕ) := RawFrame (Full p n) (Fin N) +abbrev Orient (p : Shape) (n N : ℕ) := Comp p.g → Oframe p n N + +def primary {I J E : Type} (M : Mat E (I ⊕ J)) : Mat E I := M.submatrix id Sum.inl +def channel {I J E : Type} (M : Mat E (I ⊕ J)) : Mat E J := M.submatrix id Sum.inr + +theorem fromCols_frame {I J E : Type} (M : Mat E (I ⊕ J)) : + fromCols (primary M) (channel M) = M := by ext i j; rcases j with i|j <;> rfl + +theorem primary_inj {I J E : Type} [Fintype I] [Fintype J] + {M : Mat E (I ⊕ J)} (h : Function.Injective M.mulVec) : + Function.Injective (primary M).mulVec := by + intro a b hab + let v (x : Vec I) := Sum.elim x (fun _ : J => (0:F)) + have he (x : Vec I) : M *ᵥ v x = primary M *ᵥ x := by + conv_lhs => rw [← fromCols_frame M] + unfold v; rw [fromCols_mulVec_sumElim] + change _ + (channel M *ᵥ 0) = _ + rw [Matrix.mulVec_zero,add_zero] + have hh : v a = v b := h (by rw [he,he]; exact hab) + exact funext fun i => congr_fun hh (.inl i) + +def valid (M : Moment p n) (o : Oframe p n N) : Prop := + Function.Injective o.1.mulVec ∧ Function.Injective o.2.mulVec ∧ + (primary o.1)ᵀ * primary o.2 = M ∧ (channel o.1)ᵀ * primary o.2 = 0 ∧ + (primary o.1)ᵀ * channel o.2 = 0 + +def frameLaw (m : Mixer p n) (o : Orient p n N) := + ∀ e, valid (selfM p n m.mixM) (o e) + +abbrev Ambient (p : Shape) (N : ℕ) := Comp p.g → Mat (Fin N) (Fin N) + +def Uembed (o : Orient p n N) : Profile p n →ₗ[F] Ambient p N where + toFun x e := liftM (primary (o e).1) (primary (o e).2) (x e) + map_add' x y := by funext e; simp only [Pi.add_apply,map_add] + map_smul' a x := by funext e; simp only [Pi.smul_apply,map_smul,RingHom.id_apply] + +def ufun (o : Orient p n N) : Ambient p N →ₗ[F] F where + toFun x := ∑ e, mpair (channel (o e).2 * (channel (o e).1)ᵀ) (x e) + map_add' x y := by simp only [Pi.add_apply,map_add, Finset.sum_add_distrib] + map_smul' a x := by simp only [Pi.smul_apply,map_smul,RingHom.id_apply, + smul_eq_mul,Finset.mul_sum] + +theorem Uembed_inj {m : Mixer p n} {o : Orient p n N} (h : frameLaw m o) : + Function.Injective (Uembed o) := by + intro x y e + exact funext fun i => + liftM_inj (primary_inj (h i).1) (primary_inj (h i).2.1) (congr_fun e i) + +theorem ufun_self {m : Mixer p n} {o : Orient p n N} (h : frameLaw m o) (x : Profile p n) : + ufun o (Uembed o x) = 0 := by + simp only [ufun,Uembed,LinearMap.coe_mk,AddHom.coe_mk] + refine Finset.sum_eq_zero fun i _ => ?_ + rw [mpair_liftM,liftM_def,← Matrix.mul_assoc,(h i).2.2.2.2,Matrix.zero_mul, + Matrix.zero_mul,mpair_comm,map_zero] + +/-- Witnesses v,w are in the cut-profile space. The gradients agree over that +*whole* space. -/ +def hole (m : Mixer p n) (x y : Orient p n N) := + frameLaw m x ∧ frameLaw m y ∧ ∃ v w : Profile p n, + v ∈ Xspace p n ∧ w ∈ Xspace p n ∧ + Uembed x v = Uembed y w ∧ + (∀ i ∈ Xspace p n, ufun y (Uembed x i) = grad m v i) ∧ + (∀ i ∈ Xspace p n, ufun x (Uembed y i) = grad m w i) ∧ + role p n v + role p n w = 1 + +theorem hole_sym {m : Mixer p n} {x y : Orient p n N} (h : hole m x y) : hole m y x := by + obtain ⟨hx,hy,v,w,hv,hw,e,h,g,p⟩ := h + exact ⟨hy,hx,w,v,hw,hv,e.symm,g,h,(add_comm _ _).trans p⟩ + +theorem not_hole_self (m : Mixer p n) (x : Orient p n N) : ¬hole m x x := by + rintro ⟨hx,_,v,w,_,_,e,_,_,hp⟩ + rw [Uembed_inj hx e,char_two] at hp + exact zero_ne_one hp + +theorem hole_triangle {m : Mixer p n} {x y z : Orient p n N} + (h1 : hole m x y) (h2 : hole m y z) : ¬ hole m x z := by + intro h3 + obtain ⟨_,_,a,b,ha,hb,hab,u1,u2,p1⟩ := h1 + obtain ⟨_,_,c,d,hc,hd,hcd,u3,u4,p2⟩ := h2 + obtain ⟨_,_,e,f,he,hf,hef,u5,u6,p3⟩ := h3 + have hx : grad m b c = grad m f d := by rw [←u2 _ hc, ←u6 _ hd,hcd] + have hy : grad m a e = grad m d f := by rw [←u1 _ he, ←u4 _ hf,hef] + have hz : grad m e a = grad m c b := by rw [←u5 _ ha, ←u3 _ hb,hab] + simp only [grad_val] at hx hy hz + let A := role p n + have hw (x y : F) (h : x=y) : x+y=0 := by rw [h,char_two] + have hp : (A a+A b)+(A c+A d)+(A e+A f)=0 := by + let H := Tsym m + change A _ + H _ _ = A _ + H _ _ at hx hy hz + calc (A a+A b)+(A c+A d)+(A e+A f) + _ = ((A c+H b c)+(A d+H f d)) + + ((A e+H a e)+(A f+H d f)) + + ((A a+H e a)+(A b+H c b)) := by + have h (x y) : H x y+H y x=0 := hw _ _ (T_swap m _ _) + symm + calc ((A c+H b c)+(A d+H f d)) + + ((A e+H a e)+(A f+H d f)) + + ((A a+H e a)+(A b+H c b)) + _ = ((A a+A b)+(A c+A d)+(A e+A f)) + (H b c+H c b) + + (H f d+H d f)+(H a e+H e a) := by ac_rfl + _ = _ := by simp only [h,add_zero] + _ = 0 := by rw [hw _ _ hx, hw _ _ hy, hw _ _ hz]; simp + unfold A at hp + rw [p1,p2,p3,char_two,zero_add] at hp + exact one_ne_zero hp + +def rawHoles (m : Mixer p n) : Holes (Orient p n N) where + rel := hole m + sym := hole_sym + irr := not_hole_self m + ntri := hole_triangle + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/AggregateCostBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/AggregateCostBounds.lean index 13e922ab8cbc35a83f2bdf2d11046987139b6a5c..d2713b6bec462309241ad503583340984b584b30 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/AggregateCostBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/AggregateCostBounds.lean @@ -1,124 +1,124 @@ -import OAI.Combinatorics.HadwigerCounterexample.PositiveTestMass - -namespace OAI - -/-! # Aggregate Cost Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Filter Function -open scoped BigOperators Topology -open Template -variable {p:Shape} {n N r M s0 K:ℕ} -namespace StatusAnalysis -open PreparationParameters Station DualAnalysis - -theorem couplings {I A : Type} [Fintype I] [Fintype A] (p:Wgt I)(f:I→ Wgt A) - (F:(I×A)×(I×A)→ℝ): - avg (pairW (semi p f) (semi p f)) F= - avg (pairW p p) (fun i=>avg (pairW (f i.1) (f i.2)) (fun a=>F ((i.1,a.1),(i.2,a.2)))) := by - rw [pairW_avg,pairW_avg] - simp_rw [semi_avg,pairW_avg] - refine avg_congr (fun i _=>?_); exact avg_avg .. - -theorem ship_cost (w:LeafMixture p n N)(U:Wgt (UnitType p n N))(m:Mixer p n) - (v:Station p n N K w) (i:Scrip p K) (Y:Silhouette p N r) : - avg (cirque w U) (fun x=>v.twilight i.2.2 m i.2.1 Y x.1.1 x.2.1 (x.1.2,x.2.2)) - = v.stratum i.2.2 m U i.2.1 Y := couplings (portionW U w.T) (fun i=>partW U i.val) _ - -theorem ship_pos (w:LeafMixture p n N) (m:Mixer p n) - (v:Station p n N K w) (i:Scrip p K) (Y:Silhouette p N r) - (h:i.2.2.permission)(hp:1≤p.r)(hn:2*p.r≤n) - (x:ViewPair p n N w): - 0≤ v.twilight i.2.2 m i.2.1 Y x.1.1 x.2.1 (x.1.2,x.2.2) := by - classical - let a:=i.2.2 - have hA j:= Appearance.witLaw (a.qA.allure_apt a.t a.z h.2.1 j) hp hn - have hB j:= Appearance.witLaw (a.qB.allure_apt a.t a.z h.2.2.1 j) hp hn - let s:= v.cAxes x.1.1 (toRates i.1.2.1) - let t:= v.cAxes x.2.1 (toRates i.1.2.2) - have hc (j) : 0≤ a.chimera x.1.2 x.2.2 s t m Y j := avg_nonneg (unifOn_sub _).nz - (fun k=> mul_nonneg (a.qA.seraphFloor a.t a.z x.1.2 m s Y j (hA j) k).1 - (a.qB.seraphFloor a.t a.z x.2.2 m t Y j (hB j) k).1) - have hM : 0≤a.momus:= mul_nonneg (kappa_pos _).le (kappa_pos _).le - exact mul_nonneg (ind_nonneg _) (mul_nonneg hM (Finset.prod_nonneg fun i _=>hc i)) - -theorem prognosis (w:LeafMixture p n N) (U: Wgt (UnitType p n N)) (m:Mixer p n) - (b:PreparationParameters) (v:Station p n N b.pins w) (Y:Silhouette p N r) - {ε a : ℝ} (he:0 ≤ ε)(ha:0 eligiblePair v m x.1 x.2 Y a)≤ num (Scrip p b.pins)*(ε/a) := by - classical - let J:= Scrip p b.pins; let I:=ViewPair p n N w; let V:=cirque w U - let Q (i:J)(x:I):= v.twilight i.2.2 m i.2.1 Y x.1.1 x.2.1 (x.1.2,x.2.2) - have ht:= (troupe_bill hs).1; have hv:IsLaw V:=pairW_law ht ht - let P (i:J)(x:I):= i.2.2.permission∧ a ≤ Q i x - have hF (i:J): pr V (P i)≤ ε/a := by - by_cases ht:i.2.2.permission - · simp only [P,ht,true_and] - refine (le_div_iff₀ ha).mpr ?_ - rw [mul_comm] - exact ((le_avg_markov hv.nz (ship_pos w m v i Y ht hp hn) a).trans_eq (ship_cost ..)).trans - (h i ht) - rw [show P i=(fun _=>False) from funext fun a=>eq_false fun hh=>ht hh.1,pr_false]; exact div_nonneg he ha.le - change pr V (fun x=>∃ i,P i x)≤ _ - exact ((pr_exists_le hv.nz P).trans (Finset.sum_le_sum fun i _=> hF i)).trans_eq (by simp [J,num]) - -structure Beams (b:PreparationParameters) (m:Mixer p n) (Y:Silhouette p N r) - (w:LeafMixture p n N)(U:Wgt (UnitType p n N)) (v:Station p n N b.pins w) - (a ε δ τ :ℝ):Prop where - soft : origami p r (wisp p Y) δ - rare : pr (w.sap U) (fun i=>¬gauze p δ δ Y m b.pins i) ≤ τ - zone : pr (cirque w U) (fun x=> eligiblePair v m x.1 x.2 Y a) ≤ τ - haze : 0<δ∧ δ≤ ε - -variable {l:Filter ℕ} {m:cycleM p} {U:tale p M} {w:rhythms p M} {b:PreparationParameters} -set_option maxHeartbeats 1400000 in -theorem lightmap (v:Stations p M b.pins w) (h:veil p M b s0 l m w U) - (a ε τ:ℝ) (ha:0?_⟩ - let ν:=wisp p X i j - have hs : pr ν (fun i=>¬δ≤ν i) = 1-pr ν (fun i=>δ≤ν i) :=by rw [pr_not,(show tot ν=1 - from (h0 i j).total)] - have hi:u≤1/4:=le_trans (min_le_right ..) (min_le_right ..) - simp_rw [not_le] at hs - have hf:= haze_small ν δ hd.le - linarith only [hf,hs,hV,hi,hd] - · apply (prognosis (w n) (U n) (m n) b (v n) X hη.le ha he.hR hn.age - ⟨hC.1,hP,hp.1.law,hC.2⟩ hY).trans - change L*(η/a)≤τ - have h : η/a= τ/(L+1) := by unfold η; field_simp - rw [h,mul_div_assoc',div_le_iff₀ (by linarith)] - linarith only [hτ] - have hi:u≤ε:=le_trans (min_le_right ..) (min_le_left ..) - nlinarith only [hi,hV,hd,Nat.cast_nonneg (α:=ℝ) r] - -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PositiveTestMass + +namespace OAI + +/-! # Aggregate Cost Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Filter Function +open scoped BigOperators Topology +open Template +variable {p:Shape} {n N r M s0 K:ℕ} +namespace StatusAnalysis +open PreparationParameters Station DualAnalysis + +theorem couplings {I A : Type} [Fintype I] [Fintype A] (p:Wgt I)(f:I→ Wgt A) + (F:(I×A)×(I×A)→ℝ): + avg (pairW (semi p f) (semi p f)) F= + avg (pairW p p) (fun i=>avg (pairW (f i.1) (f i.2)) (fun a=>F ((i.1,a.1),(i.2,a.2)))) := by + rw [pairW_avg,pairW_avg] + simp_rw [semi_avg,pairW_avg] + refine avg_congr (fun i _=>?_); exact avg_avg .. + +theorem ship_cost (w:LeafMixture p n N)(U:Wgt (UnitType p n N))(m:Mixer p n) + (v:Station p n N K w) (i:Scrip p K) (Y:Silhouette p N r) : + avg (cirque w U) (fun x=>v.twilight i.2.2 m i.2.1 Y x.1.1 x.2.1 (x.1.2,x.2.2)) + = v.stratum i.2.2 m U i.2.1 Y := couplings (portionW U w.T) (fun i=>partW U i.val) _ + +theorem ship_pos (w:LeafMixture p n N) (m:Mixer p n) + (v:Station p n N K w) (i:Scrip p K) (Y:Silhouette p N r) + (h:i.2.2.permission)(hp:1≤p.r)(hn:2*p.r≤n) + (x:ViewPair p n N w): + 0≤ v.twilight i.2.2 m i.2.1 Y x.1.1 x.2.1 (x.1.2,x.2.2) := by + classical + let a:=i.2.2 + have hA j:= Appearance.witLaw (a.qA.allure_apt a.t a.z h.2.1 j) hp hn + have hB j:= Appearance.witLaw (a.qB.allure_apt a.t a.z h.2.2.1 j) hp hn + let s:= v.cAxes x.1.1 (toRates i.1.2.1) + let t:= v.cAxes x.2.1 (toRates i.1.2.2) + have hc (j) : 0≤ a.chimera x.1.2 x.2.2 s t m Y j := avg_nonneg (unifOn_sub _).nz + (fun k=> mul_nonneg (a.qA.seraphFloor a.t a.z x.1.2 m s Y j (hA j) k).1 + (a.qB.seraphFloor a.t a.z x.2.2 m t Y j (hB j) k).1) + have hM : 0≤a.momus:= mul_nonneg (kappa_pos _).le (kappa_pos _).le + exact mul_nonneg (ind_nonneg _) (mul_nonneg hM (Finset.prod_nonneg fun i _=>hc i)) + +theorem prognosis (w:LeafMixture p n N) (U: Wgt (UnitType p n N)) (m:Mixer p n) + (b:PreparationParameters) (v:Station p n N b.pins w) (Y:Silhouette p N r) + {ε a : ℝ} (he:0 ≤ ε)(ha:0 eligiblePair v m x.1 x.2 Y a)≤ num (Scrip p b.pins)*(ε/a) := by + classical + let J:= Scrip p b.pins; let I:=ViewPair p n N w; let V:=cirque w U + let Q (i:J)(x:I):= v.twilight i.2.2 m i.2.1 Y x.1.1 x.2.1 (x.1.2,x.2.2) + have ht:= (troupe_bill hs).1; have hv:IsLaw V:=pairW_law ht ht + let P (i:J)(x:I):= i.2.2.permission∧ a ≤ Q i x + have hF (i:J): pr V (P i)≤ ε/a := by + by_cases ht:i.2.2.permission + · simp only [P,ht,true_and] + refine (le_div_iff₀ ha).mpr ?_ + rw [mul_comm] + exact ((le_avg_markov hv.nz (ship_pos w m v i Y ht hp hn) a).trans_eq (ship_cost ..)).trans + (h i ht) + rw [show P i=(fun _=>False) from funext fun a=>eq_false fun hh=>ht hh.1,pr_false]; exact div_nonneg he ha.le + change pr V (fun x=>∃ i,P i x)≤ _ + exact ((pr_exists_le hv.nz P).trans (Finset.sum_le_sum fun i _=> hF i)).trans_eq (by simp [J,num]) + +structure Beams (b:PreparationParameters) (m:Mixer p n) (Y:Silhouette p N r) + (w:LeafMixture p n N)(U:Wgt (UnitType p n N)) (v:Station p n N b.pins w) + (a ε δ τ :ℝ):Prop where + soft : origami p r (wisp p Y) δ + rare : pr (w.sap U) (fun i=>¬gauze p δ δ Y m b.pins i) ≤ τ + zone : pr (cirque w U) (fun x=> eligiblePair v m x.1 x.2 Y a) ≤ τ + haze : 0<δ∧ δ≤ ε + +variable {l:Filter ℕ} {m:cycleM p} {U:tale p M} {w:rhythms p M} {b:PreparationParameters} +set_option maxHeartbeats 1400000 in +theorem lightmap (v:Stations p M b.pins w) (h:veil p M b s0 l m w U) + (a ε τ:ℝ) (ha:0?_⟩ + let ν:=wisp p X i j + have hs : pr ν (fun i=>¬δ≤ν i) = 1-pr ν (fun i=>δ≤ν i) :=by rw [pr_not,(show tot ν=1 + from (h0 i j).total)] + have hi:u≤1/4:=le_trans (min_le_right ..) (min_le_right ..) + simp_rw [not_le] at hs + have hf:= haze_small ν δ hd.le + linarith only [hf,hs,hV,hi,hd] + · apply (prognosis (w n) (U n) (m n) b (v n) X hη.le ha he.hR hn.age + ⟨hC.1,hP,hp.1.law,hC.2⟩ hY).trans + change L*(η/a)≤τ + have h : η/a= τ/(L+1) := by unfold η; field_simp + rw [h,mul_div_assoc',div_le_iff₀ (by linarith)] + linarith only [hτ] + have hi:u≤ε:=le_trans (min_le_right ..) (min_le_left ..) + nlinarith only [hi,hV,hd,Nat.cast_nonneg (α:=ℝ) r] + +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/AmbientBatchSlots.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/AmbientBatchSlots.lean index a3cb00a27079aebcd61977264c289adf1ea08756..ae95ccaa214c11f01f4b28ecd4bd5f9ee6725779 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/AmbientBatchSlots.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/AmbientBatchSlots.lean @@ -1,211 +1,211 @@ -import OAI.Combinatorics.HadwigerCounterexample.TesterSummaryMass -import OAI.Combinatorics.HadwigerCounterexample.ChannelFrameLaws - -namespace OAI - -/-! # Ambient Batch Slots -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Finset Function -open scoped BigOperators -variable {I J G A B : Type} [Fintype I] [Fintype J] [Fintype A] [Fintype B] -variable {p : Shape} {n N : ℕ} - -omit [Fintype B] in -theorem mapW_equiv_val (e : A≃B) (w : Wgt A) (y : B) : - mapW w e y=w (e.symm y) := by - classical - have h : (fun x => e x=y)=(fun x => x=e.symm y) := by - funext x; apply propext - exact ⟨fun h => by rw [← h,Equiv.symm_apply_apply],fun h => by rw [h,Equiv.apply_symm_apply]⟩ - unfold mapW; rw [h]; simp - -theorem unif_equiv (e : A≃B) : mapW unif e = unif := by - funext x; rw [mapW_equiv_val, unif_apply, unif_apply, Fintype.card_congr e] - -theorem on_equiv (e : A≃B) (p : B→Prop) : - mapW (unifOn (fun x => p (e x))) e = unifOn p := by - classical - have h : nbr (fun x => p (e x))=nbr p := Equiv.sum_comp e (fun y => ind (p y)) - funext x - rw [mapW_equiv_val,unifOn_val,unifOn_val]; simp only [Equiv.apply_symm_apply,h] - -abbrev PlusRack (I : Type) (N : ℕ) := Mat (Fin N) I -abbrev Rack (I : Type) (N : ℕ) := PlusRack I N × PlusRack I N -def sectionR {I J : Type} (f : J→I) (x : Rack I N) : Rack J N := - ((x.1).submatrix _root_.id f, (x.2).submatrix _root_.id f) -abbrev Route (I G : Type) := I → G -abbrev Port {I G : Type} (f : Route I G) (g : G) := {i:I//f i=g} -abbrev Network {I G : Type} (f : Route I G) (N : ℕ) := ∀ i,Rack (Port f i) N - -variable [Fintype G] -variable [DecidableEq I] [DecidableEq J] [DecidableEq G] -variable {f : Route I G} - -def rackEquiv (f : Route I G) (N : ℕ) : Rack I N ≃ Network f N where - toFun x i := sectionR Subtype.val x - invFun x := (Matrix.of (fun j i => (x (f i)).1 j ⟨i,rfl⟩), - Matrix.of (fun j i => (x (f i)).2 j ⟨i,rfl⟩)) - left_inv x := by apply Prod.ext <;> rfl - right_inv x := by - funext i; apply Prod.ext <;> - · ext j ⟨y,rfl⟩; rfl - -abbrev GeoM (f : Route I G) := ∀ i,Mat (Port f i) (Port f i) - -def gramPart {N} (A : GeoM f) (x : Rack I N) := - ∀ i,let P:=rackEquiv f N x i; - P.1ᵀ*P.2=A i -def injPart (f : Route I G) {N} (x : Rack I N) := - ∀ i,let P:=rackEquiv f N x i; - Injective P.1.mulVec ∧ Injective P.2.mulVec - -def bothPart {N} (A : GeoM f) (x : Rack I N) := ∀ i, gramGood (A i) (rackEquiv f N x i) - -def scoreR {I : Type} (x : Rack I N) (i j : I) : F := (x.1ᵀ*x.2) i j - -omit [Fintype I] [Fintype G] [DecidableEq I] [DecidableEq G] in -theorem part_scores (x : Rack I N) (A : GeoM f) : - gramPart A x↔ ∀ i, ∀ a b : Port f i,scoreR x a.val b.val=A i a b := by - constructor - · intro h i a b; exact congr_fun (congr_fun (h i) a) b - intro h i; exact Matrix.ext (fun a b => h i a b) - -omit [Fintype G] [DecidableEq I] in -theorem both_test (A : GeoM f) (x : Rack I N) : - bothPart A x↔ gramPart A x ∧injPart f x := by simp [gramPart,injPart,bothPart,gramGood,forall_and] - -private theorem pi_unif {I : Type} [Fintype I] [DecidableEq I] - {A : I→Type} [∀ i,Fintype (A i)] : - unif (α:=(∀ i,A i)) = prodW (fun i => unif (α:=A i)) := by - classical - funext x - simp [unif_apply,prodW,Fintype.card_pi] - -private theorem pi_unifOn {I : Type} [Fintype I] [DecidableEq I] - {A : I→Type} [∀ i,Fintype (A i)] (p : ∀ i,A i→Prop) : - unifOn (fun x => ∀ i,p i (x i)) = prodW (fun i => unifOn (p i)) := by - classical - funext x - rw [unifOn_val] - have he : nbr (fun x : (∀ i, A i) => ∀ i,p i (x i)) = ∏ i,nbr (p i) := by - unfold nbr; simp_rw [ind_all] - exact prodW_tot (fun (i : I) (x : A i) => ind (p i x)) - simp only [prodW,he,unifOn_val,ind_all,Finset.prod_div_distrib] - -def rackStation (A : GeoM f) (N : ℕ) : Wgt (Rack I N) := unifOn (bothPart A) -def rackWave (A : GeoM f) (N : ℕ) : Wgt (Rack I N) := unifOn (gramPart A) - -theorem station_split (A : GeoM f) (N : ℕ) : - mapW (rackStation A N) (rackEquiv f N)= - prodW (fun i => unifOn (gramGood (A i))) := by - classical - unfold rackStation bothPart - rw [show mapW _ _= _ from on_equiv (rackEquiv f N) - (fun x => ∀ i,gramGood (A i) (x i))] - exact pi_unifOn _ - -def netSize (f : Route I G) := ∑ i : G,num (Port f i)*num (Port f i) -def netFact (f : Route I G) := - (4:ℝ)^(Fintype.card G)*bp (netSize f) - -omit [DecidableEq I] in -theorem netFact_pos : 0 gramGood (U:=Fin N) (A i) - have hnum (t : ℕ) : num (Fin t)=(t:ℝ) := by simp [num] - have ht i : num (Port f i) + num (Port f i)-num (Fin N)≤ -1 := by rw [←two_mul,hnum]; exact h _ - have he : pr unif (bothPart (N:=N) A) = ∏ i,pr unif (p i) := by - unfold bothPart - rw [←mapW_pr unif (rackEquiv f N) (fun x => ∀ i,p i (x i)), unif_equiv] - conv_lhs => rw [pi_unif] - exact prodW_pr .. - rw [he]; constructor - · let h' (i : G) := bp (-(num (Port f i))*num (Port f i))/4 - have hh i : h' i ≤ pr unif (p i) := gram_norm_quarter _ (ht _) - refine le_trans ?_ (Finset.prod_le_prod₀ (fun i _ => div_nonneg (bp_pos _).le - (by norm_num)) fun i _ => hh i) - unfold netFact - rw [_root_.mul_inv_rev,Finset.prod_div_distrib,←bp_sum,netSize,Finset.prod_const, - ← bp_neg, ← Finset.sum_neg_distrib] - simp_rw [neg_mul, Finset.card_univ,div_eq_mul_inv] - exact le_rfl - · have h i := - (gram_norm (U:=Fin N) (A i) (show _≤ _ by linarith only [ht i])).1 - unfold netSize - rw [← Finset.sum_neg_distrib, bp_sum] - apply Finset.prod_le_prod₀ (fun i _ => pr_nonneg unif_law.nz) - intro i _ - rw [pair_unif,←neg_mul] - exact h i - -theorem wave_norm (A : GeoM f) (N : ℕ) - (h : ∀ i,2*num (Port f i)-N≤ -1) : - (netFact f)⁻¹ ≤ pr unif (gramPart (N:=N) A) := - ((net_norm A N h).1).trans - (pr_mono unif_law.nz (fun _ hx => ((both_test ..).mp hx).1)) - -theorem injPart_failure (f : Route I G) (N : ℕ) (k : ℝ) (h : ∀ i,num (Port f i)≤k) : - pr unif (fun x : Rack I N => ¬injPart f x)≤num G*(2*bp (k-N)) := by - classical - let Q := fun x : Network f N => - ∀ i, Injective (x i).1.mulVec ∧ Injective (x i).2.mulVec - have he : - pr unif (fun x : Rack I N => ¬injPart f x)= - pr (prodW (fun i : G => unif (α:=Rack (Port f i) N))) (fun x => ¬Q x) := by - rw [←pi_unif,← unif_equiv (rackEquiv f N),mapW_pr] - rfl - rw [he] - let P i := fun x : Rack (Port f i) N => ¬ (Injective x.1.mulVec∧Injective x.2.mulVec) - let w : Wgt (Network f N) := prodW (fun i => unif) - have hw : IsLaw w := prodW_law (fun _ => unif_law) - have ht i : pr unif (P i) ≤ 2*bp (k-N) := by - let g := fun x : PlusRack (Port f i) N => ¬Injective x.mulVec - have hi : pr unif g≤ bp (k-N) := by - refine unif_fail.trans (bp_le ?_) - have he := h i - simp only [num,Fintype.card_fin] at * - linarith only [he] - have hQ (x : Rack (Port f i) N) : - P i x→ (True∧g x.2)∨(g x.1∧True) := by unfold P g; tauto - rw [pair_unif,two_mul] - let nz := (pairW_law (α:=PlusRack (Port f i) N) unif_law (β:=PlusRack (Port f i) N) unif_law).nz - calc pr _ _ - _ ≤ _ := pr_mono nz hQ - _ ≤ _ := pr_or_le nz - _ ≤ _ := by rw [pairW_pr unif unif (fun _ : PlusRack (Port f i) N => True) g,pairW_pr unif unif g (fun _ : PlusRack (Port f i) N => True),pr_true,unif_law.total,one_mul,mul_one] - exact add_le_add hi hi - have hP x (h : ¬Q x) : ∃ i,P i (x i) := Classical.byContradiction (fun g => - h (fun i => Classical.byContradiction (fun he => g ⟨i,he⟩))) - have hc i : - pr w (fun x => P i (x i))=pr unif (P i) := by - let g (j : G) (x : Rack (Port f j) N) := - if h:j=i then by subst i; exact P j x else True - have he (x : Network f N) : - P i (x i) ↔ ∀ j,g j (x j) := by - constructor - · intro h j - by_cases he : j=i - · subst j; exact (by simpa [g]) - simp [g,he] - · intro h; simpa [g] using h i - simp_rw [he]; unfold w; rw [prodW_pr _ g,Finset.prod_eq_single i] - · simp [g] - · intro j _ hj; simp [g,hj,unif_law.total] - simp - refine le_trans (pr_mono hw.nz hP) ((pr_exists_le hw.nz (fun i x => P i (x i))).trans ?_) - simp_rw [hc] - refine (Finset.sum_le_sum fun i _ => ht i).trans_eq ?_ - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,num] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.TesterSummaryMass +import OAI.Combinatorics.HadwigerCounterexample.ChannelFrameLaws + +namespace OAI + +/-! # Ambient Batch Slots -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Finset Function +open scoped BigOperators +variable {I J G A B : Type} [Fintype I] [Fintype J] [Fintype A] [Fintype B] +variable {p : Shape} {n N : ℕ} + +omit [Fintype B] in +theorem mapW_equiv_val (e : A≃B) (w : Wgt A) (y : B) : + mapW w e y=w (e.symm y) := by + classical + have h : (fun x => e x=y)=(fun x => x=e.symm y) := by + funext x; apply propext + exact ⟨fun h => by rw [← h,Equiv.symm_apply_apply],fun h => by rw [h,Equiv.apply_symm_apply]⟩ + unfold mapW; rw [h]; simp + +theorem unif_equiv (e : A≃B) : mapW unif e = unif := by + funext x; rw [mapW_equiv_val, unif_apply, unif_apply, Fintype.card_congr e] + +theorem on_equiv (e : A≃B) (p : B→Prop) : + mapW (unifOn (fun x => p (e x))) e = unifOn p := by + classical + have h : nbr (fun x => p (e x))=nbr p := Equiv.sum_comp e (fun y => ind (p y)) + funext x + rw [mapW_equiv_val,unifOn_val,unifOn_val]; simp only [Equiv.apply_symm_apply,h] + +abbrev PlusRack (I : Type) (N : ℕ) := Mat (Fin N) I +abbrev Rack (I : Type) (N : ℕ) := PlusRack I N × PlusRack I N +def sectionR {I J : Type} (f : J→I) (x : Rack I N) : Rack J N := + ((x.1).submatrix _root_.id f, (x.2).submatrix _root_.id f) +abbrev Route (I G : Type) := I → G +abbrev Port {I G : Type} (f : Route I G) (g : G) := {i:I//f i=g} +abbrev Network {I G : Type} (f : Route I G) (N : ℕ) := ∀ i,Rack (Port f i) N + +variable [Fintype G] +variable [DecidableEq I] [DecidableEq J] [DecidableEq G] +variable {f : Route I G} + +def rackEquiv (f : Route I G) (N : ℕ) : Rack I N ≃ Network f N where + toFun x i := sectionR Subtype.val x + invFun x := (Matrix.of (fun j i => (x (f i)).1 j ⟨i,rfl⟩), + Matrix.of (fun j i => (x (f i)).2 j ⟨i,rfl⟩)) + left_inv x := by apply Prod.ext <;> rfl + right_inv x := by + funext i; apply Prod.ext <;> + · ext j ⟨y,rfl⟩; rfl + +abbrev GeoM (f : Route I G) := ∀ i,Mat (Port f i) (Port f i) + +def gramPart {N} (A : GeoM f) (x : Rack I N) := + ∀ i,let P:=rackEquiv f N x i; + P.1ᵀ*P.2=A i +def injPart (f : Route I G) {N} (x : Rack I N) := + ∀ i,let P:=rackEquiv f N x i; + Injective P.1.mulVec ∧ Injective P.2.mulVec + +def bothPart {N} (A : GeoM f) (x : Rack I N) := ∀ i, gramGood (A i) (rackEquiv f N x i) + +def scoreR {I : Type} (x : Rack I N) (i j : I) : F := (x.1ᵀ*x.2) i j + +omit [Fintype I] [Fintype G] [DecidableEq I] [DecidableEq G] in +theorem part_scores (x : Rack I N) (A : GeoM f) : + gramPart A x↔ ∀ i, ∀ a b : Port f i,scoreR x a.val b.val=A i a b := by + constructor + · intro h i a b; exact congr_fun (congr_fun (h i) a) b + intro h i; exact Matrix.ext (fun a b => h i a b) + +omit [Fintype G] [DecidableEq I] in +theorem both_test (A : GeoM f) (x : Rack I N) : + bothPart A x↔ gramPart A x ∧injPart f x := by simp [gramPart,injPart,bothPart,gramGood,forall_and] + +private theorem pi_unif {I : Type} [Fintype I] [DecidableEq I] + {A : I→Type} [∀ i,Fintype (A i)] : + unif (α:=(∀ i,A i)) = prodW (fun i => unif (α:=A i)) := by + classical + funext x + simp [unif_apply,prodW,Fintype.card_pi] + +private theorem pi_unifOn {I : Type} [Fintype I] [DecidableEq I] + {A : I→Type} [∀ i,Fintype (A i)] (p : ∀ i,A i→Prop) : + unifOn (fun x => ∀ i,p i (x i)) = prodW (fun i => unifOn (p i)) := by + classical + funext x + rw [unifOn_val] + have he : nbr (fun x : (∀ i, A i) => ∀ i,p i (x i)) = ∏ i,nbr (p i) := by + unfold nbr; simp_rw [ind_all] + exact prodW_tot (fun (i : I) (x : A i) => ind (p i x)) + simp only [prodW,he,unifOn_val,ind_all,Finset.prod_div_distrib] + +def rackStation (A : GeoM f) (N : ℕ) : Wgt (Rack I N) := unifOn (bothPart A) +def rackWave (A : GeoM f) (N : ℕ) : Wgt (Rack I N) := unifOn (gramPart A) + +theorem station_split (A : GeoM f) (N : ℕ) : + mapW (rackStation A N) (rackEquiv f N)= + prodW (fun i => unifOn (gramGood (A i))) := by + classical + unfold rackStation bothPart + rw [show mapW _ _= _ from on_equiv (rackEquiv f N) + (fun x => ∀ i,gramGood (A i) (x i))] + exact pi_unifOn _ + +def netSize (f : Route I G) := ∑ i : G,num (Port f i)*num (Port f i) +def netFact (f : Route I G) := + (4:ℝ)^(Fintype.card G)*bp (netSize f) + +omit [DecidableEq I] in +theorem netFact_pos : 0 gramGood (U:=Fin N) (A i) + have hnum (t : ℕ) : num (Fin t)=(t:ℝ) := by simp [num] + have ht i : num (Port f i) + num (Port f i)-num (Fin N)≤ -1 := by rw [←two_mul,hnum]; exact h _ + have he : pr unif (bothPart (N:=N) A) = ∏ i,pr unif (p i) := by + unfold bothPart + rw [←mapW_pr unif (rackEquiv f N) (fun x => ∀ i,p i (x i)), unif_equiv] + conv_lhs => rw [pi_unif] + exact prodW_pr .. + rw [he]; constructor + · let h' (i : G) := bp (-(num (Port f i))*num (Port f i))/4 + have hh i : h' i ≤ pr unif (p i) := gram_norm_quarter _ (ht _) + refine le_trans ?_ (Finset.prod_le_prod₀ (fun i _ => div_nonneg (bp_pos _).le + (by norm_num)) fun i _ => hh i) + unfold netFact + rw [_root_.mul_inv_rev,Finset.prod_div_distrib,←bp_sum,netSize,Finset.prod_const, + ← bp_neg, ← Finset.sum_neg_distrib] + simp_rw [neg_mul, Finset.card_univ,div_eq_mul_inv] + exact le_rfl + · have h i := + (gram_norm (U:=Fin N) (A i) (show _≤ _ by linarith only [ht i])).1 + unfold netSize + rw [← Finset.sum_neg_distrib, bp_sum] + apply Finset.prod_le_prod₀ (fun i _ => pr_nonneg unif_law.nz) + intro i _ + rw [pair_unif,←neg_mul] + exact h i + +theorem wave_norm (A : GeoM f) (N : ℕ) + (h : ∀ i,2*num (Port f i)-N≤ -1) : + (netFact f)⁻¹ ≤ pr unif (gramPart (N:=N) A) := + ((net_norm A N h).1).trans + (pr_mono unif_law.nz (fun _ hx => ((both_test ..).mp hx).1)) + +theorem injPart_failure (f : Route I G) (N : ℕ) (k : ℝ) (h : ∀ i,num (Port f i)≤k) : + pr unif (fun x : Rack I N => ¬injPart f x)≤num G*(2*bp (k-N)) := by + classical + let Q := fun x : Network f N => + ∀ i, Injective (x i).1.mulVec ∧ Injective (x i).2.mulVec + have he : + pr unif (fun x : Rack I N => ¬injPart f x)= + pr (prodW (fun i : G => unif (α:=Rack (Port f i) N))) (fun x => ¬Q x) := by + rw [←pi_unif,← unif_equiv (rackEquiv f N),mapW_pr] + rfl + rw [he] + let P i := fun x : Rack (Port f i) N => ¬ (Injective x.1.mulVec∧Injective x.2.mulVec) + let w : Wgt (Network f N) := prodW (fun i => unif) + have hw : IsLaw w := prodW_law (fun _ => unif_law) + have ht i : pr unif (P i) ≤ 2*bp (k-N) := by + let g := fun x : PlusRack (Port f i) N => ¬Injective x.mulVec + have hi : pr unif g≤ bp (k-N) := by + refine unif_fail.trans (bp_le ?_) + have he := h i + simp only [num,Fintype.card_fin] at * + linarith only [he] + have hQ (x : Rack (Port f i) N) : + P i x→ (True∧g x.2)∨(g x.1∧True) := by unfold P g; tauto + rw [pair_unif,two_mul] + let nz := (pairW_law (α:=PlusRack (Port f i) N) unif_law (β:=PlusRack (Port f i) N) unif_law).nz + calc pr _ _ + _ ≤ _ := pr_mono nz hQ + _ ≤ _ := pr_or_le nz + _ ≤ _ := by rw [pairW_pr unif unif (fun _ : PlusRack (Port f i) N => True) g,pairW_pr unif unif g (fun _ : PlusRack (Port f i) N => True),pr_true,unif_law.total,one_mul,mul_one] + exact add_le_add hi hi + have hP x (h : ¬Q x) : ∃ i,P i (x i) := Classical.byContradiction (fun g => + h (fun i => Classical.byContradiction (fun he => g ⟨i,he⟩))) + have hc i : + pr w (fun x => P i (x i))=pr unif (P i) := by + let g (j : G) (x : Rack (Port f j) N) := + if h:j=i then by subst i; exact P j x else True + have he (x : Network f N) : + P i (x i) ↔ ∀ j,g j (x j) := by + constructor + · intro h j + by_cases he : j=i + · subst j; exact (by simpa [g]) + simp [g,he] + · intro h; simpa [g] using h i + simp_rw [he]; unfold w; rw [prodW_pr _ g,Finset.prod_eq_single i] + · simp [g] + · intro j _ hj; simp [g,hj,unif_law.total] + simp + refine le_trans (pr_mono hw.nz hP) ((pr_exists_le hw.nz (fun i x => P i (x i))).trans ?_) + simp_rw [hc] + refine (Finset.sum_le_sum fun i _ => ht i).trans_eq ?_ + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,num] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/AnalyticParameters.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/AnalyticParameters.lean index 60fdd494e2db8c0a21674160291615c75f5cdc5b..7b5ff363567f2649ed506c477b702018be34ba77 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/AnalyticParameters.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/AnalyticParameters.lean @@ -1,143 +1,143 @@ -import OAI.Combinatorics.HadwigerCounterexample.PairedMassIdentities -import OAI.Combinatorics.HadwigerCounterexample.UnaryPositivityBounds -import OAI.Combinatorics.HadwigerCounterexample.RecursiveComparisonErrors -import OAI.Combinatorics.HadwigerCounterexample.MixerExistence - -namespace OAI - -/-! # Analytic Parameters -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix -open scoped BigOperators Topology -open StatusAnalysis StatusAnalysis.Station - -def frameBills (g K : ℕ) := - 2*Fintype.card (Comp g)*K*qorth K - -structure AnalyticParameters (p : Shape) (M : ℕ) (b : PreparationParameters) (r : ℕ) : Prop where - enter : b.entry p M - thickness : 4≤ M - profiles : 2*profileA p b.pins < r - jump : 1≤p.J - bigJ : r≤p.J - gleaming : bp (-((p.J-r:ℕ):ℝ))*bp r < glintRate b.pins - penRoom : (b.pins+1)*qorth b.pins≤p.j+1 - forbid : frameBills p.g b.pins+1000 ≤ b.B - spare : 3*b.B < Fintype.card (Label p.b) - secure : ∀ᶠ n : ℕ in atTop, Station.earnsScore p n (M*n) b.pins (2*b.ζ) - -namespace PreparationParameters -variable {b : PreparationParameters} {p : Shape} {N M r : ℕ} {l : Filter ℕ} {m : cycleM p} - {s : rhythms p M} {w : tale p M} - -def conflicted {n : ℕ} (p : Shape) (m : Mixer p n) (N : ℕ) (w : Wgt (UnitType p n N)) := - pr (pairW w w) (clash p m N) ((M*n:ℕ):ℝ)) δ ∧ - ∀ᶠ n in l, ∀ (q : Format) (d e : Rates) (x : Typus p q d e) (k : Fin (2^deckMax p b.pins)), - |arena (v n) x (m n) (w n) k|≤δ n := by - let N:=fun n : ℕ=> M*n; let z:=fun n=>((N n):ℝ) - have hq := h.easel - have ht := hq.enter.first - have hz : Tendsto z l atTop := (trend_sizes l h.timeL ht.hM).2 - let C n:= ((s n).amount (w n))⁻¹ - have hc := h.durableS.mass.inv_cap - let δ n := bp (-1*z n)*C n*C n + bp (-0.005*z n)*2 - have hd : ExpSmall l z δ := - (((ExpSmall.bp_n zero_lt_one).mul hc).mul hc).add hz - ((ExpSmall.bp_n (by norm_num)).mul (expO_const hz _)) - refine ⟨δ,hd,?_⟩ - filter_upwards [h.moment,h.durableS.mass.positive,h.durableS.shape,hq.secure.filter_mono h.timeL] - with n hn hN hA hB q d e x k - have hm := hn.1.law - rw [abs_of_nonneg (arena_pos _ _ _ _ _ hN hm)] - let u:=(s n).sap (w n) - refine (arena_bound (v n) x _ _ k hA.1 hm hN hB).trans ?_ - have hμ i : 0≤u i := (LeafMixture.sapLaw hN hm).nz _ - have hk i : u i ≤ C n*w n i := LeafMixture.upper_sap hm hN i - have hv (x:UnitType p n (N n) × UnitType p n (N n)) : - pairW u u x ≤ (C n*C n)*pairW (w n) (w n) x := - (mul_le_mul (hk _) (hk _) (hμ _) ((hμ _).trans (hk _))).trans_eq (by unfold pairW; ring) - have hf : pr (pairW u u) (clash p (m n) (N n)) ≤ - (C n*C n)*bp (-100*p.g * (z n)) := (pr_cap hv _).trans - (mul_le_mul_of_nonneg_left hn.2.2.2.le (mul_self_nonneg _)) - unfold δ - rw [mul_comm _ 2] - refine add_le_add_left ((mul_le_mul_of_nonneg_left hf (bp_pos _).le).trans ?_) _ - calc _ = (beamPrice p (N n) * bp (-100 * p.g * z n))*(C n*C n) := by unfold beamPrice N; ring - _ ≤ _ := (mul_le_mul_of_nonneg_right (beam_cost p (N n) ht.hG) (mul_self_nonneg _)).trans_eq - (by unfold z; rw [neg_one_mul,mul_assoc]) - -structure Align (b : PreparationParameters) (r : ℕ) (p : Shape) (M n : ℕ) (m : Mixer p n) - (u : Wgt (UnitType p n (M*n))) : Prop where - rum : binaryGood m - hymn : unaryGood m b.pins r - age : 2*p.r ≤ n - cols : 2*num (Full p n)<(M*n:ℕ) - drain : Template.drained m b.spJoint u - -set_option maxHeartbeats 1200000 in -theorem veil.upright (h : veil p M b r l m s w) : - ∀ᶠ n in l,Align b r p M n (m n) ((s n).sap (w n)) := by - let z n:= ((M*n:ℕ):ℝ) - have ht := h.easel.enter.first - have hM : 1 ≤ (M:ℝ) := by exact_mod_cast ht.hM - let e : ℝ := 1/(128*M) - have he : 0< e:=by unfold e; positivity - have hz := (trend_sizes l h.timeL ht.hM).2 - let D n:=((s n).amount (w n))⁻¹ - filter_upwards [h.moment,h.durableS.mass.inv_cap e he, - h.durableS.mass.positive,expO_const hz b.L e he, ht.wrap.filter_mono h.timeL, - (eventually_ge_atTop (2*p.r)).filter_mono h.timeL] with n hn he' ht' hL hG hH - have hw := hn.1.law - have h1 (i) := LeafMixture.upper_sap hw ht' i - have h2 : 0≤D n := (inv_pos_of_pos ht').le - have hB : D n * b.L ≤ bp (1/32*(n:ℝ)) := by - have hi : e*z n=(1/128)*(n:ℝ) := by unfold e z; push_cast; field_simp - calc _ ≤ bp (e*z n)*bp (e*z n) := - mul_le_mul ((le_abs_self _).trans he') ((le_abs_self _).trans hL) ht.early.hL - (bp_pos _).le - _ ≤ _ := by rw [←bp_add,hi]; apply bp_le; linarith [(Nat.cast_nonneg n :0≤(n:ℝ))] - have hv := LeafMixture.upperSide hn.1.border h1 h2 hB - refine ⟨hn.2.2.1,hn.2.1,hH,hG.1, LeafMixture.sapLaw ht' hw, hv true,hv false,fun i=>?_⟩ - have hh := hn.1.total i - apply ((h1 i).trans (mul_le_mul_of_nonneg_left hh h2)).trans - rw [←mul_assoc] - refine mul_le_mul_of_nonneg_right ?_ (mul_nonneg (raw_nonneg ..) (raw_nonneg ..)) - have hx : e ≤1 := by unfold e; exact (div_le_iff₀ (by positivity)).mpr (by linarith) - refine (mul_le_mul_of_nonneg_right ((le_abs_self _).trans he') (bp_pos _).le).trans ?_ - rw [←bp_add] - unfold spJoint; refine bp_le ?_; rw [←add_mul] - exact mul_le_mul_of_nonneg_right (by linarith only [hx]) (by positivity) -end PreparationParameters -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PairedMassIdentities +import OAI.Combinatorics.HadwigerCounterexample.UnaryPositivityBounds +import OAI.Combinatorics.HadwigerCounterexample.RecursiveComparisonErrors +import OAI.Combinatorics.HadwigerCounterexample.MixerExistence + +namespace OAI + +/-! # Analytic Parameters -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix +open scoped BigOperators Topology +open StatusAnalysis StatusAnalysis.Station + +def frameBills (g K : ℕ) := + 2*Fintype.card (Comp g)*K*qorth K + +structure AnalyticParameters (p : Shape) (M : ℕ) (b : PreparationParameters) (r : ℕ) : Prop where + enter : b.entry p M + thickness : 4≤ M + profiles : 2*profileA p b.pins < r + jump : 1≤p.J + bigJ : r≤p.J + gleaming : bp (-((p.J-r:ℕ):ℝ))*bp r < glintRate b.pins + penRoom : (b.pins+1)*qorth b.pins≤p.j+1 + forbid : frameBills p.g b.pins+1000 ≤ b.B + spare : 3*b.B < Fintype.card (Label p.b) + secure : ∀ᶠ n : ℕ in atTop, Station.earnsScore p n (M*n) b.pins (2*b.ζ) + +namespace PreparationParameters +variable {b : PreparationParameters} {p : Shape} {N M r : ℕ} {l : Filter ℕ} {m : cycleM p} + {s : rhythms p M} {w : tale p M} + +def conflicted {n : ℕ} (p : Shape) (m : Mixer p n) (N : ℕ) (w : Wgt (UnitType p n N)) := + pr (pairW w w) (clash p m N) ((M*n:ℕ):ℝ)) δ ∧ + ∀ᶠ n in l, ∀ (q : Format) (d e : Rates) (x : Typus p q d e) (k : Fin (2^deckMax p b.pins)), + |arena (v n) x (m n) (w n) k|≤δ n := by + let N:=fun n : ℕ=> M*n; let z:=fun n=>((N n):ℝ) + have hq := h.easel + have ht := hq.enter.first + have hz : Tendsto z l atTop := (trend_sizes l h.timeL ht.hM).2 + let C n:= ((s n).amount (w n))⁻¹ + have hc := h.durableS.mass.inv_cap + let δ n := bp (-1*z n)*C n*C n + bp (-0.005*z n)*2 + have hd : ExpSmall l z δ := + (((ExpSmall.bp_n zero_lt_one).mul hc).mul hc).add hz + ((ExpSmall.bp_n (by norm_num)).mul (expO_const hz _)) + refine ⟨δ,hd,?_⟩ + filter_upwards [h.moment,h.durableS.mass.positive,h.durableS.shape,hq.secure.filter_mono h.timeL] + with n hn hN hA hB q d e x k + have hm := hn.1.law + rw [abs_of_nonneg (arena_pos _ _ _ _ _ hN hm)] + let u:=(s n).sap (w n) + refine (arena_bound (v n) x _ _ k hA.1 hm hN hB).trans ?_ + have hμ i : 0≤u i := (LeafMixture.sapLaw hN hm).nz _ + have hk i : u i ≤ C n*w n i := LeafMixture.upper_sap hm hN i + have hv (x:UnitType p n (N n) × UnitType p n (N n)) : + pairW u u x ≤ (C n*C n)*pairW (w n) (w n) x := + (mul_le_mul (hk _) (hk _) (hμ _) ((hμ _).trans (hk _))).trans_eq (by unfold pairW; ring) + have hf : pr (pairW u u) (clash p (m n) (N n)) ≤ + (C n*C n)*bp (-100*p.g * (z n)) := (pr_cap hv _).trans + (mul_le_mul_of_nonneg_left hn.2.2.2.le (mul_self_nonneg _)) + unfold δ + rw [mul_comm _ 2] + refine add_le_add_left ((mul_le_mul_of_nonneg_left hf (bp_pos _).le).trans ?_) _ + calc _ = (beamPrice p (N n) * bp (-100 * p.g * z n))*(C n*C n) := by unfold beamPrice N; ring + _ ≤ _ := (mul_le_mul_of_nonneg_right (beam_cost p (N n) ht.hG) (mul_self_nonneg _)).trans_eq + (by unfold z; rw [neg_one_mul,mul_assoc]) + +structure Align (b : PreparationParameters) (r : ℕ) (p : Shape) (M n : ℕ) (m : Mixer p n) + (u : Wgt (UnitType p n (M*n))) : Prop where + rum : binaryGood m + hymn : unaryGood m b.pins r + age : 2*p.r ≤ n + cols : 2*num (Full p n)<(M*n:ℕ) + drain : Template.drained m b.spJoint u + +set_option maxHeartbeats 1200000 in +theorem veil.upright (h : veil p M b r l m s w) : + ∀ᶠ n in l,Align b r p M n (m n) ((s n).sap (w n)) := by + let z n:= ((M*n:ℕ):ℝ) + have ht := h.easel.enter.first + have hM : 1 ≤ (M:ℝ) := by exact_mod_cast ht.hM + let e : ℝ := 1/(128*M) + have he : 0< e:=by unfold e; positivity + have hz := (trend_sizes l h.timeL ht.hM).2 + let D n:=((s n).amount (w n))⁻¹ + filter_upwards [h.moment,h.durableS.mass.inv_cap e he, + h.durableS.mass.positive,expO_const hz b.L e he, ht.wrap.filter_mono h.timeL, + (eventually_ge_atTop (2*p.r)).filter_mono h.timeL] with n hn he' ht' hL hG hH + have hw := hn.1.law + have h1 (i) := LeafMixture.upper_sap hw ht' i + have h2 : 0≤D n := (inv_pos_of_pos ht').le + have hB : D n * b.L ≤ bp (1/32*(n:ℝ)) := by + have hi : e*z n=(1/128)*(n:ℝ) := by unfold e z; push_cast; field_simp + calc _ ≤ bp (e*z n)*bp (e*z n) := + mul_le_mul ((le_abs_self _).trans he') ((le_abs_self _).trans hL) ht.early.hL + (bp_pos _).le + _ ≤ _ := by rw [←bp_add,hi]; apply bp_le; linarith [(Nat.cast_nonneg n :0≤(n:ℝ))] + have hv := LeafMixture.upperSide hn.1.border h1 h2 hB + refine ⟨hn.2.2.1,hn.2.1,hH,hG.1, LeafMixture.sapLaw ht' hw, hv true,hv false,fun i=>?_⟩ + have hh := hn.1.total i + apply ((h1 i).trans (mul_le_mul_of_nonneg_left hh h2)).trans + rw [←mul_assoc] + refine mul_le_mul_of_nonneg_right ?_ (mul_nonneg (raw_nonneg ..) (raw_nonneg ..)) + have hx : e ≤1 := by unfold e; exact (div_le_iff₀ (by positivity)).mpr (by linarith) + refine (mul_le_mul_of_nonneg_right ((le_abs_self _).trans he') (bp_pos _).le).trans ?_ + rw [←bp_add] + unfold spJoint; refine bp_le ?_; rw [←add_mul] + exact mul_le_mul_of_nonneg_right (by linarith only [hx]) (by positivity) +end PreparationParameters +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/AtomFlavors.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/AtomFlavors.lean index c469e2b28e5f8f5fb4fcb5308d0cfa192a2fc19e..b5fe271e45ce902086651a94d8b49a184cbfe4a6 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/AtomFlavors.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/AtomFlavors.lean @@ -1,148 +1,148 @@ -import OAI.Combinatorics.HadwigerCounterexample.QuadraticTesters -import OAI.Combinatorics.HadwigerCounterexample.KeyDirections -import OAI.Combinatorics.HadwigerCounterexample.SumRankBounds - -namespace OAI - -/-! # Atom Flavors -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Finset Function -open scoped BigOperators -variable {g r n b : ℕ} {p : Shape} - -abbrev Flavor (g : ℕ) := Option (Option (Finset (Tag g × Tag g))) -namespace Flavor -abbrev full {g : ℕ} : Flavor g := none -abbrev sharedOnly {g : ℕ} : Flavor g := some none -abbrev pure {g : ℕ} (s : Finset (Tag g × Tag g)) : Flavor g := some (some s) - -def keeps (f : Flavor g) (x : Tag g) (y : Block g) : Prop := - match f,y with - | none, .inl (i,_) => allowed i x - | some none,.inl _ => False - | some (some s),.inl (i,j) => allowed i x ∧ (i,j) ∈ s - | some (some _), .inr v => v≠0 - | _, .inr _ => True -instance (f : Flavor g) (x : Tag g) (y : Block g) : Decidable (keeps f x y) := - Classical.propDecidable _ - -theorem keep_o {f : Flavor g} {x : Tag g} {i j} - (h : keeps f x (Block.O i j)) : allowed i x := by - rcases f with (_|_|_) <;> simp [keeps] at h - · exact h - exact h.1 - -theorem keepZ (f : Flavor g) (x : Tag g) : keeps f x Block.Z := by - rcases f with (_|_|_) <;> simp [keeps] -theorem keepSharp (f : Flavor g) (x : Tag g) : keeps f x Block.sharp := by - rcases f with (_|_|_) <;> simp [keeps] - -end Flavor - -abbrev Knobs (g n : ℕ) := Block g → Vec (Fin n) - -def lit (f : Flavor g) (x : Tag g) (y : Knobs g n) : Base g n := - fun i => if f.keeps x i.1 then y i.1 i.2 else 0 - -theorem lit_allows (f : Flavor g) (x : Tag g) (y : Knobs g n) : - allows x (lit f x y) := - fun _ _ h _ => ite_eq_right (fun g => h (Flavor.keep_o g)) - -def useAtom (p : Shape) {n : ℕ} (x : Tag p.g) (s : Label p.b) (f : Flavor p.g) - (y : Knobs p.g n) := atom p x s (lit f x y) -theorem mem_useAtom (p : Shape) {n : ℕ} (x : Tag p.g) (s : Label p.b) - (f : Flavor p.g) (y : Knobs p.g n) : useAtom p x s f y∈Xspace p n := - atom_mem s (lit_allows f x y) - -abbrev ProbeIdx (g : ℕ) := (Tag g × Tag g)⊕Unit -abbrev Digest (g : ℕ) := Vec (ProbeIdx g) - -def asBlock (i : ProbeIdx g) : Block g := i.elim (fun q => Block.O q.1 q.2) (fun _ => Block.S) -theorem asBlock_inj {g : ℕ} : Injective (@asBlock g) := by - rintro (⟨i,j⟩|⟨⟩) (⟨k,l⟩|⟨⟩) e <;> simp_all [asBlock,Block.O,Block.S] - -def zget (y : Vec (Fin n)) (i : ℕ) := if h:i if Flavor.keeps f l (asBlock i) then tested p.r (x (asBlock i)) else 0 - -namespace Digest -variable (q : Digest g) - -def feasible (l : Tag g) (f : Flavor g) := ∀ i,¬ Flavor.keeps f l (asBlock i) → q i=0 - -def diagO := ∑ d : Tag g, ∑ t,q (.inl (d,t)) -def sumBit := q.diagO+q (.inr ()) - -end Digest - -theorem scan_feasible (p : Shape) {n} (l) (f : Flavor p.g) (x : Knobs p.g n) : - (scan p l f x).feasible l f := fun _ h => ite_eq_right h - -theorem scan_is (p : Shape) {n} (l) (s : Label p.b) (f : Flavor p.g) (x : Knobs p.g n) - (i : ProbeIdx p.g) : - scan p l f x i=etab p n (asBlock i) (mom p s (lit f l x)) := by - classical - rw [mom,etab_point] - let d := asBlock i - unfold scan - split - · rename_i he - have hg j : readBit (lit f l x) d j=zget (x d) j := by - by_cases h : j simp [readBit,zget,h,lit,d,he] - unfold tested test - simp_rw [show ∀ j, readBit (lit f l x) (asBlock i) j=zget (x (asBlock i)) j from hg] - rename_i he - unfold test - have hZ j : - readBit (lit f l x) (asBlock i) j=0 := by - by_cases h : j simp [readBit,lit,h,he] - simp_rw [hZ,zero_mul,Finset.sum_const_zero] - -theorem etaScan (p : Shape) {n} (l s f) (x : Knobs p.g n) : - (scan p l f x).sumBit=eta p n (mom p s (lit f l x)) := by - simp only [Digest.sumBit,Digest.diagO,eta,etaO,LinearMap.add_apply,LinearMap.sum_apply] - simp_rw [scan_is p l s] - rfl - -theorem role_scan (p : Shape) {n} (l s f) (x : Knobs p.g n) : - role p n (useAtom p l s f x)=(scan p l f x).diagO := by - unfold Digest.diagO useAtom atom - let M := mom p s (lit f l x) - have h (i : Tag p.g) : - (Pi.single l M : Tag p.g → Moment p n) i∈Wtag p n i := by - by_cases h : i=l - · subst i; rw [Pi.single_eq_same] - exact Submodule.subset_span ⟨_,_,lit_allows f l x,rfl⟩ - simp [h] - rw [role_cut _ _ h,Finset.sum_eq_single l] - · rw [Pi.single_eq_same,etaO,LinearMap.sum_apply] - simp_rw [LinearMap.sum_apply,scan_is p l s] - rfl - · intro i _ hi; simp [hi] - simp - -def dialed (p : Shape) {n} (l : Tag p.g) (f : Flavor p.g) (x : Knobs p.g n) := - (scan p l f x).sumBit - -def spins (p : Shape) (n : ℕ) : Wgt (Knobs p.g n) := draws (Block p.g) unif - -theorem spins_law (p : Shape) (n : ℕ) : IsLaw (spins p n) := draws_law unif_law - -/-- Projection notation for conditioning on a specified (possible) -diagnostic or diagonal only. -/ -def scopedBit (p : Shape) (n : ℕ) (l : Tag p.g) (f : Flavor p.g) (q : F) : - Wgt (Knobs p.g n) := onW (spins p n) (fun x => dialed p l f x=q) -def scopedScan (p : Shape) (n : ℕ) (l : Tag p.g) (f : Flavor p.g) (z : Digest p.g) : - Wgt (Knobs p.g n) := onW (spins p n) (fun x => scan p l f x=z) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.QuadraticTesters +import OAI.Combinatorics.HadwigerCounterexample.KeyDirections +import OAI.Combinatorics.HadwigerCounterexample.SumRankBounds + +namespace OAI + +/-! # Atom Flavors -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Finset Function +open scoped BigOperators +variable {g r n b : ℕ} {p : Shape} + +abbrev Flavor (g : ℕ) := Option (Option (Finset (Tag g × Tag g))) +namespace Flavor +abbrev full {g : ℕ} : Flavor g := none +abbrev sharedOnly {g : ℕ} : Flavor g := some none +abbrev pure {g : ℕ} (s : Finset (Tag g × Tag g)) : Flavor g := some (some s) + +def keeps (f : Flavor g) (x : Tag g) (y : Block g) : Prop := + match f,y with + | none, .inl (i,_) => allowed i x + | some none,.inl _ => False + | some (some s),.inl (i,j) => allowed i x ∧ (i,j) ∈ s + | some (some _), .inr v => v≠0 + | _, .inr _ => True +instance (f : Flavor g) (x : Tag g) (y : Block g) : Decidable (keeps f x y) := + Classical.propDecidable _ + +theorem keep_o {f : Flavor g} {x : Tag g} {i j} + (h : keeps f x (Block.O i j)) : allowed i x := by + rcases f with (_|_|_) <;> simp [keeps] at h + · exact h + exact h.1 + +theorem keepZ (f : Flavor g) (x : Tag g) : keeps f x Block.Z := by + rcases f with (_|_|_) <;> simp [keeps] +theorem keepSharp (f : Flavor g) (x : Tag g) : keeps f x Block.sharp := by + rcases f with (_|_|_) <;> simp [keeps] + +end Flavor + +abbrev Knobs (g n : ℕ) := Block g → Vec (Fin n) + +def lit (f : Flavor g) (x : Tag g) (y : Knobs g n) : Base g n := + fun i => if f.keeps x i.1 then y i.1 i.2 else 0 + +theorem lit_allows (f : Flavor g) (x : Tag g) (y : Knobs g n) : + allows x (lit f x y) := + fun _ _ h _ => ite_eq_right (fun g => h (Flavor.keep_o g)) + +def useAtom (p : Shape) {n : ℕ} (x : Tag p.g) (s : Label p.b) (f : Flavor p.g) + (y : Knobs p.g n) := atom p x s (lit f x y) +theorem mem_useAtom (p : Shape) {n : ℕ} (x : Tag p.g) (s : Label p.b) + (f : Flavor p.g) (y : Knobs p.g n) : useAtom p x s f y∈Xspace p n := + atom_mem s (lit_allows f x y) + +abbrev ProbeIdx (g : ℕ) := (Tag g × Tag g)⊕Unit +abbrev Digest (g : ℕ) := Vec (ProbeIdx g) + +def asBlock (i : ProbeIdx g) : Block g := i.elim (fun q => Block.O q.1 q.2) (fun _ => Block.S) +theorem asBlock_inj {g : ℕ} : Injective (@asBlock g) := by + rintro (⟨i,j⟩|⟨⟩) (⟨k,l⟩|⟨⟩) e <;> simp_all [asBlock,Block.O,Block.S] + +def zget (y : Vec (Fin n)) (i : ℕ) := if h:i if Flavor.keeps f l (asBlock i) then tested p.r (x (asBlock i)) else 0 + +namespace Digest +variable (q : Digest g) + +def feasible (l : Tag g) (f : Flavor g) := ∀ i,¬ Flavor.keeps f l (asBlock i) → q i=0 + +def diagO := ∑ d : Tag g, ∑ t,q (.inl (d,t)) +def sumBit := q.diagO+q (.inr ()) + +end Digest + +theorem scan_feasible (p : Shape) {n} (l) (f : Flavor p.g) (x : Knobs p.g n) : + (scan p l f x).feasible l f := fun _ h => ite_eq_right h + +theorem scan_is (p : Shape) {n} (l) (s : Label p.b) (f : Flavor p.g) (x : Knobs p.g n) + (i : ProbeIdx p.g) : + scan p l f x i=etab p n (asBlock i) (mom p s (lit f l x)) := by + classical + rw [mom,etab_point] + let d := asBlock i + unfold scan + split + · rename_i he + have hg j : readBit (lit f l x) d j=zget (x d) j := by + by_cases h : j simp [readBit,zget,h,lit,d,he] + unfold tested test + simp_rw [show ∀ j, readBit (lit f l x) (asBlock i) j=zget (x (asBlock i)) j from hg] + rename_i he + unfold test + have hZ j : + readBit (lit f l x) (asBlock i) j=0 := by + by_cases h : j simp [readBit,lit,h,he] + simp_rw [hZ,zero_mul,Finset.sum_const_zero] + +theorem etaScan (p : Shape) {n} (l s f) (x : Knobs p.g n) : + (scan p l f x).sumBit=eta p n (mom p s (lit f l x)) := by + simp only [Digest.sumBit,Digest.diagO,eta,etaO,LinearMap.add_apply,LinearMap.sum_apply] + simp_rw [scan_is p l s] + rfl + +theorem role_scan (p : Shape) {n} (l s f) (x : Knobs p.g n) : + role p n (useAtom p l s f x)=(scan p l f x).diagO := by + unfold Digest.diagO useAtom atom + let M := mom p s (lit f l x) + have h (i : Tag p.g) : + (Pi.single l M : Tag p.g → Moment p n) i∈Wtag p n i := by + by_cases h : i=l + · subst i; rw [Pi.single_eq_same] + exact Submodule.subset_span ⟨_,_,lit_allows f l x,rfl⟩ + simp [h] + rw [role_cut _ _ h,Finset.sum_eq_single l] + · rw [Pi.single_eq_same,etaO,LinearMap.sum_apply] + simp_rw [LinearMap.sum_apply,scan_is p l s] + rfl + · intro i _ hi; simp [hi] + simp + +def dialed (p : Shape) {n} (l : Tag p.g) (f : Flavor p.g) (x : Knobs p.g n) := + (scan p l f x).sumBit + +def spins (p : Shape) (n : ℕ) : Wgt (Knobs p.g n) := draws (Block p.g) unif + +theorem spins_law (p : Shape) (n : ℕ) : IsLaw (spins p n) := draws_law unif_law + +/-- Projection notation for conditioning on a specified (possible) +diagnostic or diagonal only. -/ +def scopedBit (p : Shape) (n : ℕ) (l : Tag p.g) (f : Flavor p.g) (q : F) : + Wgt (Knobs p.g n) := onW (spins p n) (fun x => dialed p l f x=q) +def scopedScan (p : Shape) (n : ℕ) (l : Tag p.g) (f : Flavor p.g) (z : Digest p.g) : + Wgt (Knobs p.g n) := onW (spins p n) (fun x => scan p l f x=z) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/AttackCutDecomposition.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/AttackCutDecomposition.lean index 8553b6ffffd6351297d9c478fae8ed0dbac6dbee..a356e7645a8feeaefff9a3338845f43fd305611a 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/AttackCutDecomposition.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/AttackCutDecomposition.lean @@ -1,277 +1,277 @@ -import OAI.Combinatorics.HadwigerCounterexample.ResponseAnnihilators - -namespace OAI - -/-! # Attack Cut Decomposition -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Submodule LinearMap Module Finset -open scoped BigOperators -variable {p : Shape} {n : ℕ} -variable {I J : Type} [Fintype I] [Fintype J] - -theorem colSp_kill (S : Space (Vec I)) (M : Mat I J) : - colSp M ≤ annih S ↔ ∀ x∈S,Mᵀ *ᵥ x=0 := by - constructor - · intro h x hx - refine dot_ext_zero fun y => ?_ - rw [dotProduct_transpose_mulVec,dotProduct_comm] - exact (annih_mem ..).mp (h ⟨y,rfl⟩) x hx - rintro h z ⟨y,rfl⟩ - rw [annih_mem]; intro x hx - rw [dotProduct_comm,mulVecLin_apply,←dotProduct_transpose_mulVec,h x hx,dotProduct_zero] - -theorem box_kill {S : Space (Vec I)} {T : Space (Vec J)} {M : Mat I J} : - M∈box (annih S) (annih T) ↔ (∀ x∈S,Mᵀ *ᵥ x=0) ∧ (∀ y ∈ T,M *ᵥ y=0) := by - rw [box_mem,colSp_kill,colSp_kill,transpose_transpose] - -theorem orth_sub {f b : Plan p n} {x y : Xpair p n} {C : ChanOut p n} {j} - (hx : orth p C f b j x) (hy : orth p C f b j y) : orth p C f b j (x-y) := by - intro D hd A ha; rw [map_sub,hx _ hd _ ha,hy _ hd _ ha,sub_self] - -theorem orth_sum {f b : Plan p n} (x : I→Xpair p n) (c : I→F) {C : ChanOut p n} {j} - (hx : ∀ i,orth p C f b j (x i)) : orth p C f b j (∑ i,c i • x i) := by - intro D hd A ha - rw [map_sum] - refine Finset.sum_eq_zero fun i _ => ?_ - rw [map_smul,hx i _ hd _ ha,smul_zero] - -namespace Volley -variable (v : Volley p n I) - -def strike (t : Tagging p I) (ht : v.legal t) (j : I) : Xpair p n := - Pi.single (v.obj j) (⟨v.atomAt t j,atom_mem _ (ht j)⟩ : Xspace p n) - -theorem strike_here (t : Tagging p I) (ht : v.legal t) - (c : I → F) (i : Bool) : - ((∑ j : I, c j • v.strike t ht j) i).val=∑ j∈v.here i,c j • v.atomAt t j := by - classical - rw [Finset.sum_apply] - simp only [Submodule.coe_sum, Pi.smul_apply,Submodule.coe_smul,here,Finset.sum_filter] - refine Finset.sum_congr rfl fun j _ => ?_ - by_cases h : v.obj j=i - · simp only [ite_eq_left h] - unfold strike - rw [h,Pi.single_eq_same] - simp [strike,h] - -omit [Fintype I] in -theorem strike_pair (t : Tagging p I) (ht : v.legal t) (j : I) (e : Comp p.g) : - purePair p n (v.strike t ht j) e= - if inc e (t j) then vecMulVec (v.rayLoc j) (v.rayLoc j) else 0 := by - classical - simp only [purePair, Finset.sum_apply] - rw [Finset.sum_eq_single (v.obj j)] - · rw [strike,Pi.single_eq_same] - change liftM _ _ (atom p _ _ _ e)=_ - rw [atom_def]; split - · exact liftM_outer _ _ _ _ - rw [map_zero] - · intro i _ hi; rw [strike,Pi.single_eq_of_ne hi]; exact map_zero _ - simp - -theorem strike_orth {a b : Plan p n} {C : ChanOut p n} {i : Bool} - (t : Tagging p I) (ht : v.legal t) (j : I) : - orth p C (v.frozen a t) b i (v.strike t ht j) := by - intro D hd A ha - change ∑ e, _ = _ - refine Finset.sum_eq_zero fun e _ => ?_ - rw [v.strike_pair] - by_cases h : inc e (t j) - · have hy (z) : v.rayLoc j ∈ (v.frozen a t (e,z)) := - Submodule.mem_sup_right (colSp_mem (P:=v.keyM t e) (⟨j,h⟩ : visits p t e)) - let V := v.rayLoc j - have h1 : A e *ᵥ V=0 := (box_kill.mp ((pureSpace_mem _).mp ha e)).2 V (hy false) - have h2 (z) : D (e,z) *ᵥ V=0 := - (box_kill.mp ((deltaSpace_mem _).mp hd _)).2 V (hy z) - rw [ite_eq_left h,mpair_outer,evmat] - change dotProduct V (((C (e,true))ᵀ * D (e,false)+ - (D (e,true))ᵀ * C (e,false)+A e) *ᵥ V)=_ - simp only [Matrix.add_mulVec, ← Matrix.mulVec_mulVec,h1,h2,mulVec_zero, - dotProduct_zero,zero_add,add_zero,dotProduct_transpose_mulVec] - rw [ite_eq_right h,map_zero] -end Volley - -def labStruct (p : Shape) (n : ℕ) (M : Moment p n) (R : ℕ) - (L : Finset (Label p.b)) (Z : Label p.b→BaseMat p n) := - M=labelSum p L Z ∧ L.card ≤ R ∧ (∀ s,s∉L → Z s=0) ∧ - ∀ s∈L,(Z s)ᵀ=Z s ∧ ∀ i,Z s i i=Z s none i - -private theorem struct_tri {M1 M2 M3 : Moment p n} {R : ℕ} - {L1 L2 L3 : Finset (Label p.b)} {Z1 Z2 Z3 : Label p.b→BaseMat p n} - (h1 : labStruct p n M1 R L1 Z1) - (h2 : labStruct p n M2 R L2 Z2) - (h3 : labStruct p n M3 R L3 Z3) - (hr : 3*R≤p.j) (hm : M1+M2+M3=0) (s : Label p.b) : - Z1 s+Z2 s+Z3 s=0 := by - classical - let W := L1∪L2∪L3 - have hs1 : L1⊆W := subset_trans subset_union_left subset_union_left - have hs2 : L2⊆W := subset_trans subset_union_right subset_union_left - have hs3 : L3⊆W := subset_union_right - have hh : W.card ≤ p.j+1 := - (Finset.card_union_le (L1∪L2) L3).trans ((add_le_add - ((Finset.card_union_le L1 L2).trans (add_le_add h1.2.1 h2.2.1)) h3.2.1).trans (by omega)) - by_cases hs : s∈W - · have hv {M : Moment p n} {L Z} (h : labStruct p n M R L Z) (hL : L ⊆ W) - (i j : AIdx p.g n) (r : SelIdx p.b p.j) : - (∑ s∈W,Z s i j*monoBit s r.val) = M (r,i) (emptySel,j) := by - rw [h.1,labelSum, Matrix.sum_apply,←Finset.sum_subset hL] - · simp only [mput_apply,emptySel,monoBit,Finset.prod_empty,mul_one,mul_comm] - intro y _ hy - simp [h.2.2.1 y hy] - ext i j - refine selector_indep W (fun s => (Z1 s i j+Z2 s i j+Z3 s i j)) p.j hh ?_ s hs - intro T hT - let r : SelIdx p.b p.j := ⟨T,hT⟩ - simp only [add_mul,Finset.sum_add_distrib] - rw [hv h1 hs1 i j r,hv h2 hs2 i j r,hv h3 hs3 i j r] - exact congr_fun (congr_fun hm (r,i)) (emptySel,j) - rw [h1.2.2.1 s (fun h => hs (hs1 h)), h2.2.2.1 s (fun h => hs (hs2 h)), - h3.2.2.1 s (fun h => hs (hs3 h)), zero_add,zero_add] - -namespace Volley -variable {v : Volley p n I} - -private theorem orth_structure {x : Xpair p n} {a b : Plan p n} - {C : ChanOut p n} {t : Tagging p I} {w : I→Bool} {j : Bool} - (hb : v.bounded w) (ho : orth p C (v.frozen a t) b j x) - (R : ℕ) (hr : 2*planRank a+28≤R) (hj : 6*R+4 ≤ p.j) - (i : Bool) (e : Comp p.g) : - ∃ L Z,labStruct p n ((x i).val e) R L Z := by - classical - have h (z) := v.frozen_here_dim hb a t i z - have he : ((x i).val e).rank ≤ R := - (rank_vanish (vanish_one ho i e)).trans - ((Nat.add_le_add (h (e,true)) (h (e,false))).trans (by omega)) - have hf : ((x i).val e)∈ Wspace p n := by - obtain ⟨w,h,hx⟩ := mem_X.mp (x i).property - rw [← hx] - exact ((Wspace p n).add_mem ((Wtag_le _) (h e.val.1)) ((Wtag_le _) (h e.val.2))) - obtain ⟨L,Z,hL,_,hZ,hA⟩ := label_support hf R hj he - let g (s : Label p.b) := if s∈L then Z s else 0 - refine ⟨L,g,?_,hL,(fun s hs => ite_eq_right hs), fun s hs => ?_⟩ - · rw [hZ] - exact Finset.sum_congr rfl fun s hs => by simp [g,hs] - simp only [g,ite_eq_left hs] - exact hA _ hs - -private theorem edge_at (l : Tag p.g) (e : Comp p.g) (h : inc e l) : - ∃ (k : Tag p.g) (h : l≠k),e = edge l k h := by - rcases e with ⟨⟨i,j⟩,hj⟩ - change i=l∨j=l at h - rcases h with rfl|rfl - · exact ⟨j,hj.ne,(edge_eq hj).symm⟩ - exact ⟨i,hj.ne.symm, by rw [edge_symm,edge_eq hj]⟩ - -private theorem cut_tri {x : Profile p n} (hx : x∈Xspace p n) - (l k j : Tag p.g) (h : l≠k) (h' : l ≠ j) (h'' : k≠j) : - x (edge l k h)+x (edge l j h')+x (edge k j h'')=0 := by - obtain ⟨w,hv,rfl⟩ := mem_X.mp hx - rw [← getPair_edge l k h (cut p n w), ←getPair_edge l j h' (cut p n w), ←getPair_edge k j h'' (cut p n w), - getPair_cut,getPair_cut,getPair_cut] - have he (x y z : Moment p n) : x+y+(x+z)+(y+z)=0 := calc - _ = (x+x)+(y+y)+(z+z) := by ac_rfl - _ = _ := by simp only [char_two] - exact he _ _ _ - -private theorem structure_mark {x : Xpair p n} {a b : Plan p n} - {C : ChanOut p n} {t : Tagging p I} {w : I→Bool} {j : Bool} - {q R : ℕ} (hb : v.bounded w) (ho : orth p C (v.frozen a t) b j x) (hv : v.avoids a q) - (hr : 6*R+4≤p.j) (hq : R+14≤q) - (l : I) - {L : Comp p.g → Finset (Label p.b)} {Z : Comp p.g → Label p.b → BaseMat p n} - (he : ∀ e,labStruct p n ((x (v.obj l)).val e) R (L e) (Z e)) : - ∃ c : F, ∀ e,mput p (v.sel l) (Z e (v.sel l))=c • v.atomAt t l e := by - classical - let s := v.sel l - let u := t l - let M := vecMulVec (baseV (v.par l)) (baseV (v.par l)) - let coeff := fun e : Comp p.g => Z e s none none - have h1 (e : Comp p.g) : Z e s= if inc e u then coeff e • M else 0 := by - have ⟨hE,hL,hT,hH⟩ := he e - exact mark_atom hb t hv l e _ (le_trans (Nat.add_le_add_right hL 14) hq) - _ hT hH (hE ▸ vanish_one ho (v.obj l) e) - have h2 (e f : Comp p.g) (h : inc e u) (h' : inc f u) : - coeff e=coeff f := by - by_cases hi : e=f - · rw [hi] - obtain ⟨k,hk,rfl⟩ := edge_at u e h - obtain ⟨u2,hl,rfl⟩ := edge_at u f h' - have hj : k ≠ u2 := by rintro rfl; exact hi rfl - have hh := cut_tri (x (v.obj l)).property u k u2 hk hl hj - have heq := struct_tri (he (edge u k hk)) (he (edge u u2 hl)) (he (edge k u2 hj)) - (by omega) hh s - have hn : ¬ inc (edge k u2 hj) u := fun he => by - rcases (inc_edge_iff _).mp he with h|h; exact hk h.symm; exact hl h.symm - rw [h1 (edge k u2 hj), ite_eq_right hn,add_zero] at heq - have h0 := congr_fun (congr_fun heq none) none - change coeff _ + coeff _ = 0 at h0 - exact add_right_cancel (h0.trans (char_two _).symm) - have h3 (e) : mput p s (Z e s)= coeff e • v.atomAt t l e := by - rw [h1,atomAt,atom_def] - by_cases hf : inc e u - · rw [ite_eq_left hf,ite_eq_left hf,map_smul] - change coeff e • liftM (labMat p n s) (labMat p n s) M=_ - unfold M - rw [liftM_outer,labMat_act]; rfl - rw [ite_eq_right hf,ite_eq_right hf,map_zero,smul_zero] - by_cases hh : ∃ e,inc e u - · obtain ⟨f,hf⟩ := hh - refine ⟨coeff f,fun e => ?_⟩ - by_cases h : inc e u - · exact (h3 e).trans (by rw [h2 e f h hf]) - refine (h3 e).trans ?_ - rw [atomAt,atom_def,ite_eq_right h,smul_zero,smul_zero] - refine ⟨0,fun e => ?_⟩ - refine (h3 e).trans ?_ - rw [atomAt,atom_def,ite_eq_right (show ¬inc e u from fun he => hh ⟨e,he⟩), - smul_zero,zero_smul] - -/-- a component uses at most R nonattack labels. -/ -def clean (v : Volley p n I) (i : Bool) (R : ℕ) (M : Moment p n) := - ∃ (L : Finset (Label p.b)) (Z : Label p.b → BaseMat p n), - M=labelSum p L Z ∧ L.card≤R ∧ Disjoint L (v.marked i) - -theorem split_orth {x : Xpair p n} {a b : Plan p n} - {C : ChanOut p n} {t : Tagging p I} {w : I→Bool} {j : Bool} - {q R : ℕ} (hb : v.bounded w) (ht : v.legal t) - (ho : orth p C (v.frozen a t) b j x) (hv : v.avoids a q) - (hr : 6*R+4≤p.j) (hr' : 2*planRank a+28≤R) (hq : R+14≤q) : - ∃ (c : I → F) (y : Xpair p n), x=y+∑ i,c i • v.strike t ht i ∧ - orth p C (v.frozen a t) b j y ∧ ∀ i e,v.clean i R ((y i).val e) := by - classical - choose L Z hZ using orth_structure hb ho R hr' hr - choose c hc using fun l => structure_mark hb ho hv hr hq l (hZ (v.obj l)) - let A := ∑ i,c i • v.strike t ht i - refine ⟨c,x-A,(sub_add_cancel x A).symm,orth_sub ho (orth_sum _ _ (v.strike_orth t ht)), - fun i e => ?_⟩ - obtain ⟨B,h1,hA,hv',h3⟩ := hv i - let T := v.marked i - have he : (A i).val e=labelSum p T (Z i e) := by - rw [show (A i).val=_ from v.strike_here t ht c i, Finset.sum_apply] - dsimp only [labelSum,T,marked] - rw [Finset.sum_image h3] - refine Finset.sum_congr rfl fun l hl => ?_ - have he : v.obj l=i := (mem_filter.mp hl).2 - exact (he ▸ hc l e).symm - let W := L i e - refine ⟨W \ T,Z i e,?_,(Finset.card_le_card sdiff_subset).trans (hZ i e).2.1, ?_⟩ - · change (x i).val e-(A i).val e=_ - rw [(hZ i e).1,he] - have hz : labelSum p W (Z i e)=labelSum p (W∪T) (Z i e) := by - refine Finset.sum_subset subset_union_left fun s _ hs => ?_ - rw [(hZ i e).2.2.1 s hs,map_zero] - rw [hz] - have hS : (W∪T)=(W \ T) ∪ T := by ext i; simp - rw [hS,labelSum,Finset.sum_union (show Disjoint (W \ T) T from Disjoint.symm disjoint_sdiff)] - exact add_sub_cancel_right _ _ - exact Disjoint.symm disjoint_sdiff - -end Volley -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ResponseAnnihilators + +namespace OAI + +/-! # Attack Cut Decomposition -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Submodule LinearMap Module Finset +open scoped BigOperators +variable {p : Shape} {n : ℕ} +variable {I J : Type} [Fintype I] [Fintype J] + +theorem colSp_kill (S : Space (Vec I)) (M : Mat I J) : + colSp M ≤ annih S ↔ ∀ x∈S,Mᵀ *ᵥ x=0 := by + constructor + · intro h x hx + refine dot_ext_zero fun y => ?_ + rw [dotProduct_transpose_mulVec,dotProduct_comm] + exact (annih_mem ..).mp (h ⟨y,rfl⟩) x hx + rintro h z ⟨y,rfl⟩ + rw [annih_mem]; intro x hx + rw [dotProduct_comm,mulVecLin_apply,←dotProduct_transpose_mulVec,h x hx,dotProduct_zero] + +theorem box_kill {S : Space (Vec I)} {T : Space (Vec J)} {M : Mat I J} : + M∈box (annih S) (annih T) ↔ (∀ x∈S,Mᵀ *ᵥ x=0) ∧ (∀ y ∈ T,M *ᵥ y=0) := by + rw [box_mem,colSp_kill,colSp_kill,transpose_transpose] + +theorem orth_sub {f b : Plan p n} {x y : Xpair p n} {C : ChanOut p n} {j} + (hx : orth p C f b j x) (hy : orth p C f b j y) : orth p C f b j (x-y) := by + intro D hd A ha; rw [map_sub,hx _ hd _ ha,hy _ hd _ ha,sub_self] + +theorem orth_sum {f b : Plan p n} (x : I→Xpair p n) (c : I→F) {C : ChanOut p n} {j} + (hx : ∀ i,orth p C f b j (x i)) : orth p C f b j (∑ i,c i • x i) := by + intro D hd A ha + rw [map_sum] + refine Finset.sum_eq_zero fun i _ => ?_ + rw [map_smul,hx i _ hd _ ha,smul_zero] + +namespace Volley +variable (v : Volley p n I) + +def strike (t : Tagging p I) (ht : v.legal t) (j : I) : Xpair p n := + Pi.single (v.obj j) (⟨v.atomAt t j,atom_mem _ (ht j)⟩ : Xspace p n) + +theorem strike_here (t : Tagging p I) (ht : v.legal t) + (c : I → F) (i : Bool) : + ((∑ j : I, c j • v.strike t ht j) i).val=∑ j∈v.here i,c j • v.atomAt t j := by + classical + rw [Finset.sum_apply] + simp only [Submodule.coe_sum, Pi.smul_apply,Submodule.coe_smul,here,Finset.sum_filter] + refine Finset.sum_congr rfl fun j _ => ?_ + by_cases h : v.obj j=i + · simp only [ite_eq_left h] + unfold strike + rw [h,Pi.single_eq_same] + simp [strike,h] + +omit [Fintype I] in +theorem strike_pair (t : Tagging p I) (ht : v.legal t) (j : I) (e : Comp p.g) : + purePair p n (v.strike t ht j) e= + if inc e (t j) then vecMulVec (v.rayLoc j) (v.rayLoc j) else 0 := by + classical + simp only [purePair, Finset.sum_apply] + rw [Finset.sum_eq_single (v.obj j)] + · rw [strike,Pi.single_eq_same] + change liftM _ _ (atom p _ _ _ e)=_ + rw [atom_def]; split + · exact liftM_outer _ _ _ _ + rw [map_zero] + · intro i _ hi; rw [strike,Pi.single_eq_of_ne hi]; exact map_zero _ + simp + +theorem strike_orth {a b : Plan p n} {C : ChanOut p n} {i : Bool} + (t : Tagging p I) (ht : v.legal t) (j : I) : + orth p C (v.frozen a t) b i (v.strike t ht j) := by + intro D hd A ha + change ∑ e, _ = _ + refine Finset.sum_eq_zero fun e _ => ?_ + rw [v.strike_pair] + by_cases h : inc e (t j) + · have hy (z) : v.rayLoc j ∈ (v.frozen a t (e,z)) := + Submodule.mem_sup_right (colSp_mem (P:=v.keyM t e) (⟨j,h⟩ : visits p t e)) + let V := v.rayLoc j + have h1 : A e *ᵥ V=0 := (box_kill.mp ((pureSpace_mem _).mp ha e)).2 V (hy false) + have h2 (z) : D (e,z) *ᵥ V=0 := + (box_kill.mp ((deltaSpace_mem _).mp hd _)).2 V (hy z) + rw [ite_eq_left h,mpair_outer,evmat] + change dotProduct V (((C (e,true))ᵀ * D (e,false)+ + (D (e,true))ᵀ * C (e,false)+A e) *ᵥ V)=_ + simp only [Matrix.add_mulVec, ← Matrix.mulVec_mulVec,h1,h2,mulVec_zero, + dotProduct_zero,zero_add,add_zero,dotProduct_transpose_mulVec] + rw [ite_eq_right h,map_zero] +end Volley + +def labStruct (p : Shape) (n : ℕ) (M : Moment p n) (R : ℕ) + (L : Finset (Label p.b)) (Z : Label p.b→BaseMat p n) := + M=labelSum p L Z ∧ L.card ≤ R ∧ (∀ s,s∉L → Z s=0) ∧ + ∀ s∈L,(Z s)ᵀ=Z s ∧ ∀ i,Z s i i=Z s none i + +private theorem struct_tri {M1 M2 M3 : Moment p n} {R : ℕ} + {L1 L2 L3 : Finset (Label p.b)} {Z1 Z2 Z3 : Label p.b→BaseMat p n} + (h1 : labStruct p n M1 R L1 Z1) + (h2 : labStruct p n M2 R L2 Z2) + (h3 : labStruct p n M3 R L3 Z3) + (hr : 3*R≤p.j) (hm : M1+M2+M3=0) (s : Label p.b) : + Z1 s+Z2 s+Z3 s=0 := by + classical + let W := L1∪L2∪L3 + have hs1 : L1⊆W := subset_trans subset_union_left subset_union_left + have hs2 : L2⊆W := subset_trans subset_union_right subset_union_left + have hs3 : L3⊆W := subset_union_right + have hh : W.card ≤ p.j+1 := + (Finset.card_union_le (L1∪L2) L3).trans ((add_le_add + ((Finset.card_union_le L1 L2).trans (add_le_add h1.2.1 h2.2.1)) h3.2.1).trans (by omega)) + by_cases hs : s∈W + · have hv {M : Moment p n} {L Z} (h : labStruct p n M R L Z) (hL : L ⊆ W) + (i j : AIdx p.g n) (r : SelIdx p.b p.j) : + (∑ s∈W,Z s i j*monoBit s r.val) = M (r,i) (emptySel,j) := by + rw [h.1,labelSum, Matrix.sum_apply,←Finset.sum_subset hL] + · simp only [mput_apply,emptySel,monoBit,Finset.prod_empty,mul_one,mul_comm] + intro y _ hy + simp [h.2.2.1 y hy] + ext i j + refine selector_indep W (fun s => (Z1 s i j+Z2 s i j+Z3 s i j)) p.j hh ?_ s hs + intro T hT + let r : SelIdx p.b p.j := ⟨T,hT⟩ + simp only [add_mul,Finset.sum_add_distrib] + rw [hv h1 hs1 i j r,hv h2 hs2 i j r,hv h3 hs3 i j r] + exact congr_fun (congr_fun hm (r,i)) (emptySel,j) + rw [h1.2.2.1 s (fun h => hs (hs1 h)), h2.2.2.1 s (fun h => hs (hs2 h)), + h3.2.2.1 s (fun h => hs (hs3 h)), zero_add,zero_add] + +namespace Volley +variable {v : Volley p n I} + +private theorem orth_structure {x : Xpair p n} {a b : Plan p n} + {C : ChanOut p n} {t : Tagging p I} {w : I→Bool} {j : Bool} + (hb : v.bounded w) (ho : orth p C (v.frozen a t) b j x) + (R : ℕ) (hr : 2*planRank a+28≤R) (hj : 6*R+4 ≤ p.j) + (i : Bool) (e : Comp p.g) : + ∃ L Z,labStruct p n ((x i).val e) R L Z := by + classical + have h (z) := v.frozen_here_dim hb a t i z + have he : ((x i).val e).rank ≤ R := + (rank_vanish (vanish_one ho i e)).trans + ((Nat.add_le_add (h (e,true)) (h (e,false))).trans (by omega)) + have hf : ((x i).val e)∈ Wspace p n := by + obtain ⟨w,h,hx⟩ := mem_X.mp (x i).property + rw [← hx] + exact ((Wspace p n).add_mem ((Wtag_le _) (h e.val.1)) ((Wtag_le _) (h e.val.2))) + obtain ⟨L,Z,hL,_,hZ,hA⟩ := label_support hf R hj he + let g (s : Label p.b) := if s∈L then Z s else 0 + refine ⟨L,g,?_,hL,(fun s hs => ite_eq_right hs), fun s hs => ?_⟩ + · rw [hZ] + exact Finset.sum_congr rfl fun s hs => by simp [g,hs] + simp only [g,ite_eq_left hs] + exact hA _ hs + +private theorem edge_at (l : Tag p.g) (e : Comp p.g) (h : inc e l) : + ∃ (k : Tag p.g) (h : l≠k),e = edge l k h := by + rcases e with ⟨⟨i,j⟩,hj⟩ + change i=l∨j=l at h + rcases h with rfl|rfl + · exact ⟨j,hj.ne,(edge_eq hj).symm⟩ + exact ⟨i,hj.ne.symm, by rw [edge_symm,edge_eq hj]⟩ + +private theorem cut_tri {x : Profile p n} (hx : x∈Xspace p n) + (l k j : Tag p.g) (h : l≠k) (h' : l ≠ j) (h'' : k≠j) : + x (edge l k h)+x (edge l j h')+x (edge k j h'')=0 := by + obtain ⟨w,hv,rfl⟩ := mem_X.mp hx + rw [← getPair_edge l k h (cut p n w), ←getPair_edge l j h' (cut p n w), ←getPair_edge k j h'' (cut p n w), + getPair_cut,getPair_cut,getPair_cut] + have he (x y z : Moment p n) : x+y+(x+z)+(y+z)=0 := calc + _ = (x+x)+(y+y)+(z+z) := by ac_rfl + _ = _ := by simp only [char_two] + exact he _ _ _ + +private theorem structure_mark {x : Xpair p n} {a b : Plan p n} + {C : ChanOut p n} {t : Tagging p I} {w : I→Bool} {j : Bool} + {q R : ℕ} (hb : v.bounded w) (ho : orth p C (v.frozen a t) b j x) (hv : v.avoids a q) + (hr : 6*R+4≤p.j) (hq : R+14≤q) + (l : I) + {L : Comp p.g → Finset (Label p.b)} {Z : Comp p.g → Label p.b → BaseMat p n} + (he : ∀ e,labStruct p n ((x (v.obj l)).val e) R (L e) (Z e)) : + ∃ c : F, ∀ e,mput p (v.sel l) (Z e (v.sel l))=c • v.atomAt t l e := by + classical + let s := v.sel l + let u := t l + let M := vecMulVec (baseV (v.par l)) (baseV (v.par l)) + let coeff := fun e : Comp p.g => Z e s none none + have h1 (e : Comp p.g) : Z e s= if inc e u then coeff e • M else 0 := by + have ⟨hE,hL,hT,hH⟩ := he e + exact mark_atom hb t hv l e _ (le_trans (Nat.add_le_add_right hL 14) hq) + _ hT hH (hE ▸ vanish_one ho (v.obj l) e) + have h2 (e f : Comp p.g) (h : inc e u) (h' : inc f u) : + coeff e=coeff f := by + by_cases hi : e=f + · rw [hi] + obtain ⟨k,hk,rfl⟩ := edge_at u e h + obtain ⟨u2,hl,rfl⟩ := edge_at u f h' + have hj : k ≠ u2 := by rintro rfl; exact hi rfl + have hh := cut_tri (x (v.obj l)).property u k u2 hk hl hj + have heq := struct_tri (he (edge u k hk)) (he (edge u u2 hl)) (he (edge k u2 hj)) + (by omega) hh s + have hn : ¬ inc (edge k u2 hj) u := fun he => by + rcases (inc_edge_iff _).mp he with h|h; exact hk h.symm; exact hl h.symm + rw [h1 (edge k u2 hj), ite_eq_right hn,add_zero] at heq + have h0 := congr_fun (congr_fun heq none) none + change coeff _ + coeff _ = 0 at h0 + exact add_right_cancel (h0.trans (char_two _).symm) + have h3 (e) : mput p s (Z e s)= coeff e • v.atomAt t l e := by + rw [h1,atomAt,atom_def] + by_cases hf : inc e u + · rw [ite_eq_left hf,ite_eq_left hf,map_smul] + change coeff e • liftM (labMat p n s) (labMat p n s) M=_ + unfold M + rw [liftM_outer,labMat_act]; rfl + rw [ite_eq_right hf,ite_eq_right hf,map_zero,smul_zero] + by_cases hh : ∃ e,inc e u + · obtain ⟨f,hf⟩ := hh + refine ⟨coeff f,fun e => ?_⟩ + by_cases h : inc e u + · exact (h3 e).trans (by rw [h2 e f h hf]) + refine (h3 e).trans ?_ + rw [atomAt,atom_def,ite_eq_right h,smul_zero,smul_zero] + refine ⟨0,fun e => ?_⟩ + refine (h3 e).trans ?_ + rw [atomAt,atom_def,ite_eq_right (show ¬inc e u from fun he => hh ⟨e,he⟩), + smul_zero,zero_smul] + +/-- a component uses at most R nonattack labels. -/ +def clean (v : Volley p n I) (i : Bool) (R : ℕ) (M : Moment p n) := + ∃ (L : Finset (Label p.b)) (Z : Label p.b → BaseMat p n), + M=labelSum p L Z ∧ L.card≤R ∧ Disjoint L (v.marked i) + +theorem split_orth {x : Xpair p n} {a b : Plan p n} + {C : ChanOut p n} {t : Tagging p I} {w : I→Bool} {j : Bool} + {q R : ℕ} (hb : v.bounded w) (ht : v.legal t) + (ho : orth p C (v.frozen a t) b j x) (hv : v.avoids a q) + (hr : 6*R+4≤p.j) (hr' : 2*planRank a+28≤R) (hq : R+14≤q) : + ∃ (c : I → F) (y : Xpair p n), x=y+∑ i,c i • v.strike t ht i ∧ + orth p C (v.frozen a t) b j y ∧ ∀ i e,v.clean i R ((y i).val e) := by + classical + choose L Z hZ using orth_structure hb ho R hr' hr + choose c hc using fun l => structure_mark hb ho hv hr hq l (hZ (v.obj l)) + let A := ∑ i,c i • v.strike t ht i + refine ⟨c,x-A,(sub_add_cancel x A).symm,orth_sub ho (orth_sum _ _ (v.strike_orth t ht)), + fun i e => ?_⟩ + obtain ⟨B,h1,hA,hv',h3⟩ := hv i + let T := v.marked i + have he : (A i).val e=labelSum p T (Z i e) := by + rw [show (A i).val=_ from v.strike_here t ht c i, Finset.sum_apply] + dsimp only [labelSum,T,marked] + rw [Finset.sum_image h3] + refine Finset.sum_congr rfl fun l hl => ?_ + have he : v.obj l=i := (mem_filter.mp hl).2 + exact (he ▸ hc l e).symm + let W := L i e + refine ⟨W \ T,Z i e,?_,(Finset.card_le_card sdiff_subset).trans (hZ i e).2.1, ?_⟩ + · change (x i).val e-(A i).val e=_ + rw [(hZ i e).1,he] + have hz : labelSum p W (Z i e)=labelSum p (W∪T) (Z i e) := by + refine Finset.sum_subset subset_union_left fun s _ hs => ?_ + rw [(hZ i e).2.2.1 s hs,map_zero] + rw [hz] + have hS : (W∪T)=(W \ T) ∪ T := by ext i; simp + rw [hS,labelSum,Finset.sum_union (show Disjoint (W \ T) T from Disjoint.symm disjoint_sdiff)] + exact add_sub_cancel_right _ _ + exact Disjoint.symm disjoint_sdiff + +end Volley +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/BaselineExtension.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/BaselineExtension.lean index b6a244c2b7fd5f83c2fa6134ab20ecb653d17edb..2779ff0ac3935fa1fa90022777b23a747bdf0443 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/BaselineExtension.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/BaselineExtension.lean @@ -1,124 +1,124 @@ -import OAI.Combinatorics.HadwigerCounterexample.PrimalChannelDecomposition - -namespace OAI - -/-! # Baseline Extension -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Submodule - -variable {p : Shape} {n : ℕ} - -theorem project_table (a : Plan p n) (z : Place p) (Q : Space (Dir p n)) - (hq : Q ≤ primal p n) (hd : Disjoint (tabSpace a z) Q) : - ∃ B, ProjData (tabSpace a z) Q B ∧ ∀ x∈ primal p n, B*ᵥx∈prSmall a z := by - classical - let H := channels p n - let A := primal p n - let P := prSmall a z - have hp : P≤ A := prSmall_le _ _ - have he : tabSpace a z=P ⊔ H := prSmall_table a z - obtain ⟨X,hX⟩ := proj_exists H A channels_disjoint.symm - have hj : Disjoint P (Q⊔H) := by - rw [disjoint_iff_inf_le] - rintro v ⟨hv,hv'⟩ - obtain ⟨y,hy,w,hw,g⟩ := Submodule.mem_sup.mp hv' - have h := (show w=v-y by rw [←g]; abel) ▸ - A.sub_mem (hp hv) (hq hy) - have hz : w∈ A ⊓ H := ⟨h,hw⟩ - rw [channels_disjoint.eq_bot] at hz - have hi : w=0 := by simpa using hz - rw [hi,add_zero] at g - have ht : v∈tabSpace a z ⊓ Q := - ⟨he.symm ▸ Submodule.mem_sup_left hv,g ▸ hy⟩ - rwa [hd.eq_bot] at ht - obtain ⟨Y,hY⟩ := proj_exists P (Q⊔H) hj - refine ⟨X+Y,⟨fun x => ?_,fun x hx => ?_,fun x hx => ?_⟩, fun x hx => ?_⟩ - · rw [add_mulVec,he,add_comm]; exact add_mem_sup (hY.onto _) (hX.onto _) - · rw [he] at hx - obtain ⟨v,hv,w,hw,rfl⟩ := Submodule.mem_sup.mp hx - rw [add_mulVec,mulVec_add,mulVec_add,hX.kills v (hp hv),hX.fixes _ hw,hY.fixes _ hv, - hY.kills _ (Submodule.mem_sup_right hw),add_zero,zero_add,add_comm] - · rw [add_mulVec,hX.kills x (hq hx),hY.kills x (Submodule.mem_sup_left hx),zero_add] - · rw [add_mulVec,hX.kills x hx,zero_add]; exact hY.onto _ - -abbrev CrossM (p : Shape) (n : ℕ) := Mat (JointIdx p n) (JointIdx p n) - -set_option maxHeartbeats 800000 in -theorem base_pair (a b : Plan p n) (u v : Place p) - (K J : Space (Dir p n)) (hk : K≤primal p n) (hj : J≤primal p n) - (hK : Disjoint (tabSpace a u) K) (hJ : Disjoint (tabSpace b v) J) - (A B : CrossM p n) - (heq : ∀ x∈ tabSpace a u,∀ y∈tabSpace b v,x∈a u ∨ y∈b v → evmat A x y=evmat B x y) : - ∃ M : CrossM p n, - (∀ x∈tabSpace a u,∀ y∈tabSpace b v,evmat M x y=evmat B x y) ∧ - (∀ x y, x∈ (a u⊔K) ∨ y∈(b v⊔J) → evmat M x y=evmat A x y) ∧ - (∀ i,(Mᵀ*IP p n i).rank ≤ dim (a u⊔K : Submodule _ _) + dim (b v⊔J : Submodule _ _) + - 2*planRank a) ∧ - (∀ i,(M*IP p n i).rank ≤ dim (a u⊔K : Submodule _ _) + dim (b v⊔J : Submodule _ _) + - 2*planRank b) := by - let P := a u⊔K - let Q := b v⊔J - obtain ⟨X,hX⟩ := proj_exists P ⊥ disjoint_bot_right - obtain ⟨Y,hY⟩ := proj_exists Q ⊥ disjoint_bot_right - obtain ⟨L,hL,gL⟩ := project_table a u K hk hK - obtain ⟨R,hR,gR⟩ := project_table b v J hj hJ - let C := pullM X (1:CrossM p n) A + pullM (1-X) Y A - let M := C + pullM L R (B-C) - have h1 (x y) (hx : x∈P ∨ y∈Q) : evmat C x y=evmat A x y := by - rw [show C=_ from rfl,evmat_addM,evmat_pull,evmat_pull,sub_mulVec,Matrix.one_mulVec, - Matrix.one_mulVec] - rcases hx with h|h - · rw [hX.fixes _ h,sub_self]; simp [evmat] - rw [hY.fixes _ h] - simp [evmat,sub_dotProduct] - have h2 (x y) : evmat M x y=evmat C x y+ - (evmat B (L *ᵥ x) (R *ᵥ y)-evmat C (L*ᵥ x) (R*ᵥ y)) := by - rw [show M=_ from rfl,evmat_addM,evmat_pull,evmat_subM] - have hRank : C.rank≤dim P+dim Q := by - apply (mrk_add_le ..).trans - have hx : X.rank≤dim P := rank_maps _ hX.onto - have hy : Y.rank≤dim Q := rank_maps _ hY.onto - apply Nat.add_le_add - · rw [pullM_def] - refine ((Matrix.rank_mul_le_left ..).trans (Matrix.rank_mul_le_left ..)).trans ?_ - rwa [Matrix.rank_transpose] - · rw [pullM_def]; exact (Matrix.rank_mul_le_right ..).trans hy - have hr (i) {a : Plan p n} (u) - (R : CrossM p n) (h : ∀ x∈primal p n,R*ᵥ x∈prSmall a u) : - (R*IP p n i).rank≤ 2*planRank a := by - apply le_trans (rank_maps (prSmall a u) _) - (prSmall_dim a u) - intro x - rw [← Matrix.mulVec_mulVec] - exact h _ (ip_le_primal i (show IP p n i*ᵥx∈colSp (IP p n i) from ⟨x,rfl⟩)) - refine ⟨M, fun x hx y hy => ?_, fun x y h => ?_, fun i => ?_, fun i => ?_⟩ - · rw [h2,hL.fixes x hx,hR.fixes y hy,add_sub_cancel] - · have hi : L*ᵥ x ∈ a u ∨ R *ᵥ y ∈ b v := by - rcases h with h|h - · left; obtain ⟨x,hx,y,hy,rfl⟩ := Submodule.mem_sup.mp h - rwa [Matrix.mulVec_add,hL.kills _ hy,hL.fixes _ (pin_le_table _ _ hx),add_zero] - right; obtain ⟨x,hx,y,hy,rfl⟩ := Submodule.mem_sup.mp h - rwa [Matrix.mulVec_add,hR.kills _ hy,hR.fixes _ (pin_le_table _ _ hx),add_zero] - have he : L*ᵥx ∈ P ∨ R*ᵥy∈Q := hi.imp Submodule.mem_sup_left Submodule.mem_sup_left - rw [h2,h1 _ _ h,h1 _ _ he,heq _ (hL.onto _) _ (hR.onto _) hi,sub_self,add_zero] - · unfold M - rw [transpose_add,Matrix.add_mul] - refine (mrk_add_le ..).trans (Nat.add_le_add ?_ ?_) - · exact (Matrix.rank_mul_le_left ..).trans ((Matrix.rank_transpose _).trans_le hRank) - rw [pullM_def,transpose_mul,transpose_mul,transpose_transpose,Matrix.mul_assoc, - Matrix.mul_assoc] - exact ((Matrix.rank_mul_le_right ..).trans (Matrix.rank_mul_le_right ..)).trans (hr i u L gL) - · unfold M - rw [Matrix.add_mul] - refine (mrk_add_le ..).trans (Nat.add_le_add ?_ ?_) - · exact (Matrix.rank_mul_le_left ..).trans hRank - rw [pullM_def,Matrix.mul_assoc] - exact (Matrix.rank_mul_le_right ..).trans (hr i v R gR) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PrimalChannelDecomposition + +namespace OAI + +/-! # Baseline Extension -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Submodule + +variable {p : Shape} {n : ℕ} + +theorem project_table (a : Plan p n) (z : Place p) (Q : Space (Dir p n)) + (hq : Q ≤ primal p n) (hd : Disjoint (tabSpace a z) Q) : + ∃ B, ProjData (tabSpace a z) Q B ∧ ∀ x∈ primal p n, B*ᵥx∈prSmall a z := by + classical + let H := channels p n + let A := primal p n + let P := prSmall a z + have hp : P≤ A := prSmall_le _ _ + have he : tabSpace a z=P ⊔ H := prSmall_table a z + obtain ⟨X,hX⟩ := proj_exists H A channels_disjoint.symm + have hj : Disjoint P (Q⊔H) := by + rw [disjoint_iff_inf_le] + rintro v ⟨hv,hv'⟩ + obtain ⟨y,hy,w,hw,g⟩ := Submodule.mem_sup.mp hv' + have h := (show w=v-y by rw [←g]; abel) ▸ + A.sub_mem (hp hv) (hq hy) + have hz : w∈ A ⊓ H := ⟨h,hw⟩ + rw [channels_disjoint.eq_bot] at hz + have hi : w=0 := by simpa using hz + rw [hi,add_zero] at g + have ht : v∈tabSpace a z ⊓ Q := + ⟨he.symm ▸ Submodule.mem_sup_left hv,g ▸ hy⟩ + rwa [hd.eq_bot] at ht + obtain ⟨Y,hY⟩ := proj_exists P (Q⊔H) hj + refine ⟨X+Y,⟨fun x => ?_,fun x hx => ?_,fun x hx => ?_⟩, fun x hx => ?_⟩ + · rw [add_mulVec,he,add_comm]; exact add_mem_sup (hY.onto _) (hX.onto _) + · rw [he] at hx + obtain ⟨v,hv,w,hw,rfl⟩ := Submodule.mem_sup.mp hx + rw [add_mulVec,mulVec_add,mulVec_add,hX.kills v (hp hv),hX.fixes _ hw,hY.fixes _ hv, + hY.kills _ (Submodule.mem_sup_right hw),add_zero,zero_add,add_comm] + · rw [add_mulVec,hX.kills x (hq hx),hY.kills x (Submodule.mem_sup_left hx),zero_add] + · rw [add_mulVec,hX.kills x hx,zero_add]; exact hY.onto _ + +abbrev CrossM (p : Shape) (n : ℕ) := Mat (JointIdx p n) (JointIdx p n) + +set_option maxHeartbeats 800000 in +theorem base_pair (a b : Plan p n) (u v : Place p) + (K J : Space (Dir p n)) (hk : K≤primal p n) (hj : J≤primal p n) + (hK : Disjoint (tabSpace a u) K) (hJ : Disjoint (tabSpace b v) J) + (A B : CrossM p n) + (heq : ∀ x∈ tabSpace a u,∀ y∈tabSpace b v,x∈a u ∨ y∈b v → evmat A x y=evmat B x y) : + ∃ M : CrossM p n, + (∀ x∈tabSpace a u,∀ y∈tabSpace b v,evmat M x y=evmat B x y) ∧ + (∀ x y, x∈ (a u⊔K) ∨ y∈(b v⊔J) → evmat M x y=evmat A x y) ∧ + (∀ i,(Mᵀ*IP p n i).rank ≤ dim (a u⊔K : Submodule _ _) + dim (b v⊔J : Submodule _ _) + + 2*planRank a) ∧ + (∀ i,(M*IP p n i).rank ≤ dim (a u⊔K : Submodule _ _) + dim (b v⊔J : Submodule _ _) + + 2*planRank b) := by + let P := a u⊔K + let Q := b v⊔J + obtain ⟨X,hX⟩ := proj_exists P ⊥ disjoint_bot_right + obtain ⟨Y,hY⟩ := proj_exists Q ⊥ disjoint_bot_right + obtain ⟨L,hL,gL⟩ := project_table a u K hk hK + obtain ⟨R,hR,gR⟩ := project_table b v J hj hJ + let C := pullM X (1:CrossM p n) A + pullM (1-X) Y A + let M := C + pullM L R (B-C) + have h1 (x y) (hx : x∈P ∨ y∈Q) : evmat C x y=evmat A x y := by + rw [show C=_ from rfl,evmat_addM,evmat_pull,evmat_pull,sub_mulVec,Matrix.one_mulVec, + Matrix.one_mulVec] + rcases hx with h|h + · rw [hX.fixes _ h,sub_self]; simp [evmat] + rw [hY.fixes _ h] + simp [evmat,sub_dotProduct] + have h2 (x y) : evmat M x y=evmat C x y+ + (evmat B (L *ᵥ x) (R *ᵥ y)-evmat C (L*ᵥ x) (R*ᵥ y)) := by + rw [show M=_ from rfl,evmat_addM,evmat_pull,evmat_subM] + have hRank : C.rank≤dim P+dim Q := by + apply (mrk_add_le ..).trans + have hx : X.rank≤dim P := rank_maps _ hX.onto + have hy : Y.rank≤dim Q := rank_maps _ hY.onto + apply Nat.add_le_add + · rw [pullM_def] + refine ((Matrix.rank_mul_le_left ..).trans (Matrix.rank_mul_le_left ..)).trans ?_ + rwa [Matrix.rank_transpose] + · rw [pullM_def]; exact (Matrix.rank_mul_le_right ..).trans hy + have hr (i) {a : Plan p n} (u) + (R : CrossM p n) (h : ∀ x∈primal p n,R*ᵥ x∈prSmall a u) : + (R*IP p n i).rank≤ 2*planRank a := by + apply le_trans (rank_maps (prSmall a u) _) + (prSmall_dim a u) + intro x + rw [← Matrix.mulVec_mulVec] + exact h _ (ip_le_primal i (show IP p n i*ᵥx∈colSp (IP p n i) from ⟨x,rfl⟩)) + refine ⟨M, fun x hx y hy => ?_, fun x y h => ?_, fun i => ?_, fun i => ?_⟩ + · rw [h2,hL.fixes x hx,hR.fixes y hy,add_sub_cancel] + · have hi : L*ᵥ x ∈ a u ∨ R *ᵥ y ∈ b v := by + rcases h with h|h + · left; obtain ⟨x,hx,y,hy,rfl⟩ := Submodule.mem_sup.mp h + rwa [Matrix.mulVec_add,hL.kills _ hy,hL.fixes _ (pin_le_table _ _ hx),add_zero] + right; obtain ⟨x,hx,y,hy,rfl⟩ := Submodule.mem_sup.mp h + rwa [Matrix.mulVec_add,hR.kills _ hy,hR.fixes _ (pin_le_table _ _ hx),add_zero] + have he : L*ᵥx ∈ P ∨ R*ᵥy∈Q := hi.imp Submodule.mem_sup_left Submodule.mem_sup_left + rw [h2,h1 _ _ h,h1 _ _ he,heq _ (hL.onto _) _ (hR.onto _) hi,sub_self,add_zero] + · unfold M + rw [transpose_add,Matrix.add_mul] + refine (mrk_add_le ..).trans (Nat.add_le_add ?_ ?_) + · exact (Matrix.rank_mul_le_left ..).trans ((Matrix.rank_transpose _).trans_le hRank) + rw [pullM_def,transpose_mul,transpose_mul,transpose_transpose,Matrix.mul_assoc, + Matrix.mul_assoc] + exact ((Matrix.rank_mul_le_right ..).trans (Matrix.rank_mul_le_right ..)).trans (hr i u L gL) + · unfold M + rw [Matrix.add_mul] + refine (mrk_add_le ..).trans (Nat.add_le_add ?_ ?_) + · exact (Matrix.rank_mul_le_left ..).trans hRank + rw [pullM_def,Matrix.mul_assoc] + exact (Matrix.rank_mul_le_right ..).trans (hr i v R gR) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/BaselineForms.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/BaselineForms.lean index d553e2bfc57e4d64b044d4acd0ed1ede7537c2b8..5a537b7d00b1d18c0074cce6f51d106dc6e34253 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/BaselineForms.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/BaselineForms.lean @@ -1,147 +1,147 @@ -import OAI.Combinatorics.HadwigerCounterexample.BaselineExtension - -namespace OAI - -/-! # Baseline Forms -/ - -noncomputable section -namespace HadwigerCounterexample - -open scoped BigOperators -open Matrix -variable {p : Shape} {n N : ℕ} - -def lowCross (K : ℕ) (B : Cross p n) := - ∀ z i,( (B z)ᵀ * IP p n i).rank ≤ K - -def fitsTable (a b : Plan p n) (B T : Cross p n) := - ∀ z, ∀ x∈tabSpace a z,∀ y∈tabSpace b (flipZ p z), evmat (B z) x y=evmat (T z) x y - -theorem fits_recip {B T : Cross p n} {a b : Plan p n} (h : fitsTable a b B T) : - fitsTable b a (reciprocal p B) (reciprocal p T) := by - intro z x hx y hy - have hx' : x∈tabSpace b (flipZ p (flipZ p z)) := by rwa [flipZ_flip] - change evmat _ _ _=evmat _ _ _ - unfold reciprocal - rw [evmat_transpose,evmat_transpose,h _ y hy x hx'] - -def blin (K : ℕ) := 4*K+56 - -set_option maxHeartbeats 800000 in -theorem start_form (a b : Pin p n N) (x y : UnitType p n N) (T : Cross p n) - (ka kb : Plan p n) - (hA : ∀ z,ka z≤primal p n) (hB : ∀ z,kb z≤primal p n) - (hd : ∀ z, Disjoint (tabSpace a.sp z) (ka z)) - (hd' : ∀ z, Disjoint (tabSpace b.sp z) (kb z)) - (ha : a.agree x) (hb : b.agree y) (h1 : tableFlag a b T x) - (h2 : tableFlag b a (reciprocal p T) y) - (K : ℕ) (hk : planRank a.sp ≤ K) (hk' : planRank b.sp ≤ K) - (hv : ∀ z, dim (ka z) ≤ 28) (hv' : ∀ z, dim (kb z) ≤ 28) : - ∃ M : Cross p n, fitsTable a.sp b.sp M T ∧ - rowAgree (a.sp ⊔ ka) M (actual p x y) ∧ - rowAgree (b.sp ⊔ kb) (reciprocal p M) (actual p y x) ∧ - lowCross (blin K) M ∧ lowCross (blin K) (reciprocal p M) := by - let A := actual p x y - have hh (z : Place p) (u v) (hu : u∈tabSpace a.sp z) (hv : v∈tabSpace b.sp (flipZ p z)) - (h : u∈a.sp z ∨ v∈b.sp (flipZ p z)) : evmat (A z) u v=evmat (T z) u v := by - rcases h with h|h - · have h' : u ∈ a.sp (flipZ p (flipZ p z)) := by rwa [flipZ_flip] - have he := h2 _ v hv u h' - have hf := flag_actual (a:=b) y x ha (flipZ p z) v hv u h' - have hg := hf.trans he.symm - rw [← reciprocal_actual x y] at hg - simp only [reciprocal,flipZ_flip,evmat_transpose] at hg - exact hg - exact (flag_actual (a:=a) x y hb _ u hu v h).trans (h1 _ u hu v h).symm - choose M hC hD hE hF using fun z => - base_pair a.sp b.sp z (flipZ p z) (ka z) (kb (flipZ p z)) (hA _) (hB _) (hd _) (hd' _) - (A z) (T z) (fun u hu v hv g => hh z u v hu hv g) - have hr (z) {a s : Plan p n} (h : planRank a≤K) (hg : ∀ z,dim (s z)≤28) : - dim (a z ⊔ s z : Submodule _ _) ≤ K+28 := - (Submodule.finrank_add_le_finrank_add_finrank ..).trans - (Nat.add_le_add ((dim_le_plan a _).trans h) (hg _)) - have hm z {L} (hl : L≤K) : dim (a.sp z ⊔ ka z : Submodule _ _)+ - dim (b.sp (flipZ p z) ⊔ kb (flipZ p z):Submodule _ _)+2*L ≤ blin K := by - apply le_trans (Nat.add_le_add (Nat.add_le_add (hr z hk hv) (hr _ hk' hv')) - (Nat.mul_le_mul_left 2 hl)) - unfold blin; omega - refine ⟨M,hC,(fun z u hu v => hD z u v (Or.inl hu)),?_, - fun z i => (hE z i).trans (hm z hk),?_⟩ - · rw [← reciprocal_actual x y] - intro z v hv u - unfold reciprocal; rw [evmat_transpose,evmat_transpose] - apply hD - right - rw [flipZ_flip]; exact hv - intro z i - unfold reciprocal; rw [transpose_transpose] - exact (hF (flipZ p z) i).trans (hm _ hk') - -theorem channel_eval (p : Shape) {n} (M : Cross p n) (j : Bool) (z : Place p) - (x : Dir p n) (y : Vec (Chan p)) : - dotProduct y (channelOut p M j z *ᵥ x)=evmat (M z) x (IH p n j *ᵥ y) := by - unfold channelOut evmat - rw [dotProduct_transpose_mulVec, Matrix.mulVec_mulVec] - -theorem channel_same {M T : Cross p n} (i z u) - (h : ∀ v : Vec (Chan p), evmat (M z) u (IH p n i *ᵥ v)=evmat (T z) u (IH p n i *ᵥ v)) : - channelOut p M i z *ᵥ u = channelOut p T i z *ᵥ u := by - classical - funext j - have he v : dotProduct v (channelOut p M i z *ᵥ u)=dotProduct v (channelOut p T i z*ᵥ u) := by - rw [channel_eval, channel_eval, h] - simpa using he (Pi.single j 1) - -theorem fits_channel {M T : Cross p n} {a b : Plan p n} (h : fitsTable a b M T) - (z : Place p) (x : Dir p n) (hx : x∈tabSpace a z) (j : Bool) : - channelOut p M j z *ᵥ x = channelOut p T j z *ᵥ x := by - apply channel_same j - intro v - exact h z x hx _ (channel_le_table b _ j ⟨_,rfl⟩) - -theorem fits_inj {M T : Cross p n} {a b : Plan p n} (h : fitsTable a b M T) - (ht : tableInj a b T) : tableInj a b M := by - intro z i j v hv hh - apply ht z i j v hv - rwa [fits_channel h z _ (pin_le_table a z hv) j] at hh - -private theorem cout_ev (A B : Mat (Chan p) (JointIdx p n)) (x y) : - evmat (Aᵀ*B) x y=dotProduct (A *ᵥ x) (B *ᵥ y) := by - rw [evmat,← mulVec_mulVec,dotProduct_transpose_mulVec,dotProduct_comm] - -theorem fits_contract {M T : Cross p n} {a b : Plan p n} (h : fitsTable a b M T) - (i j : Bool) (x : Profile p n) (hx : x ∈ effective a i) : - contract p M i j x=contract p T i j x := by - change ∑ e : Comp p.g, _ = _ - refine Finset.sum_congr rfl fun e _ => ?_ - apply (box_eval_iff (tabSpace a (e,true)) (tabSpace a (e,false)) _ _).mp ?_ _ - · have hp := lift_mem_box (IP p n i) (IP p n i) ((effective_mem.mp hx).2 e) - exact box_le (le_trans le_sup_left (half_le_table a _ i)) - (le_trans le_sup_left (half_le_table a _ i)) hp - intro x hx y hy; rw [cout_ev, cout_ev,fits_channel h _ _ hx,fits_channel h _ _ hy] - -variable {I : Type} [Fintype I] - -theorem frozen_contract_key {M T : Cross p n} {a} (v : Volley p n I) (t : Tagging p I) - (h : rowAgree (a⊔v.keyPlan t) M T) (i : I) (j : Bool) : - contract p M (v.obj i) j (v.atomAt t i)=contract p T (v.obj i) j (v.atomAt t i) := by - classical - change ∑ e : Comp p.g, _ = _ - refine Finset.sum_congr rfl fun e _ => ?_ - by_cases he : inc e (t i) - · have hx b : - v.rayLoc i ∈ (v.keyPlan t (e,b)) := colSp_mem (P:=v.keyM t e) - (⟨i,he⟩ : Volley.visits p t e) - have hE (b : Bool) : channelOut p M j (e,b) *ᵥ v.rayLoc i = - channelOut p T j (e,b) *ᵥ v.rayLoc i := - channel_same j _ _ (fun y => h _ _ (Submodule.mem_sup_right (hx b)) _) - simp only [Volley.atomAt,atom_def,he, ite_true,mom,liftM_outer,mpair_outer] - rw [cout_ev,cout_ev] - exact congrArg₂ dotProduct (hE true) (hE false) - simp only [Volley.atomAt,atom_def,he,ite_false,map_zero] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BaselineExtension + +namespace OAI + +/-! # Baseline Forms -/ + +noncomputable section +namespace HadwigerCounterexample + +open scoped BigOperators +open Matrix +variable {p : Shape} {n N : ℕ} + +def lowCross (K : ℕ) (B : Cross p n) := + ∀ z i,( (B z)ᵀ * IP p n i).rank ≤ K + +def fitsTable (a b : Plan p n) (B T : Cross p n) := + ∀ z, ∀ x∈tabSpace a z,∀ y∈tabSpace b (flipZ p z), evmat (B z) x y=evmat (T z) x y + +theorem fits_recip {B T : Cross p n} {a b : Plan p n} (h : fitsTable a b B T) : + fitsTable b a (reciprocal p B) (reciprocal p T) := by + intro z x hx y hy + have hx' : x∈tabSpace b (flipZ p (flipZ p z)) := by rwa [flipZ_flip] + change evmat _ _ _=evmat _ _ _ + unfold reciprocal + rw [evmat_transpose,evmat_transpose,h _ y hy x hx'] + +def blin (K : ℕ) := 4*K+56 + +set_option maxHeartbeats 800000 in +theorem start_form (a b : Pin p n N) (x y : UnitType p n N) (T : Cross p n) + (ka kb : Plan p n) + (hA : ∀ z,ka z≤primal p n) (hB : ∀ z,kb z≤primal p n) + (hd : ∀ z, Disjoint (tabSpace a.sp z) (ka z)) + (hd' : ∀ z, Disjoint (tabSpace b.sp z) (kb z)) + (ha : a.agree x) (hb : b.agree y) (h1 : tableFlag a b T x) + (h2 : tableFlag b a (reciprocal p T) y) + (K : ℕ) (hk : planRank a.sp ≤ K) (hk' : planRank b.sp ≤ K) + (hv : ∀ z, dim (ka z) ≤ 28) (hv' : ∀ z, dim (kb z) ≤ 28) : + ∃ M : Cross p n, fitsTable a.sp b.sp M T ∧ + rowAgree (a.sp ⊔ ka) M (actual p x y) ∧ + rowAgree (b.sp ⊔ kb) (reciprocal p M) (actual p y x) ∧ + lowCross (blin K) M ∧ lowCross (blin K) (reciprocal p M) := by + let A := actual p x y + have hh (z : Place p) (u v) (hu : u∈tabSpace a.sp z) (hv : v∈tabSpace b.sp (flipZ p z)) + (h : u∈a.sp z ∨ v∈b.sp (flipZ p z)) : evmat (A z) u v=evmat (T z) u v := by + rcases h with h|h + · have h' : u ∈ a.sp (flipZ p (flipZ p z)) := by rwa [flipZ_flip] + have he := h2 _ v hv u h' + have hf := flag_actual (a:=b) y x ha (flipZ p z) v hv u h' + have hg := hf.trans he.symm + rw [← reciprocal_actual x y] at hg + simp only [reciprocal,flipZ_flip,evmat_transpose] at hg + exact hg + exact (flag_actual (a:=a) x y hb _ u hu v h).trans (h1 _ u hu v h).symm + choose M hC hD hE hF using fun z => + base_pair a.sp b.sp z (flipZ p z) (ka z) (kb (flipZ p z)) (hA _) (hB _) (hd _) (hd' _) + (A z) (T z) (fun u hu v hv g => hh z u v hu hv g) + have hr (z) {a s : Plan p n} (h : planRank a≤K) (hg : ∀ z,dim (s z)≤28) : + dim (a z ⊔ s z : Submodule _ _) ≤ K+28 := + (Submodule.finrank_add_le_finrank_add_finrank ..).trans + (Nat.add_le_add ((dim_le_plan a _).trans h) (hg _)) + have hm z {L} (hl : L≤K) : dim (a.sp z ⊔ ka z : Submodule _ _)+ + dim (b.sp (flipZ p z) ⊔ kb (flipZ p z):Submodule _ _)+2*L ≤ blin K := by + apply le_trans (Nat.add_le_add (Nat.add_le_add (hr z hk hv) (hr _ hk' hv')) + (Nat.mul_le_mul_left 2 hl)) + unfold blin; omega + refine ⟨M,hC,(fun z u hu v => hD z u v (Or.inl hu)),?_, + fun z i => (hE z i).trans (hm z hk),?_⟩ + · rw [← reciprocal_actual x y] + intro z v hv u + unfold reciprocal; rw [evmat_transpose,evmat_transpose] + apply hD + right + rw [flipZ_flip]; exact hv + intro z i + unfold reciprocal; rw [transpose_transpose] + exact (hF (flipZ p z) i).trans (hm _ hk') + +theorem channel_eval (p : Shape) {n} (M : Cross p n) (j : Bool) (z : Place p) + (x : Dir p n) (y : Vec (Chan p)) : + dotProduct y (channelOut p M j z *ᵥ x)=evmat (M z) x (IH p n j *ᵥ y) := by + unfold channelOut evmat + rw [dotProduct_transpose_mulVec, Matrix.mulVec_mulVec] + +theorem channel_same {M T : Cross p n} (i z u) + (h : ∀ v : Vec (Chan p), evmat (M z) u (IH p n i *ᵥ v)=evmat (T z) u (IH p n i *ᵥ v)) : + channelOut p M i z *ᵥ u = channelOut p T i z *ᵥ u := by + classical + funext j + have he v : dotProduct v (channelOut p M i z *ᵥ u)=dotProduct v (channelOut p T i z*ᵥ u) := by + rw [channel_eval, channel_eval, h] + simpa using he (Pi.single j 1) + +theorem fits_channel {M T : Cross p n} {a b : Plan p n} (h : fitsTable a b M T) + (z : Place p) (x : Dir p n) (hx : x∈tabSpace a z) (j : Bool) : + channelOut p M j z *ᵥ x = channelOut p T j z *ᵥ x := by + apply channel_same j + intro v + exact h z x hx _ (channel_le_table b _ j ⟨_,rfl⟩) + +theorem fits_inj {M T : Cross p n} {a b : Plan p n} (h : fitsTable a b M T) + (ht : tableInj a b T) : tableInj a b M := by + intro z i j v hv hh + apply ht z i j v hv + rwa [fits_channel h z _ (pin_le_table a z hv) j] at hh + +private theorem cout_ev (A B : Mat (Chan p) (JointIdx p n)) (x y) : + evmat (Aᵀ*B) x y=dotProduct (A *ᵥ x) (B *ᵥ y) := by + rw [evmat,← mulVec_mulVec,dotProduct_transpose_mulVec,dotProduct_comm] + +theorem fits_contract {M T : Cross p n} {a b : Plan p n} (h : fitsTable a b M T) + (i j : Bool) (x : Profile p n) (hx : x ∈ effective a i) : + contract p M i j x=contract p T i j x := by + change ∑ e : Comp p.g, _ = _ + refine Finset.sum_congr rfl fun e _ => ?_ + apply (box_eval_iff (tabSpace a (e,true)) (tabSpace a (e,false)) _ _).mp ?_ _ + · have hp := lift_mem_box (IP p n i) (IP p n i) ((effective_mem.mp hx).2 e) + exact box_le (le_trans le_sup_left (half_le_table a _ i)) + (le_trans le_sup_left (half_le_table a _ i)) hp + intro x hx y hy; rw [cout_ev, cout_ev,fits_channel h _ _ hx,fits_channel h _ _ hy] + +variable {I : Type} [Fintype I] + +theorem frozen_contract_key {M T : Cross p n} {a} (v : Volley p n I) (t : Tagging p I) + (h : rowAgree (a⊔v.keyPlan t) M T) (i : I) (j : Bool) : + contract p M (v.obj i) j (v.atomAt t i)=contract p T (v.obj i) j (v.atomAt t i) := by + classical + change ∑ e : Comp p.g, _ = _ + refine Finset.sum_congr rfl fun e _ => ?_ + by_cases he : inc e (t i) + · have hx b : + v.rayLoc i ∈ (v.keyPlan t (e,b)) := colSp_mem (P:=v.keyM t e) + (⟨i,he⟩ : Volley.visits p t e) + have hE (b : Bool) : channelOut p M j (e,b) *ᵥ v.rayLoc i = + channelOut p T j (e,b) *ᵥ v.rayLoc i := + channel_same j _ _ (fun y => h _ _ (Submodule.mem_sup_right (hx b)) _) + simp only [Volley.atomAt,atom_def,he, ite_true,mom,liftM_outer,mpair_outer] + rw [cout_ev,cout_ev] + exact congrArg₂ dotProduct (hE true) (hE false) + simp only [Volley.atomAt,atom_def,he,ite_false,map_zero] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/BasisConditioning.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/BasisConditioning.lean index 5b1d288604143dd745dceea7ee2494c69f40ea16..9797b2f058bcc8cfd0ed0744ef1da2dde4ef7f2f 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/BasisConditioning.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/BasisConditioning.lean @@ -1,113 +1,113 @@ -import OAI.Combinatorics.HadwigerCounterexample.OrientationRankBounds - -namespace OAI - -/-! # Basis Conditioning -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Finset Filter Function -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] - -theorem totalRank_pos {x : Profile p n} (h : x≠0) : - 0Nat.zero_le ((x i).rank)) - (Finset.mem_univ i)) - apply Nat.pos_of_ne_zero; intro h - obtain ⟨A,B,hh⟩ := mul_factor (x i) 0 h.le - apply hi; ext a b; rw [←hh,Matrix.mul_apply]; simp - -def glintRate (K : ℕ) := bp (-((K^2:ℕ):ℝ)-3) - -theorem glint_within {K d : ℕ} (h : d≤ K^2) : - glintRate K ≤ (1/8:ℝ)*bp (- (d:ℝ)) := by - unfold glintRate - have hh : bp (-3)=1/8 := by norm_num [bp] - rw [←hh,←bp_add] - exact bp_le (by linarith only [(show (d:ℝ) ≤ ((K^2:ℕ):ℝ) from by exact_mod_cast h)]) - -namespace Template -variable (v : Solo p) - -def stains (m : Mixer p n) (f : Vec I →ₗ[F] Profile p n) (z : Knobs p.g n) : Vec I := - fun i=> Tsym m (f (Pi.single i 1)) (useAtom p (v.t ()) (v.s ()) (v.f ()) z) -theorem staining (m : Mixer p n) (f : Vec I→ₗ[F] Profile p n) (z : Knobs p.g n) (i : Vec I) : - vectorPhase i (stains v m f z)=shanty v m (f i) z := by - classical - let h := LinearMap.flip (Tsym m) (useAtom p (v.t ()) (v.s ()) (v.f ()) z) ∘ₗ f - have ht : h i=h (∑ j: I,i j • (Pi.single j 1 : Vec I)) := by - have he (j:I) : i j • (Pi.single j 1 : Vec I)=Pi.single j (i j) := by - funext k; by_cases hh:k=j <;> simp [hh] - simp_rw [he] - rw [Finset.univ_sum_single] - change wsign (∑ j:I,i j*h (Pi.single j 1))=wsign (h i) - rw [ht,map_sum]; simp_rw [map_smul]; rfl - -def luminous (v : Solo p) (m : Mixer p n) (w : Wgt (Knobs p.g n)) (D : AtomKey (p:=p) (v.t ()) - N →Prop) (K : ℕ) (i : Orient p n N) := - let P := offBeat v D i - 0 stains v m f z=x) - -set_option maxHeartbeats 800000 in -theorem glow_luminous (v : Solo p) (m : Mixer p n) (w : Wgt (Knobs p.g n)) - (hw : IsLaw w) - (S : AtomKey (p:=p) (v.t ()) N → Prop) - (K : ℕ) (i : Orient p n N) (δ : ℝ) (hδ : 0<δ) (he : δ ≤ pr w (offBeat v S i)) - (h : ∀ x, 0 ?_⟩ - let s := stains v m f - have heq : - pr u (fun z => s z=x) = avg unif (fun i => vectorPhase i x* - avg u (fun z => vectorPhase i (s z))) := by - unfold pr - simp_rw [vector_expand] - rw [avg_avg] - apply avg_congr - intro i hi - rw [avg_mul]; ring - let b := bp (-(d:ℝ)) - let Q (k : Vec (Fin d)) := vectorPhase k x * avg u (fun z => vectorPhase k (s z)) - have hb : 0 < b := bp_pos _ - have hh k : ind (k=0)-b/8 ≤ Q k := by - by_cases hk : k=0 - · subst k - have hQ : Q 0=1 := by unfold Q; simp only [vectorPhase,zero_dotProduct,wsign_zero,one_mul, - hu.avg_const] - rw [ind_one (show (0:Vec (Fin d))=0 from rfl),hQ]; linarith - let k' := f k - have hT := h k' (totalRank_pos (hf.ne hk |>.trans_eq (map_zero f))) (hg k) - have hz : |zsumPeak p w (v.shanty m k') P| ≤ (glintRate K)*pr w P := - le_of_lt (lt_of_not_ge (fun h => hT ⟨he,h⟩)) - have ht : - avg u (fun z => vectorPhase k (s z))= - zsumPeak p w (v.shanty m k') P/pr w P := by - unfold s u onW; simp_rw [staining]; rw [avg_norm,subW_tot] - congr 1; simp [zsumPeak,avg,subW,mul_assoc,k'] - have h1 : |Q k|≤b/8 := by - unfold Q; rw [ht,abs_mul,vectorPhase,wsign_abs,one_mul,abs_div,abs_of_pos hP] - refine le_trans ((div_le_iff₀ hP).mpr hz) ((glint_within hd).trans_eq (by unfold b; ring)) - rw [ind_zero hk,zero_sub]; exact (abs_le.mp h1).1 - have h0 : unif (0:Vec (Fin d))=b := by - unfold b; rw [unif_apply,card_space,dim_vec,bp_neg,Fintype.card_fin] - change _ ≤ pr u (fun z => s z=x) - rw [heq] - refine le_trans ?_ (avg_mono unif_law.nz hh) - rw [avg_sub,unif_law.avg_const, - show avg unif (fun i : Vec (Fin d)=> ind (i=0))=b from (pr_point' unif _).trans h0] - change 7/8*b≤_ - linarith -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.OrientationRankBounds + +namespace OAI + +/-! # Basis Conditioning -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Finset Filter Function +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] + +theorem totalRank_pos {x : Profile p n} (h : x≠0) : + 0Nat.zero_le ((x i).rank)) + (Finset.mem_univ i)) + apply Nat.pos_of_ne_zero; intro h + obtain ⟨A,B,hh⟩ := mul_factor (x i) 0 h.le + apply hi; ext a b; rw [←hh,Matrix.mul_apply]; simp + +def glintRate (K : ℕ) := bp (-((K^2:ℕ):ℝ)-3) + +theorem glint_within {K d : ℕ} (h : d≤ K^2) : + glintRate K ≤ (1/8:ℝ)*bp (- (d:ℝ)) := by + unfold glintRate + have hh : bp (-3)=1/8 := by norm_num [bp] + rw [←hh,←bp_add] + exact bp_le (by linarith only [(show (d:ℝ) ≤ ((K^2:ℕ):ℝ) from by exact_mod_cast h)]) + +namespace Template +variable (v : Solo p) + +def stains (m : Mixer p n) (f : Vec I →ₗ[F] Profile p n) (z : Knobs p.g n) : Vec I := + fun i=> Tsym m (f (Pi.single i 1)) (useAtom p (v.t ()) (v.s ()) (v.f ()) z) +theorem staining (m : Mixer p n) (f : Vec I→ₗ[F] Profile p n) (z : Knobs p.g n) (i : Vec I) : + vectorPhase i (stains v m f z)=shanty v m (f i) z := by + classical + let h := LinearMap.flip (Tsym m) (useAtom p (v.t ()) (v.s ()) (v.f ()) z) ∘ₗ f + have ht : h i=h (∑ j: I,i j • (Pi.single j 1 : Vec I)) := by + have he (j:I) : i j • (Pi.single j 1 : Vec I)=Pi.single j (i j) := by + funext k; by_cases hh:k=j <;> simp [hh] + simp_rw [he] + rw [Finset.univ_sum_single] + change wsign (∑ j:I,i j*h (Pi.single j 1))=wsign (h i) + rw [ht,map_sum]; simp_rw [map_smul]; rfl + +def luminous (v : Solo p) (m : Mixer p n) (w : Wgt (Knobs p.g n)) (D : AtomKey (p:=p) (v.t ()) + N →Prop) (K : ℕ) (i : Orient p n N) := + let P := offBeat v D i + 0 stains v m f z=x) + +set_option maxHeartbeats 800000 in +theorem glow_luminous (v : Solo p) (m : Mixer p n) (w : Wgt (Knobs p.g n)) + (hw : IsLaw w) + (S : AtomKey (p:=p) (v.t ()) N → Prop) + (K : ℕ) (i : Orient p n N) (δ : ℝ) (hδ : 0<δ) (he : δ ≤ pr w (offBeat v S i)) + (h : ∀ x, 0 ?_⟩ + let s := stains v m f + have heq : + pr u (fun z => s z=x) = avg unif (fun i => vectorPhase i x* + avg u (fun z => vectorPhase i (s z))) := by + unfold pr + simp_rw [vector_expand] + rw [avg_avg] + apply avg_congr + intro i hi + rw [avg_mul]; ring + let b := bp (-(d:ℝ)) + let Q (k : Vec (Fin d)) := vectorPhase k x * avg u (fun z => vectorPhase k (s z)) + have hb : 0 < b := bp_pos _ + have hh k : ind (k=0)-b/8 ≤ Q k := by + by_cases hk : k=0 + · subst k + have hQ : Q 0=1 := by unfold Q; simp only [vectorPhase,zero_dotProduct,wsign_zero,one_mul, + hu.avg_const] + rw [ind_one (show (0:Vec (Fin d))=0 from rfl),hQ]; linarith + let k' := f k + have hT := h k' (totalRank_pos (hf.ne hk |>.trans_eq (map_zero f))) (hg k) + have hz : |zsumPeak p w (v.shanty m k') P| ≤ (glintRate K)*pr w P := + le_of_lt (lt_of_not_ge (fun h => hT ⟨he,h⟩)) + have ht : + avg u (fun z => vectorPhase k (s z))= + zsumPeak p w (v.shanty m k') P/pr w P := by + unfold s u onW; simp_rw [staining]; rw [avg_norm,subW_tot] + congr 1; simp [zsumPeak,avg,subW,mul_assoc,k'] + have h1 : |Q k|≤b/8 := by + unfold Q; rw [ht,abs_mul,vectorPhase,wsign_abs,one_mul,abs_div,abs_of_pos hP] + refine le_trans ((div_le_iff₀ hP).mpr hz) ((glint_within hd).trans_eq (by unfold b; ring)) + rw [ind_zero hk,zero_sub]; exact (abs_le.mp h1).1 + have h0 : unif (0:Vec (Fin d))=b := by + unfold b; rw [unif_apply,card_space,dim_vec,bp_neg,Fintype.card_fin] + change _ ≤ pr u (fun z => s z=x) + rw [heq] + refine le_trans ?_ (avg_mono unif_law.nz hh) + rw [avg_sub,unif_law.avg_const, + show avg unif (fun i : Vec (Fin d)=> ind (i=0))=b from (pr_point' unif _).trans h0] + change 7/8*b≤_ + linarith +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/BatchCharacters.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/BatchCharacters.lean index dc1650fa65283413772b4275b3384aa5e56c4bef..7ca0800a412d811916058aee06a115fa05883516 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/BatchCharacters.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/BatchCharacters.lean @@ -1,153 +1,153 @@ -import OAI.Combinatorics.HadwigerCounterexample.CrossPatternCounting - -namespace OAI - -/-! # Batch Characters -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Module LinearMap Function Finset -variable {I J A B : Type} [Fintype I] [Fintype J] [Fintype A] [Fintype B] -variable [DecidableEq I] [DecidableEq J] [DecidableEq A] [DecidableEq B] -variable {n N t : ℕ} - -def led (i : I) (x : Rack (I×J) N) := sectionR (fun j => (i,j)) x -def relay (I J : Type) [Fintype I] [Fintype J] (N) : - Rack (I×J) N ≃ (I → Rack J N) where - toFun x i := led i x - invFun x := (Matrix.of (fun i j => (x j.1).1 i j.2), Matrix.of (fun i j => (x j.1).2 i j.2)) - left_inv x := by apply Prod.ext <;> rfl - right_inv x := funext fun _ => Prod.ext rfl rfl - -theorem led_uniform (F : Wgt (I→Rack J N)) : - avg (unif : Wgt (Rack (I×J) N)) (fun x => F (fun i => led i x))= - avg (draws I unif) F := by - change avg unif (fun x => F (relay I J N x))=_ - rw [← mapW_avg,unif_equiv,← draws_unif] - -theorem led_piece (T : Finset I) (p : I→Rack J N→Prop) : - avg unif (fun x => ∏ i∈T,ind (p i (led i x))) = - ∏ i∈T,pr unif (p i) := by - classical - let F (i : I) (z) := if i∈T then ind (p i z) else 1 - let H : Wgt (I→ Rack J N) := prodW F - have he x : (∏ i∈T,ind (p i (led i x))) = H (fun i => led i x) := by - unfold H F prodW - rw [← Finset.prod_filter]; simp - have hf i : avg unif (F i) = if i∈T then pr unif (p i) else 1 := by - by_cases hh : i∈T <;> simp [F,pr,hh,unif_law.avg_const] - simp_rw [he]; rw [led_uniform] - unfold H draws - rw [prodW_avg]; simp_rw [hf]; rw [← Finset.prod_filter]; simp - -def heard (T : A → I×J) := Finset.univ.image (Prod.fst ∘ T) - -omit [Fintype I] [Fintype J] [DecidableEq A] in -theorem heard_fresh {T : A→I × J} {i : I} (B : PlusRack A N) (h : i∉heard T) (j : J) (k) : - upliftR T B k (i,j)=0 := by - classical - unfold upliftR - rw [Matrix.mul_apply] - refine Finset.sum_eq_zero fun x _ => ?_ - have he : (i,j)≠T x := fun e => h (mem_image.mpr - ⟨x,mem_univ _, (congrArg Prod.fst e).symm⟩) - simp [embedMat,he] - -omit [Fintype I] [Fintype J] [DecidableEq A] in -private theorem led_off_r (x : Rack (I×J) N) {T : A→I×J} {i : I} (B : PlusRack A N) - (h : i∉heard T) : - led i (x+(0,upliftR T B)) = led i x := by - apply Prod.ext - · ext; simp [led,sectionR] - ext - simp only [led,sectionR,Prod.snd_add,Matrix.add_apply,Matrix.submatrix_apply, - heard_fresh B h,add_zero] - -omit [Fintype I] [Fintype J] [DecidableEq A] in -private theorem led_off_l (x : Rack (I×J) N) {T : A→I×J} {i : I} (B : PlusRack A N) - (h : i∉heard T) : - led i (x+(upliftR T B,0)) = led i x := by - apply Prod.ext - · ext - simp only [led,sectionR,Prod.fst_add,Matrix.add_apply,Matrix.submatrix_apply, - heard_fresh B h,add_zero] - ext; simp [led,sectionR] - -def phot (P : I→Rack J N→Prop) (x : Rack (I×J) N) := - ∏ i:I,ind (P i (led i x)) - -set_option maxHeartbeats 800000 in -theorem light_bound (M : Avenue I J) (P : I→Rack J N→Prop) (u : ℝ) (hu : 0 ≤ u) - (hp : ∀ i,bp (-u) ≤ pr unif (P i)) : - |avg unif (fun x => phasedBy M x*phot P x)| ≤ - bp ((-(N:ℝ)/2+2*u)*(peak M:ℝ)) * ∏ i,pr unif (P i) := by - classical - obtain ⟨T,U,hTU,hA⟩ := real_peak M - let t := peak M - let L := heard T - let R := heard U - let D := L∪R - let S := Finset.univ \ D - have hd : Disjoint L R := by - refine Finset.disjoint_left.mpr ?_ - intro x hx hy - obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨j,_,he⟩ := Finset.mem_image.mp hy - exact hTU i j he.symm - let f (Z : Finset I) (x : Rack (I×J) N) := ∏ i∈Z,ind (P i (led i x)) - have hs (V : Finset I) x : |f V x|=f V x := abs_of_nonneg (Finset.prod_nonneg (fun i _ => - ind_nonneg _)) - have heq (V : Finset I) x : |f V x|≤1 := (hs V x).trans_le - ((Finset.prod_le_prod₀ (fun _ _ => ind_nonneg _) (fun _ _ => ind_le_one _)).trans_eq (by simp)) - have h1 : - (∏ i,pr unif (P i))=(∏ i∈D,pr unif (P i))*(∏ i∈S,pr unif (P i)) := by - rw [←Finset.prod_union (show Disjoint D S from disjoint_sdiff), - Finset.union_sdiff_of_subset (Finset.subset_univ D)] - have hf x : phot P x=f L x*f R x*f S x := by - unfold phot f - rw [←Finset.prod_union hd,←Finset.prod_union (show Disjoint D S from disjoint_sdiff), - Finset.union_sdiff_of_subset (Finset.subset_univ D)] - have hl : - |avg unif (fun x => phasedBy M x*phot P x)| ≤ bp (-(N:ℝ)*t/2) * avg unif (fun x => |f S x|) := by - have he x : phasedBy M x*phot P x=phasedBy M x*f L x*f R x*f S x := by rw [hf]; ring - simp_rw [he] - rw [←show (M.submatrix T U).rank=t from - (mrk_inj.mp hA).trans (Fintype.card_fin _)] - - refine layerLeak M (f L) (f R) (f S) T U (heq _) (heq _) (fun x y => ?_) - (fun x y => ?_) (fun x y z => ?_) - · refine Finset.prod_congr rfl fun i hi => ?_ - rw [led_off_r x y (fun h => Finset.disjoint_left.mp hd hi h)] - · refine Finset.prod_congr rfl fun i hi => ?_ - rw [led_off_l x y (fun h => Finset.disjoint_left.mp hd h hi)] - · refine Finset.prod_congr rfl fun i hi => ?_ - have hr := (Finset.mem_sdiff.mp hi).2 - rw [show x+(upliftR T y,upliftR U z)=x+(0,upliftR U z)+(upliftR T y,0) from - by rw [add_assoc]; apply congrArg; apply Prod.ext <;> simp, - led_off_l _ y (fun h => hr (mem_union_left _ h)), - led_off_r _ z (fun h => hr (mem_union_right _ h))] - apply hl.trans - simp_rw [hs] - rw [show avg unif (fun x => f S x)= _ from led_piece S P,h1,← mul_assoc] - refine mul_le_mul_of_nonneg_right ?_ (Finset.prod_nonneg fun _ _ => pr_nonneg unif_law.nz) - have hc : D.card ≤ 2*t := by - apply le_trans (Finset.card_union_le ..) - have hi (T : Fin t→ I × J) : (heard T).card≤t := - Finset.card_image_le.trans_eq (by simp) - rw [two_mul]; exact add_le_add (hi T) (hi U) - have hQ : bp (-u*(2*(t:ℝ))) ≤ ∏ i∈D,pr unif (P i) := by - refine le_trans ?_ (Finset.prod_le_prod₀ (fun i _ => (bp_pos _).le) fun i _ => hp i) - rw [Finset.prod_const,←bp_mul_nat] - apply bp_le - apply mul_le_mul_of_nonpos_left - · exact_mod_cast hc - exact neg_nonpos.mpr hu - calc bp _ - _ = bp ((-(N:ℝ)/2+2*u)*(peak M:ℝ)) * bp (-u*(2*t)) := by rw [←bp_add]; congr 1; unfold t; ring - _ ≤ _ := mul_le_mul_of_nonneg_left hQ (bp_pos _).le -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CrossPatternCounting + +namespace OAI + +/-! # Batch Characters -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Module LinearMap Function Finset +variable {I J A B : Type} [Fintype I] [Fintype J] [Fintype A] [Fintype B] +variable [DecidableEq I] [DecidableEq J] [DecidableEq A] [DecidableEq B] +variable {n N t : ℕ} + +def led (i : I) (x : Rack (I×J) N) := sectionR (fun j => (i,j)) x +def relay (I J : Type) [Fintype I] [Fintype J] (N) : + Rack (I×J) N ≃ (I → Rack J N) where + toFun x i := led i x + invFun x := (Matrix.of (fun i j => (x j.1).1 i j.2), Matrix.of (fun i j => (x j.1).2 i j.2)) + left_inv x := by apply Prod.ext <;> rfl + right_inv x := funext fun _ => Prod.ext rfl rfl + +theorem led_uniform (F : Wgt (I→Rack J N)) : + avg (unif : Wgt (Rack (I×J) N)) (fun x => F (fun i => led i x))= + avg (draws I unif) F := by + change avg unif (fun x => F (relay I J N x))=_ + rw [← mapW_avg,unif_equiv,← draws_unif] + +theorem led_piece (T : Finset I) (p : I→Rack J N→Prop) : + avg unif (fun x => ∏ i∈T,ind (p i (led i x))) = + ∏ i∈T,pr unif (p i) := by + classical + let F (i : I) (z) := if i∈T then ind (p i z) else 1 + let H : Wgt (I→ Rack J N) := prodW F + have he x : (∏ i∈T,ind (p i (led i x))) = H (fun i => led i x) := by + unfold H F prodW + rw [← Finset.prod_filter]; simp + have hf i : avg unif (F i) = if i∈T then pr unif (p i) else 1 := by + by_cases hh : i∈T <;> simp [F,pr,hh,unif_law.avg_const] + simp_rw [he]; rw [led_uniform] + unfold H draws + rw [prodW_avg]; simp_rw [hf]; rw [← Finset.prod_filter]; simp + +def heard (T : A → I×J) := Finset.univ.image (Prod.fst ∘ T) + +omit [Fintype I] [Fintype J] [DecidableEq A] in +theorem heard_fresh {T : A→I × J} {i : I} (B : PlusRack A N) (h : i∉heard T) (j : J) (k) : + upliftR T B k (i,j)=0 := by + classical + unfold upliftR + rw [Matrix.mul_apply] + refine Finset.sum_eq_zero fun x _ => ?_ + have he : (i,j)≠T x := fun e => h (mem_image.mpr + ⟨x,mem_univ _, (congrArg Prod.fst e).symm⟩) + simp [embedMat,he] + +omit [Fintype I] [Fintype J] [DecidableEq A] in +private theorem led_off_r (x : Rack (I×J) N) {T : A→I×J} {i : I} (B : PlusRack A N) + (h : i∉heard T) : + led i (x+(0,upliftR T B)) = led i x := by + apply Prod.ext + · ext; simp [led,sectionR] + ext + simp only [led,sectionR,Prod.snd_add,Matrix.add_apply,Matrix.submatrix_apply, + heard_fresh B h,add_zero] + +omit [Fintype I] [Fintype J] [DecidableEq A] in +private theorem led_off_l (x : Rack (I×J) N) {T : A→I×J} {i : I} (B : PlusRack A N) + (h : i∉heard T) : + led i (x+(upliftR T B,0)) = led i x := by + apply Prod.ext + · ext + simp only [led,sectionR,Prod.fst_add,Matrix.add_apply,Matrix.submatrix_apply, + heard_fresh B h,add_zero] + ext; simp [led,sectionR] + +def phot (P : I→Rack J N→Prop) (x : Rack (I×J) N) := + ∏ i:I,ind (P i (led i x)) + +set_option maxHeartbeats 800000 in +theorem light_bound (M : Avenue I J) (P : I→Rack J N→Prop) (u : ℝ) (hu : 0 ≤ u) + (hp : ∀ i,bp (-u) ≤ pr unif (P i)) : + |avg unif (fun x => phasedBy M x*phot P x)| ≤ + bp ((-(N:ℝ)/2+2*u)*(peak M:ℝ)) * ∏ i,pr unif (P i) := by + classical + obtain ⟨T,U,hTU,hA⟩ := real_peak M + let t := peak M + let L := heard T + let R := heard U + let D := L∪R + let S := Finset.univ \ D + have hd : Disjoint L R := by + refine Finset.disjoint_left.mpr ?_ + intro x hx hy + obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨j,_,he⟩ := Finset.mem_image.mp hy + exact hTU i j he.symm + let f (Z : Finset I) (x : Rack (I×J) N) := ∏ i∈Z,ind (P i (led i x)) + have hs (V : Finset I) x : |f V x|=f V x := abs_of_nonneg (Finset.prod_nonneg (fun i _ => + ind_nonneg _)) + have heq (V : Finset I) x : |f V x|≤1 := (hs V x).trans_le + ((Finset.prod_le_prod₀ (fun _ _ => ind_nonneg _) (fun _ _ => ind_le_one _)).trans_eq (by simp)) + have h1 : + (∏ i,pr unif (P i))=(∏ i∈D,pr unif (P i))*(∏ i∈S,pr unif (P i)) := by + rw [←Finset.prod_union (show Disjoint D S from disjoint_sdiff), + Finset.union_sdiff_of_subset (Finset.subset_univ D)] + have hf x : phot P x=f L x*f R x*f S x := by + unfold phot f + rw [←Finset.prod_union hd,←Finset.prod_union (show Disjoint D S from disjoint_sdiff), + Finset.union_sdiff_of_subset (Finset.subset_univ D)] + have hl : + |avg unif (fun x => phasedBy M x*phot P x)| ≤ bp (-(N:ℝ)*t/2) * avg unif (fun x => |f S x|) := by + have he x : phasedBy M x*phot P x=phasedBy M x*f L x*f R x*f S x := by rw [hf]; ring + simp_rw [he] + rw [←show (M.submatrix T U).rank=t from + (mrk_inj.mp hA).trans (Fintype.card_fin _)] + + refine layerLeak M (f L) (f R) (f S) T U (heq _) (heq _) (fun x y => ?_) + (fun x y => ?_) (fun x y z => ?_) + · refine Finset.prod_congr rfl fun i hi => ?_ + rw [led_off_r x y (fun h => Finset.disjoint_left.mp hd hi h)] + · refine Finset.prod_congr rfl fun i hi => ?_ + rw [led_off_l x y (fun h => Finset.disjoint_left.mp hd h hi)] + · refine Finset.prod_congr rfl fun i hi => ?_ + have hr := (Finset.mem_sdiff.mp hi).2 + rw [show x+(upliftR T y,upliftR U z)=x+(0,upliftR U z)+(upliftR T y,0) from + by rw [add_assoc]; apply congrArg; apply Prod.ext <;> simp, + led_off_l _ y (fun h => hr (mem_union_left _ h)), + led_off_r _ z (fun h => hr (mem_union_right _ h))] + apply hl.trans + simp_rw [hs] + rw [show avg unif (fun x => f S x)= _ from led_piece S P,h1,← mul_assoc] + refine mul_le_mul_of_nonneg_right ?_ (Finset.prod_nonneg fun _ _ => pr_nonneg unif_law.nz) + have hc : D.card ≤ 2*t := by + apply le_trans (Finset.card_union_le ..) + have hi (T : Fin t→ I × J) : (heard T).card≤t := + Finset.card_image_le.trans_eq (by simp) + rw [two_mul]; exact add_le_add (hi T) (hi U) + have hQ : bp (-u*(2*(t:ℝ))) ≤ ∏ i∈D,pr unif (P i) := by + refine le_trans ?_ (Finset.prod_le_prod₀ (fun i _ => (bp_pos _).le) fun i _ => hp i) + rw [Finset.prod_const,←bp_mul_nat] + apply bp_le + apply mul_le_mul_of_nonpos_left + · exact_mod_cast hc + exact neg_nonpos.mpr hu + calc bp _ + _ = bp ((-(N:ℝ)/2+2*u)*(peak M:ℝ)) * bp (-u*(2*t)) := by rw [←bp_add]; congr 1; unfold t; ring + _ ≤ _ := mul_le_mul_of_nonneg_left hQ (bp_pos _).le +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/BiasedRotationBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/BiasedRotationBounds.lean index 155fe4fc3cf5ff5a945ce6cee0a80bd39c54659a..abb5118af0f6462b52b081c487d7c982d2f4c4f7 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/BiasedRotationBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/BiasedRotationBounds.lean @@ -1,142 +1,142 @@ -import OAI.Combinatorics.HadwigerCounterexample.OrthogonalSpectrumBounds - -namespace OAI - -/-! # Biased Rotation Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module Submodule Function LinearMap Filter Real -open scoped BigOperators -variable {p : Shape} {n : ℕ} - -set_option maxHeartbeats 1200000 in -theorem spinning (p : Shape) (w : Wgt (Knobs p.g n)) - (f : Flit n→Wgt (Knobs p.g n)) (P : Knobs p.g n→Prop) - (hw : IsLaw w) (hf : ∀ i j,|f i j|≤1) (h : flowZ p w) - (b g δ : ℝ) (hb : 0≤b) - (T : Space (Vec (Fin n))) (s l : ℕ) (hk : s g*pr w P ≤ |zsumPeak p w (f c) P|) ≤ - bp (1+((dim T:ℝ)+l*(dim T:ℝ)-n)*s) := by - classical - let M := g-b*bp s; have hM : 0U x ^ 2) ≤ i := by - induction i with - | zero => - refine ⟨⊥,fun _=>0,?_,?_,?_,?_⟩ - · intro i t h; simp only [zero_mul,avg_zero] - · simp [dim] - · simp [zsumPeak,avg_zero] - simp only [zero_pow (by decide : 2 ≠ 0),avg_zero,Nat.cast_zero,le_refl] - | succ i ih => - obtain ⟨S,U,hS,hU,h1,h2⟩ := ih (by omega) - let Q (c : Flit n) := s < dim (c.plume T ⊓ S : Space (Vec (Fin n))) - have hh' : ∃ c : Flit n, D c ∧ ¬ Q c := by - by_contra! hh - have hz := (pr_mono unif_law.nz (fun c (h : D c) => - (hh c h).le)).trans (Move.plume_meets n s hk T S) - have hy : (dim S:ℝ)≤ l*(dim T:ℝ) := by - exact_mod_cast (hU.trans (Nat.mul_le_mul_right _ (by omega) : i*dim T ≤ l*dim T)) - apply (not_lt_of_ge (le_trans hz (bp_le ?_))) H - nlinarith only [mul_le_mul_of_nonneg_right hy (Nat.cast_nonneg s : 0≤(s:ℝ))] - obtain ⟨c,he,hc⟩ := hh' - let W := c.plume T - have hk : dim (S ⊓ W : Space (Vec (Fin n))) ≤ s := by - have hh : dim (W⊓S : Space (Vec (Fin n))) ≤ s := le_of_not_gt hc - rw [inf_comm]; exact hh - obtain ⟨t,a,ha,hA,hy,hz⟩ := clear_band p w (f c) P hw (hf c) h b g hb he S W s hk (hh c) - let Z i := a*zim p (f c) t i - let C i := U i+Z i - have hQ : avg w (fun i=>U i * Z i)=0 := by - have he := hS (f c) t (fun i hi => (hA i hi).1) - unfold Z; simp_rw [mul_left_comm _ a,avg_mul',he,mul_zero] - refine ⟨S ⊔ W,C,?_,?_,?_,?_⟩ - · intro i s hh - have hL := zsplit_orth p (f c) i w h t s (Finset.disjoint_left.mpr (fun j hj he => - hh j he ((show W≤S⊔W from le_sup_right) (hA j hj).2))) - have he := hS i s (fun j hj h => hh j hj ((show S≤S⊔W from le_sup_left) h)) - unfold C Z; simp only [add_mul,mul_assoc,avg_add,avg_mul',he,hL,mul_zero,add_zero] - · have h := Submodule.finrank_add_le_finrank_add_finrank S W - refine le_trans h ?_ - change dim S+dim W≤_ - unfold W; rw [Move.plume_dim c T,Nat.add_mul,one_mul] - omega - · unfold zsumPeak C; simp_rw [mul_add,avg_add] - change _≤zsumPeak p w U P+zsumPeak p w Z P - change M*pr w P ≤ zsumPeak p w Z P at hy - push_cast - nlinarith only [h1,hy,mul_le_mul_of_nonneg_left hP hM.le] - · have hh (i) : C i^2=U i^2+Z i^2+2*(U i*Z i) := by unfold C; ring - simp_rw [hh,avg_add,avg_mul',hQ,mul_zero,add_zero] - exact (add_le_add h2 hz).trans_eq (by push_cast; rfl) - obtain ⟨S,U,_,_,hu,hq⟩ := progress l (le_refl _) - have hh : ↑l * (M*δ) ≤ zsumPeak p w U P := hu - have hx : - zsumPeak p w U P ^2 ≤ l := by - apply (avg_CS hw.nz (fun i=>ind (P i)) U).trans - have hz (i : Knobs p.g n) : ind (P i)^2 ≤ 1 := - calc ind (P i)^2 ≤ 1^2 := pow_le_pow_left₀ (ind_nonneg _) (ind_le_one _) _ - _ = _ := one_pow _ - exact (mul_le_mul (hw.avg_le hz) hq (avg_nonneg hw.nz (fun _ => sq_nonneg _)) - zero_le_one).trans_eq (one_mul _) - have hy := pow_le_pow_left₀ (by positivity) hh 2 - change 1<↑l*(M*δ)^2 at hL - have hl : 0 g*pr w P ≤|zsumPeak p w (v.rotor c m x) P|) ≤ bp (-(2*a:ℝ)*n) := by - classical - let b := bp (-((p.J-s:ℕ):ℝ)) - have hb : b*bp s (↑s-2*a:ℝ)*n) atTop atTop := - (tendsto_const_mul_atTop_of_pos ha).mpr tendsto_natCast_atTop_atTop - filter_upwards [eventually_gt_atTop s,hz.eventually (eventually_ge_atTop - (1+((d:ℝ)+l*d)*s))] with n hn hN m hm x hx hK w hw hh P hP - have he := spinning p w (fun c=>v.rotor c m x) P hw (by - intro i j; unfold rotor Move.zreroute shanty; rw [wsign_abs]) hh b g δ - (bp_pos _).le _ s l hn (fun c y i => v.rotor_budget c m x K s hg hm hK hx y i) - hδ hb hP ((div_lt_iff₀ ht).mp hl) - apply he.trans - apply bp_le - have hy : - dim (v.scroll m x) ≤ d := - (scroll_dim v m x).trans (by unfold d; gcongr) - have hx : ((dim (v.scroll m x)):ℝ) ≤ d := by exact_mod_cast hy - change 1+((d:ℝ)+l*d)*s≤ ((s:ℝ)-2*a)*n at hN - have hB := mul_le_mul_of_nonneg_left hx (Nat.cast_nonneg l : 0≤(l:ℝ)) - nlinarith only [mul_le_mul_of_nonneg_right (add_le_add hx hB) - (Nat.cast_nonneg s : 0≤(s:ℝ)),hN] -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.OrthogonalSpectrumBounds + +namespace OAI + +/-! # Biased Rotation Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module Submodule Function LinearMap Filter Real +open scoped BigOperators +variable {p : Shape} {n : ℕ} + +set_option maxHeartbeats 1200000 in +theorem spinning (p : Shape) (w : Wgt (Knobs p.g n)) + (f : Flit n→Wgt (Knobs p.g n)) (P : Knobs p.g n→Prop) + (hw : IsLaw w) (hf : ∀ i j,|f i j|≤1) (h : flowZ p w) + (b g δ : ℝ) (hb : 0≤b) + (T : Space (Vec (Fin n))) (s l : ℕ) (hk : s g*pr w P ≤ |zsumPeak p w (f c) P|) ≤ + bp (1+((dim T:ℝ)+l*(dim T:ℝ)-n)*s) := by + classical + let M := g-b*bp s; have hM : 0U x ^ 2) ≤ i := by + induction i with + | zero => + refine ⟨⊥,fun _=>0,?_,?_,?_,?_⟩ + · intro i t h; simp only [zero_mul,avg_zero] + · simp [dim] + · simp [zsumPeak,avg_zero] + simp only [zero_pow (by decide : 2 ≠ 0),avg_zero,Nat.cast_zero,le_refl] + | succ i ih => + obtain ⟨S,U,hS,hU,h1,h2⟩ := ih (by omega) + let Q (c : Flit n) := s < dim (c.plume T ⊓ S : Space (Vec (Fin n))) + have hh' : ∃ c : Flit n, D c ∧ ¬ Q c := by + by_contra! hh + have hz := (pr_mono unif_law.nz (fun c (h : D c) => + (hh c h).le)).trans (Move.plume_meets n s hk T S) + have hy : (dim S:ℝ)≤ l*(dim T:ℝ) := by + exact_mod_cast (hU.trans (Nat.mul_le_mul_right _ (by omega) : i*dim T ≤ l*dim T)) + apply (not_lt_of_ge (le_trans hz (bp_le ?_))) H + nlinarith only [mul_le_mul_of_nonneg_right hy (Nat.cast_nonneg s : 0≤(s:ℝ))] + obtain ⟨c,he,hc⟩ := hh' + let W := c.plume T + have hk : dim (S ⊓ W : Space (Vec (Fin n))) ≤ s := by + have hh : dim (W⊓S : Space (Vec (Fin n))) ≤ s := le_of_not_gt hc + rw [inf_comm]; exact hh + obtain ⟨t,a,ha,hA,hy,hz⟩ := clear_band p w (f c) P hw (hf c) h b g hb he S W s hk (hh c) + let Z i := a*zim p (f c) t i + let C i := U i+Z i + have hQ : avg w (fun i=>U i * Z i)=0 := by + have he := hS (f c) t (fun i hi => (hA i hi).1) + unfold Z; simp_rw [mul_left_comm _ a,avg_mul',he,mul_zero] + refine ⟨S ⊔ W,C,?_,?_,?_,?_⟩ + · intro i s hh + have hL := zsplit_orth p (f c) i w h t s (Finset.disjoint_left.mpr (fun j hj he => + hh j he ((show W≤S⊔W from le_sup_right) (hA j hj).2))) + have he := hS i s (fun j hj h => hh j hj ((show S≤S⊔W from le_sup_left) h)) + unfold C Z; simp only [add_mul,mul_assoc,avg_add,avg_mul',he,hL,mul_zero,add_zero] + · have h := Submodule.finrank_add_le_finrank_add_finrank S W + refine le_trans h ?_ + change dim S+dim W≤_ + unfold W; rw [Move.plume_dim c T,Nat.add_mul,one_mul] + omega + · unfold zsumPeak C; simp_rw [mul_add,avg_add] + change _≤zsumPeak p w U P+zsumPeak p w Z P + change M*pr w P ≤ zsumPeak p w Z P at hy + push_cast + nlinarith only [h1,hy,mul_le_mul_of_nonneg_left hP hM.le] + · have hh (i) : C i^2=U i^2+Z i^2+2*(U i*Z i) := by unfold C; ring + simp_rw [hh,avg_add,avg_mul',hQ,mul_zero,add_zero] + exact (add_le_add h2 hz).trans_eq (by push_cast; rfl) + obtain ⟨S,U,_,_,hu,hq⟩ := progress l (le_refl _) + have hh : ↑l * (M*δ) ≤ zsumPeak p w U P := hu + have hx : + zsumPeak p w U P ^2 ≤ l := by + apply (avg_CS hw.nz (fun i=>ind (P i)) U).trans + have hz (i : Knobs p.g n) : ind (P i)^2 ≤ 1 := + calc ind (P i)^2 ≤ 1^2 := pow_le_pow_left₀ (ind_nonneg _) (ind_le_one _) _ + _ = _ := one_pow _ + exact (mul_le_mul (hw.avg_le hz) hq (avg_nonneg hw.nz (fun _ => sq_nonneg _)) + zero_le_one).trans_eq (one_mul _) + have hy := pow_le_pow_left₀ (by positivity) hh 2 + change 1<↑l*(M*δ)^2 at hL + have hl : 0 g*pr w P ≤|zsumPeak p w (v.rotor c m x) P|) ≤ bp (-(2*a:ℝ)*n) := by + classical + let b := bp (-((p.J-s:ℕ):ℝ)) + have hb : b*bp s (↑s-2*a:ℝ)*n) atTop atTop := + (tendsto_const_mul_atTop_of_pos ha).mpr tendsto_natCast_atTop_atTop + filter_upwards [eventually_gt_atTop s,hz.eventually (eventually_ge_atTop + (1+((d:ℝ)+l*d)*s))] with n hn hN m hm x hx hK w hw hh P hP + have he := spinning p w (fun c=>v.rotor c m x) P hw (by + intro i j; unfold rotor Move.zreroute shanty; rw [wsign_abs]) hh b g δ + (bp_pos _).le _ s l hn (fun c y i => v.rotor_budget c m x K s hg hm hK hx y i) + hδ hb hP ((div_lt_iff₀ ht).mp hl) + apply he.trans + apply bp_le + have hy : + dim (v.scroll m x) ≤ d := + (scroll_dim v m x).trans (by unfold d; gcongr) + have hx : ((dim (v.scroll m x)):ℝ) ≤ d := by exact_mod_cast hy + change 1+((d:ℝ)+l*d)*s≤ ((s:ℝ)-2*a)*n at hN + have hB := mul_le_mul_of_nonneg_left hx (Nat.cast_nonneg l : 0≤(l:ℝ)) + nlinarith only [mul_le_mul_of_nonneg_right (add_le_add hx hB) + (Nat.cast_nonneg s : 0≤(s:ℝ)),hN] +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/BilinearBlockCorrelation.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/BilinearBlockCorrelation.lean index 2a1f250aaf42a155e7d7d5a4d3c9ec7419795b39..7a3858b5657fb11a6e82daf593c1820e4518a236 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/BilinearBlockCorrelation.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/BilinearBlockCorrelation.lean @@ -1,107 +1,107 @@ -import OAI.Combinatorics.HadwigerCounterexample.OppositeEndpointForms - -namespace OAI - -/-! # Bilinear Block Correlation -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset LinearMap Module Matrix Function -open scoped BigOperators -variable {p : Shape} {I J A : Type} [Fintype I] [Fintype J] [Fintype A] -variable {n : ℕ} - -def spring (p : Shape) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) - (y : Knobs p.g n) := point p s (lit f l y) - -theorem spring_update (p : Shape) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) - (y : Knobs p.g n) (B) (h : f.keeps l B) (z : Vec (Fin n)) : - spring p l s f (update y B z)= spring p l s f (update y B 0)+ - blockRay p n s B *ᵥ z := by - classical - have he : baseV (lit f l (update y B z))=baseV (lit f l (update y B 0))+blockA p n B *ᵥ z := by - funext a - rcases a with _|⟨d,j⟩ - · simp [baseV,blockA,mulVec,dotProduct,embedMat] - by_cases hk : d=B - · subst d; simp [baseV,blockA,mulVec,dotProduct,embedMat,lit,h] - simp [baseV,blockA,mulVec,dotProduct,embedMat,lit,hk] - unfold spring point blockRay - rw [he,map_add,←Matrix.mulVec_mulVec,labMat_act] - -private def dotLB (I : Type) [Fintype I] : Vec I →ₗ[F] Vec I→ₗ[F] F where - toFun := dotL - map_add' p q := LinearMap.ext fun i => add_dotProduct p q i - map_smul' a p := LinearMap.ext fun i => by - change dotProduct (a • p) i=a*dotProduct p i - rw [smul_dotProduct]; rfl - -theorem spark_walsh [DecidableEq I] [DecidableEq J] (M : Mat I J) (p : Wgt (Vec I)) (q : Wgt (Vec J)) - (hp : ∀ i, |p i|≤1) (hq : ∀ i, |q i|≤1) : - |avg (pairW unif unif) (fun i => wsign (evmat M i.1 i.2)*(p i.1*q i.2))| ≤ - bp (-(M.rank:ℝ)/2) := by - classical - let Q := dotLB I - let L := Q ∘ₗ M.mulVecLin - have he (i j) : evmat M i j=L j i := dotProduct_comm .. - have hh : Injective Q := fun x y h => funext (fun i => by - have hg := LinearMap.congr_fun h (Pi.single i 1) - change dotProduct x (Pi.single i 1)=dotProduct y (Pi.single i 1) at hg - simpa using hg) - have ht : rk L=M.rank := by - have h : LinearMap.ker L=LinearMap.ker M.mulVecLin := by - ext x; change Q (M.mulVecLin x)=0 ↔ M.mulVecLin x=0 - rw [← map_zero Q,hh.eq_iff] - have hv := L.finrank_range_add_finrank_ker - rw [h, ← M.mulVecLin.finrank_range_add_finrank_ker] at hv - exact Nat.add_right_cancel hv - rw [pairW_avg] - have hz (x : Vec I) (y : Vec J) : wsign (evmat M x y)*(p x*q y)=p x*(q y*wsign (L y x)) := by - rw [he]; ring - simp_rw [hz,avg_mul'] - rw [←ht] - exact walsh_bound _ q p hq hp - -set_option maxHeartbeats 800000 in -theorem spark_uncap (p : Shape) (M : Moment p n) (s t : Label p.b) (l j : Tag p.g) - (f g : Flavor p.g) (B) (hB : f.keeps l B) (hB' : g.keeps j B) - (w u : Wgt (Knobs p.g n)) (hw : ∀ i,|w i| ≤ 1) (hu : ∀ i,|u i|≤1) : - let Q i z := evmat M (spring p l s f i) (spring p j t g z) - |avg (pairW unif unif) (fun x => wsign (Q x.1 x.2)*(w x.1*u x.2))|≤ - bp (-(blockRank B s t M:ℝ)/2) := by - classical - intro Q - let F (x : Knobs p.g n × _) := wsign (Q x.1 x.2)*(w x.1*u x.2) - let K := Wgt (Vec (Fin n)) - let v : Block p.g→ K := fun _ => unif - have ht := update2_avg v v B F unif_law unif_law - have he : prodW v=unif := draws_unif.symm - let R := blockRay p n s B; let S:=blockRay p n t B - let H := pullM R S M - have hi (x y : Knobs p.g n) : - |avg (pairW (v B) (v B)) (fun i => F (update x B i.1,update y B i.2))|≤ - bp (-(blockRank B s t M:ℝ)/2) := by - let X := spring p l s f (update x B 0); let Y := spring p j t g (update y B 0) - let A i := evmat M (R *ᵥ i) Y; let D j := evmat M X (S *ᵥ j)+evmat M X Y - let Z i := wsign (A i)*w (update x B i); let W j := wsign (D j)*u (update y B j) - have hp i j' : - Q (update x B i) (update y B j')= evmat H i j'+(A i+D j') := by - unfold Q; rw [spring_update _ _ _ _ _ _ hB,spring_update _ _ _ _ _ _ hB'] - unfold H A D X Y; rw [evmat_pull] - simp only [evmat,mulVec_add,add_dotProduct,dotProduct_add,R,S]; ac_rfl - have hh i j : F (update x B i,update y B j)=wsign (evmat H i j)*(Z i*W j) := by - unfold F Z W; dsimp only; rw [hp,wsign_add,wsign_add]; ring - have hz i : |Z i|≤1 := by unfold Z; rw [abs_mul,wsign_abs,one_mul]; exact hw _ - have hy i : |W i|≤1 := by unfold W; rw [abs_mul,wsign_abs,one_mul]; exact hu _ - simp_rw [hh] - exact spark_walsh _ Z W hz hy - simp only [he] at ht - change |avg (pairW unif unif) F|≤_ - rw [ht] - let hq := pairW_law (α:=Knobs p.g n) (β:=Knobs p.g n) unif_law unif_law - exact (abs_avg_le hq.nz).trans (hq.avg_le fun x => hi x.1 x.2) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.OppositeEndpointForms + +namespace OAI + +/-! # Bilinear Block Correlation -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset LinearMap Module Matrix Function +open scoped BigOperators +variable {p : Shape} {I J A : Type} [Fintype I] [Fintype J] [Fintype A] +variable {n : ℕ} + +def spring (p : Shape) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) + (y : Knobs p.g n) := point p s (lit f l y) + +theorem spring_update (p : Shape) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) + (y : Knobs p.g n) (B) (h : f.keeps l B) (z : Vec (Fin n)) : + spring p l s f (update y B z)= spring p l s f (update y B 0)+ + blockRay p n s B *ᵥ z := by + classical + have he : baseV (lit f l (update y B z))=baseV (lit f l (update y B 0))+blockA p n B *ᵥ z := by + funext a + rcases a with _|⟨d,j⟩ + · simp [baseV,blockA,mulVec,dotProduct,embedMat] + by_cases hk : d=B + · subst d; simp [baseV,blockA,mulVec,dotProduct,embedMat,lit,h] + simp [baseV,blockA,mulVec,dotProduct,embedMat,lit,hk] + unfold spring point blockRay + rw [he,map_add,←Matrix.mulVec_mulVec,labMat_act] + +private def dotLB (I : Type) [Fintype I] : Vec I →ₗ[F] Vec I→ₗ[F] F where + toFun := dotL + map_add' p q := LinearMap.ext fun i => add_dotProduct p q i + map_smul' a p := LinearMap.ext fun i => by + change dotProduct (a • p) i=a*dotProduct p i + rw [smul_dotProduct]; rfl + +theorem spark_walsh [DecidableEq I] [DecidableEq J] (M : Mat I J) (p : Wgt (Vec I)) (q : Wgt (Vec J)) + (hp : ∀ i, |p i|≤1) (hq : ∀ i, |q i|≤1) : + |avg (pairW unif unif) (fun i => wsign (evmat M i.1 i.2)*(p i.1*q i.2))| ≤ + bp (-(M.rank:ℝ)/2) := by + classical + let Q := dotLB I + let L := Q ∘ₗ M.mulVecLin + have he (i j) : evmat M i j=L j i := dotProduct_comm .. + have hh : Injective Q := fun x y h => funext (fun i => by + have hg := LinearMap.congr_fun h (Pi.single i 1) + change dotProduct x (Pi.single i 1)=dotProduct y (Pi.single i 1) at hg + simpa using hg) + have ht : rk L=M.rank := by + have h : LinearMap.ker L=LinearMap.ker M.mulVecLin := by + ext x; change Q (M.mulVecLin x)=0 ↔ M.mulVecLin x=0 + rw [← map_zero Q,hh.eq_iff] + have hv := L.finrank_range_add_finrank_ker + rw [h, ← M.mulVecLin.finrank_range_add_finrank_ker] at hv + exact Nat.add_right_cancel hv + rw [pairW_avg] + have hz (x : Vec I) (y : Vec J) : wsign (evmat M x y)*(p x*q y)=p x*(q y*wsign (L y x)) := by + rw [he]; ring + simp_rw [hz,avg_mul'] + rw [←ht] + exact walsh_bound _ q p hq hp + +set_option maxHeartbeats 800000 in +theorem spark_uncap (p : Shape) (M : Moment p n) (s t : Label p.b) (l j : Tag p.g) + (f g : Flavor p.g) (B) (hB : f.keeps l B) (hB' : g.keeps j B) + (w u : Wgt (Knobs p.g n)) (hw : ∀ i,|w i| ≤ 1) (hu : ∀ i,|u i|≤1) : + let Q i z := evmat M (spring p l s f i) (spring p j t g z) + |avg (pairW unif unif) (fun x => wsign (Q x.1 x.2)*(w x.1*u x.2))|≤ + bp (-(blockRank B s t M:ℝ)/2) := by + classical + intro Q + let F (x : Knobs p.g n × _) := wsign (Q x.1 x.2)*(w x.1*u x.2) + let K := Wgt (Vec (Fin n)) + let v : Block p.g→ K := fun _ => unif + have ht := update2_avg v v B F unif_law unif_law + have he : prodW v=unif := draws_unif.symm + let R := blockRay p n s B; let S:=blockRay p n t B + let H := pullM R S M + have hi (x y : Knobs p.g n) : + |avg (pairW (v B) (v B)) (fun i => F (update x B i.1,update y B i.2))|≤ + bp (-(blockRank B s t M:ℝ)/2) := by + let X := spring p l s f (update x B 0); let Y := spring p j t g (update y B 0) + let A i := evmat M (R *ᵥ i) Y; let D j := evmat M X (S *ᵥ j)+evmat M X Y + let Z i := wsign (A i)*w (update x B i); let W j := wsign (D j)*u (update y B j) + have hp i j' : + Q (update x B i) (update y B j')= evmat H i j'+(A i+D j') := by + unfold Q; rw [spring_update _ _ _ _ _ _ hB,spring_update _ _ _ _ _ _ hB'] + unfold H A D X Y; rw [evmat_pull] + simp only [evmat,mulVec_add,add_dotProduct,dotProduct_add,R,S]; ac_rfl + have hh i j : F (update x B i,update y B j)=wsign (evmat H i j)*(Z i*W j) := by + unfold F Z W; dsimp only; rw [hp,wsign_add,wsign_add]; ring + have hz i : |Z i|≤1 := by unfold Z; rw [abs_mul,wsign_abs,one_mul]; exact hw _ + have hy i : |W i|≤1 := by unfold W; rw [abs_mul,wsign_abs,one_mul]; exact hu _ + simp_rw [hh] + exact spark_walsh _ Z W hz hy + simp only [he] at ht + change |avg (pairW unif unif) F|≤_ + rw [ht] + let hq := pairW_law (α:=Knobs p.g n) (β:=Knobs p.g n) unif_law unif_law + exact (abs_avg_le hq.nz).trans (hq.avg_le fun x => hi x.1 x.2) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/BilinearCompression.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/BilinearCompression.lean index 918421222ed9c99bcedf4afdc61d5c0088d7f0fb..93ba8dc605e6a9a64ffa5b7adea15df6192605c8 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/BilinearCompression.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/BilinearCompression.lean @@ -1,126 +1,126 @@ -import OAI.Combinatorics.HadwigerCounterexample.PrimalSpaceCompression - -namespace OAI - -/-! # Bilinear Compression -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Submodule Module Finset -open scoped BigOperators - -variable {p : Shape} {n : ℕ} {I J : Type} [Fintype I] [Fintype J] - -def dqBound (p : Shape) (T H R : ℕ) := 2*(drow p T R+H) - -private theorem pullM_fix (A : Mat I I) (P : Mat I I) - (h : ∀ x ∈ colSp P,Aᵀ *ᵥ x=x) (h' : ∀ x∈colSp Pᵀ,Aᵀ *ᵥ x=x) : - pullM A A P=P := by - rw [pullM_def,mat_mul_fix h] - have he := congrArg Matrix.transpose (mat_mul_fix h') - simpa only [Matrix.transpose_mul,Matrix.transpose_transpose] using he - -private def dualSpace (M : Profile p n) (z : Place p) := - colSp (if z.2 then M z.1 else (M z.1)ᵀ) -private theorem dualSpace_dim (M : Profile p n) (z : Place p) : - dim (dualSpace M z)=(M z.1).rank := by - cases z with - | mk i b => - cases b; exact Matrix.rank_transpose _; rfl - -private def jointShrink (A : Bool → Nendo p n) (B : Place p → Bool → Mat (Chan p) (Chan p)) - (z : Place p) := - ∑ i : Bool,(liftM (IP p n i) (IP p n i) (rowShrink p (A i))+ - liftM (IH p n i) (IH p n i) (B z i)) - -private theorem joint_ip (A : Bool → Nendo p n) (B : Place p → Bool → Mat (Chan p) (Chan p)) - (z : Place p) (i : Bool) : - jointShrink A B z * IP p n i = IP p n i * rowShrink p (A i) := by - classical - simp only [jointShrink,Fintype.sum_bool,liftM_def,Matrix.add_mul,Matrix.mul_assoc, - IH_IP,Matrix.mul_zero,add_zero] - cases i <;> simp only [IP_self,IP_cross (show true≠false by decide), - IP_cross (show false≠true by decide),Matrix.mul_zero,Matrix.mul_one,add_zero,zero_add] - -set_option maxHeartbeats 800000 in -theorem shrink_pure {f : Plan p n} {M : Individual p n} {P : PureForms p n} - (T H R : ℕ) (ht : ∀ z i,dim (sPin f z i)≤T) (hh : ∀ z i,dim (hPin f z i)≤H) - (hr : ∀ i e,(M i e).rank≤R) - (hp : P∈pureSpace p f) (he : obsPair p P=obsI p M) : - ∃ Q∈pureSpace p f,obsPair p Q=obsPair p P ∧ ∀ e,(Q e).rank≤dqBound p T H R := by - classical - choose A hA hL hT using fun i => shrink_both (fun z => sPin f z i) (dualSpace (M i)) T R - (fun z => ht z i) (fun z => by rw [dualSpace_dim]; exact hr i z.1) - choose B hB using fun z i => proj_exists (hPin f z i) ⊥ disjoint_bot_right - let D := jointShrink A B - have hf (z : Place p) (x : Dir p n) (hx : x∈f z) : D z *ᵥ x=x := by - have h1 (i : Bool) : rowShrink p (A i) *ᵥ ((IP p n i)ᵀ *ᵥ x)=(IP p n i)ᵀ *ᵥ x := - hA i z _ ⟨_,hx,rfl⟩ - have h2 (i : Bool) : B z i *ᵥ ((IH p n i)ᵀ *ᵥ x)=(IH p n i)ᵀ *ᵥ x := - (hB z i).fixes _ ⟨_,hx,rfl⟩ - unfold D jointShrink - simp only [Matrix.sum_mulVec,Matrix.add_mulVec,liftM_def,← Matrix.mulVec_mulVec,h1,h2] - exact ip_decomp x - have hR (z : Place p) : (D z).rank ≤ dqBound p T H R := by - apply le_trans (mrk_sum_le ..) - have hx i : - (liftM (IP p n i) (IP p n i) (rowShrink p (A i))+ - liftM (IH p n i) (IH p n i) (B z i)).rank ≤ drow p T R+H := - (mrk_add_le ..).trans (add_le_add - ((rank_lift_le ..).trans (hT i)) ((rank_lift_le ..).trans - ((rank_maps (hPin f z i) (hB z i).onto).trans (hh z i)))) - rw [Fintype.sum_bool,dqBound,two_mul]; exact add_le_add (hx _) (hx _) - let Q (e : Comp p.g) := pullM (D (e,true)) (D (e,false)) (P e) - have hG (i : Bool) (e : Comp p.g) : pullM (rowShrink p (A i)) (rowShrink p (A i)) (M i e)= - M i e := pullM_fix _ _ (hL i (e,true)) (hL i (e,false)) - have hY (i : Bool) (e : Comp p.g) : eachF p Q i e= - pullM (rowShrink p (A i)) (rowShrink p (A i)) (eachF p P i e) := by - change pullM _ _ (Q e)=pullM _ _ (pullM _ _ _) - let G := IP p n i - have hw {I J K U V W : Type} [Fintype U] [Fintype V] [Fintype W] [Fintype I] - [Fintype J] [Fintype K] (L : Mat U I) (R : Mat V J) - (L' : Mat I K) (R' : Mat J W) (P : Mat U V) : - pullM L' R' (pullM L R P) = pullM (L*L') (R*R') P := by - unfold pullM - rw [liftM_comp,Matrix.transpose_mul,Matrix.transpose_mul] - unfold Q - rw [hw,hw] - have h (b) := joint_ip A B (e,b) i - rw [show D (e,true)*IP p n i=_ from h true, show D (e,false)*IP p n i=_ from h false] - - refine ⟨Q,?_,?_,fun e => ?_⟩ - · refine (pureSpace_mem _).mpr fun e => ?_ - obtain ⟨h1,h2⟩ := box_kill.mp ((pureSpace_mem _).mp hp e) - unfold Q; rw [box_kill,pullM_def]; constructor - · intro x hx - simp only [transpose_mul,transpose_transpose,←Matrix.mulVec_mulVec,hf (e,true) x hx,h1 x hx, - mulVec_zero] - intro x hx - rw [← mulVec_mulVec,hf (e,false) x hx] - rw [← mulVec_mulVec,h2 x hx,mulVec_zero] - · rw [he,obsPair_each] - rw [obsPair_each] at he - change combineF p _=combineF p _ - change combineF p _=combineF p _ at he - have he := (combineF_same ..).mp he - apply (combineF_same ..).mpr - intro i x hx - let y : Profile p n := fun e => liftM (rowShrink p (A i)) (rowShrink p (A i)) (x e) - rw [repF_rep,repF_rep] - have hv := he i y (shrink_X (A i) x hx) - rw [repF_rep,repF_rep] at hv - have hu (F : Individual p n) : (∑ e,mpair (F i e) (y e))= - ∑ e,mpair (pullM (rowShrink p (A i)) (rowShrink p (A i)) (F i e)) (x e) := - Finset.sum_congr rfl fun e _ => mpair_liftM .. - rw [hu,hu] at hv - simp_rw [← hY,hG] at hv - exact hv - unfold Q; rw [pullM_def] - exact ((Matrix.rank_mul_le_left ..).trans (Matrix.rank_mul_le_left ..)).trans - (by rw [Matrix.rank_transpose]; exact hR _) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PrimalSpaceCompression + +namespace OAI + +/-! # Bilinear Compression -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Submodule Module Finset +open scoped BigOperators + +variable {p : Shape} {n : ℕ} {I J : Type} [Fintype I] [Fintype J] + +def dqBound (p : Shape) (T H R : ℕ) := 2*(drow p T R+H) + +private theorem pullM_fix (A : Mat I I) (P : Mat I I) + (h : ∀ x ∈ colSp P,Aᵀ *ᵥ x=x) (h' : ∀ x∈colSp Pᵀ,Aᵀ *ᵥ x=x) : + pullM A A P=P := by + rw [pullM_def,mat_mul_fix h] + have he := congrArg Matrix.transpose (mat_mul_fix h') + simpa only [Matrix.transpose_mul,Matrix.transpose_transpose] using he + +private def dualSpace (M : Profile p n) (z : Place p) := + colSp (if z.2 then M z.1 else (M z.1)ᵀ) +private theorem dualSpace_dim (M : Profile p n) (z : Place p) : + dim (dualSpace M z)=(M z.1).rank := by + cases z with + | mk i b => + cases b; exact Matrix.rank_transpose _; rfl + +private def jointShrink (A : Bool → Nendo p n) (B : Place p → Bool → Mat (Chan p) (Chan p)) + (z : Place p) := + ∑ i : Bool,(liftM (IP p n i) (IP p n i) (rowShrink p (A i))+ + liftM (IH p n i) (IH p n i) (B z i)) + +private theorem joint_ip (A : Bool → Nendo p n) (B : Place p → Bool → Mat (Chan p) (Chan p)) + (z : Place p) (i : Bool) : + jointShrink A B z * IP p n i = IP p n i * rowShrink p (A i) := by + classical + simp only [jointShrink,Fintype.sum_bool,liftM_def,Matrix.add_mul,Matrix.mul_assoc, + IH_IP,Matrix.mul_zero,add_zero] + cases i <;> simp only [IP_self,IP_cross (show true≠false by decide), + IP_cross (show false≠true by decide),Matrix.mul_zero,Matrix.mul_one,add_zero,zero_add] + +set_option maxHeartbeats 800000 in +theorem shrink_pure {f : Plan p n} {M : Individual p n} {P : PureForms p n} + (T H R : ℕ) (ht : ∀ z i,dim (sPin f z i)≤T) (hh : ∀ z i,dim (hPin f z i)≤H) + (hr : ∀ i e,(M i e).rank≤R) + (hp : P∈pureSpace p f) (he : obsPair p P=obsI p M) : + ∃ Q∈pureSpace p f,obsPair p Q=obsPair p P ∧ ∀ e,(Q e).rank≤dqBound p T H R := by + classical + choose A hA hL hT using fun i => shrink_both (fun z => sPin f z i) (dualSpace (M i)) T R + (fun z => ht z i) (fun z => by rw [dualSpace_dim]; exact hr i z.1) + choose B hB using fun z i => proj_exists (hPin f z i) ⊥ disjoint_bot_right + let D := jointShrink A B + have hf (z : Place p) (x : Dir p n) (hx : x∈f z) : D z *ᵥ x=x := by + have h1 (i : Bool) : rowShrink p (A i) *ᵥ ((IP p n i)ᵀ *ᵥ x)=(IP p n i)ᵀ *ᵥ x := + hA i z _ ⟨_,hx,rfl⟩ + have h2 (i : Bool) : B z i *ᵥ ((IH p n i)ᵀ *ᵥ x)=(IH p n i)ᵀ *ᵥ x := + (hB z i).fixes _ ⟨_,hx,rfl⟩ + unfold D jointShrink + simp only [Matrix.sum_mulVec,Matrix.add_mulVec,liftM_def,← Matrix.mulVec_mulVec,h1,h2] + exact ip_decomp x + have hR (z : Place p) : (D z).rank ≤ dqBound p T H R := by + apply le_trans (mrk_sum_le ..) + have hx i : + (liftM (IP p n i) (IP p n i) (rowShrink p (A i))+ + liftM (IH p n i) (IH p n i) (B z i)).rank ≤ drow p T R+H := + (mrk_add_le ..).trans (add_le_add + ((rank_lift_le ..).trans (hT i)) ((rank_lift_le ..).trans + ((rank_maps (hPin f z i) (hB z i).onto).trans (hh z i)))) + rw [Fintype.sum_bool,dqBound,two_mul]; exact add_le_add (hx _) (hx _) + let Q (e : Comp p.g) := pullM (D (e,true)) (D (e,false)) (P e) + have hG (i : Bool) (e : Comp p.g) : pullM (rowShrink p (A i)) (rowShrink p (A i)) (M i e)= + M i e := pullM_fix _ _ (hL i (e,true)) (hL i (e,false)) + have hY (i : Bool) (e : Comp p.g) : eachF p Q i e= + pullM (rowShrink p (A i)) (rowShrink p (A i)) (eachF p P i e) := by + change pullM _ _ (Q e)=pullM _ _ (pullM _ _ _) + let G := IP p n i + have hw {I J K U V W : Type} [Fintype U] [Fintype V] [Fintype W] [Fintype I] + [Fintype J] [Fintype K] (L : Mat U I) (R : Mat V J) + (L' : Mat I K) (R' : Mat J W) (P : Mat U V) : + pullM L' R' (pullM L R P) = pullM (L*L') (R*R') P := by + unfold pullM + rw [liftM_comp,Matrix.transpose_mul,Matrix.transpose_mul] + unfold Q + rw [hw,hw] + have h (b) := joint_ip A B (e,b) i + rw [show D (e,true)*IP p n i=_ from h true, show D (e,false)*IP p n i=_ from h false] + + refine ⟨Q,?_,?_,fun e => ?_⟩ + · refine (pureSpace_mem _).mpr fun e => ?_ + obtain ⟨h1,h2⟩ := box_kill.mp ((pureSpace_mem _).mp hp e) + unfold Q; rw [box_kill,pullM_def]; constructor + · intro x hx + simp only [transpose_mul,transpose_transpose,←Matrix.mulVec_mulVec,hf (e,true) x hx,h1 x hx, + mulVec_zero] + intro x hx + rw [← mulVec_mulVec,hf (e,false) x hx] + rw [← mulVec_mulVec,h2 x hx,mulVec_zero] + · rw [he,obsPair_each] + rw [obsPair_each] at he + change combineF p _=combineF p _ + change combineF p _=combineF p _ at he + have he := (combineF_same ..).mp he + apply (combineF_same ..).mpr + intro i x hx + let y : Profile p n := fun e => liftM (rowShrink p (A i)) (rowShrink p (A i)) (x e) + rw [repF_rep,repF_rep] + have hv := he i y (shrink_X (A i) x hx) + rw [repF_rep,repF_rep] at hv + have hu (F : Individual p n) : (∑ e,mpair (F i e) (y e))= + ∑ e,mpair (pullM (rowShrink p (A i)) (rowShrink p (A i)) (F i e)) (x e) := + Finset.sum_congr rfl fun e _ => mpair_liftM .. + rw [hu,hu] at hv + simp_rw [← hY,hG] at hv + exact hv + unfold Q; rw [pullM_def] + exact ((Matrix.rank_mul_le_left ..).trans (Matrix.rank_mul_le_left ..)).trans + (by rw [Matrix.rank_transpose]; exact hR _) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryEvaluationForms.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryEvaluationForms.lean index f9cacfdc2cf35836d7f73cc821fb6929f6f91c8f..964d92bff2b9964eccca7eb255f16642a3f43143 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryEvaluationForms.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryEvaluationForms.lean @@ -1,174 +1,174 @@ -import OAI.Combinatorics.HadwigerCounterexample.MixerConditions - -namespace OAI - -/-! # Binary Evaluation Forms -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix -variable {p : Shape} {n : ℕ} - -theorem pullT {I J V U : Type} [Fintype V] [Fintype U] - (A : Mat V U) (P : Mat U I) (Q : Mat V J) : - pullM P Q Aᵀ = (pullM Q P A)ᵀ := by - rw [pullM_def,pullM_def,transpose_mul,transpose_mul,transpose_transpose,Matrix.mul_assoc] - -theorem indexed_linear {c : Vec (MBits p)} {D D' : Draw p n} : - indexedSum (drawn (p:=p) (D+D')) c = - indexedSum (drawn D) c + indexedSum (drawn D') c := by - have h (i : MBits p) : - eitherM i.2 (orderedM (drawn (p:=p) (D+D')) i.1) = - eitherM i.2 (orderedM (drawn D) i.1) + eitherM i.2 (orderedM (drawn D') i.1) := by - rcases i with ⟨⟨⟨a,b,d⟩,_|_⟩,_|_⟩ <;> rfl - unfold indexedSum - simp_rw [h,smul_add,Finset.sum_add_distrib] - -def obsZ (p : Shape) (n : ℕ) (s t : Label p.b) (c : Vec (MBits p)) : - Draw p n →ₗ[F] Mat (Fin n) (Fin n) where - toFun D := pullM (blockRay p n s Block.Z) (blockRay p n t Block.Z) (indexedSum (drawn D) c) - map_add' _ _ := by rw [indexed_linear,map_add] - map_smul' a x := by - have h (i : MBits p) : - eitherM i.2 (orderedM (drawn (p:=p) (a•x)) i.1)= - a • eitherM i.2 (orderedM (drawn x) i.1) := by - rcases i with ⟨⟨⟨a,b,d⟩,_|_⟩,_|_⟩ <;> rfl - simp only [indexedSum,h,map_sum,map_smul,RingHom.id_apply,Finset.smul_sum] - exact Finset.sum_congr rfl fun i _ => smul_comm _ _ _ - -theorem obsZ_self (s t : Label p.b) (f : Vec Bool) (m : Mixer p n) : - pullM (blockRay p n s Block.Z) (blockRay p n t Block.Z) (selfSum m f) = 0 := by - rw [selfSum,Fintype.sum_bool,map_add,map_smul,map_smul] - change _ • pullM _ _ (selfM p n m.mixM) + _ • pullM _ _ (selfM p n m.mixM)ᵀ = 0 - rw [pullT,pull_self_Z,pull_self_Z] - simp - -private theorem two_eval (s t : Label p.b) (hj : 1≤p.j) (hs : s≠t) - (x : Bool → Mat (Fin n) (Fin n)) : - ∃ A : Moment p n, ∀ b, pullM (blockRay p n s Block.Z) (blockRay p n t Block.Z) - (eitherM b A) = x b := by - let P := blockRay p n s Block.Z - let Q := blockRay p n t Block.Z - have hh : Function.Injective (fromCols P Q).mulVec := joined_block_inj hj hs _ - obtain ⟨L,hL⟩ := prescribe_between hh hh - (fromBlocks (0:Mat (Fin n) (Fin n)) (x true) (x false)ᵀ (0:Mat (Fin n) (Fin n))) - rw [transpose_fromCols,fromRows_mul,fromRows_mul_fromCols] at hL - have hx : pullM P Q L = x true := congrArg Matrix.toBlocks₁₂ hL - have hy : pullM Q P L = (x false)ᵀ := congrArg Matrix.toBlocks₂₁ hL - refine ⟨L,fun b => ?_⟩ - cases b - · change pullM P Q Lᵀ=x false - rw [pullT,hy,transpose_transpose] - · exact hx - -theorem obsZ_surj (s t : Label p.b) (hj : 1≤p.j) (hs : s≠t) - {c : Vec (MBits p)} (hc : c ≠ 0) : Function.Surjective (obsZ p n s t c) := by - classical - simp only [ne_eq,funext_iff,Pi.zero_apply,not_forall] at hc - obtain ⟨i,hi⟩ := hc - intro M - let y (j : MBits p) := if j=i then M else 0 - choose A hA using fun j : MOne p => two_eval s t hj hs (fun b => y (j,b)) - let D : Draw p n := (fun j => A (j,true), fun j => A (j,false), 0) - have he (j : MBits p) : - pullM (blockRay p n s Block.Z) (blockRay p n t Block.Z) - (eitherM j.2 (orderedM (drawn D) j.1)) = y j := by - rcases j with ⟨⟨j,_|_⟩,x⟩ - · exact hA _ _ - · exact hA _ _ - refine ⟨D,?_⟩ - simp only [obsZ,indexedSum,map_sum,map_smul,he,LinearMap.coe_mk,AddHom.coe_mk] - rw [Finset.sum_eq_single i] - · simp [y,(bit_cases (c i)).resolve_left hi] - · intro j _ hj; simp [y,hj] - simp - -def selfPartial (s t : Label p.b) (f : Vec Bool) (D : Draw p n) : Mat (Fin n) (Fin n) := - let A := ∑ a, (s a+t a) • D.2.2 a - f true • A+f false • Aᵀ - -theorem pull_selfPart (s t : Label p.b) (hj : 1 ≤ p.j) (f : Vec Bool) (D : Draw p n) : - pullM (blockRay p n s Block.sharp) (blockRay p n t Block.sharp) (selfSum (drawn D) f) = - selfPartial (p:=p) s t f D := by - rw [selfSum, Fintype.sum_bool,map_add,map_smul,map_smul] - change _ • pullM _ _ (selfM p n D.2.2) + _ • pullM _ _ (selfM p n D.2.2)ᵀ = _ - rw [pullT,pull_self_sharp _ _ _ hj,pull_self_sharp _ _ _ hj] - unfold selfPartial - congr 2 - simp only [add_comm] - -def obsHalf (p : Shape) (s t : Label p.b) (f : Vec Bool) (n : ℕ) - (l r : Fin (n/2)→Fin n) : Draw p n →ₗ[F] Mat (Fin (n/2)) (Fin (n/2)) where - toFun D := (selfPartial (p:=p) s t f D).submatrix l r - map_add' _ _ := by - simp only [selfPartial, Prod.snd_add, Pi.add_apply, smul_add, Finset.sum_add_distrib, - transpose_add, Matrix.submatrix_add] - abel - map_smul' a D := by - simp only [selfPartial,Prod.smul_snd,Pi.smul_apply,RingHom.id_apply] - let F (D : Draw p n) := ∑ i, (s i+t i) • D.2.2 i - have h : - ∑ i, (s i+t i) • (a • D.2.2 i) = a • F D := by - unfold F; rw [Finset.smul_sum]; exact Finset.sum_congr rfl fun _ _ => smul_comm _ _ _ - rw [h,Matrix.transpose_smul] - rw [smul_comm (f true),smul_comm (f false) a, ← smul_add] - rfl - -/-- Uniform off-diagonal block even in transpose-character case. -/ -theorem obsHalf_surj (s t : Label p.b) (hs : s≠t) {f : Vec Bool} (hf : f≠0) (n : ℕ) - {l r : Fin (n/2)→Fin n} (hl : Function.Injective l) (hr : Function.Injective r) - (h : ∀ i j,l i≠r j) : Function.Surjective (obsHalf p s t f n l r) := by - classical - intro M - obtain ⟨a,ha⟩ : ∃ a,s a+t a=1 := by - obtain ⟨a,ha⟩ := Function.ne_iff.mp hs - exact ⟨a,(bit_cases _).resolve_left (fun h => ha - (add_right_cancel (h.trans (char_two _).symm)))⟩ - let m := n/2 - let P := embedMat l - let Q := embedMat r - have hi : Function.Injective (fromCols P Q).mulVec := by - have he : fromCols P Q = embedMat (Sum.elim l r) := by ext i j; cases j <;> rfl - rw [he]; apply embedMat_inj - rintro (x|x) (y|y) g - · rw [hl g] - · exact (h _ _ g).elim - · exact (h _ _ g.symm).elim - · rw [hr g] - have hv (x y : Mat (Fin m) (Fin m)) : - ∃ A : Mat (Fin n) (Fin n), A.submatrix l r=x ∧ Aᵀ.submatrix l r=y := by - obtain ⟨A,hA⟩ := prescribe_between hi hi (fromBlocks (0:Mat (Fin m) (Fin m)) x yᵀ - (0:Mat (Fin m) (Fin m))) - rw [transpose_fromCols,fromRows_mul,fromRows_mul_fromCols] at hA - have h1 : Pᵀ*A*Q=x := congrArg Matrix.toBlocks₁₂ hA - have h2 : Qᵀ*A*P=yᵀ := congrArg Matrix.toBlocks₂₁ hA - unfold P Q at * - rw [embedMat_mul,mul_embedMat] at h1 h2 - exact ⟨A,h1,congrArg Matrix.transpose h2⟩ - obtain ⟨x,y,hx⟩ : ∃ x y : Mat (Fin m) (Fin m), f true • x+f false • y=M := by - rcases bit_cases (f true) with g|g - · have hg : f false≠0 := fun hg => hf (funext fun i => by cases i <;> assumption) - exact ⟨0,M,by rw [(bit_cases _).resolve_left hg]; simp⟩ - · exact ⟨M,0,by rw [g]; simp⟩ - obtain ⟨A,h1,h2⟩ := hv x y - let D : Draw p n := (0,0,Pi.single a A) - have hE : - ∑ i,(s i+t i) • D.2.2 i=A := by - rw [Finset.sum_eq_single a] - · simp [D,ha] - · intro i _ hi; simp [D,Pi.single_eq_of_ne hi] - simp - refine ⟨D,?_⟩ - change (selfPartial (p:=p) s t f D).submatrix l r=M - unfold selfPartial - rw [hE] - change (f true • A + f false • Aᵀ).submatrix l r = _ - change f true • A.submatrix l r + f false • Aᵀ.submatrix l r = M - rw [h1,h2,hx] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.MixerConditions + +namespace OAI + +/-! # Binary Evaluation Forms -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix +variable {p : Shape} {n : ℕ} + +theorem pullT {I J V U : Type} [Fintype V] [Fintype U] + (A : Mat V U) (P : Mat U I) (Q : Mat V J) : + pullM P Q Aᵀ = (pullM Q P A)ᵀ := by + rw [pullM_def,pullM_def,transpose_mul,transpose_mul,transpose_transpose,Matrix.mul_assoc] + +theorem indexed_linear {c : Vec (MBits p)} {D D' : Draw p n} : + indexedSum (drawn (p:=p) (D+D')) c = + indexedSum (drawn D) c + indexedSum (drawn D') c := by + have h (i : MBits p) : + eitherM i.2 (orderedM (drawn (p:=p) (D+D')) i.1) = + eitherM i.2 (orderedM (drawn D) i.1) + eitherM i.2 (orderedM (drawn D') i.1) := by + rcases i with ⟨⟨⟨a,b,d⟩,_|_⟩,_|_⟩ <;> rfl + unfold indexedSum + simp_rw [h,smul_add,Finset.sum_add_distrib] + +def obsZ (p : Shape) (n : ℕ) (s t : Label p.b) (c : Vec (MBits p)) : + Draw p n →ₗ[F] Mat (Fin n) (Fin n) where + toFun D := pullM (blockRay p n s Block.Z) (blockRay p n t Block.Z) (indexedSum (drawn D) c) + map_add' _ _ := by rw [indexed_linear,map_add] + map_smul' a x := by + have h (i : MBits p) : + eitherM i.2 (orderedM (drawn (p:=p) (a•x)) i.1)= + a • eitherM i.2 (orderedM (drawn x) i.1) := by + rcases i with ⟨⟨⟨a,b,d⟩,_|_⟩,_|_⟩ <;> rfl + simp only [indexedSum,h,map_sum,map_smul,RingHom.id_apply,Finset.smul_sum] + exact Finset.sum_congr rfl fun i _ => smul_comm _ _ _ + +theorem obsZ_self (s t : Label p.b) (f : Vec Bool) (m : Mixer p n) : + pullM (blockRay p n s Block.Z) (blockRay p n t Block.Z) (selfSum m f) = 0 := by + rw [selfSum,Fintype.sum_bool,map_add,map_smul,map_smul] + change _ • pullM _ _ (selfM p n m.mixM) + _ • pullM _ _ (selfM p n m.mixM)ᵀ = 0 + rw [pullT,pull_self_Z,pull_self_Z] + simp + +private theorem two_eval (s t : Label p.b) (hj : 1≤p.j) (hs : s≠t) + (x : Bool → Mat (Fin n) (Fin n)) : + ∃ A : Moment p n, ∀ b, pullM (blockRay p n s Block.Z) (blockRay p n t Block.Z) + (eitherM b A) = x b := by + let P := blockRay p n s Block.Z + let Q := blockRay p n t Block.Z + have hh : Function.Injective (fromCols P Q).mulVec := joined_block_inj hj hs _ + obtain ⟨L,hL⟩ := prescribe_between hh hh + (fromBlocks (0:Mat (Fin n) (Fin n)) (x true) (x false)ᵀ (0:Mat (Fin n) (Fin n))) + rw [transpose_fromCols,fromRows_mul,fromRows_mul_fromCols] at hL + have hx : pullM P Q L = x true := congrArg Matrix.toBlocks₁₂ hL + have hy : pullM Q P L = (x false)ᵀ := congrArg Matrix.toBlocks₂₁ hL + refine ⟨L,fun b => ?_⟩ + cases b + · change pullM P Q Lᵀ=x false + rw [pullT,hy,transpose_transpose] + · exact hx + +theorem obsZ_surj (s t : Label p.b) (hj : 1≤p.j) (hs : s≠t) + {c : Vec (MBits p)} (hc : c ≠ 0) : Function.Surjective (obsZ p n s t c) := by + classical + simp only [ne_eq,funext_iff,Pi.zero_apply,not_forall] at hc + obtain ⟨i,hi⟩ := hc + intro M + let y (j : MBits p) := if j=i then M else 0 + choose A hA using fun j : MOne p => two_eval s t hj hs (fun b => y (j,b)) + let D : Draw p n := (fun j => A (j,true), fun j => A (j,false), 0) + have he (j : MBits p) : + pullM (blockRay p n s Block.Z) (blockRay p n t Block.Z) + (eitherM j.2 (orderedM (drawn D) j.1)) = y j := by + rcases j with ⟨⟨j,_|_⟩,x⟩ + · exact hA _ _ + · exact hA _ _ + refine ⟨D,?_⟩ + simp only [obsZ,indexedSum,map_sum,map_smul,he,LinearMap.coe_mk,AddHom.coe_mk] + rw [Finset.sum_eq_single i] + · simp [y,(bit_cases (c i)).resolve_left hi] + · intro j _ hj; simp [y,hj] + simp + +def selfPartial (s t : Label p.b) (f : Vec Bool) (D : Draw p n) : Mat (Fin n) (Fin n) := + let A := ∑ a, (s a+t a) • D.2.2 a + f true • A+f false • Aᵀ + +theorem pull_selfPart (s t : Label p.b) (hj : 1 ≤ p.j) (f : Vec Bool) (D : Draw p n) : + pullM (blockRay p n s Block.sharp) (blockRay p n t Block.sharp) (selfSum (drawn D) f) = + selfPartial (p:=p) s t f D := by + rw [selfSum, Fintype.sum_bool,map_add,map_smul,map_smul] + change _ • pullM _ _ (selfM p n D.2.2) + _ • pullM _ _ (selfM p n D.2.2)ᵀ = _ + rw [pullT,pull_self_sharp _ _ _ hj,pull_self_sharp _ _ _ hj] + unfold selfPartial + congr 2 + simp only [add_comm] + +def obsHalf (p : Shape) (s t : Label p.b) (f : Vec Bool) (n : ℕ) + (l r : Fin (n/2)→Fin n) : Draw p n →ₗ[F] Mat (Fin (n/2)) (Fin (n/2)) where + toFun D := (selfPartial (p:=p) s t f D).submatrix l r + map_add' _ _ := by + simp only [selfPartial, Prod.snd_add, Pi.add_apply, smul_add, Finset.sum_add_distrib, + transpose_add, Matrix.submatrix_add] + abel + map_smul' a D := by + simp only [selfPartial,Prod.smul_snd,Pi.smul_apply,RingHom.id_apply] + let F (D : Draw p n) := ∑ i, (s i+t i) • D.2.2 i + have h : + ∑ i, (s i+t i) • (a • D.2.2 i) = a • F D := by + unfold F; rw [Finset.smul_sum]; exact Finset.sum_congr rfl fun _ _ => smul_comm _ _ _ + rw [h,Matrix.transpose_smul] + rw [smul_comm (f true),smul_comm (f false) a, ← smul_add] + rfl + +/-- Uniform off-diagonal block even in transpose-character case. -/ +theorem obsHalf_surj (s t : Label p.b) (hs : s≠t) {f : Vec Bool} (hf : f≠0) (n : ℕ) + {l r : Fin (n/2)→Fin n} (hl : Function.Injective l) (hr : Function.Injective r) + (h : ∀ i j,l i≠r j) : Function.Surjective (obsHalf p s t f n l r) := by + classical + intro M + obtain ⟨a,ha⟩ : ∃ a,s a+t a=1 := by + obtain ⟨a,ha⟩ := Function.ne_iff.mp hs + exact ⟨a,(bit_cases _).resolve_left (fun h => ha + (add_right_cancel (h.trans (char_two _).symm)))⟩ + let m := n/2 + let P := embedMat l + let Q := embedMat r + have hi : Function.Injective (fromCols P Q).mulVec := by + have he : fromCols P Q = embedMat (Sum.elim l r) := by ext i j; cases j <;> rfl + rw [he]; apply embedMat_inj + rintro (x|x) (y|y) g + · rw [hl g] + · exact (h _ _ g).elim + · exact (h _ _ g.symm).elim + · rw [hr g] + have hv (x y : Mat (Fin m) (Fin m)) : + ∃ A : Mat (Fin n) (Fin n), A.submatrix l r=x ∧ Aᵀ.submatrix l r=y := by + obtain ⟨A,hA⟩ := prescribe_between hi hi (fromBlocks (0:Mat (Fin m) (Fin m)) x yᵀ + (0:Mat (Fin m) (Fin m))) + rw [transpose_fromCols,fromRows_mul,fromRows_mul_fromCols] at hA + have h1 : Pᵀ*A*Q=x := congrArg Matrix.toBlocks₁₂ hA + have h2 : Qᵀ*A*P=yᵀ := congrArg Matrix.toBlocks₂₁ hA + unfold P Q at * + rw [embedMat_mul,mul_embedMat] at h1 h2 + exact ⟨A,h1,congrArg Matrix.transpose h2⟩ + obtain ⟨x,y,hx⟩ : ∃ x y : Mat (Fin m) (Fin m), f true • x+f false • y=M := by + rcases bit_cases (f true) with g|g + · have hg : f false≠0 := fun hg => hf (funext fun i => by cases i <;> assumption) + exact ⟨0,M,by rw [(bit_cases _).resolve_left hg]; simp⟩ + · exact ⟨M,0,by rw [g]; simp⟩ + obtain ⟨A,h1,h2⟩ := hv x y + let D : Draw p n := (0,0,Pi.single a A) + have hE : + ∑ i,(s i+t i) • D.2.2 i=A := by + rw [Finset.sum_eq_single a] + · simp [D,ha] + · intro i _ hi; simp [D,Pi.single_eq_of_ne hi] + simp + refine ⟨D,?_⟩ + change (selfPartial (p:=p) s t f D).submatrix l r=M + unfold selfPartial + rw [hE] + change (f true • A + f false • Aᵀ).submatrix l r = _ + change f true • A.submatrix l r + f false • Aᵀ.submatrix l r = M + rw [h1,h2,hx] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryMatrices.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryMatrices.lean index 2125ec6d19fa6238ecaf8303ea2007aea36320ea..a477ddcd0bf8dbd7b55e2a2417593e64c07a6794 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryMatrices.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryMatrices.lean @@ -1,125 +1,125 @@ -import Mathlib.Algebra.Field.ZMod -import Mathlib.LinearAlgebra.Matrix.Rank -import Mathlib.LinearAlgebra.Matrix.Trace -import Mathlib.FieldTheory.Finiteness -import Mathlib.Tactic.Ring - -namespace OAI - -/-! # Binary Matrices -/ - -noncomputable section -namespace HadwigerCounterexample - -open scoped BigOperators -open Matrix - -abbrev F := ZMod 2 -abbrev Vec (I : Type) := I → F -abbrev Mat (I J : Type) := Matrix I J F -abbrev Space (V : Type) [AddCommGroup V] [Module F V] := Submodule F V - -theorem bit_cases (x : F) : x = 0 ∨ x = 1 := - (by decide : ∀ x : ZMod 2, x = 0 ∨ x = 1) x -theorem bit_sq (x : F) : x*x = x := by rcases bit_cases x with e|e <;> rw [e] <;> simp -theorem char_two {V : Type*} [AddCommGroup V] [Module F V] (x : V) : x+x=0 := - ZModModule.add_self x -theorem odd_smul_bit {n : ℕ} (hn : Odd n) (x : F) : n • x = x := by - obtain ⟨m,rfl⟩ := hn - rw [add_smul, one_smul, mul_smul, two_smul,char_two,zero_add] - -section Linear - -variable {I J K L R S : Type} [Fintype I] [Fintype J] - -def evmat (M : Mat I J) (x : Vec I) (y : Vec J) := dotProduct x (M *ᵥ y) - -def mpair (M : Mat I J) : Mat I J →ₗ[F] F where - toFun A := ∑ i, ∑ j, M i j * A i j - map_add' A B := by simp only [Matrix.add_apply,mul_add,Finset.sum_add_distrib] - map_smul' b A := by - simp only [Matrix.smul_apply, smul_eq_mul,RingHom.id_apply,Finset.mul_sum,mul_left_comm b] - -theorem mpair_comm (M A : Mat I J) : mpair M A = mpair A M := by - dsimp [mpair] - simp only [mul_comm] - -theorem mpair_outer (M : Mat I J) (x : Vec I) (y : Vec J) : - mpair M (vecMulVec x y) = evmat M x y := by - dsimp [mpair,evmat,mulVec,dotProduct,vecMulVec] - simp only [Finset.mul_sum,mul_left_comm] - -/-- Apply frame maps to the two factors of every tensor. -/ -def liftM (P : Mat K I) (Q : Mat L J) : Mat I J →ₗ[F] Mat K L where - toFun A := P*A*Qᵀ - map_add' A B := by rw [Matrix.mul_add,Matrix.add_mul] - map_smul' b A := by simp only [Matrix.mul_smul, Matrix.smul_mul,RingHom.id_apply] - -theorem liftM_def (P : Mat K I) (Q : Mat L J) (A : Mat I J) : - liftM P Q A = P*A*Qᵀ := rfl - -theorem liftM_outer (P : Mat K I) (Q : Mat L J) (x : Vec I) (y : Vec J) : - liftM P Q (vecMulVec x y) = vecMulVec (P *ᵥ x) (Q *ᵥ y) := by - rw [liftM_def,mul_vecMulVec,vecMulVec_mul,vecMul_transpose] - -variable [Fintype K] [Fintype L] - -theorem liftM_comp (P : Mat K I) (Q : Mat L J) (P' : Mat R K) (Q' : Mat S L) - (A : Mat I J) : - liftM P' Q' (liftM P Q A) = liftM (P'*P) (Q'*Q) A := by - simp only [liftM_def, Matrix.transpose_mul,Matrix.mul_assoc] - -theorem mpair_liftM (P : Mat K I) (Q : Mat L J) (M : Mat K L) (A : Mat I J) : - mpair M (liftM P Q A) = mpair (liftM Pᵀ Qᵀ M) A := by - - simp only [liftM_def, mpair, transpose_transpose, LinearMap.coe_mk,AddHom.coe_mk, - Matrix.mul_apply, Finset.sum_mul, Finset.mul_sum, transpose_apply] - - conv_lhs => - arg 2 - intro k - rw [Finset.sum_comm] - rw [Finset.sum_comm] - - conv_rhs => rw [Finset.sum_comm] - refine Finset.sum_congr rfl fun j _ => ?_ - conv_lhs => - arg 2 - intro k - rw [Finset.sum_comm] - rw [Finset.sum_comm] - refine Finset.sum_congr rfl fun i _ => ?_ - rw [Finset.sum_comm] - refine Finset.sum_congr rfl fun l _ => Finset.sum_congr rfl fun k _ => ?_ - ring - -theorem mat_left_inv [DecidableEq I] {P : Mat K I} (hp : Function.Injective P.mulVec) : - ∃ Q : Mat I K, Q*P = 1 := by - classical - have hp' : Function.Injective (P.mulVecLin) := hp - obtain ⟨f,hf⟩ := P.mulVecLin.exists_leftInverse_of_injective (LinearMap.ker_eq_bot.mpr hp') - refine ⟨LinearMap.toMatrix' f, ?_⟩ - apply Matrix.toLin'.injective - rw [Matrix.toLin'_mul] - simp only [Matrix.toLin'_one] - change ((LinearMap.toMatrix').symm _) ∘ₗ _ = _ - rw [LinearEquiv.symm_apply_apply] - exact hf - -theorem liftM_inj {P : Mat K I} {Q : Mat L J} (hp : Function.Injective P.mulVec) - (hq : Function.Injective Q.mulVec) : Function.Injective (liftM P Q) := by - classical - obtain ⟨P', hP⟩ := mat_left_inv hp - obtain ⟨Q', hQ⟩ := mat_left_inv hq - intro A B hab - have hh := congrArg (liftM P' Q') hab - rw [liftM_comp,liftM_comp,hP,hQ] at hh - simpa only [liftM_def, Matrix.one_mul, Matrix.transpose_one, - Matrix.mul_one] using hh - -end Linear -end HadwigerCounterexample - -end - -end OAI +import Mathlib.Algebra.Field.ZMod +import Mathlib.LinearAlgebra.Matrix.Rank +import Mathlib.LinearAlgebra.Matrix.Trace +import Mathlib.FieldTheory.Finiteness +import Mathlib.Tactic.Ring + +namespace OAI + +/-! # Binary Matrices -/ + +noncomputable section +namespace HadwigerCounterexample + +open scoped BigOperators +open Matrix + +abbrev F := ZMod 2 +abbrev Vec (I : Type) := I → F +abbrev Mat (I J : Type) := Matrix I J F +abbrev Space (V : Type) [AddCommGroup V] [Module F V] := Submodule F V + +theorem bit_cases (x : F) : x = 0 ∨ x = 1 := + (by decide : ∀ x : ZMod 2, x = 0 ∨ x = 1) x +theorem bit_sq (x : F) : x*x = x := by rcases bit_cases x with e|e <;> rw [e] <;> simp +theorem char_two {V : Type*} [AddCommGroup V] [Module F V] (x : V) : x+x=0 := + ZModModule.add_self x +theorem odd_smul_bit {n : ℕ} (hn : Odd n) (x : F) : n • x = x := by + obtain ⟨m,rfl⟩ := hn + rw [add_smul, one_smul, mul_smul, two_smul,char_two,zero_add] + +section Linear + +variable {I J K L R S : Type} [Fintype I] [Fintype J] + +def evmat (M : Mat I J) (x : Vec I) (y : Vec J) := dotProduct x (M *ᵥ y) + +def mpair (M : Mat I J) : Mat I J →ₗ[F] F where + toFun A := ∑ i, ∑ j, M i j * A i j + map_add' A B := by simp only [Matrix.add_apply,mul_add,Finset.sum_add_distrib] + map_smul' b A := by + simp only [Matrix.smul_apply, smul_eq_mul,RingHom.id_apply,Finset.mul_sum,mul_left_comm b] + +theorem mpair_comm (M A : Mat I J) : mpair M A = mpair A M := by + dsimp [mpair] + simp only [mul_comm] + +theorem mpair_outer (M : Mat I J) (x : Vec I) (y : Vec J) : + mpair M (vecMulVec x y) = evmat M x y := by + dsimp [mpair,evmat,mulVec,dotProduct,vecMulVec] + simp only [Finset.mul_sum,mul_left_comm] + +/-- Apply frame maps to the two factors of every tensor. -/ +def liftM (P : Mat K I) (Q : Mat L J) : Mat I J →ₗ[F] Mat K L where + toFun A := P*A*Qᵀ + map_add' A B := by rw [Matrix.mul_add,Matrix.add_mul] + map_smul' b A := by simp only [Matrix.mul_smul, Matrix.smul_mul,RingHom.id_apply] + +theorem liftM_def (P : Mat K I) (Q : Mat L J) (A : Mat I J) : + liftM P Q A = P*A*Qᵀ := rfl + +theorem liftM_outer (P : Mat K I) (Q : Mat L J) (x : Vec I) (y : Vec J) : + liftM P Q (vecMulVec x y) = vecMulVec (P *ᵥ x) (Q *ᵥ y) := by + rw [liftM_def,mul_vecMulVec,vecMulVec_mul,vecMul_transpose] + +variable [Fintype K] [Fintype L] + +theorem liftM_comp (P : Mat K I) (Q : Mat L J) (P' : Mat R K) (Q' : Mat S L) + (A : Mat I J) : + liftM P' Q' (liftM P Q A) = liftM (P'*P) (Q'*Q) A := by + simp only [liftM_def, Matrix.transpose_mul,Matrix.mul_assoc] + +theorem mpair_liftM (P : Mat K I) (Q : Mat L J) (M : Mat K L) (A : Mat I J) : + mpair M (liftM P Q A) = mpair (liftM Pᵀ Qᵀ M) A := by + + simp only [liftM_def, mpair, transpose_transpose, LinearMap.coe_mk,AddHom.coe_mk, + Matrix.mul_apply, Finset.sum_mul, Finset.mul_sum, transpose_apply] + + conv_lhs => + arg 2 + intro k + rw [Finset.sum_comm] + rw [Finset.sum_comm] + + conv_rhs => rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun j _ => ?_ + conv_lhs => + arg 2 + intro k + rw [Finset.sum_comm] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun l _ => Finset.sum_congr rfl fun k _ => ?_ + ring + +theorem mat_left_inv [DecidableEq I] {P : Mat K I} (hp : Function.Injective P.mulVec) : + ∃ Q : Mat I K, Q*P = 1 := by + classical + have hp' : Function.Injective (P.mulVecLin) := hp + obtain ⟨f,hf⟩ := P.mulVecLin.exists_leftInverse_of_injective (LinearMap.ker_eq_bot.mpr hp') + refine ⟨LinearMap.toMatrix' f, ?_⟩ + apply Matrix.toLin'.injective + rw [Matrix.toLin'_mul] + simp only [Matrix.toLin'_one] + change ((LinearMap.toMatrix').symm _) ∘ₗ _ = _ + rw [LinearEquiv.symm_apply_apply] + exact hf + +theorem liftM_inj {P : Mat K I} {Q : Mat L J} (hp : Function.Injective P.mulVec) + (hq : Function.Injective Q.mulVec) : Function.Injective (liftM P Q) := by + classical + obtain ⟨P', hP⟩ := mat_left_inv hp + obtain ⟨Q', hQ⟩ := mat_left_inv hq + intro A B hab + have hh := congrArg (liftM P' Q') hab + rw [liftM_comp,liftM_comp,hP,hQ] at hh + simpa only [liftM_def, Matrix.one_mul, Matrix.transpose_one, + Matrix.mul_one] using hh + +end Linear +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryMixingBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryMixingBounds.lean index 54e59389c29de8af8e2043844a3f6e1910a6b7b7..9c301863251800da0ff7a994f52cc4c51f39e62b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryMixingBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryMixingBounds.lean @@ -1,106 +1,106 @@ -import OAI.Combinatorics.HadwigerCounterexample.KeyTestCorrespondence - -namespace OAI - -/-! # Binary Mixing Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Filter Matrix Function -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] -namespace Template -variable (v : Template p I) - -def kappa := wavelength v.Abbey -omit [DecidableEq I] in -theorem kappa_pos : 0 c (.inl y) - let b : Vec Bool := fun y => c (.inr y) - have hh : v.s j≠v.s l := hv j l (v.choral.diff (.inl i)) i.property.1 - by_cases h : a=0 - · refine ⟨Block.sharp,Flavor.keepSharp ..,Flavor.keepSharp ..,?_⟩ - have he : indexedSum m a=0 := by simp [h,indexedSum] - rw [chorus_same] - change n ≤ 5*blockRank _ _ _ (indexedSum m a+selfSum m b) - rw [he,zero_add] - have hz : b≠0 := by - intro hb; apply hc; funext y - cases y - next l => exact congr_fun h l - next l => exact congr_fun hb l - exact (hm _ _ hh).2 b hz - refine ⟨Block.Z,Flavor.keepZ ..,Flavor.keepZ ..,?_⟩ - rw [chorus_same]; exact (hm _ _ hh).1 a b h - intro j l; refine ⟨Block.Z,Flavor.keepZ ..,Flavor.keepZ ..,?_⟩ - obtain ⟨w,hw,hh⟩ := chorus_cross v m x i c hc - rw [hh]; exact hx _ _ w hw - -theorem resonant (v : Template p I) (m : Mixer p n) (hm : binaryGood m) - (x : UnitType p n N) (hx : litFire p x) (hv : v.diffsel) - (w : I → Wgt (Knobs p.g n)) (hw : ∀ i,IsLaw (w i)) - (C : ℝ) (hC : 0 < C) (hc : ∀ i j,w i j ≤ C*unif j) - (s : Script p I) : - ∀ u : I → Wgt (Knobs p.g n),(∀ i x, |u i x|≤1) → - |avg (prodW w) (fun z => ind (v.performs s m x z)*prodW u z) - - v.kappa * ∏ i:I,avg (w i) (u i)|≤ C^2*bp (-(n:ℝ)/10) := by - classical - refine hear_band v.choral (v.chime m x) (v.lyrics s) w hw _ - (mul_nonneg (sq_nonneg _) (bp_pos _).le) ?_ - intro i c hc' p q hp hq - obtain ⟨b,hb,hb',hz⟩ := v.choral_live m hm x hx hv i c hc' - simp_rw [vectorPhase,v.chime_seq] - exact spark_condition _ (v.chorusM m x i c) _ _ _ _ _ _ b hb hb' p q hp hq - _ _ (hw _) (hw _) C hC (hc _) (hc _) hz - -theorem resonance_calendar (v : Template p I) (M : ℕ) (hM : 4≤ M) (C L : ℝ) (hL : 0¬litFire p i) ≤ bp (-(n:ℝ)*n/8) ∧ - ∀ x : UnitType p n N,litFire p x → - ∀ w : I → Wgt (Knobs p.g n),(∀ i,IsLaw (w i)) → - (∀ i j,w i j≤ L*unif j) → - ∀ (s : Script p I) (u : I→ Wgt (Knobs p.g n)),(∀ i j,|u i j|≤1) → - |avg (prodW w) (fun z => ind (v.performs s m x z)*prodW u z) - - v.kappa*∏ i:I,avg (w i) (u i)| ≤ bp (-(1/20:ℝ)*n) := by - filter_upwards [litFire_calendar p C M hM,pay_nat (a:=1/10) (b:=1/20) (L^2) (by norm_num)] - with n hn ha N m hm hv hN ρ hρ - refine ⟨hn m hN ρ hρ,fun x hx w hw hh s u hu => ?_⟩ - exact (resonant v m hm x hx hv w hw L hL hh s u hu).trans - (by rw [show -(↑n:ℝ)/10 = -(1/10:ℝ)*n by ring]; exact ha) -end Template - -theorem scanCap (p : Shape) {n : ℕ} (l : Tag p.g) (z : Digest p.g) - (f : Flavor p.g) (hr : 1 ≤ p.r) (hn : 2*p.r≤n) (h : z.feasible l f) : - ∀ x,scopedScan p n l f z x≤(scanPrice p)⁻¹*unif x := by - intro x - refine (on_mon (spins_law p n).nz (scanPrice_pos p) (scan_fraction l f z hr hn h) - x).trans_eq ?_ - rw [spins,← draws_unif] - -theorem dialCap (p : Shape) {n : ℕ} (l : Tag p.g) (z : F) - (f : Flavor p.g) (hr : 1 ≤ p.r) (hn : 2*p.r≤n) (h : canDial p l f z) : - ∀ x,scopedBit p n l f z x≤(scanPrice p)⁻¹*unif x := by - intro x - refine (on_mon (spins_law p n).nz (scanPrice_pos p) (dial_fraction p n _ _ _ hr hn h) - x).trans_eq ?_ - rw [spins,← draws_unif] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.KeyTestCorrespondence + +namespace OAI + +/-! # Binary Mixing Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Filter Matrix Function +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] +namespace Template +variable (v : Template p I) + +def kappa := wavelength v.Abbey +omit [DecidableEq I] in +theorem kappa_pos : 0 c (.inl y) + let b : Vec Bool := fun y => c (.inr y) + have hh : v.s j≠v.s l := hv j l (v.choral.diff (.inl i)) i.property.1 + by_cases h : a=0 + · refine ⟨Block.sharp,Flavor.keepSharp ..,Flavor.keepSharp ..,?_⟩ + have he : indexedSum m a=0 := by simp [h,indexedSum] + rw [chorus_same] + change n ≤ 5*blockRank _ _ _ (indexedSum m a+selfSum m b) + rw [he,zero_add] + have hz : b≠0 := by + intro hb; apply hc; funext y + cases y + next l => exact congr_fun h l + next l => exact congr_fun hb l + exact (hm _ _ hh).2 b hz + refine ⟨Block.Z,Flavor.keepZ ..,Flavor.keepZ ..,?_⟩ + rw [chorus_same]; exact (hm _ _ hh).1 a b h + intro j l; refine ⟨Block.Z,Flavor.keepZ ..,Flavor.keepZ ..,?_⟩ + obtain ⟨w,hw,hh⟩ := chorus_cross v m x i c hc + rw [hh]; exact hx _ _ w hw + +theorem resonant (v : Template p I) (m : Mixer p n) (hm : binaryGood m) + (x : UnitType p n N) (hx : litFire p x) (hv : v.diffsel) + (w : I → Wgt (Knobs p.g n)) (hw : ∀ i,IsLaw (w i)) + (C : ℝ) (hC : 0 < C) (hc : ∀ i j,w i j ≤ C*unif j) + (s : Script p I) : + ∀ u : I → Wgt (Knobs p.g n),(∀ i x, |u i x|≤1) → + |avg (prodW w) (fun z => ind (v.performs s m x z)*prodW u z) - + v.kappa * ∏ i:I,avg (w i) (u i)|≤ C^2*bp (-(n:ℝ)/10) := by + classical + refine hear_band v.choral (v.chime m x) (v.lyrics s) w hw _ + (mul_nonneg (sq_nonneg _) (bp_pos _).le) ?_ + intro i c hc' p q hp hq + obtain ⟨b,hb,hb',hz⟩ := v.choral_live m hm x hx hv i c hc' + simp_rw [vectorPhase,v.chime_seq] + exact spark_condition _ (v.chorusM m x i c) _ _ _ _ _ _ b hb hb' p q hp hq + _ _ (hw _) (hw _) C hC (hc _) (hc _) hz + +theorem resonance_calendar (v : Template p I) (M : ℕ) (hM : 4≤ M) (C L : ℝ) (hL : 0¬litFire p i) ≤ bp (-(n:ℝ)*n/8) ∧ + ∀ x : UnitType p n N,litFire p x → + ∀ w : I → Wgt (Knobs p.g n),(∀ i,IsLaw (w i)) → + (∀ i j,w i j≤ L*unif j) → + ∀ (s : Script p I) (u : I→ Wgt (Knobs p.g n)),(∀ i j,|u i j|≤1) → + |avg (prodW w) (fun z => ind (v.performs s m x z)*prodW u z) - + v.kappa*∏ i:I,avg (w i) (u i)| ≤ bp (-(1/20:ℝ)*n) := by + filter_upwards [litFire_calendar p C M hM,pay_nat (a:=1/10) (b:=1/20) (L^2) (by norm_num)] + with n hn ha N m hm hv hN ρ hρ + refine ⟨hn m hN ρ hρ,fun x hx w hw hh s u hu => ?_⟩ + exact (resonant v m hm x hx hv w hw L hL hh s u hu).trans + (by rw [show -(↑n:ℝ)/10 = -(1/10:ℝ)*n by ring]; exact ha) +end Template + +theorem scanCap (p : Shape) {n : ℕ} (l : Tag p.g) (z : Digest p.g) + (f : Flavor p.g) (hr : 1 ≤ p.r) (hn : 2*p.r≤n) (h : z.feasible l f) : + ∀ x,scopedScan p n l f z x≤(scanPrice p)⁻¹*unif x := by + intro x + refine (on_mon (spins_law p n).nz (scanPrice_pos p) (scan_fraction l f z hr hn h) + x).trans_eq ?_ + rw [spins,← draws_unif] + +theorem dialCap (p : Shape) {n : ℕ} (l : Tag p.g) (z : F) + (f : Flavor p.g) (hr : 1 ≤ p.r) (hn : 2*p.r≤n) (h : canDial p l f z) : + ∀ x,scopedBit p n l f z x≤(scanPrice p)⁻¹*unif x := by + intro x + refine (on_mon (spins_law p n).nz (scanPrice_pos p) (dial_fraction p n _ _ _ hr hn h) + x).trans_eq ?_ + rw [spins,← draws_unif] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryPrescriptions.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryPrescriptions.lean index 4033bfa2a09401d478295bb8482874cd6dde23cf..d8e3e3a75270cfe17387027ddaf7e326188562e1 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryPrescriptions.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryPrescriptions.lean @@ -1,265 +1,265 @@ -import OAI.Combinatorics.HadwigerCounterexample.RealizationConditions -import OAI.Combinatorics.HadwigerCounterexample.MixerConditions - -namespace OAI - -/-! # Binary Prescriptions -/ - -noncomputable section -namespace HadwigerCounterexample - -open scoped BigOperators -open Matrix Finset -variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] - -/-- list for a cross edge -/ -def aiming (a b : I → Bool) (i j : Bool) := - Finset.univ.filter (fun x => a x=i ∧ b x=j) - -/-- within-endpoint L/R bit tests. Read only a x=a y, x≠y. -(tests between ordered points; no double counting since L,R and -both orientations are in the mixer hypothesis). -/ -abbrev Script (p : Shape) (I : Type) := I → I → Vec (MOne p) - -namespace Volley -variable (v : Volley p n I) -def reads (s : Script p I) (m : Mixer p n) := - ∀ x y : I,x≠y → v.obj x=v.obj y → - ∀ i : MOne p, s x y i = evmat (orderedM m i) (v.rayAt x) (v.rayAt y) -end Volley - -def prescribedB (p : Shape) (t : Tagging p I) (s : Script p I) (x y : I) := - ∑ i : Fin p.J,∑ e : Comp p.g, ∑ f : Comp p.g, if inc e (t x) ∧ inc f (t y) then - s x y ((i,e,f),true)*s x y ((i,e,f),false) else 0 - -noncomputable def prescribedT (p : Shape) (t : Tagging p I) (d : Vec I) - (h : Mat I I) (s : Script p I) (x y : I) : F := - @ite _ (x=y) (Classical.propDecidable _) (d x) - (h x y+(prescribedB p t s x y+prescribedB p t s y x)) - -def fulfills (p : Shape) (t : Tagging p I) (d f : Vec I) (u : Mat I I) - (s : Script p I) (a b : I → Bool) := - ∀ (x : I) (j : Bool), - d x+ (∑ i∈aiming a b (a x) j, prescribedT p t d u s i x) = - if j=b x then 0 else f x - -namespace Volley -variable {v : Volley p n I} - -omit [Fintype I] in -private theorem B1_eval {s : Script p I} (t : Tagging p I) (m : Mixer p n) - (ha : v.reads s m) {x y : I} (hg : x ≠ y) (hh : v.obj x=v.obj y) : - B1 m (v.atomAt t x) (v.atomAt t y)=prescribedB p t s x y := by - classical - change ∑ i : Fin p.J, _ = _ - refine Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun e _ => - Finset.sum_congr rfl fun f _ => ?_ - by_cases he : inc e (t x) - · by_cases hf : inc f (t y) - · rw [ite_eq_left ⟨he,hf⟩,ha x y hg hh,ha x y hg hh] - simp only [atomAt,atom_def,he,hf,ite_true,mom,liftM_outer,pair_outers] - rfl - rw [ite_eq_right (show ¬ (_ ∧ _) from fun h => hf h.2)] - simp only [atomAt,atom_def,hf,ite_false,map_zero] - rw [ite_eq_right (show ¬ (_ ∧ _) from fun h => he h.1)] - simp only [atomAt,atom_def,he,ite_false] - rw [mpair_comm,map_zero] - -theorem grads_by_script (t : Tagging p I) (m : Mixer p n) (w : Volley p n I) - (y : UnitType p n N) {d f : Vec I} {u : Mat I I} {s : Script p I} - (h : fulfills p t d f u s v.obj w.obj) (hs : v.reads s m) - (hd : ∀ x,role p n (v.atomAt t x)=d x) - (hf : ∀ x,innerP p y (w.obj x) (w.atomAt t x)=f x) - (hu : ∀ x y : I,T0 p n (v.atomAt t x) (v.atomAt t y)=u x y) : - v.attackGrad w t m y := by - classical - intro x j - rw [grad_val,hd,hf,sumAt,map_sum,LinearMap.sum_apply] - rw [← h x j]; congr 1 - refine Finset.sum_congr rfl fun i hi => ?_ - unfold prescribedT - split - · rename_i he - subst x - rw [T_diag,hd] - rename_i he - have hx := (Finset.mem_filter.mp hi).2.1 - rw [Tsym_val,hu, B1_eval t m hs he hx,B1_eval t m hs (Ne.symm he) hx.symm] -end Volley - -/-- Solve symmetric row sums at one endpoint. Couple via opposite -same-target pmiss/role sum equality. Only the resulting necessary -(common d+f sum) is used as input here. -/ -private theorem binary_plan (a b : I→Bool) (i : Bool) (d f : Vec I) - (h : (∑ j∈aiming a b i true,(d j+f j))=∑ j∈aiming a b i false,(d j+f j)) - (h' : ∀ j,(aiming a b i j).Nonempty) : - ∃ M : Mat I I, Mᵀ=M ∧ (∀ x,M x x=d x) ∧ ∀ j : Bool,∀ x∈Finset.univ.filter (fun l => a l=i), - (∑ l∈aiming a b i j,M l x) = d x+(if j=b x then 0 else f x) := by - classical - let S := aiming a b i - let X : Mat I Bool := Matrix.of (fun i j => if i∈S j then 1 else 0) - let V : Mat I Bool := Matrix.of (fun x j => d x + (if j=b x then 0 else f x)) - let D := Matrix.diagonal d - let Y := V+D*X - obtain ⟨L,hL⟩ := mat_left_inv (P:=X) (by - intro x y he - funext j - obtain ⟨v,hv⟩ := h' j - have ha := (Finset.mem_filter.mp hv).2 - have heq (x) : (X *ᵥ x) v=x j := by - unfold X Matrix.mulVec dotProduct - rw [Finset.sum_eq_single j] - · simp [hv,S] - · intro k _ hk; simp [S,aiming,ha,hk.symm] - simp - rw [← heq x,← heq y,he]) - let B := Xᵀ*Y - have hg (j k : Bool) : B j k=if j=k then 0 else (∑ l∈S j,(d l+f l)) := by - have hi {l : I} (hh : l∈S j) : a l=i ∧ b l=j := (Finset.mem_filter.mp hh).2 - have hy {l : I} (hL : l∈S j) : - Y l k= (if j=k then 0 else d l+f l) := by - unfold Y V X; rw [Matrix.add_apply,Matrix.of_apply,Matrix.diagonal_mul,Matrix.of_apply] - by_cases h : j=k - · subst k - simp only [(hi hL).2,hL,ite_true,add_zero,mul_one,char_two] - have hv : l∉S k := fun hw => h ((hi hL).2.symm.trans (Finset.mem_filter.mp hw).2.2) - simp [h,Ne.symm h,(hi hL).2,hv] - have ht (l : I) : X l j*Y l k= if l∈S j then Y l k else 0 := by - by_cases hv : l∈S j <;> simp [X,hv] - unfold B; rw [Matrix.mul_apply] - simp_rw [Matrix.transpose_apply,ht,← Finset.sum_filter] - rw [show Finset.univ.filter (fun x => x∈S j)=S j from (by simp)] - by_cases g : j=k - · rw [ite_eq_left g] - exact Finset.sum_eq_zero fun l hl => (hy hl).trans (ite_eq_left g) - rw [ite_eq_right g] - exact Finset.sum_congr rfl fun l hl => (hy hl).trans (ite_eq_right g) - have ha (j : Bool) : B j j=0 := by rw [hg,ite_eq_left rfl] - have hB : Bᵀ=B := by - ext j k - rw [Matrix.transpose_apply,hg,hg] - cases j <;> cases k - all_goals simp - · exact h - exact h.symm - let W := Lᵀ*B*L - have hW : Wᵀ=W := by unfold W; simp only [transpose_mul,transpose_transpose,hB,Matrix.mul_assoc] - have hw (x : I) : W x x=0 := by - unfold W - have hf : B false true=B true false := congr_fun (congr_fun hB true) false - simp only [Matrix.mul_apply,Fintype.sum_bool,Matrix.transpose_apply,ha,mul_zero,zero_add, - add_zero,hf] - rw [mul_right_comm (L false x), show L true x * B true false * L false x= - L false x * L true x * B true false from (by ring),char_two] - let Z := Y*L+(Y*L)ᵀ + W - have he : (D+Z)*X=V := by - have he : (Y*L)ᵀ*X=W*X := by - unfold W - have hh : Yᵀ * X=B := by - have ht : Bᵀ=Yᵀ*X := by unfold B; rw [Matrix.transpose_mul,transpose_transpose] - rw [← ht,hB] - rw [Matrix.transpose_mul,Matrix.mul_assoc Lᵀ Yᵀ X,hh,Matrix.mul_assoc _ L X,hL, - Matrix.mul_one] - unfold Z - rw [Matrix.add_mul,Matrix.add_mul,Matrix.add_mul,Matrix.mul_assoc Y L X,hL, - Matrix.mul_one,he,add_assoc Y,char_two,add_zero] - unfold Y - rw [add_left_comm,char_two,add_zero] - refine ⟨D+Z,?_,?_,fun j x hx => ?_⟩ - · unfold Z D - simp only [transpose_add,Matrix.diagonal_transpose,transpose_transpose,hW] - ac_rfl - · intro x - unfold D Z - simp only [Matrix.add_apply,Matrix.diagonal_apply_eq,Matrix.transpose_apply,hw, - char_two,add_zero] - let Q := D+Z - have hq : Qᵀ=Q := by - unfold Q Z D - simp only [transpose_add,Matrix.diagonal_transpose,transpose_transpose,hW] - ac_rfl - have h1 : (Q * X) x j= _ := congr_fun (congr_fun he x) j - rw [Matrix.mul_apply] at h1 - have hy : ∑ l∈S j, Q l x =∑ l, Q x l * X l j := by - conv_rhs => unfold X - simp only [Matrix.of_apply,mul_ite,mul_one,mul_zero, ←Finset.sum_filter] - rw [show Finset.univ.filter (fun x => x∈ S j)=S j from (by simp)] - exact Finset.sum_congr rfl fun l _ => congr_fun (congr_fun hq x) l - exact hy.trans h1 - -omit [Fintype I] in -private theorem scripted (p : Shape) (t : Tagging p I) (g : I→I→F) - (h : 2≤p.g) (hJ : 1 ≤ p.J) : - ∃ s : Script p I,∀ x y,prescribedB p t s x y=g x y := by - classical - have hh (x : I) : ∃ i : Comp p.g,inc i (t x) := by - have he := card_star (t x) - have hi : Nonempty (TagStar (t x)) := Fintype.card_pos_iff.mp (by omega) - obtain ⟨⟨i,h⟩⟩ := hi - exact ⟨i,h⟩ - choose q hq using hh - let i0 : Fin p.J := ⟨0,hJ⟩ - let s : Script p I := fun x y i => - if i.1=(i0,q x,q y) then if i.2 then g x y else 1 else 0 - refine ⟨s,fun x y => ?_⟩ - unfold prescribedB - rw [Finset.sum_eq_single i0] - · rw [Finset.sum_eq_single (q x)] - · rw [Finset.sum_eq_single (q y)] - · simp [s,hq] - · intro i _ hi; simp [s,hi] - simp - · intro i _ hi; simp [s,hi] - simp - · intro i _ hi; simp [s,hi] - simp - -set_option maxHeartbeats 600000 in -theorem choose_script (p : Shape) (t : Tagging p I) (a b : I→Bool) - (d : Vec I) - (f : Vec I) - (d' : Vec I) - (h : ∀ i : Bool,(∑ x∈aiming a b i true,(d' x+f x)) = - ∑ x∈aiming a b i false,(d' x+f x)) - (ha : ∀ i j : Bool, ∑ x∈aiming a b i j,(d x+d' x)=1) - (hc : ∀ i j : Bool,(aiming a b i j).Nonempty) - (u : Mat I I) (hu : uᵀ=u) - (hg : 2≤p.g) (hi : 1≤p.J) : - ∃ s : Script p I, fulfills p t d f u s a b := by - classical - have hh (i j : Bool) : - (∑ x∈aiming a b i j,(d x+f x))=1+ ∑ x∈aiming a b i j,(d' x+f x) := by - rw [←ha,← Finset.sum_add_distrib] - refine Finset.sum_congr rfl fun x _ => ?_ - rw [add_assoc,←add_assoc (d' x),char_two,zero_add] - choose M hM hD hA using fun i : Bool => binary_plan a b i d f (by rw [hh,hh,h]) (hc i) - let F' := Fintype.equivFin I - let g (x y : I) := if F' x < F' y then M (a x) x y+u x y else 0 - obtain ⟨s,hs⟩ := scripted p t g hg hi - have hf (x y : I) (h : a x=a y) : prescribedT p t d u s x y=M (a x) x y := by - unfold prescribedT - split - · rename_i he - subst y - exact (hD _ _).symm - rename_i he - rw [hs x y, hs y x] - rcases lt_or_gt_of_ne (show F' x ≠ F' y from fun h => he (F'.injective h)) with e|e - · simp only [g, ite_eq_left e,ite_eq_right (not_lt.mpr e.le),add_zero] - rw [add_left_comm,char_two,add_zero] - simp only [g,ite_eq_left e,ite_eq_right (not_lt.mpr e.le),zero_add] - rw [←h,show u y x=u x y from congr_fun (congr_fun hu x) y, - show M (a x) y x=M (a x) x y from congr_fun (congr_fun (hM (a x)) x) y] - rw [add_left_comm,char_two,add_zero] - refine ⟨s,fun x j => ?_⟩ - let S := aiming a b (a x) j - have he : ∑ i∈S,prescribedT p t d u s i x=∑ i∈S,M (a x) i x := - Finset.sum_congr rfl fun i hi => by - have hm : a i=a x := (Finset.mem_filter.mp hi).2.1 - rw [hf i x hm,hm] - rw [he,hA (a x) j x (by simp), ← add_assoc, char_two,zero_add] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RealizationConditions +import OAI.Combinatorics.HadwigerCounterexample.MixerConditions + +namespace OAI + +/-! # Binary Prescriptions -/ + +noncomputable section +namespace HadwigerCounterexample + +open scoped BigOperators +open Matrix Finset +variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] + +/-- list for a cross edge -/ +def aiming (a b : I → Bool) (i j : Bool) := + Finset.univ.filter (fun x => a x=i ∧ b x=j) + +/-- within-endpoint L/R bit tests. Read only a x=a y, x≠y. +(tests between ordered points; no double counting since L,R and +both orientations are in the mixer hypothesis). -/ +abbrev Script (p : Shape) (I : Type) := I → I → Vec (MOne p) + +namespace Volley +variable (v : Volley p n I) +def reads (s : Script p I) (m : Mixer p n) := + ∀ x y : I,x≠y → v.obj x=v.obj y → + ∀ i : MOne p, s x y i = evmat (orderedM m i) (v.rayAt x) (v.rayAt y) +end Volley + +def prescribedB (p : Shape) (t : Tagging p I) (s : Script p I) (x y : I) := + ∑ i : Fin p.J,∑ e : Comp p.g, ∑ f : Comp p.g, if inc e (t x) ∧ inc f (t y) then + s x y ((i,e,f),true)*s x y ((i,e,f),false) else 0 + +noncomputable def prescribedT (p : Shape) (t : Tagging p I) (d : Vec I) + (h : Mat I I) (s : Script p I) (x y : I) : F := + @ite _ (x=y) (Classical.propDecidable _) (d x) + (h x y+(prescribedB p t s x y+prescribedB p t s y x)) + +def fulfills (p : Shape) (t : Tagging p I) (d f : Vec I) (u : Mat I I) + (s : Script p I) (a b : I → Bool) := + ∀ (x : I) (j : Bool), + d x+ (∑ i∈aiming a b (a x) j, prescribedT p t d u s i x) = + if j=b x then 0 else f x + +namespace Volley +variable {v : Volley p n I} + +omit [Fintype I] in +private theorem B1_eval {s : Script p I} (t : Tagging p I) (m : Mixer p n) + (ha : v.reads s m) {x y : I} (hg : x ≠ y) (hh : v.obj x=v.obj y) : + B1 m (v.atomAt t x) (v.atomAt t y)=prescribedB p t s x y := by + classical + change ∑ i : Fin p.J, _ = _ + refine Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun e _ => + Finset.sum_congr rfl fun f _ => ?_ + by_cases he : inc e (t x) + · by_cases hf : inc f (t y) + · rw [ite_eq_left ⟨he,hf⟩,ha x y hg hh,ha x y hg hh] + simp only [atomAt,atom_def,he,hf,ite_true,mom,liftM_outer,pair_outers] + rfl + rw [ite_eq_right (show ¬ (_ ∧ _) from fun h => hf h.2)] + simp only [atomAt,atom_def,hf,ite_false,map_zero] + rw [ite_eq_right (show ¬ (_ ∧ _) from fun h => he h.1)] + simp only [atomAt,atom_def,he,ite_false] + rw [mpair_comm,map_zero] + +theorem grads_by_script (t : Tagging p I) (m : Mixer p n) (w : Volley p n I) + (y : UnitType p n N) {d f : Vec I} {u : Mat I I} {s : Script p I} + (h : fulfills p t d f u s v.obj w.obj) (hs : v.reads s m) + (hd : ∀ x,role p n (v.atomAt t x)=d x) + (hf : ∀ x,innerP p y (w.obj x) (w.atomAt t x)=f x) + (hu : ∀ x y : I,T0 p n (v.atomAt t x) (v.atomAt t y)=u x y) : + v.attackGrad w t m y := by + classical + intro x j + rw [grad_val,hd,hf,sumAt,map_sum,LinearMap.sum_apply] + rw [← h x j]; congr 1 + refine Finset.sum_congr rfl fun i hi => ?_ + unfold prescribedT + split + · rename_i he + subst x + rw [T_diag,hd] + rename_i he + have hx := (Finset.mem_filter.mp hi).2.1 + rw [Tsym_val,hu, B1_eval t m hs he hx,B1_eval t m hs (Ne.symm he) hx.symm] +end Volley + +/-- Solve symmetric row sums at one endpoint. Couple via opposite +same-target pmiss/role sum equality. Only the resulting necessary +(common d+f sum) is used as input here. -/ +private theorem binary_plan (a b : I→Bool) (i : Bool) (d f : Vec I) + (h : (∑ j∈aiming a b i true,(d j+f j))=∑ j∈aiming a b i false,(d j+f j)) + (h' : ∀ j,(aiming a b i j).Nonempty) : + ∃ M : Mat I I, Mᵀ=M ∧ (∀ x,M x x=d x) ∧ ∀ j : Bool,∀ x∈Finset.univ.filter (fun l => a l=i), + (∑ l∈aiming a b i j,M l x) = d x+(if j=b x then 0 else f x) := by + classical + let S := aiming a b i + let X : Mat I Bool := Matrix.of (fun i j => if i∈S j then 1 else 0) + let V : Mat I Bool := Matrix.of (fun x j => d x + (if j=b x then 0 else f x)) + let D := Matrix.diagonal d + let Y := V+D*X + obtain ⟨L,hL⟩ := mat_left_inv (P:=X) (by + intro x y he + funext j + obtain ⟨v,hv⟩ := h' j + have ha := (Finset.mem_filter.mp hv).2 + have heq (x) : (X *ᵥ x) v=x j := by + unfold X Matrix.mulVec dotProduct + rw [Finset.sum_eq_single j] + · simp [hv,S] + · intro k _ hk; simp [S,aiming,ha,hk.symm] + simp + rw [← heq x,← heq y,he]) + let B := Xᵀ*Y + have hg (j k : Bool) : B j k=if j=k then 0 else (∑ l∈S j,(d l+f l)) := by + have hi {l : I} (hh : l∈S j) : a l=i ∧ b l=j := (Finset.mem_filter.mp hh).2 + have hy {l : I} (hL : l∈S j) : + Y l k= (if j=k then 0 else d l+f l) := by + unfold Y V X; rw [Matrix.add_apply,Matrix.of_apply,Matrix.diagonal_mul,Matrix.of_apply] + by_cases h : j=k + · subst k + simp only [(hi hL).2,hL,ite_true,add_zero,mul_one,char_two] + have hv : l∉S k := fun hw => h ((hi hL).2.symm.trans (Finset.mem_filter.mp hw).2.2) + simp [h,Ne.symm h,(hi hL).2,hv] + have ht (l : I) : X l j*Y l k= if l∈S j then Y l k else 0 := by + by_cases hv : l∈S j <;> simp [X,hv] + unfold B; rw [Matrix.mul_apply] + simp_rw [Matrix.transpose_apply,ht,← Finset.sum_filter] + rw [show Finset.univ.filter (fun x => x∈S j)=S j from (by simp)] + by_cases g : j=k + · rw [ite_eq_left g] + exact Finset.sum_eq_zero fun l hl => (hy hl).trans (ite_eq_left g) + rw [ite_eq_right g] + exact Finset.sum_congr rfl fun l hl => (hy hl).trans (ite_eq_right g) + have ha (j : Bool) : B j j=0 := by rw [hg,ite_eq_left rfl] + have hB : Bᵀ=B := by + ext j k + rw [Matrix.transpose_apply,hg,hg] + cases j <;> cases k + all_goals simp + · exact h + exact h.symm + let W := Lᵀ*B*L + have hW : Wᵀ=W := by unfold W; simp only [transpose_mul,transpose_transpose,hB,Matrix.mul_assoc] + have hw (x : I) : W x x=0 := by + unfold W + have hf : B false true=B true false := congr_fun (congr_fun hB true) false + simp only [Matrix.mul_apply,Fintype.sum_bool,Matrix.transpose_apply,ha,mul_zero,zero_add, + add_zero,hf] + rw [mul_right_comm (L false x), show L true x * B true false * L false x= + L false x * L true x * B true false from (by ring),char_two] + let Z := Y*L+(Y*L)ᵀ + W + have he : (D+Z)*X=V := by + have he : (Y*L)ᵀ*X=W*X := by + unfold W + have hh : Yᵀ * X=B := by + have ht : Bᵀ=Yᵀ*X := by unfold B; rw [Matrix.transpose_mul,transpose_transpose] + rw [← ht,hB] + rw [Matrix.transpose_mul,Matrix.mul_assoc Lᵀ Yᵀ X,hh,Matrix.mul_assoc _ L X,hL, + Matrix.mul_one] + unfold Z + rw [Matrix.add_mul,Matrix.add_mul,Matrix.add_mul,Matrix.mul_assoc Y L X,hL, + Matrix.mul_one,he,add_assoc Y,char_two,add_zero] + unfold Y + rw [add_left_comm,char_two,add_zero] + refine ⟨D+Z,?_,?_,fun j x hx => ?_⟩ + · unfold Z D + simp only [transpose_add,Matrix.diagonal_transpose,transpose_transpose,hW] + ac_rfl + · intro x + unfold D Z + simp only [Matrix.add_apply,Matrix.diagonal_apply_eq,Matrix.transpose_apply,hw, + char_two,add_zero] + let Q := D+Z + have hq : Qᵀ=Q := by + unfold Q Z D + simp only [transpose_add,Matrix.diagonal_transpose,transpose_transpose,hW] + ac_rfl + have h1 : (Q * X) x j= _ := congr_fun (congr_fun he x) j + rw [Matrix.mul_apply] at h1 + have hy : ∑ l∈S j, Q l x =∑ l, Q x l * X l j := by + conv_rhs => unfold X + simp only [Matrix.of_apply,mul_ite,mul_one,mul_zero, ←Finset.sum_filter] + rw [show Finset.univ.filter (fun x => x∈ S j)=S j from (by simp)] + exact Finset.sum_congr rfl fun l _ => congr_fun (congr_fun hq x) l + exact hy.trans h1 + +omit [Fintype I] in +private theorem scripted (p : Shape) (t : Tagging p I) (g : I→I→F) + (h : 2≤p.g) (hJ : 1 ≤ p.J) : + ∃ s : Script p I,∀ x y,prescribedB p t s x y=g x y := by + classical + have hh (x : I) : ∃ i : Comp p.g,inc i (t x) := by + have he := card_star (t x) + have hi : Nonempty (TagStar (t x)) := Fintype.card_pos_iff.mp (by omega) + obtain ⟨⟨i,h⟩⟩ := hi + exact ⟨i,h⟩ + choose q hq using hh + let i0 : Fin p.J := ⟨0,hJ⟩ + let s : Script p I := fun x y i => + if i.1=(i0,q x,q y) then if i.2 then g x y else 1 else 0 + refine ⟨s,fun x y => ?_⟩ + unfold prescribedB + rw [Finset.sum_eq_single i0] + · rw [Finset.sum_eq_single (q x)] + · rw [Finset.sum_eq_single (q y)] + · simp [s,hq] + · intro i _ hi; simp [s,hi] + simp + · intro i _ hi; simp [s,hi] + simp + · intro i _ hi; simp [s,hi] + simp + +set_option maxHeartbeats 600000 in +theorem choose_script (p : Shape) (t : Tagging p I) (a b : I→Bool) + (d : Vec I) + (f : Vec I) + (d' : Vec I) + (h : ∀ i : Bool,(∑ x∈aiming a b i true,(d' x+f x)) = + ∑ x∈aiming a b i false,(d' x+f x)) + (ha : ∀ i j : Bool, ∑ x∈aiming a b i j,(d x+d' x)=1) + (hc : ∀ i j : Bool,(aiming a b i j).Nonempty) + (u : Mat I I) (hu : uᵀ=u) + (hg : 2≤p.g) (hi : 1≤p.J) : + ∃ s : Script p I, fulfills p t d f u s a b := by + classical + have hh (i j : Bool) : + (∑ x∈aiming a b i j,(d x+f x))=1+ ∑ x∈aiming a b i j,(d' x+f x) := by + rw [←ha,← Finset.sum_add_distrib] + refine Finset.sum_congr rfl fun x _ => ?_ + rw [add_assoc,←add_assoc (d' x),char_two,zero_add] + choose M hM hD hA using fun i : Bool => binary_plan a b i d f (by rw [hh,hh,h]) (hc i) + let F' := Fintype.equivFin I + let g (x y : I) := if F' x < F' y then M (a x) x y+u x y else 0 + obtain ⟨s,hs⟩ := scripted p t g hg hi + have hf (x y : I) (h : a x=a y) : prescribedT p t d u s x y=M (a x) x y := by + unfold prescribedT + split + · rename_i he + subst y + exact (hD _ _).symm + rename_i he + rw [hs x y, hs y x] + rcases lt_or_gt_of_ne (show F' x ≠ F' y from fun h => he (F'.injective h)) with e|e + · simp only [g, ite_eq_left e,ite_eq_right (not_lt.mpr e.le),add_zero] + rw [add_left_comm,char_two,add_zero] + simp only [g,ite_eq_left e,ite_eq_right (not_lt.mpr e.le),zero_add] + rw [←h,show u y x=u x y from congr_fun (congr_fun hu x) y, + show M (a x) y x=M (a x) x y from congr_fun (congr_fun (hM (a x)) x) y] + rw [add_left_comm,char_two,add_zero] + refine ⟨s,fun x j => ?_⟩ + let S := aiming a b (a x) j + have he : ∑ i∈S,prescribedT p t d u s i x=∑ i∈S,M (a x) i x := + Finset.sum_congr rfl fun i hi => by + have hm : a i=a x := (Finset.mem_filter.mp hi).2.1 + rw [hf i x hm,hm] + rw [he,hA (a x) j x (by simp), ← add_assoc, char_two,zero_add] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryStatusComparison.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryStatusComparison.lean index c96e9e95dc45dd87e7d4ed33ec77cf05a9da9ddf..43e4337fc93366b21c2ee24b6bd62444bc34b64e 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryStatusComparison.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/BinaryStatusComparison.lean @@ -1,143 +1,143 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteOptionLabels - -namespace OAI - -/-! # Binary Status Comparison -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Filter Function Submodule Module LinearMap -open scoped BigOperators -variable {A B J H : Type} [Fintype A] [Fintype B] [Fintype J] - -theorem disagreement_bound (w : Wgt A) (hw : ∀ x,0 ≤ w x) (f g h:A→ H) : - pr w (fun i=> f i≠ h i) ≤ pr w (fun i=>f i≠ g i) + pr w (fun i=>g i≠h i) := - let p (i:A) := f i≠g i∨g i≠h i - ((pr_mono hw fun i h=>show p i from Classical.byContradiction (fun hi => h (Eq.trans - (not_not.mp (mt Or.inl hi)) (not_not.mp (mt Or.inr hi))))).trans (pr_or_le hw)) - -def majority (w : Wgt A) (f : A→F) := - if 1/2≤ pr w (fun i=>f i=0) then (0:F) else 1 - -theorem majority_bound (w : Wgt A) (hw:IsLaw w) (f : A→F) : - 1/2 ≤ pr w (fun i=> f i= majority w f) := by - classical - unfold majority - split - next h => exact h - next h => - have hi i : f i=1 ↔ ¬f i=0 := - ⟨fun hh=>by rw [hh]; exact one_ne_zero,fun hh=>(bit_cases _).resolve_left hh⟩ - simp_rw [hi,pr_not,hw.total] - exact le_of_lt (by linarith only [h]) - -theorem majority_charge (p:Wgt A) (q:Wgt B) (hp:IsLaw p) (hq:IsLaw q) - (f:A→F) (g:B→F) : - pr p (fun i=> f i≠majority q g)≤2 * pr (pairW p q) (fun i=> f i.1≠g i.2) := by - classical - let Q i:= g i=majority q g; let P i:= f i≠majority q g - let v:= pairW p q - have hm (z:A×B) (h:P z.1∧Q z.2): f z.1≠g z.2 := h.2 ▸ h.1 - have hh : pr p P*pr q Q ≤ pr v (fun i=>f i.1≠g i.2) := - (pairW_pr ..).symm.le.trans (pr_mono (pairW_law hp hq).nz hm) - have hx:=majority_bound q hq g - have hh' := mul_le_mul_of_nonneg_left hx (pr_nonneg (p:=P) hp.nz) - change _* (1/2) ≤ _*pr q Q at hh' - change pr p P≤2*pr v _ - linarith only [hh,hh'] - -theorem reflect_cost (p:Wgt A) (q:Wgt B) (hp:IsLaw p) (hq:IsLaw q) - (f:A→H) (g:B→H) (k:H) : - pr q (fun i=>g i≠k)≤ pr (pairW p q) (fun i=>f i.1≠g i.2)+pr p (fun i=>f i≠k) := by - let w:=pairW p q - let t i:= g i≠k; let s i:= f i≠k - have hi : pr q t=pr w (fun i=> t i.2) := by simpa [hp.total] using - (pairW_pr p q (fun _=>True) t).symm - have hj : pr p s=pr w (fun i=>s i.1) := by simpa [hq.total] using - (pairW_pr p q s (fun _=>True)).symm - let P (i:A×B):= f i.1 ≠ g i.2 - rw [hi,hj] - have hh (i:A×B) (h:t i.2): P i∨ s i.1 := by - by_cases he:P i - · exact Or.inl he - exact Or.inr (fun hc=> h ((not_not.mp he).symm.trans hc)) - exact (pr_mono (pairW_law hp hq).nz hh).trans (pr_or_le (pairW_law hp hq).nz) - -namespace StatusAnalysis -namespace DualAnalysis -variable {p:Shape} {d e: Rates} {r K:ℕ} -abbrev Pulsar (p:Shape) (r:ℕ):= Tag p.g → F → Fin r→F -variable (u:Terrain p r) (s:Gazette p r d) (t:Gazette p r e) - -def shot (i:Nodes) (x:Appearance p) (a:RhymeSet (d i)) (f:Pulsar p r) := - avg (u x.l x.q) (fun j=>pr (s i x j) (fun v=> a.soot x v ≠f x.l x.q j)) -def praise (u:Terrain p r) (s:Gazette p r d) (i:Nodes) - (A:Finset (Label p.b)) (a:RhymeSet (d i)) (f:Pulsar p r) (ε:ℝ) := - ∀ x:Appearance p,x.s∉A →x.apt → shot u s i x a f≤ε -def counsel (i:Grid) (A B:Finset (Label p.b)) - (a : RhymeSet (d i.1)) (b : RhymeSet (e i.2)) (ε :ℝ) := - ∀ x:Zodiac p,x.common → x.s true∉A →x.s false∉ B →charge u x s t i a b≤ε - -def amazes (p:Shape) (z:Label p.b) (l: Tag p.g) (q:F):Appearance p:=⟨l,z,Flavor.full,q⟩ -def amends (p:Shape) (x y:Appearance p): Zodiac p := - {l:=x.l - q:=x.q - s i:=if i then x.s else y.s - f i:=if i then x.f else y.f} -theorem amendsB (x y: Appearance p)(h:x.l=y.l)(ht:x.q=y.q): - (amends p x y).aspect false=y := by cases x; cases y; simp_all [amends,Zodiac.aspect] - -theorem splitCounsel (i:Grid) (A B:Finset (Label p.b)) - (a : RhymeSet (d i.1)) (b : RhymeSet (e i.2)) (ε :ℝ) - (h:counsel u s t i A B a b ε) (x y:Appearance p) - (hx:x.s∉A) (hy:y.s∉B) (he:x.apt) (hf:y.apt) (hg:x.l=y.l) (hk:x.q=y.q) : - avg (u x.l x.q) (fun j=>pr (pairW (s i.1 x j) (t i.2 y j)) (fun k=>a.soot x k.1 ≠ - b.soot y k.2))≤ε := by - classical - let Z:=amends p x y - have hQ : Z.aspect false=y := amendsB _ _ hg hk - have hP : Z.aspect true=x := rfl - have hm : Z.common := by intro i;cases i; rw [hQ];exact hf; rw [hP];exact he - have hi:= h Z hm hx hy - unfold charge circlet pr couplePage at hi - rw [mixW_avg,hQ,hP] at hi - exact hi - -set_option maxHeartbeats 800000 in -theorem paeans {β δ:ℝ} (hu:origami p r u δ)(hs:reports p r u s β δ)(ht:reports p r u t β δ) - (i:Grid) (A B:Finset (Label p.b)) (hx:A.card majority_charge (s i.1 z j) (t i.2 w j) - (hs.law _ _ hhq _) (ht.law _ _ ht' _) (a.soot z) (b.soot w))) ?_ - rw [avg_mul'] - exact mul_le_mul_of_nonneg_left hh (by norm_num) - refine ⟨f,fun w hw hx=>(hl _ hw hx).trans (by linarith only [he]), fun w hw hv=>?_⟩ - let z:=amazes p x w.l w.q - have hf : z.apt:=generic_apt _ hg _ rfl - have hx0:= splitCounsel u s t i A B a b ε h z w hx hw hf hv rfl rfl - have hl0:=hl z hx hf - let W:=u w.l w.q - have heq j:= reflect_cost (s i.1 z j) (t i.2 w j) (hs.law _ _ hf j) (ht.law _ _ hv j) - (a.soot z) (b.soot w) (f w.l w.q j) - apply (avg_mono (hu.1 w.l w.q).nz heq).trans - rw [avg_add]; exact (add_le_add hx0 hl0).trans_eq (by ring) -end DualAnalysis -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteOptionLabels + +namespace OAI + +/-! # Binary Status Comparison -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Filter Function Submodule Module LinearMap +open scoped BigOperators +variable {A B J H : Type} [Fintype A] [Fintype B] [Fintype J] + +theorem disagreement_bound (w : Wgt A) (hw : ∀ x,0 ≤ w x) (f g h:A→ H) : + pr w (fun i=> f i≠ h i) ≤ pr w (fun i=>f i≠ g i) + pr w (fun i=>g i≠h i) := + let p (i:A) := f i≠g i∨g i≠h i + ((pr_mono hw fun i h=>show p i from Classical.byContradiction (fun hi => h (Eq.trans + (not_not.mp (mt Or.inl hi)) (not_not.mp (mt Or.inr hi))))).trans (pr_or_le hw)) + +def majority (w : Wgt A) (f : A→F) := + if 1/2≤ pr w (fun i=>f i=0) then (0:F) else 1 + +theorem majority_bound (w : Wgt A) (hw:IsLaw w) (f : A→F) : + 1/2 ≤ pr w (fun i=> f i= majority w f) := by + classical + unfold majority + split + next h => exact h + next h => + have hi i : f i=1 ↔ ¬f i=0 := + ⟨fun hh=>by rw [hh]; exact one_ne_zero,fun hh=>(bit_cases _).resolve_left hh⟩ + simp_rw [hi,pr_not,hw.total] + exact le_of_lt (by linarith only [h]) + +theorem majority_charge (p:Wgt A) (q:Wgt B) (hp:IsLaw p) (hq:IsLaw q) + (f:A→F) (g:B→F) : + pr p (fun i=> f i≠majority q g)≤2 * pr (pairW p q) (fun i=> f i.1≠g i.2) := by + classical + let Q i:= g i=majority q g; let P i:= f i≠majority q g + let v:= pairW p q + have hm (z:A×B) (h:P z.1∧Q z.2): f z.1≠g z.2 := h.2 ▸ h.1 + have hh : pr p P*pr q Q ≤ pr v (fun i=>f i.1≠g i.2) := + (pairW_pr ..).symm.le.trans (pr_mono (pairW_law hp hq).nz hm) + have hx:=majority_bound q hq g + have hh' := mul_le_mul_of_nonneg_left hx (pr_nonneg (p:=P) hp.nz) + change _* (1/2) ≤ _*pr q Q at hh' + change pr p P≤2*pr v _ + linarith only [hh,hh'] + +theorem reflect_cost (p:Wgt A) (q:Wgt B) (hp:IsLaw p) (hq:IsLaw q) + (f:A→H) (g:B→H) (k:H) : + pr q (fun i=>g i≠k)≤ pr (pairW p q) (fun i=>f i.1≠g i.2)+pr p (fun i=>f i≠k) := by + let w:=pairW p q + let t i:= g i≠k; let s i:= f i≠k + have hi : pr q t=pr w (fun i=> t i.2) := by simpa [hp.total] using + (pairW_pr p q (fun _=>True) t).symm + have hj : pr p s=pr w (fun i=>s i.1) := by simpa [hq.total] using + (pairW_pr p q s (fun _=>True)).symm + let P (i:A×B):= f i.1 ≠ g i.2 + rw [hi,hj] + have hh (i:A×B) (h:t i.2): P i∨ s i.1 := by + by_cases he:P i + · exact Or.inl he + exact Or.inr (fun hc=> h ((not_not.mp he).symm.trans hc)) + exact (pr_mono (pairW_law hp hq).nz hh).trans (pr_or_le (pairW_law hp hq).nz) + +namespace StatusAnalysis +namespace DualAnalysis +variable {p:Shape} {d e: Rates} {r K:ℕ} +abbrev Pulsar (p:Shape) (r:ℕ):= Tag p.g → F → Fin r→F +variable (u:Terrain p r) (s:Gazette p r d) (t:Gazette p r e) + +def shot (i:Nodes) (x:Appearance p) (a:RhymeSet (d i)) (f:Pulsar p r) := + avg (u x.l x.q) (fun j=>pr (s i x j) (fun v=> a.soot x v ≠f x.l x.q j)) +def praise (u:Terrain p r) (s:Gazette p r d) (i:Nodes) + (A:Finset (Label p.b)) (a:RhymeSet (d i)) (f:Pulsar p r) (ε:ℝ) := + ∀ x:Appearance p,x.s∉A →x.apt → shot u s i x a f≤ε +def counsel (i:Grid) (A B:Finset (Label p.b)) + (a : RhymeSet (d i.1)) (b : RhymeSet (e i.2)) (ε :ℝ) := + ∀ x:Zodiac p,x.common → x.s true∉A →x.s false∉ B →charge u x s t i a b≤ε + +def amazes (p:Shape) (z:Label p.b) (l: Tag p.g) (q:F):Appearance p:=⟨l,z,Flavor.full,q⟩ +def amends (p:Shape) (x y:Appearance p): Zodiac p := + {l:=x.l + q:=x.q + s i:=if i then x.s else y.s + f i:=if i then x.f else y.f} +theorem amendsB (x y: Appearance p)(h:x.l=y.l)(ht:x.q=y.q): + (amends p x y).aspect false=y := by cases x; cases y; simp_all [amends,Zodiac.aspect] + +theorem splitCounsel (i:Grid) (A B:Finset (Label p.b)) + (a : RhymeSet (d i.1)) (b : RhymeSet (e i.2)) (ε :ℝ) + (h:counsel u s t i A B a b ε) (x y:Appearance p) + (hx:x.s∉A) (hy:y.s∉B) (he:x.apt) (hf:y.apt) (hg:x.l=y.l) (hk:x.q=y.q) : + avg (u x.l x.q) (fun j=>pr (pairW (s i.1 x j) (t i.2 y j)) (fun k=>a.soot x k.1 ≠ + b.soot y k.2))≤ε := by + classical + let Z:=amends p x y + have hQ : Z.aspect false=y := amendsB _ _ hg hk + have hP : Z.aspect true=x := rfl + have hm : Z.common := by intro i;cases i; rw [hQ];exact hf; rw [hP];exact he + have hi:= h Z hm hx hy + unfold charge circlet pr couplePage at hi + rw [mixW_avg,hQ,hP] at hi + exact hi + +set_option maxHeartbeats 800000 in +theorem paeans {β δ:ℝ} (hu:origami p r u δ)(hs:reports p r u s β δ)(ht:reports p r u t β δ) + (i:Grid) (A B:Finset (Label p.b)) (hx:A.card majority_charge (s i.1 z j) (t i.2 w j) + (hs.law _ _ hhq _) (ht.law _ _ ht' _) (a.soot z) (b.soot w))) ?_ + rw [avg_mul'] + exact mul_le_mul_of_nonneg_left hh (by norm_num) + refine ⟨f,fun w hw hx=>(hl _ hw hx).trans (by linarith only [he]), fun w hw hv=>?_⟩ + let z:=amazes p x w.l w.q + have hf : z.apt:=generic_apt _ hg _ rfl + have hx0:= splitCounsel u s t i A B a b ε h z w hx hw hf hv rfl rfl + have hl0:=hl z hx hf + let W:=u w.l w.q + have heq j:= reflect_cost (s i.1 z j) (t i.2 w j) (hs.law _ _ hf j) (ht.law _ _ hv j) + (a.soot z) (b.soot w) (f w.l w.q j) + apply (avg_mono (hu.1 w.l w.q).nz heq).trans + rw [avg_add]; exact (add_le_add hx0 hl0).trans_eq (by ring) +end DualAnalysis +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/BooleanLabels.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/BooleanLabels.lean index fd9a51feb9b03edfca22e13524aba7f2d9ef97ed..fc40f1d27e3a134747ae57bd920bc7408760dab6 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/BooleanLabels.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/BooleanLabels.lean @@ -1,151 +1,151 @@ -import OAI.Combinatorics.HadwigerCounterexample.MomentCoordinates -import OAI.Combinatorics.HadwigerCounterexample.MatrixFactorization - -namespace OAI - -/-! # Boolean Labels -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Finset -variable {b : ℕ} - -def monoBit (s : Label b) (S : Finset (Fin b)) := ∏ i ∈ S, s i - -theorem mono_insert (s : Label b) (S : Finset (Fin b)) (i) : - monoBit s (insert i S) = s i * monoBit s S := by - by_cases h : i∈S - · rw [insert_eq_of_mem h] - unfold monoBit - rw [← Finset.mul_prod_erase _ _ h,← mul_assoc,bit_sq] - · simp [monoBit,h] - -theorem mono_union (s : Label b) (S T : Finset (Fin b)) : - monoBit s (S∪T)= monoBit s S*monoBit s T := by - induction S using Finset.induction with - | empty => simp [monoBit] - | insert i S h ih => - rw [insert_union,mono_insert,mono_insert,ih,mul_assoc] - -/-- Independence up to degree j for at most j+1 labels, in coefficient form. -/ -theorem selector_indep (L : Finset (Label b)) (c : Label b → F) (j : ℕ) - (h : L.card ≤ j+1) (hf : ∀ S : Finset (Fin b), S.card ≤ j → - ∑ s ∈ L,c s*monoBit s S=0) : ∀ i∈L,c i=0 := by - classical - intro s hs - induction L using Finset.strongInductionOn generalizing c j with | _ L ih - by_cases hL : ∃ i∈L,i≠s - · obtain ⟨t,ht,hst⟩ := hL - obtain ⟨i,hi⟩ : ∃ i : Fin b,t i≠s i := Function.ne_iff.mp hst - let d (u : Label b) := (u i-t i) * c u - have hg : j>0 := by have he := Finset.one_lt_card.mpr ⟨t,ht,s,hs,hst⟩; omega - have he : (L.erase t).card ≤ (j-1)+1 := by - have he := card_erase_add_one ht; omega - have hw (U : Finset (Fin b)) (hu : U.card ≤ j-1) : - ∑ s ∈ L.erase t,d s*monoBit s U=0 := by - have heq (s : Label b) : - d s * monoBit s U = c s * monoBit s (insert i U) - t i*(c s*monoBit s U) := by - unfold d; rw [mono_insert]; ring - rw [show ∑ s ∈ L.erase t,d s*monoBit s U = ∑ s ∈ L,d s*monoBit s U by - conv_rhs => rw [← Finset.add_sum_erase _ _ ht] - simp [d]] - simp_rw [heq, Finset.sum_sub_distrib,← Finset.mul_sum] - have hj : (insert i U).card ≤ j := by - by_cases hh : i∈U - · rw [insert_eq_of_mem hh]; omega - · rw [card_insert_of_notMem hh]; omega - rw [hf _ hj, hf _ (by omega),mul_zero,sub_zero] - have hu := ih (L.erase t) (erase_ssubset ht) d (j-1) he hw - (Finset.mem_erase.mpr ⟨hst.symm,hs⟩) - exact (mul_eq_zero.mp hu).resolve_left (sub_ne_zero.mpr hi.symm) - · have he : L={s} := by - ext x; constructor - · intro hx; exact mem_singleton.mpr (Classical.byContradiction fun h => hL ⟨x,hx,h⟩) - intro hx; rwa [mem_singleton.mp hx] - have hh := hf ∅ (by simp) - simpa [he,monoBit] using hh - -variable {p : Shape} {n : ℕ} - -def hankel (M : Moment p n) := - ∀ (i k : AIdx p.g n) (a b c d : SelIdx p.b p.j), - a.val ∪ b.val = c.val ∪ d.val → M (a,i) (b,k) = M (c,i) (d,k) - -def diagBase (M : Moment p n) := - ∀ (i : AIdx p.g n) (a b : SelIdx p.b p.j), M (a,i) (b,i) = M (a,none) (b,i) - -theorem point_eval (p : Shape) (s : Label p.b) (z : Base p.g n) - (r : SelIdx p.b p.j) (i : AIdx p.g n) : point p s z (r,i) = monoBit s r.val * baseV z i := - rfl - -theorem Wspace_hank {M : Moment p n} (h : M∈Wspace p n) : hankel M := by - intro i k a b c d hab - unfold Wspace at h - induction h using Submodule.span_induction with - | mem M hm => - obtain ⟨s,z,rfl⟩ := hm - have h (a b : SelIdx p.b p.j) : - mom p s z (a,i) (b,k) = monoBit s (a.val ∪ b.val) * (baseV z i*baseV z k) := by - simp only [mom,vecMulVec_apply,point_eval,mono_union]; ring - rw [h,h,hab] - | zero => rfl - | add x y _ _ hx hy => simp only [Matrix.add_apply,hx,hy] - | smul v x _ hx => simp only [Matrix.smul_apply,hx] - -theorem Wspace_diag {M : Moment p n} (h : M∈Wspace p n) : diagBase M := by - intro i a b - unfold Wspace at h - induction h using Submodule.span_induction with - | mem M hm => - obtain ⟨s,z,rfl⟩ := hm - simp only [mom,vecMulVec_apply,point_eval,baseV] - rw [mul_mul_mul_comm,bit_sq] - have hn : Option.elim' (1:F) z none = 1 := rfl - rw [hn] - ring - | zero => rfl - | add x y _ _ hx hy => simp only [Matrix.add_apply,hx,hy] - | smul v x _ hx => simp only [Matrix.smul_apply,hx] - -abbrev BaseMat (p : Shape) (n : ℕ) := Mat (AIdx p.g n) (AIdx p.g n) - -def labMat (p : Shape) (n) (s : Label p.b) : - Mat (Row p n) (AIdx p.g n) := - Matrix.of (fun v i => if v.2=i then monoBit s v.1.val else 0) - -theorem labMat_act (s) (z : Vec (AIdx p.g n)) : - labMat p n s *ᵥ z = putLab p n s z := by - funext i - simp [Matrix.mulVec,dotProduct,labMat,putLab,monoBit,selV] - -def mput (p : Shape) (s : Label p.b) {n} : - BaseMat p n →ₗ[F] Moment p n := liftM (labMat p n s) (labMat p n s) - -theorem mput_apply (s) (Z : BaseMat p n) (i j) : mput p s Z i j = - monoBit s i.1.val*monoBit s j.1.val*Z i.2 j.2 := by - classical - simp [mput,liftM_def,Matrix.mul_apply,transpose_apply,labMat, mul_comm,mul_left_comm,mul_assoc] - -theorem mput_hank (s) (Z : BaseMat p n) : hankel (mput p s Z) := by - intro i j a b c d h - rw [mput_apply,mput_apply] - simp_rw [← mono_union,h] - -/-- Short label-tagged rays give a direct family of copies of the affine-vector space. -/ -theorem ray_indep (L : Finset (Label p.b)) (Z : Label p.b → Vec (AIdx p.g n)) - (hj : L.card ≤ p.j+1) (he : ∑ i∈L, putLab p n i (Z i) = 0) : - ∀ i∈L, Z i=0 := by - have hg (u : AIdx p.g n) (i : Label p.b) (hi : i ∈ L) : - Z i u=0 := by - refine selector_indep L (fun i => Z i u) p.j hj ?_ i hi - intro S hS - have hh := congr_fun he ((⟨S,hS⟩ : SelIdx p.b p.j),u) - simpa [putLab,Finset.sum_apply,monoBit,selV,mul_comm] using hh - exact fun i hi => funext (fun u => hg u i hi) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.MomentCoordinates +import OAI.Combinatorics.HadwigerCounterexample.MatrixFactorization + +namespace OAI + +/-! # Boolean Labels -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Finset +variable {b : ℕ} + +def monoBit (s : Label b) (S : Finset (Fin b)) := ∏ i ∈ S, s i + +theorem mono_insert (s : Label b) (S : Finset (Fin b)) (i) : + monoBit s (insert i S) = s i * monoBit s S := by + by_cases h : i∈S + · rw [insert_eq_of_mem h] + unfold monoBit + rw [← Finset.mul_prod_erase _ _ h,← mul_assoc,bit_sq] + · simp [monoBit,h] + +theorem mono_union (s : Label b) (S T : Finset (Fin b)) : + monoBit s (S∪T)= monoBit s S*monoBit s T := by + induction S using Finset.induction with + | empty => simp [monoBit] + | insert i S h ih => + rw [insert_union,mono_insert,mono_insert,ih,mul_assoc] + +/-- Independence up to degree j for at most j+1 labels, in coefficient form. -/ +theorem selector_indep (L : Finset (Label b)) (c : Label b → F) (j : ℕ) + (h : L.card ≤ j+1) (hf : ∀ S : Finset (Fin b), S.card ≤ j → + ∑ s ∈ L,c s*monoBit s S=0) : ∀ i∈L,c i=0 := by + classical + intro s hs + induction L using Finset.strongInductionOn generalizing c j with | _ L ih + by_cases hL : ∃ i∈L,i≠s + · obtain ⟨t,ht,hst⟩ := hL + obtain ⟨i,hi⟩ : ∃ i : Fin b,t i≠s i := Function.ne_iff.mp hst + let d (u : Label b) := (u i-t i) * c u + have hg : j>0 := by have he := Finset.one_lt_card.mpr ⟨t,ht,s,hs,hst⟩; omega + have he : (L.erase t).card ≤ (j-1)+1 := by + have he := card_erase_add_one ht; omega + have hw (U : Finset (Fin b)) (hu : U.card ≤ j-1) : + ∑ s ∈ L.erase t,d s*monoBit s U=0 := by + have heq (s : Label b) : + d s * monoBit s U = c s * monoBit s (insert i U) - t i*(c s*monoBit s U) := by + unfold d; rw [mono_insert]; ring + rw [show ∑ s ∈ L.erase t,d s*monoBit s U = ∑ s ∈ L,d s*monoBit s U by + conv_rhs => rw [← Finset.add_sum_erase _ _ ht] + simp [d]] + simp_rw [heq, Finset.sum_sub_distrib,← Finset.mul_sum] + have hj : (insert i U).card ≤ j := by + by_cases hh : i∈U + · rw [insert_eq_of_mem hh]; omega + · rw [card_insert_of_notMem hh]; omega + rw [hf _ hj, hf _ (by omega),mul_zero,sub_zero] + have hu := ih (L.erase t) (erase_ssubset ht) d (j-1) he hw + (Finset.mem_erase.mpr ⟨hst.symm,hs⟩) + exact (mul_eq_zero.mp hu).resolve_left (sub_ne_zero.mpr hi.symm) + · have he : L={s} := by + ext x; constructor + · intro hx; exact mem_singleton.mpr (Classical.byContradiction fun h => hL ⟨x,hx,h⟩) + intro hx; rwa [mem_singleton.mp hx] + have hh := hf ∅ (by simp) + simpa [he,monoBit] using hh + +variable {p : Shape} {n : ℕ} + +def hankel (M : Moment p n) := + ∀ (i k : AIdx p.g n) (a b c d : SelIdx p.b p.j), + a.val ∪ b.val = c.val ∪ d.val → M (a,i) (b,k) = M (c,i) (d,k) + +def diagBase (M : Moment p n) := + ∀ (i : AIdx p.g n) (a b : SelIdx p.b p.j), M (a,i) (b,i) = M (a,none) (b,i) + +theorem point_eval (p : Shape) (s : Label p.b) (z : Base p.g n) + (r : SelIdx p.b p.j) (i : AIdx p.g n) : point p s z (r,i) = monoBit s r.val * baseV z i := + rfl + +theorem Wspace_hank {M : Moment p n} (h : M∈Wspace p n) : hankel M := by + intro i k a b c d hab + unfold Wspace at h + induction h using Submodule.span_induction with + | mem M hm => + obtain ⟨s,z,rfl⟩ := hm + have h (a b : SelIdx p.b p.j) : + mom p s z (a,i) (b,k) = monoBit s (a.val ∪ b.val) * (baseV z i*baseV z k) := by + simp only [mom,vecMulVec_apply,point_eval,mono_union]; ring + rw [h,h,hab] + | zero => rfl + | add x y _ _ hx hy => simp only [Matrix.add_apply,hx,hy] + | smul v x _ hx => simp only [Matrix.smul_apply,hx] + +theorem Wspace_diag {M : Moment p n} (h : M∈Wspace p n) : diagBase M := by + intro i a b + unfold Wspace at h + induction h using Submodule.span_induction with + | mem M hm => + obtain ⟨s,z,rfl⟩ := hm + simp only [mom,vecMulVec_apply,point_eval,baseV] + rw [mul_mul_mul_comm,bit_sq] + have hn : Option.elim' (1:F) z none = 1 := rfl + rw [hn] + ring + | zero => rfl + | add x y _ _ hx hy => simp only [Matrix.add_apply,hx,hy] + | smul v x _ hx => simp only [Matrix.smul_apply,hx] + +abbrev BaseMat (p : Shape) (n : ℕ) := Mat (AIdx p.g n) (AIdx p.g n) + +def labMat (p : Shape) (n) (s : Label p.b) : + Mat (Row p n) (AIdx p.g n) := + Matrix.of (fun v i => if v.2=i then monoBit s v.1.val else 0) + +theorem labMat_act (s) (z : Vec (AIdx p.g n)) : + labMat p n s *ᵥ z = putLab p n s z := by + funext i + simp [Matrix.mulVec,dotProduct,labMat,putLab,monoBit,selV] + +def mput (p : Shape) (s : Label p.b) {n} : + BaseMat p n →ₗ[F] Moment p n := liftM (labMat p n s) (labMat p n s) + +theorem mput_apply (s) (Z : BaseMat p n) (i j) : mput p s Z i j = + monoBit s i.1.val*monoBit s j.1.val*Z i.2 j.2 := by + classical + simp [mput,liftM_def,Matrix.mul_apply,transpose_apply,labMat, mul_comm,mul_left_comm,mul_assoc] + +theorem mput_hank (s) (Z : BaseMat p n) : hankel (mput p s Z) := by + intro i j a b c d h + rw [mput_apply,mput_apply] + simp_rw [← mono_union,h] + +/-- Short label-tagged rays give a direct family of copies of the affine-vector space. -/ +theorem ray_indep (L : Finset (Label p.b)) (Z : Label p.b → Vec (AIdx p.g n)) + (hj : L.card ≤ p.j+1) (he : ∑ i∈L, putLab p n i (Z i) = 0) : + ∀ i∈L, Z i=0 := by + have hg (u : AIdx p.g n) (i : Label p.b) (hi : i ∈ L) : + Z i u=0 := by + refine selector_indep L (fun i => Z i u) p.j hj ?_ i hi + intro S hS + have hh := congr_fun he ((⟨S,hS⟩ : SelIdx p.b p.j),u) + simpa [putLab,Finset.sum_apply,monoBit,selV,mul_comm] using hh + exact fun i hi => funext (fun u => hg u i hi) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/BoundedQueryTemplates.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/BoundedQueryTemplates.lean index cbbd34490224191a715c9bfdfa3aff9f1b68918b..89d9ecceef2178369eb0e9ae4b497fe539cdb00a 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/BoundedQueryTemplates.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/BoundedQueryTemplates.lean @@ -1,134 +1,134 @@ -import OAI.Combinatorics.HadwigerCounterexample.IndependentColumnBatches -import OAI.Combinatorics.HadwigerCounterexample.CollisionInequality - -namespace OAI - -/-! # Bounded Query Templates -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Module LinearMap Function -variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] - -structure Template (p : Shape) (I : Type) where - aim : I→Bool - t : Tagging p I - s : I→Label p.b - f : I→Flavor p.g - -abbrev Inputs (p : Shape) (n : ℕ) (I : Type) := I → Knobs p.g n - -namespace Template -variable (v : Template p I) - -def draw (y : Inputs p n I) : Volley p n I where - obj := v.aim - sel := v.s - par i := lit (v.f i) (v.t i) (y i) - -def state (q : I→F) (n : ℕ) : Wgt (Inputs p n I) := - prodW (fun i : I => scopedBit p n (v.t i) (v.f i) (q i)) -omit [Fintype I] [DecidableEq I] in -theorem draw_legal (y : Inputs p n I) : (v.draw y).legal v.t := - fun _ => lit_allows _ _ _ -end Template - -abbrev KeySlots (p : Shape) (t : Tagging p I) := Σ i, TagStar (t i) - -def scatter (t : Tagging p I) (N : ℕ) : Keys (p:=p) t N ≃ Rack (KeySlots p t) N where - toFun x := (Matrix.of (fun j i => x i.1 i.2 true j),Matrix.of (fun j i => x i.1 i.2 false j)) - invFun x := fun i j b => if b then x.1.col ⟨i,j⟩ else x.2.col ⟨i,j⟩ - left_inv x := by funext i j b; cases b <;> rfl - right_inv x := by apply Prod.ext <;> rfl - -def globPort (p : Shape) (t : Tagging p I) (q : I→Bool) : - Route (KeySlots p t) (Ports p) := - fun x => (q x.1,x.2.val) - -def nomAsk (t : Tagging p I) (v : Volley p n I) : - NomQuery p n (globPort p t v.obj) := - fun _ => Matrix.of (fun i j => v.rayAt j.val.1 i) - -omit [Fintype I] [DecidableEq I] in -theorem peek_keys (t : Tagging p I) (v : Volley p n I) (x : UnitType p n N) : - peekR p (globPort p t v.obj) (nomAsk t v) (nomAsk t v) (mergeR p x) = - scatter t N (v.keys t x) := by - apply Prod.ext - · ext i j; rfl - · ext i j; rfl - -theorem raw_keys (t : Tagging p I) (v : Volley p n I) (m : Mixer p n) {N : ℕ} - (hN : 2*num (Full p n) x.2.val -def ownMap (t : Tagging p I) (q : I→F) : GeoM (ownPort (p:=p) t) := - fun _ => Matrix.diagonal (fun i => q i.val.1) -def ownPart (t : Tagging p I) (q : I→F) {N : ℕ} - (x : Keys (p:=p) t N) := - gramPart (ownMap (p:=p) t q) (scatter t N x) -def lawNu (p : Shape) (N : ℕ) (t : Tagging p I) (q : I→F) : - Wgt (Keys (p:=p) t N) := unifOn (ownPart (p:=p) t q) - -theorem lawNu_rack (t : Tagging p I) (q : I→F) : - mapW (lawNu p N t q) (scatter t N) = rackWave (ownMap t q) N := - on_equiv .. - -def ownOne (p : Shape) {N : ℕ} (l : Tag p.g) (q : F) (x : AtomKey (p:=p) l N) := - ∀ i,dotProduct (x i true) (x i false) = q -def lawOmega (p : Shape) (N : ℕ) (l : Tag p.g) (q : F) : - Wgt (AtomKey (p:=p) l N) := unifOn (ownOne p l q) - -omit [Fintype I] in -theorem ownPart_def (t : Tagging p I) (q : I→F) {N : ℕ} (x : Keys (p:=p) t N) : - ownPart (p:=p) t q x ↔ - (∀ i, ownOne p (t i) (q i) (x i)) ∧ - ∀ (i j : I) (e : Comp p.g) (hi : inc e (t i)) (hj : inc e (t j)), i≠j → - dotProduct (x i ⟨e,hi⟩ true) (x j ⟨e,hj⟩ false)=0 := by - classical - let Q := ownPort (p:=p) t - unfold ownPart - rw [part_scores] - have he i j (e : Comp p.g) (hi : inc e (t i)) (hj : inc e (t j)) : - let a : Port Q e := ⟨⟨i,⟨e,hi⟩⟩,rfl⟩ - let b : Port Q e := ⟨⟨j,⟨e,hj⟩⟩,rfl⟩ - scoreR (scatter t N x) a b=dotProduct (x i ⟨e,hi⟩ true) (x j ⟨e,hj⟩ false) := rfl - constructor - · intro h - constructor - · rintro i ⟨e,hi⟩ - let a : Port Q e := ⟨⟨i,⟨e,hi⟩⟩,rfl⟩ - exact (he i i e hi hi).symm.trans ((h e a a).trans (Matrix.diagonal_apply_eq ..)) - intro i j e hi hj heq - let a : Port Q e := ⟨⟨i,⟨e,hi⟩⟩,rfl⟩ - let b : Port Q e := ⟨⟨j,⟨e,hj⟩⟩,rfl⟩ - have hh : a≠b := fun h => heq (congrArg (fun x:Port Q e => x.val.1) h) - exact (he i j e hi hj).symm.trans ((h e a b).trans (Matrix.diagonal_apply_ne _ hh)) - · rintro ⟨h,h'⟩ e ⟨⟨i,v⟩,ha⟩ ⟨⟨j,w⟩,hb⟩ - rcases v with ⟨v,hv⟩; rcases w with ⟨w,hw⟩ - change v = e at ha; change w=e at hb - subst v; subst w - let a : Port Q e := ⟨⟨i,⟨e,hv⟩⟩,rfl⟩ - let b : Port Q e := ⟨⟨j,⟨e,hw⟩⟩,rfl⟩ - by_cases he : i=j - · subst j - refine (show scoreR (scatter t N x) a.val a.val=_ from h i ⟨e,hv⟩).trans ?_ - exact (Matrix.diagonal_apply_eq (fun j : Port Q e => q j.val.1) a).symm - have hh : a≠b := fun h => he (congrArg (fun x:Port Q e => x.val.1) h) - refine Eq.trans (h' i j e hv hw he) ?_ - exact (Matrix.diagonal_apply_ne (fun j : Port Q e => q j.val.1) hh).symm - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.IndependentColumnBatches +import OAI.Combinatorics.HadwigerCounterexample.CollisionInequality + +namespace OAI + +/-! # Bounded Query Templates -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Module LinearMap Function +variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] + +structure Template (p : Shape) (I : Type) where + aim : I→Bool + t : Tagging p I + s : I→Label p.b + f : I→Flavor p.g + +abbrev Inputs (p : Shape) (n : ℕ) (I : Type) := I → Knobs p.g n + +namespace Template +variable (v : Template p I) + +def draw (y : Inputs p n I) : Volley p n I where + obj := v.aim + sel := v.s + par i := lit (v.f i) (v.t i) (y i) + +def state (q : I→F) (n : ℕ) : Wgt (Inputs p n I) := + prodW (fun i : I => scopedBit p n (v.t i) (v.f i) (q i)) +omit [Fintype I] [DecidableEq I] in +theorem draw_legal (y : Inputs p n I) : (v.draw y).legal v.t := + fun _ => lit_allows _ _ _ +end Template + +abbrev KeySlots (p : Shape) (t : Tagging p I) := Σ i, TagStar (t i) + +def scatter (t : Tagging p I) (N : ℕ) : Keys (p:=p) t N ≃ Rack (KeySlots p t) N where + toFun x := (Matrix.of (fun j i => x i.1 i.2 true j),Matrix.of (fun j i => x i.1 i.2 false j)) + invFun x := fun i j b => if b then x.1.col ⟨i,j⟩ else x.2.col ⟨i,j⟩ + left_inv x := by funext i j b; cases b <;> rfl + right_inv x := by apply Prod.ext <;> rfl + +def globPort (p : Shape) (t : Tagging p I) (q : I→Bool) : + Route (KeySlots p t) (Ports p) := + fun x => (q x.1,x.2.val) + +def nomAsk (t : Tagging p I) (v : Volley p n I) : + NomQuery p n (globPort p t v.obj) := + fun _ => Matrix.of (fun i j => v.rayAt j.val.1 i) + +omit [Fintype I] [DecidableEq I] in +theorem peek_keys (t : Tagging p I) (v : Volley p n I) (x : UnitType p n N) : + peekR p (globPort p t v.obj) (nomAsk t v) (nomAsk t v) (mergeR p x) = + scatter t N (v.keys t x) := by + apply Prod.ext + · ext i j; rfl + · ext i j; rfl + +theorem raw_keys (t : Tagging p I) (v : Volley p n I) (m : Mixer p n) {N : ℕ} + (hN : 2*num (Full p n) x.2.val +def ownMap (t : Tagging p I) (q : I→F) : GeoM (ownPort (p:=p) t) := + fun _ => Matrix.diagonal (fun i => q i.val.1) +def ownPart (t : Tagging p I) (q : I→F) {N : ℕ} + (x : Keys (p:=p) t N) := + gramPart (ownMap (p:=p) t q) (scatter t N x) +def lawNu (p : Shape) (N : ℕ) (t : Tagging p I) (q : I→F) : + Wgt (Keys (p:=p) t N) := unifOn (ownPart (p:=p) t q) + +theorem lawNu_rack (t : Tagging p I) (q : I→F) : + mapW (lawNu p N t q) (scatter t N) = rackWave (ownMap t q) N := + on_equiv .. + +def ownOne (p : Shape) {N : ℕ} (l : Tag p.g) (q : F) (x : AtomKey (p:=p) l N) := + ∀ i,dotProduct (x i true) (x i false) = q +def lawOmega (p : Shape) (N : ℕ) (l : Tag p.g) (q : F) : + Wgt (AtomKey (p:=p) l N) := unifOn (ownOne p l q) + +omit [Fintype I] in +theorem ownPart_def (t : Tagging p I) (q : I→F) {N : ℕ} (x : Keys (p:=p) t N) : + ownPart (p:=p) t q x ↔ + (∀ i, ownOne p (t i) (q i) (x i)) ∧ + ∀ (i j : I) (e : Comp p.g) (hi : inc e (t i)) (hj : inc e (t j)), i≠j → + dotProduct (x i ⟨e,hi⟩ true) (x j ⟨e,hj⟩ false)=0 := by + classical + let Q := ownPort (p:=p) t + unfold ownPart + rw [part_scores] + have he i j (e : Comp p.g) (hi : inc e (t i)) (hj : inc e (t j)) : + let a : Port Q e := ⟨⟨i,⟨e,hi⟩⟩,rfl⟩ + let b : Port Q e := ⟨⟨j,⟨e,hj⟩⟩,rfl⟩ + scoreR (scatter t N x) a b=dotProduct (x i ⟨e,hi⟩ true) (x j ⟨e,hj⟩ false) := rfl + constructor + · intro h + constructor + · rintro i ⟨e,hi⟩ + let a : Port Q e := ⟨⟨i,⟨e,hi⟩⟩,rfl⟩ + exact (he i i e hi hi).symm.trans ((h e a a).trans (Matrix.diagonal_apply_eq ..)) + intro i j e hi hj heq + let a : Port Q e := ⟨⟨i,⟨e,hi⟩⟩,rfl⟩ + let b : Port Q e := ⟨⟨j,⟨e,hj⟩⟩,rfl⟩ + have hh : a≠b := fun h => heq (congrArg (fun x:Port Q e => x.val.1) h) + exact (he i j e hi hj).symm.trans ((h e a b).trans (Matrix.diagonal_apply_ne _ hh)) + · rintro ⟨h,h'⟩ e ⟨⟨i,v⟩,ha⟩ ⟨⟨j,w⟩,hb⟩ + rcases v with ⟨v,hv⟩; rcases w with ⟨w,hw⟩ + change v = e at ha; change w=e at hb + subst v; subst w + let a : Port Q e := ⟨⟨i,⟨e,hv⟩⟩,rfl⟩ + let b : Port Q e := ⟨⟨j,⟨e,hw⟩⟩,rfl⟩ + by_cases he : i=j + · subst j + refine (show scoreR (scatter t N x) a.val a.val=_ from h i ⟨e,hv⟩).trans ?_ + exact (Matrix.diagonal_apply_eq (fun j : Port Q e => q j.val.1) a).symm + have hh : a≠b := fun h => he (congrArg (fun x:Port Q e => x.val.1) h) + refine Eq.trans (h' i j e hv hw he) ?_ + exact (Matrix.diagonal_apply_ne (fun j : Port Q e => q j.val.1) hh).symm + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CellPositivityScales.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CellPositivityScales.lean index b539a9340e8bd4e75d3cb1d990eda628a1fbb0a9..d139d5c95a2b302380bfa15accff3d07ab2447b1 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CellPositivityScales.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CellPositivityScales.lean @@ -1,177 +1,177 @@ -import OAI.Combinatorics.HadwigerCounterexample.SurrogateStatusLaws - -namespace OAI - -/-! # Cell Positivity Scales -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix Function -open scoped BigOperators Topology -variable {p:Shape} {n N K M r : ℕ} -namespace StatusAnalysis -open Template -variable {b : PreparationParameters} - -namespace Appearance -variable (x : Appearance p) {s0 : ℕ} - -theorem readCap (x : Appearance p) (r M : ℕ) (h : AnalyticParameters p M b s0) - (ε : ℝ) (hε : 0<ε) : - ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ m : Mixer p n,2*num (Full p n)<(N:ℝ) → - ∀ Y : Silhouette p N r,pr (raw m N) (fun o=> x.apt∧¬ x.close Y o ε)≤bp (-(1/16:ℝ)*n) := by - classical - have hp:=h.enter.first - by_cases ha : x.apt - · let δ : ℝ := ε/(r+1:ℝ) - have hδ : 0<δ:=by unfold δ; positivity - filter_upwards [flat_recital x.trot M hp.hM hp.hJ δ hδ,eventually_ge_atTop (2*p.r), - pay_nat (a:=1/8) (b:=1/16) (num (Fin r)) (by norm_num)] with n hn ht hB N m hN Y - let w:= x.wit n; let v:= raw m N - have hw : IsLaw w:= witLaw ha hp.hR ht - let P (i : Fin r) (o : Orient p n N):= - δ≤ |x.empirical Y o i - x.reference Y i| - have hk (i : Fin r) : pr v (P i) ≤ bp (-(1/8:ℝ)*n) := by - let S (z) := ind (Y x.l x.q z=i) - have hf z : |S z|≤1 := by unfold S; rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ - refine hn m w x.q hw (normW_carried (subW_carried _ _)) - (scopedZ_bit p n _ _ _ hw) hN S hf - have he (o : Orient p n N) (h : x.apt∧¬x.close Y o ε) : ∃ i,P i o := by - by_contra! hh - apply h.2 - unfold close varOne - calc _ ≤ ∑ i : Fin r,δ:= Finset.sum_le_sum fun i _=>le_trans (abs_sub_comm ..).le - (le_of_not_ge (hh i)) - _ ≤ ε := by - simp; unfold δ - calc _ ≤ ((r:ℝ)+1)* (ε/(r+1:ℝ)) := mul_le_mul_of_nonneg_right (by linarith) hδ.le - _ = ε := by field_simp - have hv : IsLaw v:= raw_law m hN - exact ((pr_mono hv.nz he).trans (pr_exists_le hv.nz P)).trans - (((Finset.sum_le_sum fun i _=>hk i).trans_eq (by simp [num])).trans hB) - filter_upwards with n N m hN Y - simp_rw [show (x.apt)=False from eq_false ha,false_and,pr_false]; exact (bp_pos _).le - -def foil (x : Appearance p) (Y : Silhouette p N r) (o : Orient p n N) - (m : Mixer p n) (K : ℕ) (δ : ℝ) := - ∀ (z:Digest p.g) (i:Fin r), z.feasible x.l x.f → z.sumBit=x.q → - δ ≤ x.reference Y i → Template.patrol x.trot m (scopedScan p n x.l x.f z) - (fun y => Y x.l x.q y=i) K x.q o - -theorem foilCap (x : Appearance p) (r M : ℕ) (h : AnalyticParameters p M b s0) - (δ:ℝ) (hδ:0<δ) : - ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ m : Mixer p n,2*num (Full p n)<(N:ℝ) → - unaryGood m b.pins s0 → ∀ Y: Silhouette p N r, - pr (raw m N) (fun i=>¬x.foil Y i m b.pins δ)≤bp (-(1/18:ℝ)*n) := by - classical - have ht:=h.enter.first - let A:= Digest p.g × Fin r - let Q n (m:Mixer p n) (Y:Silhouette p (M*n) r) (a : A) (o : Orient p n (M*n)) := - a.1.feasible x.l x.f ∧ a.1.sumBit=x.q ∧ δ≤x.reference Y a.2 ∧ - ¬Template.patrol x.trot m (scopedScan p n x.l x.f a.1) - (fun y=>Y x.l x.q y=a.2) b.pins x.q o - have hg (a:A) : - ∀ᶠ n:ℕ in atTop,let N:=M*n;∀ m:Mixer p n,2*num (Full p n)<(N:ℝ) → - unaryGood m b.pins s0→∀ Y:Silhouette p N r, - pr (raw m N) (Q n m Y a) ≤ bp (-(1/16:ℝ)*n) := by - by_cases hf : a.1.feasible x.l x.f ∧ a.1.sumBit=x.q - · filter_upwards [patrolled x.trot M ht.hM ht.hg ht.hJ a.1 hf.1 ht.hR δ hδ h.profiles - h.gleaming] with n hn N m hN hM Y - by_cases he : δ ≤ x.reference Y a.2 - · let S : AtomKey (p:=p) (x.trot.t ()) (M*n) →Prop := fun i=>Y x.l x.q i=a.2 - let v:=scopedScan p n (x.trot.t ()) (x.trot.f ()) a.1 - have hx : δ ≤ pr (lawOmega p (M*n) (x.trot.t ()) a.1.sumBit) S := by - rw [hf.2]; exact he - have hh (i:Orient p n (M*n)) (h:Q n m Y a i) : - ¬Template.patrol x.trot m v S b.pins a.1.sumBit i := hf.2 ▸ h.2.2.2 - exact (pr_mono (raw_law m hN).nz hh).trans (hn m hM hN S hx) - have hg : Q n m Y a=fun _=> False := - funext fun i=> eq_false (fun h=>he h.2.2.1) - change pr (raw m (M*n)) (Q n m Y a) ≤ _ - rw [hg,pr_false]; exact (bp_pos _).le - filter_upwards with n N m hN hg Y - have hh : Q n m Y a=fun _=> False := - funext fun i=> eq_false (fun h=> hf ⟨h.1,h.2.1⟩) - change pr (raw m (M*n)) (Q n m Y a) ≤ _ - rw [hh,pr_false]; exact (bp_pos _).le - filter_upwards [eventually_all.mpr hg,pay_nat (a:=1/16) (b:=1/18) (num A) (by norm_num)] - with n hn hB N m hN hM Y - have he o (h : ¬x.foil Y o m b.pins δ) : ∃ i, Q n m Y i o := by - unfold foil at h - push Not at h - obtain ⟨z,i,h⟩:=h - exact ⟨(z,i),h⟩ - let v:=raw m N - have hv : IsLaw v:=raw_law m hN - exact ((pr_mono hv.nz he).trans (pr_exists_le hv.nz _)).trans - (((Finset.sum_le_sum fun i _=>hn i m hN hM Y).trans_eq (by simp [num])).trans hB) -end Appearance - -def smoothSilk (p : Shape) (ε δ:ℝ) (Y:Silhouette p N r) - (m:Mixer p n) (K:ℕ) (o:Orient p n N) := - ∀ x : Appearance p,(x.apt → x.close Y o ε) ∧ x.foil Y o m K δ - -variable {s0 : ℕ} - -def gauze (p : Shape) (ε δ:ℝ) (Y:Silhouette p N r) - (m:Mixer p n) (K:ℕ) (o:UnitType p n N) := - ∀ i,smoothSilk p ε δ Y m K (onSide o i) - -private theorem silken (p : Shape) (r M : ℕ) (h : AnalyticParameters p M b s0) - (ε δ : ℝ) (he:0<ε) (hd:0<δ) : - ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ m : Mixer p n,2*num (Full p n)<(N:ℝ) → - unaryGood m b.pins s0 → ∀ Y: Silhouette p N r, - pr (raw m N) (fun i=>¬smoothSilk p ε δ Y m b.pins i)≤bp (-(1/20:ℝ)*n) := by - classical - let A:= Appearance p - filter_upwards [eventually_all.mpr (fun x:A=>x.foilCap r M h δ hd), - eventually_all.mpr (fun x:A=>x.readCap r M h ε he), - pay_nat (a:=1/18) (b:=1/20) (num A*2) (by norm_num)] with n hn ht hB N m hN hM Y - let v:=raw m N - have hv : IsLaw v:=raw_law m hN - let P (x:A) (o:Orient p n N) := - (x.apt ∧ ¬x.close Y o ε)∨ ¬x.foil Y o m b.pins δ - have hk x : pr v (P x) ≤ 2*bp (-(1/18:ℝ)*n) := by - rw [two_mul]; apply (pr_or_le hv.nz).trans - refine add_le_add ((ht x m hN Y).trans (bp_le ?_)) (hn x m hN hM Y) - linarith [(Nat.cast_nonneg n :0≤(n:ℝ))] - have hi o (h : ¬smoothSilk p ε δ Y m b.pins o) : ∃ i, P i o := by - unfold smoothSilk at h - obtain ⟨i,h⟩:= Classical.not_forall.mp h - exact ⟨i,by unfold P; tauto⟩ - refine ((pr_mono hv.nz hi).trans (pr_exists_le hv.nz _)).trans - (((Finset.sum_le_sum fun i _=>hk i).trans_eq ?_).trans hB) - simp [num,mul_assoc] - -theorem gauzeCalendar (p : Shape) (r M : ℕ) (h : AnalyticParameters p M b s0) - (ε δ:ℝ) (he:0<ε) (hd:0<δ) : - ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ m : Mixer p n,∀ u : Wgt (UnitType p n N), - PreparationParameters.Align b s0 p M n m u → ∀ Y: Silhouette p N r, - pr u (fun i=>¬gauze p ε δ Y m b.pins i)≤bp (-(1/100:ℝ)*n) := by - classical - filter_upwards [silken p r M h ε δ he hd,pay_nat (a:=1/20-1/32) (b:=1/100) 2 - (by norm_num)] with n hn ht N m u hu Y - let P (o:Orient p n N) := ¬smoothSilk p ε δ Y m b.pins o - let Q (i:Bool) (o:UnitType p n N):=P (onSide o i) - have hc : bySide p u m (bp ((1/32:ℝ)*n)) := fun i=> by - have hh:= hu.drain - cases i; exact hh.2.2.1; exact hh.2.1 - have hf : ∀ i,pr u (Q i) ≤bp (-((1/20:ℝ)-1/32)*n) := by - intro i - let x := fun o:UnitType p n N=>onSide o i - change pr u (fun i=>P (x i)) ≤_ - rw [←mapW_pr] - exact (pr_cap (hc i) P).trans ((mul_le_mul_of_nonneg_left - (hn m hu.cols hu.hymn Y) (bp_pos _).le).trans_eq (by rw [←bp_add]; congr 1; ring)) - have he o (h : ¬gauze p ε δ Y m b.pins o) : ∃ i,Q i o := Classical.not_forall.mp h - have hv : IsLaw u:=hu.drain.1 - rw [two_mul] at ht - refine ((pr_mono hv.nz he).trans ((pr_exists_le hv.nz _).trans ?_)) - rw [Fintype.sum_bool]; exact (add_le_add (hf _) (hf _)).trans ht - -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SurrogateStatusLaws + +namespace OAI + +/-! # Cell Positivity Scales -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix Function +open scoped BigOperators Topology +variable {p:Shape} {n N K M r : ℕ} +namespace StatusAnalysis +open Template +variable {b : PreparationParameters} + +namespace Appearance +variable (x : Appearance p) {s0 : ℕ} + +theorem readCap (x : Appearance p) (r M : ℕ) (h : AnalyticParameters p M b s0) + (ε : ℝ) (hε : 0<ε) : + ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ m : Mixer p n,2*num (Full p n)<(N:ℝ) → + ∀ Y : Silhouette p N r,pr (raw m N) (fun o=> x.apt∧¬ x.close Y o ε)≤bp (-(1/16:ℝ)*n) := by + classical + have hp:=h.enter.first + by_cases ha : x.apt + · let δ : ℝ := ε/(r+1:ℝ) + have hδ : 0<δ:=by unfold δ; positivity + filter_upwards [flat_recital x.trot M hp.hM hp.hJ δ hδ,eventually_ge_atTop (2*p.r), + pay_nat (a:=1/8) (b:=1/16) (num (Fin r)) (by norm_num)] with n hn ht hB N m hN Y + let w:= x.wit n; let v:= raw m N + have hw : IsLaw w:= witLaw ha hp.hR ht + let P (i : Fin r) (o : Orient p n N):= + δ≤ |x.empirical Y o i - x.reference Y i| + have hk (i : Fin r) : pr v (P i) ≤ bp (-(1/8:ℝ)*n) := by + let S (z) := ind (Y x.l x.q z=i) + have hf z : |S z|≤1 := by unfold S; rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ + refine hn m w x.q hw (normW_carried (subW_carried _ _)) + (scopedZ_bit p n _ _ _ hw) hN S hf + have he (o : Orient p n N) (h : x.apt∧¬x.close Y o ε) : ∃ i,P i o := by + by_contra! hh + apply h.2 + unfold close varOne + calc _ ≤ ∑ i : Fin r,δ:= Finset.sum_le_sum fun i _=>le_trans (abs_sub_comm ..).le + (le_of_not_ge (hh i)) + _ ≤ ε := by + simp; unfold δ + calc _ ≤ ((r:ℝ)+1)* (ε/(r+1:ℝ)) := mul_le_mul_of_nonneg_right (by linarith) hδ.le + _ = ε := by field_simp + have hv : IsLaw v:= raw_law m hN + exact ((pr_mono hv.nz he).trans (pr_exists_le hv.nz P)).trans + (((Finset.sum_le_sum fun i _=>hk i).trans_eq (by simp [num])).trans hB) + filter_upwards with n N m hN Y + simp_rw [show (x.apt)=False from eq_false ha,false_and,pr_false]; exact (bp_pos _).le + +def foil (x : Appearance p) (Y : Silhouette p N r) (o : Orient p n N) + (m : Mixer p n) (K : ℕ) (δ : ℝ) := + ∀ (z:Digest p.g) (i:Fin r), z.feasible x.l x.f → z.sumBit=x.q → + δ ≤ x.reference Y i → Template.patrol x.trot m (scopedScan p n x.l x.f z) + (fun y => Y x.l x.q y=i) K x.q o + +theorem foilCap (x : Appearance p) (r M : ℕ) (h : AnalyticParameters p M b s0) + (δ:ℝ) (hδ:0<δ) : + ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ m : Mixer p n,2*num (Full p n)<(N:ℝ) → + unaryGood m b.pins s0 → ∀ Y: Silhouette p N r, + pr (raw m N) (fun i=>¬x.foil Y i m b.pins δ)≤bp (-(1/18:ℝ)*n) := by + classical + have ht:=h.enter.first + let A:= Digest p.g × Fin r + let Q n (m:Mixer p n) (Y:Silhouette p (M*n) r) (a : A) (o : Orient p n (M*n)) := + a.1.feasible x.l x.f ∧ a.1.sumBit=x.q ∧ δ≤x.reference Y a.2 ∧ + ¬Template.patrol x.trot m (scopedScan p n x.l x.f a.1) + (fun y=>Y x.l x.q y=a.2) b.pins x.q o + have hg (a:A) : + ∀ᶠ n:ℕ in atTop,let N:=M*n;∀ m:Mixer p n,2*num (Full p n)<(N:ℝ) → + unaryGood m b.pins s0→∀ Y:Silhouette p N r, + pr (raw m N) (Q n m Y a) ≤ bp (-(1/16:ℝ)*n) := by + by_cases hf : a.1.feasible x.l x.f ∧ a.1.sumBit=x.q + · filter_upwards [patrolled x.trot M ht.hM ht.hg ht.hJ a.1 hf.1 ht.hR δ hδ h.profiles + h.gleaming] with n hn N m hN hM Y + by_cases he : δ ≤ x.reference Y a.2 + · let S : AtomKey (p:=p) (x.trot.t ()) (M*n) →Prop := fun i=>Y x.l x.q i=a.2 + let v:=scopedScan p n (x.trot.t ()) (x.trot.f ()) a.1 + have hx : δ ≤ pr (lawOmega p (M*n) (x.trot.t ()) a.1.sumBit) S := by + rw [hf.2]; exact he + have hh (i:Orient p n (M*n)) (h:Q n m Y a i) : + ¬Template.patrol x.trot m v S b.pins a.1.sumBit i := hf.2 ▸ h.2.2.2 + exact (pr_mono (raw_law m hN).nz hh).trans (hn m hM hN S hx) + have hg : Q n m Y a=fun _=> False := + funext fun i=> eq_false (fun h=>he h.2.2.1) + change pr (raw m (M*n)) (Q n m Y a) ≤ _ + rw [hg,pr_false]; exact (bp_pos _).le + filter_upwards with n N m hN hg Y + have hh : Q n m Y a=fun _=> False := + funext fun i=> eq_false (fun h=> hf ⟨h.1,h.2.1⟩) + change pr (raw m (M*n)) (Q n m Y a) ≤ _ + rw [hh,pr_false]; exact (bp_pos _).le + filter_upwards [eventually_all.mpr hg,pay_nat (a:=1/16) (b:=1/18) (num A) (by norm_num)] + with n hn hB N m hN hM Y + have he o (h : ¬x.foil Y o m b.pins δ) : ∃ i, Q n m Y i o := by + unfold foil at h + push Not at h + obtain ⟨z,i,h⟩:=h + exact ⟨(z,i),h⟩ + let v:=raw m N + have hv : IsLaw v:=raw_law m hN + exact ((pr_mono hv.nz he).trans (pr_exists_le hv.nz _)).trans + (((Finset.sum_le_sum fun i _=>hn i m hN hM Y).trans_eq (by simp [num])).trans hB) +end Appearance + +def smoothSilk (p : Shape) (ε δ:ℝ) (Y:Silhouette p N r) + (m:Mixer p n) (K:ℕ) (o:Orient p n N) := + ∀ x : Appearance p,(x.apt → x.close Y o ε) ∧ x.foil Y o m K δ + +variable {s0 : ℕ} + +def gauze (p : Shape) (ε δ:ℝ) (Y:Silhouette p N r) + (m:Mixer p n) (K:ℕ) (o:UnitType p n N) := + ∀ i,smoothSilk p ε δ Y m K (onSide o i) + +private theorem silken (p : Shape) (r M : ℕ) (h : AnalyticParameters p M b s0) + (ε δ : ℝ) (he:0<ε) (hd:0<δ) : + ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ m : Mixer p n,2*num (Full p n)<(N:ℝ) → + unaryGood m b.pins s0 → ∀ Y: Silhouette p N r, + pr (raw m N) (fun i=>¬smoothSilk p ε δ Y m b.pins i)≤bp (-(1/20:ℝ)*n) := by + classical + let A:= Appearance p + filter_upwards [eventually_all.mpr (fun x:A=>x.foilCap r M h δ hd), + eventually_all.mpr (fun x:A=>x.readCap r M h ε he), + pay_nat (a:=1/18) (b:=1/20) (num A*2) (by norm_num)] with n hn ht hB N m hN hM Y + let v:=raw m N + have hv : IsLaw v:=raw_law m hN + let P (x:A) (o:Orient p n N) := + (x.apt ∧ ¬x.close Y o ε)∨ ¬x.foil Y o m b.pins δ + have hk x : pr v (P x) ≤ 2*bp (-(1/18:ℝ)*n) := by + rw [two_mul]; apply (pr_or_le hv.nz).trans + refine add_le_add ((ht x m hN Y).trans (bp_le ?_)) (hn x m hN hM Y) + linarith [(Nat.cast_nonneg n :0≤(n:ℝ))] + have hi o (h : ¬smoothSilk p ε δ Y m b.pins o) : ∃ i, P i o := by + unfold smoothSilk at h + obtain ⟨i,h⟩:= Classical.not_forall.mp h + exact ⟨i,by unfold P; tauto⟩ + refine ((pr_mono hv.nz hi).trans (pr_exists_le hv.nz _)).trans + (((Finset.sum_le_sum fun i _=>hk i).trans_eq ?_).trans hB) + simp [num,mul_assoc] + +theorem gauzeCalendar (p : Shape) (r M : ℕ) (h : AnalyticParameters p M b s0) + (ε δ:ℝ) (he:0<ε) (hd:0<δ) : + ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ m : Mixer p n,∀ u : Wgt (UnitType p n N), + PreparationParameters.Align b s0 p M n m u → ∀ Y: Silhouette p N r, + pr u (fun i=>¬gauze p ε δ Y m b.pins i)≤bp (-(1/100:ℝ)*n) := by + classical + filter_upwards [silken p r M h ε δ he hd,pay_nat (a:=1/20-1/32) (b:=1/100) 2 + (by norm_num)] with n hn ht N m u hu Y + let P (o:Orient p n N) := ¬smoothSilk p ε δ Y m b.pins o + let Q (i:Bool) (o:UnitType p n N):=P (onSide o i) + have hc : bySide p u m (bp ((1/32:ℝ)*n)) := fun i=> by + have hh:= hu.drain + cases i; exact hh.2.2.1; exact hh.2.1 + have hf : ∀ i,pr u (Q i) ≤bp (-((1/20:ℝ)-1/32)*n) := by + intro i + let x := fun o:UnitType p n N=>onSide o i + change pr u (fun i=>P (x i)) ≤_ + rw [←mapW_pr] + exact (pr_cap (hc i) P).trans ((mul_le_mul_of_nonneg_left + (hn m hu.cols hu.hymn Y) (bp_pos _).le).trans_eq (by rw [←bp_add]; congr 1; ring)) + have he o (h : ¬gauze p ε δ Y m b.pins o) : ∃ i,Q i o := Classical.not_forall.mp h + have hv : IsLaw u:=hu.drain.1 + rw [two_mul] at ht + refine ((pr_mono hv.nz he).trans ((pr_exists_le hv.nz _).trans ?_)) + rw [Fintype.sum_bool]; exact (add_le_add (hf _) (hf _)).trans ht + +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CellPruning.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CellPruning.lean index c68553b8177c14d8b4df209247811f419539d129..d21557c7a4bc6f9e72154fc9f45b14e5c76c06ef 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CellPruning.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CellPruning.lean @@ -1,128 +1,128 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteConditioning -import OAI.Combinatorics.HadwigerCounterexample.ConditionalProductLaws - -namespace OAI - -/-! # Cell Pruning -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Finset -variable {A B I J : Type} [Fintype A] [Fintype B] [Fintype I] [Fintype J] - -theorem sum_pr_tag (w : Wgt A) (P : A → Prop) (f : A→I) : - ∑ i:I,pr w (fun x => P x ∧ f x=i) = pr w P := by - classical - unfold pr - rw [← avg_sum] - refine avg_congr fun x _ => ?_ - simp only [ind_and, ← Finset.mul_sum] - rw [Finset.sum_eq_single (f x)] - · rw [ind_one rfl,mul_one] - · intro j _ hj; exact ind_zero hj.symm - simp - -/-- implication needed only almost surely for finite measures. -/ -theorem pr_on_mono {w : Wgt A} (hw : ∀ x,0≤w x) {P Q : A→Prop} - (h : ∀ x,w x≠0→ P x→ Q x) : pr w P ≤ pr w Q := - Finset.sum_le_sum (fun x _ => by - by_cases he : w x=0 - · simp [he] - exact mul_le_mul_of_nonneg_left (ind_mono (h x he)) (hw x)) - -theorem sum_pr_cells (w : Wgt (A × B)) (P : A × B → Prop) (f : A→I) (g : B→J) : - ∑ i:I,∑ j:J,pr w (fun x => P x ∧ f x.1=i ∧ g x.2=j) = pr w P := by - classical - rw [← sum_pr_tag w P (fun x => (f x.1,g x.2)), Fintype.sum_prod_type] - simp only [Prod.mk.injEq] - -/-- restore the full pair-event probability in a specified cell. -/ -theorem pair_restore (u : Wgt A) (v : Wgt B) (P : A → Prop) (Q : B → Prop) - (hP : 0 < pr u P) (hQ : 0 < pr v Q) - (c : A × B → Prop) : - pr (pairW u v) (fun x => P x.1 ∧ Q x.2 ∧ c x)= - pr u P * pr v Q * pr (pairW (onW u P) (onW v Q)) c := by - classical - let D := pr u P * pr v Q - let d := pairW (onW u P) (onW v Q) - change avg _ _ = D*avg d _ - unfold avg - rw [Finset.mul_sum] - refine Finset.sum_congr rfl fun i _ => ?_ - simp only [pairW,d,onW_val,D,ind_and] - field_simp - -def memberC (p : A→Prop) (f : A→I) (i : I) (x : A) := p x ∧ f x=i - -/-- heavy cells criterion. Loss charged to τ times opposite mass -rather than τ alone (key q fixed). -/ -theorem prune_pairs (w : Wgt A) (v : Wgt B) (hw : SubLaw w) (hv : SubLaw v) - (P : A → Prop) (Q : B→Prop) (f : A→I) (g : B→J) - (C : A×B→Prop) (H T : ℝ) (hH : 0≤H) (hT : 0 P x.1 ∧ Q x.2 ∧ C x) + - (H*T*L)*(pr w P+pr v Q) := by - classical - let a (i:I) := pr w (memberC P f i) - let b (i:J) := pr v (memberC Q g i) - let d (i:I) (j:J) := pr (pairW w v) (fun x => memberC P f i x.1 ∧ memberC Q g j x.2 ∧ C x) - have ha i : 0≤a i := pr_nonneg hw.nz - have hb i : 0≤b i := pr_nonneg hv.nz - have he i j : H*(a i*b j) ≤ d i j+ H*T*b j + H*T*a i := by - have hz : 0≤ d i j := pr_nonneg (subLaw_pair hw hv).nz - have ha' := mul_nonneg (mul_nonneg hH hT.le) (ha i) - have hb' := mul_nonneg (mul_nonneg hH hT.le) (hb j) - by_cases ht : T ≤ a i - · by_cases hh : T ≤ b j - · have hc := mul_le_mul_of_nonneg_right (h i j ht hh) (mul_nonneg (ha i) (hb j)) - have h1 := pair_restore w v _ _ (lt_of_lt_of_le hT ht) (lt_of_lt_of_le hT hh) C - refine hc.trans ?_ - rw [mul_comm (pr _ C)] - change _ ≤ d i j + _ + _ - unfold d - rw [h1] - change _ ≤ a i*b j * _ + _+_ - linarith - · have hg := mul_le_mul_of_nonneg_left (le_of_not_ge hh) (mul_nonneg hH (ha i)) - calc H*(a i*b j) ≤ H*T*a i := by linarith only [hg] - _ ≤ _ := by linarith only [hb',hz] - have hg := mul_le_mul_of_nonneg_left (le_of_not_ge ht) (mul_nonneg hH (hb j)) - calc H*(a i*b j) ≤ H*T*b j := by linarith only [hg] - _ ≤ _ := by linarith only [ha',hz] - have hA : pr w P=∑ i,a i := (sum_pr_tag w P f).symm - have hB : pr v Q=∑ j,b j := (sum_pr_tag v Q g).symm - have hC : - pr (pairW w v) (fun x => P x.1 ∧ Q x.2 ∧ C x) = ∑ i,∑ j,d i j := by - rw [← sum_pr_cells (pairW w v) _ f g] - refine Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun j _ => ?_ - unfold d; congr 1; unfold memberC; ext; tauto - have h1 : H * (pr w P * pr v Q)=∑ i,∑ j,H*(a i*b j) := by - rw [hA,hB] - simp only [Finset.sum_mul,Finset.mul_sum] - exact Finset.sum_comm; - have h2 : ∑ i:I,∑ j:J,H*T*b j=(Fintype.card I:ℝ)*(H*T*pr v Q) := by - simp only [← Finset.mul_sum,←hB,Finset.sum_const, Finset.card_univ, nsmul_eq_mul] - ring - have h3 : ∑ i:I,∑ j:J,H*T*a i=(Fintype.card J:ℝ)*(H*T*pr w P) := by - rw [Finset.sum_comm] - simp only [← Finset.mul_sum,←hA,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - ring - rw [h1] - refine (Finset.sum_le_sum fun i _ => Finset.sum_le_sum fun j _ => he i j).trans ?_ - simp only [Finset.sum_add_distrib] - rw [h2,h3,← hC] - have hh := mul_le_mul_of_nonneg_right hj (show 0≤H*T*pr w P from - mul_nonneg (mul_nonneg hH hT.le) (pr_nonneg hw.nz)) - have hh' := mul_le_mul_of_nonneg_right hi (show 0≤H*T*pr v Q from - mul_nonneg (mul_nonneg hH hT.le) (pr_nonneg hv.nz)) - linarith only [hh,hh'] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteConditioning +import OAI.Combinatorics.HadwigerCounterexample.ConditionalProductLaws + +namespace OAI + +/-! # Cell Pruning -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Finset +variable {A B I J : Type} [Fintype A] [Fintype B] [Fintype I] [Fintype J] + +theorem sum_pr_tag (w : Wgt A) (P : A → Prop) (f : A→I) : + ∑ i:I,pr w (fun x => P x ∧ f x=i) = pr w P := by + classical + unfold pr + rw [← avg_sum] + refine avg_congr fun x _ => ?_ + simp only [ind_and, ← Finset.mul_sum] + rw [Finset.sum_eq_single (f x)] + · rw [ind_one rfl,mul_one] + · intro j _ hj; exact ind_zero hj.symm + simp + +/-- implication needed only almost surely for finite measures. -/ +theorem pr_on_mono {w : Wgt A} (hw : ∀ x,0≤w x) {P Q : A→Prop} + (h : ∀ x,w x≠0→ P x→ Q x) : pr w P ≤ pr w Q := + Finset.sum_le_sum (fun x _ => by + by_cases he : w x=0 + · simp [he] + exact mul_le_mul_of_nonneg_left (ind_mono (h x he)) (hw x)) + +theorem sum_pr_cells (w : Wgt (A × B)) (P : A × B → Prop) (f : A→I) (g : B→J) : + ∑ i:I,∑ j:J,pr w (fun x => P x ∧ f x.1=i ∧ g x.2=j) = pr w P := by + classical + rw [← sum_pr_tag w P (fun x => (f x.1,g x.2)), Fintype.sum_prod_type] + simp only [Prod.mk.injEq] + +/-- restore the full pair-event probability in a specified cell. -/ +theorem pair_restore (u : Wgt A) (v : Wgt B) (P : A → Prop) (Q : B → Prop) + (hP : 0 < pr u P) (hQ : 0 < pr v Q) + (c : A × B → Prop) : + pr (pairW u v) (fun x => P x.1 ∧ Q x.2 ∧ c x)= + pr u P * pr v Q * pr (pairW (onW u P) (onW v Q)) c := by + classical + let D := pr u P * pr v Q + let d := pairW (onW u P) (onW v Q) + change avg _ _ = D*avg d _ + unfold avg + rw [Finset.mul_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + simp only [pairW,d,onW_val,D,ind_and] + field_simp + +def memberC (p : A→Prop) (f : A→I) (i : I) (x : A) := p x ∧ f x=i + +/-- heavy cells criterion. Loss charged to τ times opposite mass +rather than τ alone (key q fixed). -/ +theorem prune_pairs (w : Wgt A) (v : Wgt B) (hw : SubLaw w) (hv : SubLaw v) + (P : A → Prop) (Q : B→Prop) (f : A→I) (g : B→J) + (C : A×B→Prop) (H T : ℝ) (hH : 0≤H) (hT : 0 P x.1 ∧ Q x.2 ∧ C x) + + (H*T*L)*(pr w P+pr v Q) := by + classical + let a (i:I) := pr w (memberC P f i) + let b (i:J) := pr v (memberC Q g i) + let d (i:I) (j:J) := pr (pairW w v) (fun x => memberC P f i x.1 ∧ memberC Q g j x.2 ∧ C x) + have ha i : 0≤a i := pr_nonneg hw.nz + have hb i : 0≤b i := pr_nonneg hv.nz + have he i j : H*(a i*b j) ≤ d i j+ H*T*b j + H*T*a i := by + have hz : 0≤ d i j := pr_nonneg (subLaw_pair hw hv).nz + have ha' := mul_nonneg (mul_nonneg hH hT.le) (ha i) + have hb' := mul_nonneg (mul_nonneg hH hT.le) (hb j) + by_cases ht : T ≤ a i + · by_cases hh : T ≤ b j + · have hc := mul_le_mul_of_nonneg_right (h i j ht hh) (mul_nonneg (ha i) (hb j)) + have h1 := pair_restore w v _ _ (lt_of_lt_of_le hT ht) (lt_of_lt_of_le hT hh) C + refine hc.trans ?_ + rw [mul_comm (pr _ C)] + change _ ≤ d i j + _ + _ + unfold d + rw [h1] + change _ ≤ a i*b j * _ + _+_ + linarith + · have hg := mul_le_mul_of_nonneg_left (le_of_not_ge hh) (mul_nonneg hH (ha i)) + calc H*(a i*b j) ≤ H*T*a i := by linarith only [hg] + _ ≤ _ := by linarith only [hb',hz] + have hg := mul_le_mul_of_nonneg_left (le_of_not_ge ht) (mul_nonneg hH (hb j)) + calc H*(a i*b j) ≤ H*T*b j := by linarith only [hg] + _ ≤ _ := by linarith only [ha',hz] + have hA : pr w P=∑ i,a i := (sum_pr_tag w P f).symm + have hB : pr v Q=∑ j,b j := (sum_pr_tag v Q g).symm + have hC : + pr (pairW w v) (fun x => P x.1 ∧ Q x.2 ∧ C x) = ∑ i,∑ j,d i j := by + rw [← sum_pr_cells (pairW w v) _ f g] + refine Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun j _ => ?_ + unfold d; congr 1; unfold memberC; ext; tauto + have h1 : H * (pr w P * pr v Q)=∑ i,∑ j,H*(a i*b j) := by + rw [hA,hB] + simp only [Finset.sum_mul,Finset.mul_sum] + exact Finset.sum_comm; + have h2 : ∑ i:I,∑ j:J,H*T*b j=(Fintype.card I:ℝ)*(H*T*pr v Q) := by + simp only [← Finset.mul_sum,←hB,Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + ring + have h3 : ∑ i:I,∑ j:J,H*T*a i=(Fintype.card J:ℝ)*(H*T*pr w P) := by + rw [Finset.sum_comm] + simp only [← Finset.mul_sum,←hA,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + ring + rw [h1] + refine (Finset.sum_le_sum fun i _ => Finset.sum_le_sum fun j _ => he i j).trans ?_ + simp only [Finset.sum_add_distrib] + rw [h2,h3,← hC] + have hh := mul_le_mul_of_nonneg_right hj (show 0≤H*T*pr w P from + mul_nonneg (mul_nonneg hH hT.le) (pr_nonneg hw.nz)) + have hh' := mul_le_mul_of_nonneg_right hi (show 0≤H*T*pr v Q from + mul_nonneg (mul_nonneg hH hT.le) (pr_nonneg hv.nz)) + linarith only [hh,hh'] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ChannelFactorization.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ChannelFactorization.lean index 69c916a1f034b3b02b0ec59fc2236b2523de64f6..d06a6d00eb3d8bc4d7957108ca4558c09e944cc6 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ChannelFactorization.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ChannelFactorization.lean @@ -1,144 +1,144 @@ -import OAI.Combinatorics.HadwigerCounterexample.BilinearCompression - -namespace OAI - -/-! # Channel Factorization -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Submodule Module -open scoped BigOperators -variable {p : Shape} {n : ℕ} -variable {I J : Type} [Fintype I] [Fintype J] - -/-- Pairing rank after imposing orthogonality constraints. -/ -theorem biorth_exists (S T : Space (Vec I)) (r : ℕ) - (h : r+dim S+dim T≤Fintype.card I) : - ∃ A B : Mat I (Fin r), colSp A≤ annih S ∧ colSp B≤ annih T ∧ Aᵀ*B=1 := by - classical - let V := annih S - let W := annih T - let M := (pack V)ᵀ * pack W - let t := M.rank - have ht : r≤t := by - have h1 := rank_ge_mul (pack V)ᵀ (pack W) - rw [Matrix.rank_transpose,mrk_inj.mp (pack_inj V),mrk_inj.mp (pack_inj W), - Fintype.card_fin,Fintype.card_fin] at h1 - have h2 : dim S+dim V=Fintype.card I := annih_dim S - have h3 : dim T+dim W=Fintype.card I := annih_dim T - have he (a b c d t r e : ℕ) (h : r+a+b ≤ e) (hx : a+c=e) (hy : b+d=e) (ht : c+d≤t+e) : - r≤t := by omega - exact he _ _ _ _ _ _ _ h h2 h3 h1 - obtain ⟨A,B,hA,hB,hM⟩ := rank_product M - obtain ⟨L,hL⟩ := mat_left_inv hA - obtain ⟨R,hR⟩ := mat_left_inv (P:=Bᵀ) (transpose_surj_iff.mp (by rw [Matrix.transpose_transpose]; exact hB)) - let E := embedMat (Fin.castLE ht) - refine ⟨pack V * (Lᵀ * E),pack W*(Rᵀ*E),?_,?_,?_⟩ - · rintro x ⟨x,rfl⟩ - rw [Matrix.mulVecLin_apply,← Matrix.mulVec_mulVec] - exact (pack_mem_iff ..).mpr ⟨_,rfl⟩ - · rintro x ⟨x,rfl⟩ - rw [Matrix.mulVecLin_apply,← Matrix.mulVec_mulVec] - exact (pack_mem_iff ..).mpr ⟨_,rfl⟩ - have he : L*M*Rᵀ=1 := by - have hg : B*Rᵀ=1 := by - simpa only [Matrix.transpose_mul, Matrix.transpose_transpose, Matrix.transpose_one] using - congrArg Matrix.transpose hR - refine (congrArg (fun X => L*X*Rᵀ) hM).symm.trans ?_ - rw [← Matrix.mul_assoc L,hL,Matrix.one_mul,hg] - have heq : Eᵀ * E=1 := embedMat_self (Fin.castLE_injective ht) - rw [Matrix.transpose_mul,Matrix.transpose_mul,Matrix.transpose_transpose] - calc _ = Eᵀ*(L*M*Rᵀ)*E := by simp only [M,Matrix.mul_assoc] - _ = _ := by rw [he,Matrix.mul_one,heq] - -/-- split desired respective bounded-rank bilinear form -/ -theorem pure_chan_split (M : Mat J J) (S T : Space (Vec I)) (X Y : Space (Vec J)) - (h : M∈box (annih X) (annih Y)) (ht : M.rank+dim S+dim T ≤ Fintype.card I) : - ∃ A ∈ box (annih S) (annih X),∃ B∈box (annih T) (annih Y), Aᵀ * B=M := by - classical - obtain ⟨P,Q,hP,hQ,hM⟩ := rank_product M - obtain ⟨A,B,hA,hB,he⟩ := biorth_exists S T M.rank ht - obtain ⟨hx,hy⟩ := box_kill.mp h - refine ⟨A * Pᵀ,?_,B*Q,?_,?_⟩ - · rw [box_kill] - constructor - · intro x hx; rw [Matrix.transpose_mul,← Matrix.mulVec_mulVec,(colSp_kill ..).mp hA x hx, - Matrix.mulVec_zero] - intro x hv - have hv' : Pᵀ *ᵥ x=0 := by - have hqi := (transpose_surj_iff (P:=Qᵀ)).mp (by rw [Matrix.transpose_transpose]; exact hQ) - apply hqi - rw [Matrix.mulVec_mulVec,← Matrix.transpose_mul,hM,hx x hv,Matrix.mulVec_zero] - rw [←Matrix.mulVec_mulVec,hv',mulVec_zero] - · rw [box_kill] - constructor - · intro x hv; rw [Matrix.transpose_mul,←Matrix.mulVec_mulVec,(colSp_kill ..).mp hB x hv, - Matrix.mulVec_zero] - intro y hv - have hv' : Q *ᵥ y=0 := by - apply hP - rw [Matrix.mulVec_mulVec,hM,hy y hv,mulVec_zero] - rw [←Matrix.mulVec_mulVec,hv',mulVec_zero] - · rw [Matrix.transpose_mul,Matrix.transpose_transpose,← Matrix.mul_assoc _ B, Matrix.mul_assoc P, - he,Matrix.mul_one,hM] - -/-- The final channel change for fixed B endpoint. -/ -theorem chan_factor {f b : Plan p n} {P : PureForms p n} {C : ChanOut p n} {j : Bool} - (H T K : ℕ) (hc : outSmall H C) (hK : ∀ z,dim (hPin b z j)≤K) - (hh : T+2*(K+2*H)≤p.h) - (hP : P∈pureSpace p f) (ht : ∀ e,(P e).rank≤T) : - ∃ D∈deltaSpace p f b j,obsPair p (chanInner p (C+D) (C+D))= - obsPair p (chanInner p C C)+obsPair p P := by - classical - let S (z : Place p) := hPin b (flipZ p z) j ⊔ priOut p C (flipZ p z) - have h (z : Place p) : dim (S z) ≤ K+2*H := - (Submodule.finrank_add_le_finrank_add_finrank ..).trans - (add_le_add (hK _) (dim_priOut hc _)) - choose A hA B hB hQ using fun e : Comp p.g => - pure_chan_split (P e) (S (e,true)) (S (e,false)) (f (e,true)) (f (e,false)) - ((pureSpace_mem _).mp hP e) ((add_le_add - (add_le_add (ht e) (h (e,true))) (h (e,false))).trans - (by - rw [Fintype.card_fin] - rwa [two_mul, ← add_assoc] at hh)) - let D : ChanOut p n := fun z => if z.2 then A z.1 else B z.1 - have h1 (z : Place p) : D z∈box (annih (S z)) (annih (f z)) := by - cases z with | mk e c => cases c; exact hB e; exact hA e - refine ⟨D,(deltaSpace_mem _).mpr ?_,?_⟩ - · intro z - refine box_le ?_ le_rfl (h1 z) - intro x hx - rw [annih_mem] - exact fun y hy => (annih_mem ..).mp hx y (Submodule.mem_sup_left hy) - have hg : chanInner p D D=P := funext (fun e => hQ e) - have he (z : Place p) (i l : Bool) (x y : Ray p n) : - dotProduct ((C (flipZ p z)*IP p n i) *ᵥ x) ((D z*IP p n l)*ᵥ y)=0 := by - have hq : ((C (flipZ p z)*IP p n i) *ᵥ x) ∈ S z := - Submodule.mem_sup_right (le_priOut C _ i ⟨x,rfl⟩) - have hl : ((D z * IP p n l)*ᵥ y) ∈ annih (S z) := by - rw [←Matrix.mulVec_mulVec] - exact ((box_mem ..).mp (h1 z)).1 ⟨_,rfl⟩ - rw [dotProduct_comm] - exact (annih_mem ..).mp hl _ hq - have hd : obsPair p (chanDeriv p C D)=0 := by - rw [←obsI_each] - have hz : eachF p (chanDeriv p C D)=0 := by - unfold chanDeriv; rw [map_add] - funext i e - rw [Pi.add_apply,Pi.add_apply,each_chan_val,each_chan_val] - refine evmat_ext fun x y => ?_ - rw [evmat_addM,ev_duom,ev_duom] - have hh1 := he (e,false) i i x y - have hh2 := he (e,true) i i y x - simp only [flipZ,Bool.not_false,Bool.not_true] at hh1 hh2 - rw [hh1, - dotProduct_comm ((D (e,true) * IP p n i) *ᵥ _),hh2] - simp [evmat] - rw [hz,map_zero] - rw [obsPair_chan_change,hd,add_zero,hg] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BilinearCompression + +namespace OAI + +/-! # Channel Factorization -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Submodule Module +open scoped BigOperators +variable {p : Shape} {n : ℕ} +variable {I J : Type} [Fintype I] [Fintype J] + +/-- Pairing rank after imposing orthogonality constraints. -/ +theorem biorth_exists (S T : Space (Vec I)) (r : ℕ) + (h : r+dim S+dim T≤Fintype.card I) : + ∃ A B : Mat I (Fin r), colSp A≤ annih S ∧ colSp B≤ annih T ∧ Aᵀ*B=1 := by + classical + let V := annih S + let W := annih T + let M := (pack V)ᵀ * pack W + let t := M.rank + have ht : r≤t := by + have h1 := rank_ge_mul (pack V)ᵀ (pack W) + rw [Matrix.rank_transpose,mrk_inj.mp (pack_inj V),mrk_inj.mp (pack_inj W), + Fintype.card_fin,Fintype.card_fin] at h1 + have h2 : dim S+dim V=Fintype.card I := annih_dim S + have h3 : dim T+dim W=Fintype.card I := annih_dim T + have he (a b c d t r e : ℕ) (h : r+a+b ≤ e) (hx : a+c=e) (hy : b+d=e) (ht : c+d≤t+e) : + r≤t := by omega + exact he _ _ _ _ _ _ _ h h2 h3 h1 + obtain ⟨A,B,hA,hB,hM⟩ := rank_product M + obtain ⟨L,hL⟩ := mat_left_inv hA + obtain ⟨R,hR⟩ := mat_left_inv (P:=Bᵀ) (transpose_surj_iff.mp (by rw [Matrix.transpose_transpose]; exact hB)) + let E := embedMat (Fin.castLE ht) + refine ⟨pack V * (Lᵀ * E),pack W*(Rᵀ*E),?_,?_,?_⟩ + · rintro x ⟨x,rfl⟩ + rw [Matrix.mulVecLin_apply,← Matrix.mulVec_mulVec] + exact (pack_mem_iff ..).mpr ⟨_,rfl⟩ + · rintro x ⟨x,rfl⟩ + rw [Matrix.mulVecLin_apply,← Matrix.mulVec_mulVec] + exact (pack_mem_iff ..).mpr ⟨_,rfl⟩ + have he : L*M*Rᵀ=1 := by + have hg : B*Rᵀ=1 := by + simpa only [Matrix.transpose_mul, Matrix.transpose_transpose, Matrix.transpose_one] using + congrArg Matrix.transpose hR + refine (congrArg (fun X => L*X*Rᵀ) hM).symm.trans ?_ + rw [← Matrix.mul_assoc L,hL,Matrix.one_mul,hg] + have heq : Eᵀ * E=1 := embedMat_self (Fin.castLE_injective ht) + rw [Matrix.transpose_mul,Matrix.transpose_mul,Matrix.transpose_transpose] + calc _ = Eᵀ*(L*M*Rᵀ)*E := by simp only [M,Matrix.mul_assoc] + _ = _ := by rw [he,Matrix.mul_one,heq] + +/-- split desired respective bounded-rank bilinear form -/ +theorem pure_chan_split (M : Mat J J) (S T : Space (Vec I)) (X Y : Space (Vec J)) + (h : M∈box (annih X) (annih Y)) (ht : M.rank+dim S+dim T ≤ Fintype.card I) : + ∃ A ∈ box (annih S) (annih X),∃ B∈box (annih T) (annih Y), Aᵀ * B=M := by + classical + obtain ⟨P,Q,hP,hQ,hM⟩ := rank_product M + obtain ⟨A,B,hA,hB,he⟩ := biorth_exists S T M.rank ht + obtain ⟨hx,hy⟩ := box_kill.mp h + refine ⟨A * Pᵀ,?_,B*Q,?_,?_⟩ + · rw [box_kill] + constructor + · intro x hx; rw [Matrix.transpose_mul,← Matrix.mulVec_mulVec,(colSp_kill ..).mp hA x hx, + Matrix.mulVec_zero] + intro x hv + have hv' : Pᵀ *ᵥ x=0 := by + have hqi := (transpose_surj_iff (P:=Qᵀ)).mp (by rw [Matrix.transpose_transpose]; exact hQ) + apply hqi + rw [Matrix.mulVec_mulVec,← Matrix.transpose_mul,hM,hx x hv,Matrix.mulVec_zero] + rw [←Matrix.mulVec_mulVec,hv',mulVec_zero] + · rw [box_kill] + constructor + · intro x hv; rw [Matrix.transpose_mul,←Matrix.mulVec_mulVec,(colSp_kill ..).mp hB x hv, + Matrix.mulVec_zero] + intro y hv + have hv' : Q *ᵥ y=0 := by + apply hP + rw [Matrix.mulVec_mulVec,hM,hy y hv,mulVec_zero] + rw [←Matrix.mulVec_mulVec,hv',mulVec_zero] + · rw [Matrix.transpose_mul,Matrix.transpose_transpose,← Matrix.mul_assoc _ B, Matrix.mul_assoc P, + he,Matrix.mul_one,hM] + +/-- The final channel change for fixed B endpoint. -/ +theorem chan_factor {f b : Plan p n} {P : PureForms p n} {C : ChanOut p n} {j : Bool} + (H T K : ℕ) (hc : outSmall H C) (hK : ∀ z,dim (hPin b z j)≤K) + (hh : T+2*(K+2*H)≤p.h) + (hP : P∈pureSpace p f) (ht : ∀ e,(P e).rank≤T) : + ∃ D∈deltaSpace p f b j,obsPair p (chanInner p (C+D) (C+D))= + obsPair p (chanInner p C C)+obsPair p P := by + classical + let S (z : Place p) := hPin b (flipZ p z) j ⊔ priOut p C (flipZ p z) + have h (z : Place p) : dim (S z) ≤ K+2*H := + (Submodule.finrank_add_le_finrank_add_finrank ..).trans + (add_le_add (hK _) (dim_priOut hc _)) + choose A hA B hB hQ using fun e : Comp p.g => + pure_chan_split (P e) (S (e,true)) (S (e,false)) (f (e,true)) (f (e,false)) + ((pureSpace_mem _).mp hP e) ((add_le_add + (add_le_add (ht e) (h (e,true))) (h (e,false))).trans + (by + rw [Fintype.card_fin] + rwa [two_mul, ← add_assoc] at hh)) + let D : ChanOut p n := fun z => if z.2 then A z.1 else B z.1 + have h1 (z : Place p) : D z∈box (annih (S z)) (annih (f z)) := by + cases z with | mk e c => cases c; exact hB e; exact hA e + refine ⟨D,(deltaSpace_mem _).mpr ?_,?_⟩ + · intro z + refine box_le ?_ le_rfl (h1 z) + intro x hx + rw [annih_mem] + exact fun y hy => (annih_mem ..).mp hx y (Submodule.mem_sup_left hy) + have hg : chanInner p D D=P := funext (fun e => hQ e) + have he (z : Place p) (i l : Bool) (x y : Ray p n) : + dotProduct ((C (flipZ p z)*IP p n i) *ᵥ x) ((D z*IP p n l)*ᵥ y)=0 := by + have hq : ((C (flipZ p z)*IP p n i) *ᵥ x) ∈ S z := + Submodule.mem_sup_right (le_priOut C _ i ⟨x,rfl⟩) + have hl : ((D z * IP p n l)*ᵥ y) ∈ annih (S z) := by + rw [←Matrix.mulVec_mulVec] + exact ((box_mem ..).mp (h1 z)).1 ⟨_,rfl⟩ + rw [dotProduct_comm] + exact (annih_mem ..).mp hl _ hq + have hd : obsPair p (chanDeriv p C D)=0 := by + rw [←obsI_each] + have hz : eachF p (chanDeriv p C D)=0 := by + unfold chanDeriv; rw [map_add] + funext i e + rw [Pi.add_apply,Pi.add_apply,each_chan_val,each_chan_val] + refine evmat_ext fun x y => ?_ + rw [evmat_addM,ev_duom,ev_duom] + have hh1 := he (e,false) i i x y + have hh2 := he (e,true) i i y x + simp only [flipZ,Bool.not_false,Bool.not_true] at hh1 hh2 + rw [hh1, + dotProduct_comm ((D (e,true) * IP p n i) *ᵥ _),hh2] + simp [evmat] + rw [hz,map_zero] + rw [obsPair_chan_change,hd,add_zero,hg] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ChannelFrameLaws.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ChannelFrameLaws.lean index 19b09a5d7fd824de55bc2314e703df76860e9adc..a492c71750529233c5af82840981d76d0459d9d2 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ChannelFrameLaws.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ChannelFrameLaws.lean @@ -1,186 +1,186 @@ -import OAI.Combinatorics.HadwigerCounterexample.SumRankBounds - -namespace OAI - -/-! # Channel Frame Laws -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Finset Function -open scoped BigOperators - -variable {A B : Type} [Fintype A] [Fintype B] - -theorem map_pair_law {C D : Type} [Fintype C] [Fintype D] - (w : Wgt A) (v : Wgt B) (f : A→C) (g : B→D) : - mapW (pairW w v) (Prod.map f g)=pairW (mapW w f) (mapW v g) := by - funext x - unfold mapW pairW - simp only [Prod.ext_iff] - exact pairW_pr w v (fun y => f y=x.1) (fun y => g y=x.2) - -theorem mapW_nested {C : Type} (w : Wgt A) (f : A→B) (g : B→C) : - mapW (mapW w f) g=mapW w (g ∘ f) := - funext fun _ => mapW_pr _ _ _ - -omit [Fintype B] in -theorem mapW_repeat {I : Type} [Fintype I] [DecidableEq I] - (w : I→ Wgt A) (f : I→ A→B) : - mapW (prodW w) (fun x i => f i (x i))=prodW (fun i => mapW (w i) (f i)) := by - funext x - unfold mapW - simp_rw [funext_iff] - exact prodW_pr _ (fun i y => f i y=x i) - -omit [Fintype B] in -theorem mapW_pr_eq (e : A≃A) (f : A→B) (u : B≃B) (h : ∀ x,f (e x)=u (f x)) - (w : Wgt A) (hw : ∀ x, w (e x)=w x) (x : B) : mapW w f (u x)=mapW w f x := by - have he := avg_bij e w (fun y => ind (f y=u x)) - simp_rw [hw,h,u.injective.eq_iff] at he - exact he.symm - -private theorem pmax_test {x : A} (p : A → Prop) {w : Wgt A} (hw : SubLaw w) - (h : ∀ y, p y → w y=w x) {m : ℝ} (hm : 0 < m) - (hp : m ≤ pr unif p) [Nonempty A] : - w x ≤ m⁻¹ * unif x := by - have hh : pr w p=w x*nbr p := by - simp only [pr,avg,nbr,tot,Finset.mul_sum] - refine Finset.sum_congr rfl fun i _ => ?_ - by_cases he : p i - · rw [h i he] - rw [ind_zero he,mul_zero,mul_zero] - have h1 := (pr_le_tot (p:=p) hw.nz).trans hw.total - rw [hh] at h1 - have hU : 0 < (Fintype.card A : ℝ) := by exact_mod_cast Fintype.card_pos - rw [pr_unif (A:=A)] at hp - have hi := (le_div_iff₀ hU).mp hp - rw [unif_apply] - field_simp - nlinarith only [h1,hi,mul_le_mul_of_nonneg_left hi (hw.nz x)] - -theorem gram_norm_quarter {I J L : Type} [Fintype I] [Fintype J] [Fintype L] - [DecidableEq I] [DecidableEq J] [DecidableEq L] (G : Mat I J) - (h : num I + num J-num L ≤ -1) : - bp (-num I * num J)/4 ≤ pr unif (gramGood (U:=L) G) := by - have hn := (gram_norm G (by linarith : num I+num J≤num L)).2 - rw [pair_unif] - refine le_trans ?_ hn - have he {x : ℝ} (hx : x ≤ -1) : (1/2 : ℝ)≤ 1-bp x := by - have ht := bp_le hx - rw [bp_neg,bp_one] at ht - linarith only [ht] - let d := bp (-num I*num J) - change d/4 ≤ d* _ * _ - have hk : 0 < d := bp_pos _ - have h1 := he (x:= num I-num L) (by - have hg : 0≤num J := Nat.cast_nonneg _ - linarith) - calc d/4 = d*(1/2)*(1/2) := by ring - _ ≤ _ := mul_le_mul (mul_le_mul_of_nonneg_left h1 hk.le) (he h) (by norm_num) - (mul_nonneg hk.le (le_trans (by norm_num) h1)) - -variable {I J U : Type} [Fintype I] [Fintype J] [Fintype U] -variable [DecidableEq I] [DecidableEq J] [DecidableEq U] - -theorem gramObsCap {C : Mat (I⊕J) (I⊕J) → Prop} - (hc : ∃ x : Mat U (I⊕J) × _, FramesAt C x) - (T : Mat (I⊕J) J) (ht : Function.Injective T.mulVec) - (hN : 2*num J-num U≤ -1) : - let w := unifOn (FramesAt C) - ∀ x : Mat U J × Mat U J, - mapW w (observe T T) x ≤ (4*bp (num J*num J))*pairW unif unif x := by - classical - let w := unifOn (FramesAt (U:=U) C) - have hw := unifOn_law hc - let f := observe T T (U:=U) - let v := mapW w f - have hv : IsLaw v := mapW_law hw f - have hg : - carried v (fun x : Mat U J × _ => Injective x.1.mulVec ∧ Injective x.2.mulVec) := by - refine mapW_carried (unifOn_carried _) (fun x hx => ?_) - exact ⟨inj_comp_mat _ _ hx.2.1 ht,inj_comp_mat _ _ hx.2.2 ht⟩ - dsimp only - intro x - rw [← pair_unif] - by_cases h : v x≠0 - · let G := (x.1ᵀ*x.2 : Mat J J) - have hx : gramGood G x := ⟨rfl,Classical.byContradiction fun he => h (hg x he)⟩ - let m := bp (-num J*num J)/4 - have he (y : Mat U J × Mat U J) (hy : gramGood G y) : v y=v x := by - obtain ⟨L,hL⟩ := move_exists G x y hx hy - let e := L.perm (I⊕J) (I⊕J) - have hl (y) : f (e y)=(L.perm J J) (f y) := - Prod.ext (Matrix.mul_assoc ..) (Matrix.mul_assoc ..) - have hp y : w (e y)=w y := by - unfold w; rw [unifOn_val, unifOn_val] - congr 2 - exact propext (L.invar C y).symm - exact hL ▸ mapW_pr_eq e f (L.perm J J) hl w hp x - have hi := pmax_test (gramGood (U:=U) G) hv.sub he (m:=m) - (div_pos (bp_pos _) (by norm_num)) (gram_norm_quarter G (by linarith only [hN])) - apply hi.trans - unfold m; rw [neg_mul,bp_neg]; field_simp - exact le_rfl - · change v x ≤ _ - rw [not_ne_iff.mp h] - exact mul_nonneg (mul_nonneg (by norm_num) (bp_pos _).le) (unif_subLaw.nz _) - -variable {p : Shape} {n N : ℕ} -abbrev HMat (p : Shape) (N : ℕ) := Mat (Fin N) (Chan p) -abbrev HFrame (p : Shape) (N : ℕ) := HMat p N × HMat p N -abbrev HCube (p : Shape) (N : ℕ) := Comp p.g → HFrame p N - -def hchan (p : Shape) {n N} (x : Oframe p n N) : HFrame p N := - (channel x.1,channel x.2) -def hcube (p : Shape) {n N} (x : Orient p n N) : HCube p N := fun z => hchan p (x z) -def lawH (p : Shape) (N : ℕ) : Wgt (HCube p N) := - prodW (fun (_ : Comp p.g) => pairW unif unif) - -def intoChan (p : Shape) (n) : Mat (Full p n) (Chan p) := embedMat (.inr ·) - -theorem intoChan_inj : Injective (intoChan p n).mulVec := - embedMat_inj Sum.inr_injective -theorem intoChan_val (p : Shape) {n N} (x : Mat (Fin N) (Full p n)) : - x * intoChan p n=channel x := by rw [intoChan,mul_embedMat]; rfl -theorem hchan_val (p : Shape) {n N} : - hchan p (n:=n) (N:=N) = observe (intoChan p n) (intoChan p n) := by - funext x - exact Prod.ext (intoChan_val ..).symm (intoChan_val ..).symm - -def chanPrice (p : Shape) : ℝ := - (4*bp ((p.h:ℝ)*p.h))^(Fintype.card (Comp p.g)) - -theorem hchan_cap (m : Mixer p n) (hN : 2*num (Full p n)-N≤ -1) : - let w := unifOn (FramesAt (U:=Fin N) (gramCond m)) - ∀ x : HFrame p N,mapW w (hchan p) x≤(4*bp ((p.h:ℝ)*p.h))*pairW unif unif x := by - classical - have he : 2*num (Full p n)-num (Fin N)≤ -1 := by simpa [num] using hN - have hh : ∃ x : Oframe p n N, FramesAt (gramCond m) x := - framesAt_exists (gramCond_exists m) (by linarith only [he]) - rw [hchan_val] - have hr : num (Chan p) ≤ num (Full p n) := by - have hf : Fintype.card (Row p n) + Fintype.card (Chan p)=Fintype.card (Full p n) := - (Fintype.card_sum ..).symm - exact_mod_cast (show Fintype.card (Chan p)≤Fintype.card (Full p n) by omega) - have hk := gramObsCap hh (intoChan p n) intoChan_inj (by linarith only [he,hr]) - rw [show num (Chan p)=(p.h:ℝ) from (by simp [num,Chan])] at hk - exact hk - -theorem hcube_cap (m : Mixer p n) (hN : 2*num (Full p n)-N≤ -1) - (x : HCube p N) : mapW (raw m N) (hcube p) x ≤ chanPrice p*lawH p N x := by - let w := unifOn (FramesAt (U:=Fin N) (gramCond m)) - have hh i := hchan_cap m hN (x i) - change mapW (prodW (fun (_ : Comp p.g) => w)) _ x ≤ _ - unfold hcube - rw [mapW_repeat (w:=fun (_:Comp p.g) => w) (f:=fun i => hchan p (n:=n) (N:=N))] - refine le_trans (Finset.prod_le_prod₀ ?_ fun i _ => hh i) ?_ - · intro i _ - exact pr_nonneg (unifOn_sub _).nz - rw [Finset.prod_mul_distrib] - simp [chanPrice,lawH,prodW] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SumRankBounds + +namespace OAI + +/-! # Channel Frame Laws -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Finset Function +open scoped BigOperators + +variable {A B : Type} [Fintype A] [Fintype B] + +theorem map_pair_law {C D : Type} [Fintype C] [Fintype D] + (w : Wgt A) (v : Wgt B) (f : A→C) (g : B→D) : + mapW (pairW w v) (Prod.map f g)=pairW (mapW w f) (mapW v g) := by + funext x + unfold mapW pairW + simp only [Prod.ext_iff] + exact pairW_pr w v (fun y => f y=x.1) (fun y => g y=x.2) + +theorem mapW_nested {C : Type} (w : Wgt A) (f : A→B) (g : B→C) : + mapW (mapW w f) g=mapW w (g ∘ f) := + funext fun _ => mapW_pr _ _ _ + +omit [Fintype B] in +theorem mapW_repeat {I : Type} [Fintype I] [DecidableEq I] + (w : I→ Wgt A) (f : I→ A→B) : + mapW (prodW w) (fun x i => f i (x i))=prodW (fun i => mapW (w i) (f i)) := by + funext x + unfold mapW + simp_rw [funext_iff] + exact prodW_pr _ (fun i y => f i y=x i) + +omit [Fintype B] in +theorem mapW_pr_eq (e : A≃A) (f : A→B) (u : B≃B) (h : ∀ x,f (e x)=u (f x)) + (w : Wgt A) (hw : ∀ x, w (e x)=w x) (x : B) : mapW w f (u x)=mapW w f x := by + have he := avg_bij e w (fun y => ind (f y=u x)) + simp_rw [hw,h,u.injective.eq_iff] at he + exact he.symm + +private theorem pmax_test {x : A} (p : A → Prop) {w : Wgt A} (hw : SubLaw w) + (h : ∀ y, p y → w y=w x) {m : ℝ} (hm : 0 < m) + (hp : m ≤ pr unif p) [Nonempty A] : + w x ≤ m⁻¹ * unif x := by + have hh : pr w p=w x*nbr p := by + simp only [pr,avg,nbr,tot,Finset.mul_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + by_cases he : p i + · rw [h i he] + rw [ind_zero he,mul_zero,mul_zero] + have h1 := (pr_le_tot (p:=p) hw.nz).trans hw.total + rw [hh] at h1 + have hU : 0 < (Fintype.card A : ℝ) := by exact_mod_cast Fintype.card_pos + rw [pr_unif (A:=A)] at hp + have hi := (le_div_iff₀ hU).mp hp + rw [unif_apply] + field_simp + nlinarith only [h1,hi,mul_le_mul_of_nonneg_left hi (hw.nz x)] + +theorem gram_norm_quarter {I J L : Type} [Fintype I] [Fintype J] [Fintype L] + [DecidableEq I] [DecidableEq J] [DecidableEq L] (G : Mat I J) + (h : num I + num J-num L ≤ -1) : + bp (-num I * num J)/4 ≤ pr unif (gramGood (U:=L) G) := by + have hn := (gram_norm G (by linarith : num I+num J≤num L)).2 + rw [pair_unif] + refine le_trans ?_ hn + have he {x : ℝ} (hx : x ≤ -1) : (1/2 : ℝ)≤ 1-bp x := by + have ht := bp_le hx + rw [bp_neg,bp_one] at ht + linarith only [ht] + let d := bp (-num I*num J) + change d/4 ≤ d* _ * _ + have hk : 0 < d := bp_pos _ + have h1 := he (x:= num I-num L) (by + have hg : 0≤num J := Nat.cast_nonneg _ + linarith) + calc d/4 = d*(1/2)*(1/2) := by ring + _ ≤ _ := mul_le_mul (mul_le_mul_of_nonneg_left h1 hk.le) (he h) (by norm_num) + (mul_nonneg hk.le (le_trans (by norm_num) h1)) + +variable {I J U : Type} [Fintype I] [Fintype J] [Fintype U] +variable [DecidableEq I] [DecidableEq J] [DecidableEq U] + +theorem gramObsCap {C : Mat (I⊕J) (I⊕J) → Prop} + (hc : ∃ x : Mat U (I⊕J) × _, FramesAt C x) + (T : Mat (I⊕J) J) (ht : Function.Injective T.mulVec) + (hN : 2*num J-num U≤ -1) : + let w := unifOn (FramesAt C) + ∀ x : Mat U J × Mat U J, + mapW w (observe T T) x ≤ (4*bp (num J*num J))*pairW unif unif x := by + classical + let w := unifOn (FramesAt (U:=U) C) + have hw := unifOn_law hc + let f := observe T T (U:=U) + let v := mapW w f + have hv : IsLaw v := mapW_law hw f + have hg : + carried v (fun x : Mat U J × _ => Injective x.1.mulVec ∧ Injective x.2.mulVec) := by + refine mapW_carried (unifOn_carried _) (fun x hx => ?_) + exact ⟨inj_comp_mat _ _ hx.2.1 ht,inj_comp_mat _ _ hx.2.2 ht⟩ + dsimp only + intro x + rw [← pair_unif] + by_cases h : v x≠0 + · let G := (x.1ᵀ*x.2 : Mat J J) + have hx : gramGood G x := ⟨rfl,Classical.byContradiction fun he => h (hg x he)⟩ + let m := bp (-num J*num J)/4 + have he (y : Mat U J × Mat U J) (hy : gramGood G y) : v y=v x := by + obtain ⟨L,hL⟩ := move_exists G x y hx hy + let e := L.perm (I⊕J) (I⊕J) + have hl (y) : f (e y)=(L.perm J J) (f y) := + Prod.ext (Matrix.mul_assoc ..) (Matrix.mul_assoc ..) + have hp y : w (e y)=w y := by + unfold w; rw [unifOn_val, unifOn_val] + congr 2 + exact propext (L.invar C y).symm + exact hL ▸ mapW_pr_eq e f (L.perm J J) hl w hp x + have hi := pmax_test (gramGood (U:=U) G) hv.sub he (m:=m) + (div_pos (bp_pos _) (by norm_num)) (gram_norm_quarter G (by linarith only [hN])) + apply hi.trans + unfold m; rw [neg_mul,bp_neg]; field_simp + exact le_rfl + · change v x ≤ _ + rw [not_ne_iff.mp h] + exact mul_nonneg (mul_nonneg (by norm_num) (bp_pos _).le) (unif_subLaw.nz _) + +variable {p : Shape} {n N : ℕ} +abbrev HMat (p : Shape) (N : ℕ) := Mat (Fin N) (Chan p) +abbrev HFrame (p : Shape) (N : ℕ) := HMat p N × HMat p N +abbrev HCube (p : Shape) (N : ℕ) := Comp p.g → HFrame p N + +def hchan (p : Shape) {n N} (x : Oframe p n N) : HFrame p N := + (channel x.1,channel x.2) +def hcube (p : Shape) {n N} (x : Orient p n N) : HCube p N := fun z => hchan p (x z) +def lawH (p : Shape) (N : ℕ) : Wgt (HCube p N) := + prodW (fun (_ : Comp p.g) => pairW unif unif) + +def intoChan (p : Shape) (n) : Mat (Full p n) (Chan p) := embedMat (.inr ·) + +theorem intoChan_inj : Injective (intoChan p n).mulVec := + embedMat_inj Sum.inr_injective +theorem intoChan_val (p : Shape) {n N} (x : Mat (Fin N) (Full p n)) : + x * intoChan p n=channel x := by rw [intoChan,mul_embedMat]; rfl +theorem hchan_val (p : Shape) {n N} : + hchan p (n:=n) (N:=N) = observe (intoChan p n) (intoChan p n) := by + funext x + exact Prod.ext (intoChan_val ..).symm (intoChan_val ..).symm + +def chanPrice (p : Shape) : ℝ := + (4*bp ((p.h:ℝ)*p.h))^(Fintype.card (Comp p.g)) + +theorem hchan_cap (m : Mixer p n) (hN : 2*num (Full p n)-N≤ -1) : + let w := unifOn (FramesAt (U:=Fin N) (gramCond m)) + ∀ x : HFrame p N,mapW w (hchan p) x≤(4*bp ((p.h:ℝ)*p.h))*pairW unif unif x := by + classical + have he : 2*num (Full p n)-num (Fin N)≤ -1 := by simpa [num] using hN + have hh : ∃ x : Oframe p n N, FramesAt (gramCond m) x := + framesAt_exists (gramCond_exists m) (by linarith only [he]) + rw [hchan_val] + have hr : num (Chan p) ≤ num (Full p n) := by + have hf : Fintype.card (Row p n) + Fintype.card (Chan p)=Fintype.card (Full p n) := + (Fintype.card_sum ..).symm + exact_mod_cast (show Fintype.card (Chan p)≤Fintype.card (Full p n) by omega) + have hk := gramObsCap hh (intoChan p n) intoChan_inj (by linarith only [he,hr]) + rw [show num (Chan p)=(p.h:ℝ) from (by simp [num,Chan])] at hk + exact hk + +theorem hcube_cap (m : Mixer p n) (hN : 2*num (Full p n)-N≤ -1) + (x : HCube p N) : mapW (raw m N) (hcube p) x ≤ chanPrice p*lawH p N x := by + let w := unifOn (FramesAt (U:=Fin N) (gramCond m)) + have hh i := hchan_cap m hN (x i) + change mapW (prodW (fun (_ : Comp p.g) => w)) _ x ≤ _ + unfold hcube + rw [mapW_repeat (w:=fun (_:Comp p.g) => w) (f:=fun i => hchan p (n:=n) (N:=N))] + refine le_trans (Finset.prod_le_prod₀ ?_ fun i _ => hh i) ?_ + · intro i _ + exact pr_nonneg (unifOn_sub _).nz + rw [Finset.prod_mul_distrib] + simp [chanPrice,lawH,prodW] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CollisionInequality.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CollisionInequality.lean index 599d98230a4cbb89536e0aed92184d5e1baa9236..06486f597341cd1be167dd5df45d2ab21a100ded 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CollisionInequality.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CollisionInequality.lean @@ -1,204 +1,204 @@ -import OAI.Combinatorics.HadwigerCounterexample.UnaryRecords -import OAI.Combinatorics.HadwigerCounterexample.ConstructionScales - -namespace OAI - -/-! # Collision Inequality -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module Finset Filter -open scoped BigOperators -variable {p : Shape} {n N : ℕ} -variable {I A B : Type} [Fintype I] [Fintype A] [Fintype B] - -def density (v w : Wgt I) := fun x => w x/v x -def overlap (v a b : Wgt I) := - avg v (fun x => density v a x*density v b x) - -theorem overlap_count (P : I→Prop) (p q : Wgt I) (h : ∀ x, 0 ≤ p x) (h' : ∀ x, 0≤ q x) : - overlap (unifOn P) p q ≤ (Fintype.card I:ℝ) * (∑ i, p i*q i) := by - classical - simp only [overlap,density, avg,Finset.mul_sum] - refine Finset.sum_le_sum fun i _ => ?_ - have hg := mul_nonneg (h i) (h' i) - have hw : 0 ≤ (↑(Fintype.card I) : ℝ) := Nat.cast_nonneg _ - by_cases he : P i - · have hh : 0 < nbr P := by - have hpos : 0 < Fintype.card {x//P x} := Fintype.card_pos_iff.mpr ⟨⟨i,he⟩⟩ - rw [nbr_eq_card]; exact_mod_cast hpos - have hd : unifOn P i * (p i/unifOn P i * (q i / unifOn P i))=nbr P*(p i*q i) := by - rw [unifOn_val,ind_one he] - field_simp - rw [hd] - apply mul_le_mul_of_nonneg_right _ hg - rw [nbr_eq_card] - exact_mod_cast Fintype.card_le_of_injective _ (@Subtype.val_injective _ P) - rw [unifOn_carried P i he,zero_mul] - exact mul_nonneg hw hg - -namespace Volley - -/-- law of accepted keys as an unnormalized histogram -/ -def hist (v : A → Volley p n I) (t : Tagging p I) - (μ : Wgt (UnitType p n N)) (rho' : Wgt A) (U : A → UnitType p n N → Prop) : - Wgt (Keys (p:=p) t N) := - fun u => avg rho' (fun a => pr μ (fun x => U a x ∧ (v a).keys t x=u)) - -set_option maxHeartbeats 800000 in -private theorem record_sum (v w : Volley p n I) {t : Tagging p I} (m : Mixer p n) - {a b : Pin p n N} {μ δ : Wgt (UnitType p n N)} - (U V : UnitType p n N → Prop) - (ha : ∀ x, U x → a.agree x ∧ (∀ i,frameLaw m (onSide x i))) - (hb : ∀ x, V x → b.agree x ∧ (∀ i,frameLaw m (onSide x i))) - {ζ : ℝ} {q : ℕ} - (h : ∀ x,U x → ∀ y,V y → v.keys t x=w.keys t y → v.promised w t m a.sp b.sp x y) - (hv : v.avoids a.sp q) (hw : w.avoids b.sp q) - (hz : ζ ≤ 0.004) (hK : ζ*(kslots p I) ≤ 0.004) - (hμ : SubLaw μ) (hδ : SubLaw δ) - (hA : a.clear ζ μ) (hB : b.clear ζ δ) - (hN : 100 ≤ N) (hT : (dim (CheckGram p n) : ℝ) ≤ 0.01*N) - (L : ℝ) - (hLf : bp (dim (Ledger (v.frozen a.sp t))) ≤ L) - (hLg : bp (dim (Ledger (w.frozen b.sp t))) ≤ L) : - hit N * - (∑ u : Keys (p:=p) t N, pr μ (fun x => U x ∧ v.keys t x=u) * - pr δ (fun x => V x ∧ w.keys t x=u)) ≤ - pr (pairW μ δ) (fun x => (rawHoles m).conflict x.1 x.2)+ - 2*(hit N*tau N (kslots p I)*L) := by - classical - let X := UnitType p n N - let T := Keys (p:=p) t N - let K (u : T) (x : X) := U x ∧ v.keys t x=u - let K' (u : T) (x : X) := V x ∧ w.keys t x=u - let H := hit N*tau N (kslots p I)*L - let P := pairW μ δ - let C (x : X × X) := (rawHoles m).conflict x.1 x.2 - let G (u : T) (x : X × X) := K u x.1 ∧ K' u x.2 ∧ C x - rw [Finset.mul_sum] - have hh (i : Keys (p:=p) t N) : - hit N * (pr μ (K i) * pr δ (K' i))≤ pr P (G i)+H*(pr μ (K i)+pr δ (K' i)) := by - apply record_hit v w m (K i) (K' i) i _ _ _ hv hw hz hK hμ hδ hA hB hN hT L hLf hLg - · exact fun x h => ⟨(ha x h.1).1,(ha x h.1).2,h.2⟩ - · exact fun x h => ⟨(hb x h.1).1,(hb x h.1).2,h.2⟩ - exact fun x hx y hy => h x hx.1 y hy.1 (hx.2.trans hy.2.symm) - refine (Finset.sum_le_sum fun i _ => hh i).trans ?_ - rw [Finset.sum_add_distrib] - have hi : (∑ i : Keys (p:=p) t N, pr P (G i)) ≤ pr P C := by - rw [← sum_pr_tag P C (v.keys t ∘ Prod.fst)] - exact Finset.sum_le_sum fun i _ => pr_mono (subLaw_pair hμ hδ).nz (fun x h => ⟨h.2.2,h.1.2⟩) - refine add_le_add hi ?_ - have hU : (∑ i : Keys (p:=p) t N, pr μ (K i))≤1 := - (sum_pr_tag μ U (v.keys t)).trans_le ((pr_le_tot hμ.nz).trans hμ.total) - have hV : (∑ i : Keys (p:=p) t N, pr δ (K' i))≤1 := - (sum_pr_tag δ V (w.keys t)).trans_le ((pr_le_tot hδ.nz).trans hδ.total) - have hz : 0 ≤ H := mul_nonneg (mul_nonneg (bp_pos _).le (bp_pos _).le) ((bp_pos _).le.trans hLf) - rw [← Finset.mul_sum,Finset.sum_add_distrib,mul_comm 2] - exact mul_le_mul_of_nonneg_left (by linarith only [hU,hV]) hz - -set_option maxHeartbeats 1200000 in -theorem collision (v : A→Volley p n I) (w : B→Volley p n I) - {t : Tagging p I} (m : Mixer p n) - {a b : Pin p n N} {μ δ : Wgt (UnitType p n N)} - (rhoA : Wgt A) (rhoB : Wgt B) - (U : A → UnitType p n N → Prop) (V : B → UnitType p n N → Prop) - (ha : ∀ i x, U i x → a.agree x ∧ (∀ i,frameLaw m (onSide x i))) - (hb : ∀ i x, V i x → b.agree x ∧ (∀ i,frameLaw m (onSide x i))) - {ζ : ℝ} {q K : ℕ} - (h : ∀ i j x,U i x → ∀ y,V j y → (v i).keys t x=(w j).keys t y → - (v i).promised (w j) t m a.sp b.sp x y) - (hv : ∀ i, (v i).avoids a.sp q) (hw : ∀ i, (w i).avoids b.sp q) - (hκ : planRank a.sp≤K) (hκ' : planRank b.sp≤K) - (hz : ζ ≤ 0.004) (hK : ζ*(kslots p I) ≤ 0.004) (hslots : kslots p I≤kmax p) - (hμ : SubLaw μ) (hδ : SubLaw δ) (hu : SubLaw rhoA) (hu' : SubLaw rhoB) - (hA : a.clear ζ μ) (hB : b.clear ζ δ) - (hN : 100 ≤ N) (hT : (dim (CheckGram p n) : ℝ) ≤ 0.01*N) - (hL : (K+(kmax p:ℝ))*num (JointIdx p n) ≤ 0.005*N) - (J : Keys (p:=p) t N → Prop) : - overlap (unifOn J) (hist v t μ rhoA U) (hist w t δ rhoB V) ≤ - bp (((kslots p I:ℝ)+0.02)*N)*pr (pairW μ δ) (fun x => - (rawHoles m).conflict x.1 x.2) + 2*bp (-0.005*N) := by - classical - let k := kslots p I - let L := bp (0.005*N) - let C := fun (x : UnitType p n N × _) => (rawHoles m).conflict x.1 x.2 - let X := hist v t μ rhoA U - let Y := hist w t δ rhoB V - let H := hit N*tau N k*L - let D := pr (pairW μ δ) C - let α (u : Keys (p:=p) t N) i := pr μ (fun x => U i x ∧ (v i).keys t x=u) - let β (u : Keys (p:=p) t N) i := pr δ (fun x => V i x ∧ (w i).keys t x=u) - have hX u : 0≤ X u := avg_nonneg hu.nz (fun i => pr_nonneg hμ.nz) - have hY u : 0≤ Y u := avg_nonneg hu'.nz (fun i => pr_nonneg hδ.nz) - have hW (f : Plan p n) (hk : planRank f ≤ K) (v : Volley p n I) (hv : v.avoids f q) : - bp (dim (Ledger (v.frozen f t)))≤L := by - apply bp_le - rw [ledger_dim] - push_cast - have ht : (planRank (v.frozen f t) : ℝ) ≤ K+(kmax p:ℝ) := by - have hh := plan_add_rank f (v.keyPlan t) - rw [key_slots t hv] at hh - exact_mod_cast (show planRank (f⊔v.keyPlan t) ≤ K+kmax p from - hh.symm ▸ add_le_add hk hslots) - exact le_trans (mul_le_mul_of_nonneg_right ht (Nat.cast_nonneg _)) hL - have hf (x : A × B) : - hit N * (∑ u : Keys (p:=p) t N, α u x.1*β u x.2) ≤ D+ 2*H := - record_sum (v x.1) (w x.2) m (U _) (V _) (ha x.1) (hb x.2) (h x.1 x.2) - (hv x.1) (hw x.2) hz hK hμ hδ hA hB hN hT L (hW a.sp hκ _ (hv _)) (hW _ hκ' _ (hw _)) - have hh : hit N * (∑ u : Keys (p:=p) t N,X u * Y u) ≤ D + 2*H := by - let F := pairW rhoA rhoB - have hh' : 0 ≤ D+2*H := by - apply add_nonneg (pr_nonneg (subLaw_pair hμ hδ).nz) - exact mul_nonneg (by norm_num) (mul_nonneg (mul_nonneg (bp_pos _).le (bp_pos _).le) - (bp_pos _).le) - have hl := (subLaw_pair hu hu').avg_le hh' hf - rw [avg_mul',avg_sum] at hl - have ht (u : Keys (p:=p) t N) : - X u*Y u=avg F (fun x : A×B => α u x.1*β u x.2) := (pairW_separate ..).symm - simp_rw [ht]; exact hl - apply (overlap_count J X Y hX hY).trans - rw [card_space,dim_keys,Nat.cast_mul] - let Z := bp (((k:ℝ)+0.02)*N) - have he : Z*hit N = bp ((k:ℝ)*N) := by - unfold Z hit; rw [← bp_add]; congr 1; ring - have he' : Z*H = bp (-0.005*N) := by - unfold H; rw [← mul_assoc,← mul_assoc,he] - unfold L tau - rw [← bp_add,← bp_add]; congr 1; ring - change bp ((k:ℝ)*N)*_≤ Z*D+_ - rw [← he, mul_assoc,← he'] - refine (mul_le_mul_of_nonneg_left hh (bp_pos _).le).trans_eq ?_ - ring -end Volley - -theorem collision_scales (p : Shape) (K : ℕ) : - ∀ᶠ M : ℕ in atTop,∀ᶠ n : ℕ in atTop, let N := M*n; - 100≤N ∧ (dim (CheckGram p n):ℝ) ≤ 0.01*N ∧ - (K+(kmax p:ℝ))*num (JointIdx p n) ≤ 0.005*N := by - filter_upwards [columns_budget p (δ:=0.01) (by norm_num) - (16*(ncComp p:ℝ)*p.h) 0 (by positivity) (by norm_num), - columns_budget p (δ:=0.005) (by norm_num) - (2*(K+(kmax p:ℝ))) 0 (by positivity) (by norm_num),eventually_ge_atTop 1] with M hM hB hg - filter_upwards [eventually_ge_atTop 100] with n hn - specialize hM n (by omega) - specialize hB n (by omega) - have hN : 100 ≤ M*n := by nlinarith - refine ⟨hN,?_,?_⟩ - · rw [checkgram_dim] - simp only [Nat.cast_mul,Nat.cast_ofNat]; unfold num at hM - have hi : (↑(Fintype.card (Row p n)):ℝ)≤Fintype.card (Full p n) := by - have he : Fintype.card (Full p n)=_+_ := Fintype.card_sum .. - exact_mod_cast (show Fintype.card (Row p n)≤Fintype.card (Full p n) from he.symm ▸ - Nat.le_add_right ..) - rw [add_zero] at hM - rw [Nat.cast_mul] at hM - exact le_trans (mul_le_mul_of_nonneg_left hi (by positivity)) hM - rw [show num (JointIdx p n) = 2*num (Full p n) from (by - unfold num JointIdx; rw [Fintype.card_sum]; push_cast; ring)] - linarith only [hB] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.UnaryRecords +import OAI.Combinatorics.HadwigerCounterexample.ConstructionScales + +namespace OAI + +/-! # Collision Inequality -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module Finset Filter +open scoped BigOperators +variable {p : Shape} {n N : ℕ} +variable {I A B : Type} [Fintype I] [Fintype A] [Fintype B] + +def density (v w : Wgt I) := fun x => w x/v x +def overlap (v a b : Wgt I) := + avg v (fun x => density v a x*density v b x) + +theorem overlap_count (P : I→Prop) (p q : Wgt I) (h : ∀ x, 0 ≤ p x) (h' : ∀ x, 0≤ q x) : + overlap (unifOn P) p q ≤ (Fintype.card I:ℝ) * (∑ i, p i*q i) := by + classical + simp only [overlap,density, avg,Finset.mul_sum] + refine Finset.sum_le_sum fun i _ => ?_ + have hg := mul_nonneg (h i) (h' i) + have hw : 0 ≤ (↑(Fintype.card I) : ℝ) := Nat.cast_nonneg _ + by_cases he : P i + · have hh : 0 < nbr P := by + have hpos : 0 < Fintype.card {x//P x} := Fintype.card_pos_iff.mpr ⟨⟨i,he⟩⟩ + rw [nbr_eq_card]; exact_mod_cast hpos + have hd : unifOn P i * (p i/unifOn P i * (q i / unifOn P i))=nbr P*(p i*q i) := by + rw [unifOn_val,ind_one he] + field_simp + rw [hd] + apply mul_le_mul_of_nonneg_right _ hg + rw [nbr_eq_card] + exact_mod_cast Fintype.card_le_of_injective _ (@Subtype.val_injective _ P) + rw [unifOn_carried P i he,zero_mul] + exact mul_nonneg hw hg + +namespace Volley + +/-- law of accepted keys as an unnormalized histogram -/ +def hist (v : A → Volley p n I) (t : Tagging p I) + (μ : Wgt (UnitType p n N)) (rho' : Wgt A) (U : A → UnitType p n N → Prop) : + Wgt (Keys (p:=p) t N) := + fun u => avg rho' (fun a => pr μ (fun x => U a x ∧ (v a).keys t x=u)) + +set_option maxHeartbeats 800000 in +private theorem record_sum (v w : Volley p n I) {t : Tagging p I} (m : Mixer p n) + {a b : Pin p n N} {μ δ : Wgt (UnitType p n N)} + (U V : UnitType p n N → Prop) + (ha : ∀ x, U x → a.agree x ∧ (∀ i,frameLaw m (onSide x i))) + (hb : ∀ x, V x → b.agree x ∧ (∀ i,frameLaw m (onSide x i))) + {ζ : ℝ} {q : ℕ} + (h : ∀ x,U x → ∀ y,V y → v.keys t x=w.keys t y → v.promised w t m a.sp b.sp x y) + (hv : v.avoids a.sp q) (hw : w.avoids b.sp q) + (hz : ζ ≤ 0.004) (hK : ζ*(kslots p I) ≤ 0.004) + (hμ : SubLaw μ) (hδ : SubLaw δ) + (hA : a.clear ζ μ) (hB : b.clear ζ δ) + (hN : 100 ≤ N) (hT : (dim (CheckGram p n) : ℝ) ≤ 0.01*N) + (L : ℝ) + (hLf : bp (dim (Ledger (v.frozen a.sp t))) ≤ L) + (hLg : bp (dim (Ledger (w.frozen b.sp t))) ≤ L) : + hit N * + (∑ u : Keys (p:=p) t N, pr μ (fun x => U x ∧ v.keys t x=u) * + pr δ (fun x => V x ∧ w.keys t x=u)) ≤ + pr (pairW μ δ) (fun x => (rawHoles m).conflict x.1 x.2)+ + 2*(hit N*tau N (kslots p I)*L) := by + classical + let X := UnitType p n N + let T := Keys (p:=p) t N + let K (u : T) (x : X) := U x ∧ v.keys t x=u + let K' (u : T) (x : X) := V x ∧ w.keys t x=u + let H := hit N*tau N (kslots p I)*L + let P := pairW μ δ + let C (x : X × X) := (rawHoles m).conflict x.1 x.2 + let G (u : T) (x : X × X) := K u x.1 ∧ K' u x.2 ∧ C x + rw [Finset.mul_sum] + have hh (i : Keys (p:=p) t N) : + hit N * (pr μ (K i) * pr δ (K' i))≤ pr P (G i)+H*(pr μ (K i)+pr δ (K' i)) := by + apply record_hit v w m (K i) (K' i) i _ _ _ hv hw hz hK hμ hδ hA hB hN hT L hLf hLg + · exact fun x h => ⟨(ha x h.1).1,(ha x h.1).2,h.2⟩ + · exact fun x h => ⟨(hb x h.1).1,(hb x h.1).2,h.2⟩ + exact fun x hx y hy => h x hx.1 y hy.1 (hx.2.trans hy.2.symm) + refine (Finset.sum_le_sum fun i _ => hh i).trans ?_ + rw [Finset.sum_add_distrib] + have hi : (∑ i : Keys (p:=p) t N, pr P (G i)) ≤ pr P C := by + rw [← sum_pr_tag P C (v.keys t ∘ Prod.fst)] + exact Finset.sum_le_sum fun i _ => pr_mono (subLaw_pair hμ hδ).nz (fun x h => ⟨h.2.2,h.1.2⟩) + refine add_le_add hi ?_ + have hU : (∑ i : Keys (p:=p) t N, pr μ (K i))≤1 := + (sum_pr_tag μ U (v.keys t)).trans_le ((pr_le_tot hμ.nz).trans hμ.total) + have hV : (∑ i : Keys (p:=p) t N, pr δ (K' i))≤1 := + (sum_pr_tag δ V (w.keys t)).trans_le ((pr_le_tot hδ.nz).trans hδ.total) + have hz : 0 ≤ H := mul_nonneg (mul_nonneg (bp_pos _).le (bp_pos _).le) ((bp_pos _).le.trans hLf) + rw [← Finset.mul_sum,Finset.sum_add_distrib,mul_comm 2] + exact mul_le_mul_of_nonneg_left (by linarith only [hU,hV]) hz + +set_option maxHeartbeats 1200000 in +theorem collision (v : A→Volley p n I) (w : B→Volley p n I) + {t : Tagging p I} (m : Mixer p n) + {a b : Pin p n N} {μ δ : Wgt (UnitType p n N)} + (rhoA : Wgt A) (rhoB : Wgt B) + (U : A → UnitType p n N → Prop) (V : B → UnitType p n N → Prop) + (ha : ∀ i x, U i x → a.agree x ∧ (∀ i,frameLaw m (onSide x i))) + (hb : ∀ i x, V i x → b.agree x ∧ (∀ i,frameLaw m (onSide x i))) + {ζ : ℝ} {q K : ℕ} + (h : ∀ i j x,U i x → ∀ y,V j y → (v i).keys t x=(w j).keys t y → + (v i).promised (w j) t m a.sp b.sp x y) + (hv : ∀ i, (v i).avoids a.sp q) (hw : ∀ i, (w i).avoids b.sp q) + (hκ : planRank a.sp≤K) (hκ' : planRank b.sp≤K) + (hz : ζ ≤ 0.004) (hK : ζ*(kslots p I) ≤ 0.004) (hslots : kslots p I≤kmax p) + (hμ : SubLaw μ) (hδ : SubLaw δ) (hu : SubLaw rhoA) (hu' : SubLaw rhoB) + (hA : a.clear ζ μ) (hB : b.clear ζ δ) + (hN : 100 ≤ N) (hT : (dim (CheckGram p n) : ℝ) ≤ 0.01*N) + (hL : (K+(kmax p:ℝ))*num (JointIdx p n) ≤ 0.005*N) + (J : Keys (p:=p) t N → Prop) : + overlap (unifOn J) (hist v t μ rhoA U) (hist w t δ rhoB V) ≤ + bp (((kslots p I:ℝ)+0.02)*N)*pr (pairW μ δ) (fun x => + (rawHoles m).conflict x.1 x.2) + 2*bp (-0.005*N) := by + classical + let k := kslots p I + let L := bp (0.005*N) + let C := fun (x : UnitType p n N × _) => (rawHoles m).conflict x.1 x.2 + let X := hist v t μ rhoA U + let Y := hist w t δ rhoB V + let H := hit N*tau N k*L + let D := pr (pairW μ δ) C + let α (u : Keys (p:=p) t N) i := pr μ (fun x => U i x ∧ (v i).keys t x=u) + let β (u : Keys (p:=p) t N) i := pr δ (fun x => V i x ∧ (w i).keys t x=u) + have hX u : 0≤ X u := avg_nonneg hu.nz (fun i => pr_nonneg hμ.nz) + have hY u : 0≤ Y u := avg_nonneg hu'.nz (fun i => pr_nonneg hδ.nz) + have hW (f : Plan p n) (hk : planRank f ≤ K) (v : Volley p n I) (hv : v.avoids f q) : + bp (dim (Ledger (v.frozen f t)))≤L := by + apply bp_le + rw [ledger_dim] + push_cast + have ht : (planRank (v.frozen f t) : ℝ) ≤ K+(kmax p:ℝ) := by + have hh := plan_add_rank f (v.keyPlan t) + rw [key_slots t hv] at hh + exact_mod_cast (show planRank (f⊔v.keyPlan t) ≤ K+kmax p from + hh.symm ▸ add_le_add hk hslots) + exact le_trans (mul_le_mul_of_nonneg_right ht (Nat.cast_nonneg _)) hL + have hf (x : A × B) : + hit N * (∑ u : Keys (p:=p) t N, α u x.1*β u x.2) ≤ D+ 2*H := + record_sum (v x.1) (w x.2) m (U _) (V _) (ha x.1) (hb x.2) (h x.1 x.2) + (hv x.1) (hw x.2) hz hK hμ hδ hA hB hN hT L (hW a.sp hκ _ (hv _)) (hW _ hκ' _ (hw _)) + have hh : hit N * (∑ u : Keys (p:=p) t N,X u * Y u) ≤ D + 2*H := by + let F := pairW rhoA rhoB + have hh' : 0 ≤ D+2*H := by + apply add_nonneg (pr_nonneg (subLaw_pair hμ hδ).nz) + exact mul_nonneg (by norm_num) (mul_nonneg (mul_nonneg (bp_pos _).le (bp_pos _).le) + (bp_pos _).le) + have hl := (subLaw_pair hu hu').avg_le hh' hf + rw [avg_mul',avg_sum] at hl + have ht (u : Keys (p:=p) t N) : + X u*Y u=avg F (fun x : A×B => α u x.1*β u x.2) := (pairW_separate ..).symm + simp_rw [ht]; exact hl + apply (overlap_count J X Y hX hY).trans + rw [card_space,dim_keys,Nat.cast_mul] + let Z := bp (((k:ℝ)+0.02)*N) + have he : Z*hit N = bp ((k:ℝ)*N) := by + unfold Z hit; rw [← bp_add]; congr 1; ring + have he' : Z*H = bp (-0.005*N) := by + unfold H; rw [← mul_assoc,← mul_assoc,he] + unfold L tau + rw [← bp_add,← bp_add]; congr 1; ring + change bp ((k:ℝ)*N)*_≤ Z*D+_ + rw [← he, mul_assoc,← he'] + refine (mul_le_mul_of_nonneg_left hh (bp_pos _).le).trans_eq ?_ + ring +end Volley + +theorem collision_scales (p : Shape) (K : ℕ) : + ∀ᶠ M : ℕ in atTop,∀ᶠ n : ℕ in atTop, let N := M*n; + 100≤N ∧ (dim (CheckGram p n):ℝ) ≤ 0.01*N ∧ + (K+(kmax p:ℝ))*num (JointIdx p n) ≤ 0.005*N := by + filter_upwards [columns_budget p (δ:=0.01) (by norm_num) + (16*(ncComp p:ℝ)*p.h) 0 (by positivity) (by norm_num), + columns_budget p (δ:=0.005) (by norm_num) + (2*(K+(kmax p:ℝ))) 0 (by positivity) (by norm_num),eventually_ge_atTop 1] with M hM hB hg + filter_upwards [eventually_ge_atTop 100] with n hn + specialize hM n (by omega) + specialize hB n (by omega) + have hN : 100 ≤ M*n := by nlinarith + refine ⟨hN,?_,?_⟩ + · rw [checkgram_dim] + simp only [Nat.cast_mul,Nat.cast_ofNat]; unfold num at hM + have hi : (↑(Fintype.card (Row p n)):ℝ)≤Fintype.card (Full p n) := by + have he : Fintype.card (Full p n)=_+_ := Fintype.card_sum .. + exact_mod_cast (show Fintype.card (Row p n)≤Fintype.card (Full p n) from he.symm ▸ + Nat.le_add_right ..) + rw [add_zero] at hM + rw [Nat.cast_mul] at hM + exact le_trans (mul_le_mul_of_nonneg_left hi (by positivity)) hM + rw [show num (JointIdx p n) = 2*num (Full p n) from (by + unfold num JointIdx; rw [Fintype.card_sum]; push_cast; ring)] + linarith only [hB] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CommonPartitionRefinement.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CommonPartitionRefinement.lean index 781fc1e08b6aed89b761f38fb7df2968cef771e6..7b41a06640f53abefe084627657067a870273fb5 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CommonPartitionRefinement.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CommonPartitionRefinement.lean @@ -1,79 +1,79 @@ -import OAI.Combinatorics.HadwigerCounterexample.RectangleComparisons - -namespace OAI - -/-! # Common Partition Refinement -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix Function -open scoped BigOperators Topology -variable {p:Shape} {n N K M r : ℕ} - -def refines {r r':ℕ} (Y:Silhouette p N r) (Y':Silhouette p N r') := - ∀ l q, ∃ f:Fin r→Fin r',∀ x,Y' l q x=f (Y l q x) - -theorem self_refine (Y:Silhouette p N r): refines Y Y := - fun _ _=> ⟨id,fun _=>rfl⟩ -theorem refines_next {r s t:ℕ} {Y:Silhouette p N r} {X:Silhouette p N s} - {Z:Silhouette p N t} (h : refines Y X) (hg : refines X Z) : - refines Y Z := by - intro l q - obtain ⟨f,hf⟩:=h l q; obtain ⟨g,hg⟩:=hg l q - refine ⟨g∘ f,fun x => ?_⟩; rw [hg,hf]; rfl - -variable {A B : Type} [Fintype A] [Fintype B] [DecidableEq A] [DecidableEq B] - -def bouquet (f : A→ℕ) := Fintype.card ((i:A)→ Fin (f i)) -def bundleY (f:A→ℕ) (w: (i:A)→ Silhouette p N (f i)) : - Silhouette p N (bouquet f) := - fun l q x=> Fintype.equivFin ((i:A)→ Fin (f i)) (fun i=> w i l q x) -theorem bundle_refines (f:A→ℕ) (w:(i:A)→ Silhouette p N (f i)) : - ∀ i,refines (bundleY f w) (w i) := by - intro i l q - let e:= Fintype.equivFin ((i:A)→Fin (f i)) - exact ⟨fun x=> e.symm x i,fun x=>(congr_fun (e.symm_apply_apply (fun i=> w i l q x)) i).symm⟩ - -def duoY {r s} (Y : Silhouette p N r) (X : Silhouette p N s) : - Silhouette p N (r*s) := - open scoped Classical in fun i q x => finProdFinEquiv (Y i q x,X i q x) -theorem duo_good {r s} (Y : Silhouette p N r) (X : Silhouette p N s) : - refines (duoY Y X) Y ∧ refines (duoY Y X) X := by - let e : Fin r × Fin s ≃ Fin (r*s):=finProdFinEquiv - constructor - · intro i j; exact ⟨fun k=>(e.symm k).1,fun x=> (congrArg Prod.fst - (e.symm_apply_apply (Y i j x,X i j x))).symm⟩ - intro i j; exact ⟨fun k=>(e.symm k).2,fun x=> (congrArg Prod.snd - (e.symm_apply_apply (Y i j x,X i j x))).symm⟩ - -namespace StatusAnalysis -variable (v : Template p A) - -def paletteSize (A B : Type) [Fintype A] [Fintype B] [DecidableEq A] [DecidableEq B] := Fintype.card (B × A → Bool) -theorem buildPalette (N : ℕ) (q : A → F) (w : B → Template.Paint v N) : - ∃ Y : Silhouette p N (paletteSize A B),∀ i,pigments q Y (w i) := by - classical - let E := Fintype.equivFin (B × A→Bool) - let H (l) (q:F) (x : AtomKey (p:=p) l N) (i:B) (j:A) := - if h:v.t j=l then decide ((w i).flies j (h ▸ x)) else false - let Y : Silhouette p N (paletteSize A B) := - fun l q x=> E (fun i=> H l q x i.1 i.2) - refine ⟨Y,fun i j=>⟨fun x=>(E.symm x (i,j)),fun x=>?_⟩⟩ - change _ ↔ E.symm (E (fun i => H (v.t j) (q j) x i.1 i.2)) (i,j)=true - rw [Equiv.symm_apply_apply] - unfold H; rw [dite_eq_left rfl]; simp - -omit [Fintype A] [DecidableEq A] in -theorem finerPigment {v : Template p A} {r s:ℕ} (Y : Silhouette p N r) - (Y' : Silhouette p N s) (h : refines Y' Y) {q} (w : Template.Paint v N) - (hh : pigments q Y w) : pigments q Y' w := by - intro i - obtain ⟨g,hg⟩:=hh i; obtain ⟨f,hf⟩:=h (v.t i) (q i) - exact ⟨g∘ f,fun x=> (hg x).trans (by rw [hf]; rfl)⟩ - -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RectangleComparisons + +namespace OAI + +/-! # Common Partition Refinement -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix Function +open scoped BigOperators Topology +variable {p:Shape} {n N K M r : ℕ} + +def refines {r r':ℕ} (Y:Silhouette p N r) (Y':Silhouette p N r') := + ∀ l q, ∃ f:Fin r→Fin r',∀ x,Y' l q x=f (Y l q x) + +theorem self_refine (Y:Silhouette p N r): refines Y Y := + fun _ _=> ⟨id,fun _=>rfl⟩ +theorem refines_next {r s t:ℕ} {Y:Silhouette p N r} {X:Silhouette p N s} + {Z:Silhouette p N t} (h : refines Y X) (hg : refines X Z) : + refines Y Z := by + intro l q + obtain ⟨f,hf⟩:=h l q; obtain ⟨g,hg⟩:=hg l q + refine ⟨g∘ f,fun x => ?_⟩; rw [hg,hf]; rfl + +variable {A B : Type} [Fintype A] [Fintype B] [DecidableEq A] [DecidableEq B] + +def bouquet (f : A→ℕ) := Fintype.card ((i:A)→ Fin (f i)) +def bundleY (f:A→ℕ) (w: (i:A)→ Silhouette p N (f i)) : + Silhouette p N (bouquet f) := + fun l q x=> Fintype.equivFin ((i:A)→ Fin (f i)) (fun i=> w i l q x) +theorem bundle_refines (f:A→ℕ) (w:(i:A)→ Silhouette p N (f i)) : + ∀ i,refines (bundleY f w) (w i) := by + intro i l q + let e:= Fintype.equivFin ((i:A)→Fin (f i)) + exact ⟨fun x=> e.symm x i,fun x=>(congr_fun (e.symm_apply_apply (fun i=> w i l q x)) i).symm⟩ + +def duoY {r s} (Y : Silhouette p N r) (X : Silhouette p N s) : + Silhouette p N (r*s) := + open scoped Classical in fun i q x => finProdFinEquiv (Y i q x,X i q x) +theorem duo_good {r s} (Y : Silhouette p N r) (X : Silhouette p N s) : + refines (duoY Y X) Y ∧ refines (duoY Y X) X := by + let e : Fin r × Fin s ≃ Fin (r*s):=finProdFinEquiv + constructor + · intro i j; exact ⟨fun k=>(e.symm k).1,fun x=> (congrArg Prod.fst + (e.symm_apply_apply (Y i j x,X i j x))).symm⟩ + intro i j; exact ⟨fun k=>(e.symm k).2,fun x=> (congrArg Prod.snd + (e.symm_apply_apply (Y i j x,X i j x))).symm⟩ + +namespace StatusAnalysis +variable (v : Template p A) + +def paletteSize (A B : Type) [Fintype A] [Fintype B] [DecidableEq A] [DecidableEq B] := Fintype.card (B × A → Bool) +theorem buildPalette (N : ℕ) (q : A → F) (w : B → Template.Paint v N) : + ∃ Y : Silhouette p N (paletteSize A B),∀ i,pigments q Y (w i) := by + classical + let E := Fintype.equivFin (B × A→Bool) + let H (l) (q:F) (x : AtomKey (p:=p) l N) (i:B) (j:A) := + if h:v.t j=l then decide ((w i).flies j (h ▸ x)) else false + let Y : Silhouette p N (paletteSize A B) := + fun l q x=> E (fun i=> H l q x i.1 i.2) + refine ⟨Y,fun i j=>⟨fun x=>(E.symm x (i,j)),fun x=>?_⟩⟩ + change _ ↔ E.symm (E (fun i => H (v.t j) (q j) x i.1 i.2)) (i,j)=true + rw [Equiv.symm_apply_apply] + unfold H; rw [dite_eq_left rfl]; simp + +omit [Fintype A] [DecidableEq A] in +theorem finerPigment {v : Template p A} {r s:ℕ} (Y : Silhouette p N r) + (Y' : Silhouette p N s) (h : refines Y' Y) {q} (w : Template.Paint v N) + (hh : pigments q Y w) : pigments q Y' w := by + intro i + obtain ⟨g,hg⟩:=hh i; obtain ⟨f,hf⟩:=h (v.t i) (q i) + exact ⟨g∘ f,fun x=> (hg x).trans (by rw [hf]; rfl)⟩ + +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CommonPartitions.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CommonPartitions.lean index 5df384550e913575f27ef95971054e2f91f8dd91..bb54400e2bcfd87db6a2e24df59939d7365b01f0 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CommonPartitions.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CommonPartitions.lean @@ -1,119 +1,119 @@ -import OAI.Combinatorics.HadwigerCounterexample.ProjectionError - -namespace OAI - -/-! # Common Partitions -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Module Matrix Filter Function -open scoped BigOperators -variable {A B I J X : Type} [Fintype A] [Fintype B] [Fintype I] [Fintype J] [Fintype X] -variable (u : Wgt A) (w : Wgt I) (v : Wgt J) - -set_option maxHeartbeats 800000 in -theorem rollup [Nonempty B] (hw : IsLaw w) (hv : IsLaw v) (hu : IsLaw u) - (f : I×B→Wgt A) (g : J×B→Wgt A) (h k : I×J→ B) (R : ℝ) (hr : 0 |rebate u (f (i.1,h i)) (g (i.2,k i)) p|) ≤ - num B ^ 2 * (R*ε) := by - classical - let H (i : I × B) (j : J × B) := |rebate u (f i) (g j) p| - let T := num B - have ht : 0 H i j)≤ R*ε := by - let g' (i:A) := g j i/R - have hh (i) : |g' i|≤1 := by - unfold g'; rw [abs_div,abs_of_pos hr,div_le_one hr]; exact hg _ _ - have hz (i) : - H i j=R* |dip u (fun x=> f i x-banner u p (f i) x) g'| := by - unfold H; rw [rebate_calc _ _ _ _ hu.nz] - unfold g' dip; simp_rw [←mul_div_assoc,avg_div] - rw [abs_div,abs_of_pos hr]; field_simp - simp_rw [hz,avg_mul']; exact mul_le_mul_of_nonneg_left (hx g' hh) hr.le - have hh i j : - H (i,h (i,j)) (j,k (i,j))≤ ∑ b : B,∑ c : B,H (i,b) (j,c) := - (Finset.single_le_sum (f:=fun x=> H (i,h (i,j)) (j,x)) (fun _ _ => abs_nonneg _) (mem_univ (k (i,j)))).trans - (Finset.single_le_sum (f:=fun x => ∑ c:B,H (i,x) (j,c)) (fun _ _=> Finset.sum_nonneg (fun _ _=>abs_nonneg _)) (mem_univ (h (i,j)))) - have hi j c : - avg w (fun i=>∑ b : B,H (i,b) (j,c))≤ T*(R*ε) := by - have hg : ∀ i : I,(∑ b:B,H (i,b) (j,c))=T*avg unif (fun b=> H (i,b) (j,c)) := by - intro i; simp only [avg,unif_apply,← Finset.mul_sum] - change _ = T*(T⁻¹ * _) - rw [←mul_assoc,mul_inv_cancel₀ ht.ne',one_mul] - simp_rw [hg,avg_mul'] - refine mul_le_mul_of_nonneg_left ?_ ht.le; rw [← pairW_avg w unif (fun p : I×B=>H p (j,c))] - exact he _ - change avg (pairW w v) _ ≤ T^2*(R*ε) - rw [pairW_avg,avg_avg] - refine hv.avg_le fun j=> ?_ - have hz i : ∑ b:B,∑ c:B,H (i,b) (j,c)=∑ c:B,∑ b:B,H (i,b) (j,c) := - Finset.sum_comm - apply (avg_mono hw.nz (fun i => (hh i j).trans_eq (hz i))).trans - rw [avg_sum] - exact (Finset.sum_le_sum fun i _=>hi j i).trans_eq (by - simp only [sum_const,nsmul_eq_mul,Finset.card_univ,T,num]; ring) - -set_option maxHeartbeats 1200000 in -theorem global_net (R ε : ℝ) (hr : 0 |rebate u (mcut R u (f i)) (mcut R u (g i)) p|)≤ ε := by - classical - let δ := ε/(8*R) - have hd : 0<δ := by positivity - refine ⟨δ,hd,fun r=>?_⟩ - let B:=Fin (r+1); let t:=num B - have ht : 0?_⟩ - choose s hs h1 using fun i=> roster_clip R u hu hr.le (P i) r δ (hp i) - choose y hy h2 using fun i=> roster_clip R u hu hr.le (Q i) r δ (hq i) - let F : I×B→Wgt A := uncurry s - let G : J×B→Wgt A := uncurry y - obtain ⟨m,hm,p,hP⟩:= hl A (I×B) (pairW w unif) u F (pairW_law hw unif_law) hu (fun i j=> hs _ _ _) - refine ⟨m,hm,p,fun f g hf hg=>?_⟩ - let f' (i : I×J):= mcut R u (f i) - let g' (i : I×J):= mcut R u (g i) - choose a hA using fun i:I×J => h1 i.1 (f i) (hf i) - choose b hB using fun i:I×J => h2 i.2 (g i) (hg i) - let H (i:I×J) := |rebate u (F (i.1,a i)) (G (i.2,b i)) p| - let D:=pairW w v; have hD:= pairW_law hw hv - have he := rollup u w v hw hv hu F G a b R hr (fun i j=> hy _ _ _) p c hP - have hb : 0≤2*R := by linarith only [hr] - have hi (i:I×J) : |rebate u (f' i) (g' i) p|≤ H i+(δ*(4*R)) := by - let A' := F (i.1,a i); let B' := G (i.2,b i) - have h1 (j) : |g' i j|≤R := by - rw [abs_of_nonneg ((mcut_range _ _ _ hr.le j).1)] - exact (mcut_range _ _ _ hr.le j).2 - have h3 : |rebate u (f' i) (g' i) p - rebate u A' (g' i) p|≤ δ*(2*R) := by - exact (rebate_cost u _ _ A' p hu.nz R hr.le h1).trans (mul_le_mul_of_nonneg_right (hA i) hb) - have h4 : |rebate u A' (g' i) p - rebate u A' B' p|≤δ*(2*R) := by - rw [rebate_sym u A',rebate_sym u A'] - exact (rebate_cost u _ _ B' p hu.nz R hr.le (fun i=>hs _ _ _)).trans - (mul_le_mul_of_nonneg_right (hB i) hb) - let U:=rebate u A' B' p - let X:=rebate u (f' i) (g' i) p - have hz:= (abs_sub_le X (rebate u A' (g' i) p) U).trans (add_le_add h3 h4) - calc |X| = |(X-U)+U| := by rw [sub_add_cancel] - _ ≤ _ := ((abs_add_le _ _).trans (add_le_add_left hz _)).trans_eq (by - change _+ |U| = |U|+δ*(4*R) - ring) - refine (avg_mono hD.nz hi).trans ?_ - rw [avg_add,hD.avg_const] - exact (add_le_add_left he _).trans_eq (by - change t^2*(R*c)+δ*(4*R)=_ - unfold δ c; field_simp; ring) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ProjectionError + +namespace OAI + +/-! # Common Partitions -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Module Matrix Filter Function +open scoped BigOperators +variable {A B I J X : Type} [Fintype A] [Fintype B] [Fintype I] [Fintype J] [Fintype X] +variable (u : Wgt A) (w : Wgt I) (v : Wgt J) + +set_option maxHeartbeats 800000 in +theorem rollup [Nonempty B] (hw : IsLaw w) (hv : IsLaw v) (hu : IsLaw u) + (f : I×B→Wgt A) (g : J×B→Wgt A) (h k : I×J→ B) (R : ℝ) (hr : 0 |rebate u (f (i.1,h i)) (g (i.2,k i)) p|) ≤ + num B ^ 2 * (R*ε) := by + classical + let H (i : I × B) (j : J × B) := |rebate u (f i) (g j) p| + let T := num B + have ht : 0 H i j)≤ R*ε := by + let g' (i:A) := g j i/R + have hh (i) : |g' i|≤1 := by + unfold g'; rw [abs_div,abs_of_pos hr,div_le_one hr]; exact hg _ _ + have hz (i) : + H i j=R* |dip u (fun x=> f i x-banner u p (f i) x) g'| := by + unfold H; rw [rebate_calc _ _ _ _ hu.nz] + unfold g' dip; simp_rw [←mul_div_assoc,avg_div] + rw [abs_div,abs_of_pos hr]; field_simp + simp_rw [hz,avg_mul']; exact mul_le_mul_of_nonneg_left (hx g' hh) hr.le + have hh i j : + H (i,h (i,j)) (j,k (i,j))≤ ∑ b : B,∑ c : B,H (i,b) (j,c) := + (Finset.single_le_sum (f:=fun x=> H (i,h (i,j)) (j,x)) (fun _ _ => abs_nonneg _) (mem_univ (k (i,j)))).trans + (Finset.single_le_sum (f:=fun x => ∑ c:B,H (i,x) (j,c)) (fun _ _=> Finset.sum_nonneg (fun _ _=>abs_nonneg _)) (mem_univ (h (i,j)))) + have hi j c : + avg w (fun i=>∑ b : B,H (i,b) (j,c))≤ T*(R*ε) := by + have hg : ∀ i : I,(∑ b:B,H (i,b) (j,c))=T*avg unif (fun b=> H (i,b) (j,c)) := by + intro i; simp only [avg,unif_apply,← Finset.mul_sum] + change _ = T*(T⁻¹ * _) + rw [←mul_assoc,mul_inv_cancel₀ ht.ne',one_mul] + simp_rw [hg,avg_mul'] + refine mul_le_mul_of_nonneg_left ?_ ht.le; rw [← pairW_avg w unif (fun p : I×B=>H p (j,c))] + exact he _ + change avg (pairW w v) _ ≤ T^2*(R*ε) + rw [pairW_avg,avg_avg] + refine hv.avg_le fun j=> ?_ + have hz i : ∑ b:B,∑ c:B,H (i,b) (j,c)=∑ c:B,∑ b:B,H (i,b) (j,c) := + Finset.sum_comm + apply (avg_mono hw.nz (fun i => (hh i j).trans_eq (hz i))).trans + rw [avg_sum] + exact (Finset.sum_le_sum fun i _=>hi j i).trans_eq (by + simp only [sum_const,nsmul_eq_mul,Finset.card_univ,T,num]; ring) + +set_option maxHeartbeats 1200000 in +theorem global_net (R ε : ℝ) (hr : 0 |rebate u (mcut R u (f i)) (mcut R u (g i)) p|)≤ ε := by + classical + let δ := ε/(8*R) + have hd : 0<δ := by positivity + refine ⟨δ,hd,fun r=>?_⟩ + let B:=Fin (r+1); let t:=num B + have ht : 0?_⟩ + choose s hs h1 using fun i=> roster_clip R u hu hr.le (P i) r δ (hp i) + choose y hy h2 using fun i=> roster_clip R u hu hr.le (Q i) r δ (hq i) + let F : I×B→Wgt A := uncurry s + let G : J×B→Wgt A := uncurry y + obtain ⟨m,hm,p,hP⟩:= hl A (I×B) (pairW w unif) u F (pairW_law hw unif_law) hu (fun i j=> hs _ _ _) + refine ⟨m,hm,p,fun f g hf hg=>?_⟩ + let f' (i : I×J):= mcut R u (f i) + let g' (i : I×J):= mcut R u (g i) + choose a hA using fun i:I×J => h1 i.1 (f i) (hf i) + choose b hB using fun i:I×J => h2 i.2 (g i) (hg i) + let H (i:I×J) := |rebate u (F (i.1,a i)) (G (i.2,b i)) p| + let D:=pairW w v; have hD:= pairW_law hw hv + have he := rollup u w v hw hv hu F G a b R hr (fun i j=> hy _ _ _) p c hP + have hb : 0≤2*R := by linarith only [hr] + have hi (i:I×J) : |rebate u (f' i) (g' i) p|≤ H i+(δ*(4*R)) := by + let A' := F (i.1,a i); let B' := G (i.2,b i) + have h1 (j) : |g' i j|≤R := by + rw [abs_of_nonneg ((mcut_range _ _ _ hr.le j).1)] + exact (mcut_range _ _ _ hr.le j).2 + have h3 : |rebate u (f' i) (g' i) p - rebate u A' (g' i) p|≤ δ*(2*R) := by + exact (rebate_cost u _ _ A' p hu.nz R hr.le h1).trans (mul_le_mul_of_nonneg_right (hA i) hb) + have h4 : |rebate u A' (g' i) p - rebate u A' B' p|≤δ*(2*R) := by + rw [rebate_sym u A',rebate_sym u A'] + exact (rebate_cost u _ _ B' p hu.nz R hr.le (fun i=>hs _ _ _)).trans + (mul_le_mul_of_nonneg_right (hB i) hb) + let U:=rebate u A' B' p + let X:=rebate u (f' i) (g' i) p + have hz:= (abs_sub_le X (rebate u A' (g' i) p) U).trans (add_le_add h3 h4) + calc |X| = |(X-U)+U| := by rw [sub_add_cancel] + _ ≤ _ := ((abs_add_le _ _).trans (add_le_add_left hz _)).trans_eq (by + change _+ |U| = |U|+δ*(4*R) + ring) + refine (avg_mono hD.nz hi).trans ?_ + rw [avg_add,hD.avg_const] + exact (add_le_add_left he _).trans_eq (by + change t^2*(R*c)+δ*(4*R)=_ + unfold δ c; field_simp; ring) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CommonPredictions.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CommonPredictions.lean index 170c568ca322d1e92110ba2febc7f99c7765bd8e..a657b2444041d9a388addbe4a4740b2399dd7763 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CommonPredictions.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CommonPredictions.lean @@ -1,112 +1,112 @@ -import OAI.Combinatorics.HadwigerCounterexample.PointAtomVanishing -import OAI.Combinatorics.HadwigerCounterexample.UnaryPositivityBounds - -namespace OAI - -/-! # Common Predictions -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Function Finset Submodule -open scoped BigOperators -variable {p : Shape} {n N : ℕ} - -abbrev Augur (p : Shape) (N : ℕ) := ∀ t : Tag p.g,F→AtomKey (p:=p) t N→F -def mismatch (p : Shape) {n N : ℕ} (g : Augur p N) (F : Pdual p n) (l : Tag p.g) - (s : Label p.b) (f : Flavor p.g) (x : Orient p n N) (y : Knobs p.g n) := - F (useAtom p l s f y)≠ g l (dialed p l f y) (keyOne p l s (lit f l y) x) -def postulates (p : Shape) (o : Orient p n N) - (g : Augur p N) (w : Pdual p n) (E : Finset (Label p.b)) (δ : ℝ) := - ∀ s,s∉E→∀ l f, pr (spins p n) (fun i => mismatch p g w l s f o i)≤δ - -def yoke (p : Shape) (m : Mixer p n) (x : UnitType p n N) (i : Bool) - (u : Profile p n) (α : F) : Pdual p n := - innerP p x i + (Tsym m u + α • role p n) - -def claimed (p : Shape) (x : UnitType p n N) - (g : Bool→Augur p N) (m : Mixer p n) - (w : Bool→Profile p n) (α : Bool→F) (L : Bool → Finset (Label p.b)) (δ : ℝ) := - ∀ i,postulates p (onSide x i) (g i) (yoke p m x i (w i) (α i)) (L i) δ - -def silent (w : Pdual p n) := ∀ x, x∈Xspace p n → w x=0 - -def fixStar (p : Shape) (n : ℕ) (l : Tag p.g) : - Moment p n →ₗ[F] Profile p n := - cut p n ∘ₗ LinearMap.single F (fun _ : Tag p.g => Moment p n) l -theorem fix_one (p : Shape) (n : ℕ) (l : Tag p.g) (s : Label p.b) (z : Base p.g n) : - atom p l s z=fixStar p n l (mom p s z) := rfl - -theorem atom_silent {w : Pdual p n} - (h : ∀ l s z,allows l z → w (atom p l s z)=0) : silent w := by - classical - intro x hx - obtain ⟨u,hu,rfl⟩ := mem_X.mp hx - have he l : Wtag p n l≤LinearMap.ker (w∘ₗfixStar p n l) := by - refine Submodule.span_le.mpr ?_ - rintro x ⟨s,z,hz,rfl⟩ - exact h l s z hz - have ht : (cut p n u)=∑ i : Tag p.g,fixStar p n i (u i) := by - have hh := Finset.univ_sum_single u - unfold fixStar - simp_rw [LinearMap.comp_apply, ← map_sum (cut p n)] - exact congrArg (cut p n) (Eq.symm hh) - rw [ht,map_sum]; exact Finset.sum_eq_zero fun i _=>he _ (hu i) - -theorem shared_base (p : Shape) (hn : 2*p.r≤n) (hr : 1 ≤ p.r) (hg : 0 < p.g) : - ∃ (z : Base p.g n) (s : Label p.b), (∀ l, allows l z) ∧ eta p n (mom p s z)=1 := by - classical - let l : Tag p.g := ⟨0,hg⟩ - let f : Flavor p.g:= Flavor.sharedOnly - let i := (Sum.inr () : ProbeIdx p.g) - let v : Digest p.g := Pi.single i 1 - have hx : v.feasible l f := by - rintro (x|⟨⟩) _ - · exact Pi.single_eq_of_ne (by simp [i]) _ - exact (‹¬_› trivial).elim - have he := exists_of_pr_pos (spins_law p n).nz - ((scanPrice_pos p).trans_le (scan_fraction (n:=n) l f v hr hn hx)) - obtain ⟨x,h,_⟩ := he - refine ⟨lit f l x,0,fun i d t h k => ite_eq_right (by simp [f,Flavor.keeps]),?_⟩ - rw [←etaScan,h]; simp [v,Digest.sumBit,Digest.diagO,i] - -theorem atom_union (p : Shape) (n : ℕ) (z : Base p.g n) (s : Label p.b) : - ∑ i:Tag p.g,atom p i s z=0 := by - simp_rw [atom,←map_sum (cut p n)] - rw [Finset.univ_sum_single (fun i : Tag p.g => mom p s z)] - funext x - exact char_two (mom p s z) - -set_option maxHeartbeats 800000 in -theorem exact_vat (w : Pdual p n) (E : Finset (Label p.b)) (g : F) - (hE : (E.card:ℝ) w (useAtom p l s Flavor.full x)≠g *dialed p l Flavor.full x)<1/4) : - g=0∧ silent w := by - classical - let Q l := w ∘ₗ fixStar p n l - g • eta p n - have hi (l : Tag p.g) (s : Label p.b) (z : Base p.g n) : - Q l (mom p s z)= w (atom p l s z)-g*eta p n (mom p s z) := rfl - have hh (l s z) (hz : allows l z) : Q l (mom p s z)=0 := by - have he (s) (hs : s∉E) : - pr (spins p n) (fun x=> Q l (mom p s (lit Flavor.full l x))≠0)<1/4 := by - simp_rw [hi,←etaScan p l s Flavor.full] - simpa only [sub_ne_zero,useAtom,dialed] using h l s hs - exact vat_excluded z E (Q l) (fun i h=>vat_erase l i (Q l) (he i h) z hz) hE s - simp_rw [hi] at hh - have he l s z (h : allows l z) : w (atom p l s z) =g*eta p n (mom p s z) := - sub_eq_zero.mp (hh l s z h) - obtain ⟨z,s,hz,hb⟩ := shared_base p hn hr (by obtain ⟨_,hh⟩ := hj; omega) - have h0 : g=0 := by - have ht : w (∑ l:Tag p.g,atom p l s z)=0 := by rw [atom_union,map_zero] - rw [map_sum] at ht - simp_rw [he _ s z (hz _),hb,mul_one] at ht - simpa only [Finset.sum_const, Finset.card_univ,Tag,Fintype.card_fin, - odd_smul_bit hj] using ht - refine ⟨h0,atom_silent (fun i s z h=> (he i s z h).trans ?_)⟩ - rw [h0,zero_mul] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PointAtomVanishing +import OAI.Combinatorics.HadwigerCounterexample.UnaryPositivityBounds + +namespace OAI + +/-! # Common Predictions -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Function Finset Submodule +open scoped BigOperators +variable {p : Shape} {n N : ℕ} + +abbrev Augur (p : Shape) (N : ℕ) := ∀ t : Tag p.g,F→AtomKey (p:=p) t N→F +def mismatch (p : Shape) {n N : ℕ} (g : Augur p N) (F : Pdual p n) (l : Tag p.g) + (s : Label p.b) (f : Flavor p.g) (x : Orient p n N) (y : Knobs p.g n) := + F (useAtom p l s f y)≠ g l (dialed p l f y) (keyOne p l s (lit f l y) x) +def postulates (p : Shape) (o : Orient p n N) + (g : Augur p N) (w : Pdual p n) (E : Finset (Label p.b)) (δ : ℝ) := + ∀ s,s∉E→∀ l f, pr (spins p n) (fun i => mismatch p g w l s f o i)≤δ + +def yoke (p : Shape) (m : Mixer p n) (x : UnitType p n N) (i : Bool) + (u : Profile p n) (α : F) : Pdual p n := + innerP p x i + (Tsym m u + α • role p n) + +def claimed (p : Shape) (x : UnitType p n N) + (g : Bool→Augur p N) (m : Mixer p n) + (w : Bool→Profile p n) (α : Bool→F) (L : Bool → Finset (Label p.b)) (δ : ℝ) := + ∀ i,postulates p (onSide x i) (g i) (yoke p m x i (w i) (α i)) (L i) δ + +def silent (w : Pdual p n) := ∀ x, x∈Xspace p n → w x=0 + +def fixStar (p : Shape) (n : ℕ) (l : Tag p.g) : + Moment p n →ₗ[F] Profile p n := + cut p n ∘ₗ LinearMap.single F (fun _ : Tag p.g => Moment p n) l +theorem fix_one (p : Shape) (n : ℕ) (l : Tag p.g) (s : Label p.b) (z : Base p.g n) : + atom p l s z=fixStar p n l (mom p s z) := rfl + +theorem atom_silent {w : Pdual p n} + (h : ∀ l s z,allows l z → w (atom p l s z)=0) : silent w := by + classical + intro x hx + obtain ⟨u,hu,rfl⟩ := mem_X.mp hx + have he l : Wtag p n l≤LinearMap.ker (w∘ₗfixStar p n l) := by + refine Submodule.span_le.mpr ?_ + rintro x ⟨s,z,hz,rfl⟩ + exact h l s z hz + have ht : (cut p n u)=∑ i : Tag p.g,fixStar p n i (u i) := by + have hh := Finset.univ_sum_single u + unfold fixStar + simp_rw [LinearMap.comp_apply, ← map_sum (cut p n)] + exact congrArg (cut p n) (Eq.symm hh) + rw [ht,map_sum]; exact Finset.sum_eq_zero fun i _=>he _ (hu i) + +theorem shared_base (p : Shape) (hn : 2*p.r≤n) (hr : 1 ≤ p.r) (hg : 0 < p.g) : + ∃ (z : Base p.g n) (s : Label p.b), (∀ l, allows l z) ∧ eta p n (mom p s z)=1 := by + classical + let l : Tag p.g := ⟨0,hg⟩ + let f : Flavor p.g:= Flavor.sharedOnly + let i := (Sum.inr () : ProbeIdx p.g) + let v : Digest p.g := Pi.single i 1 + have hx : v.feasible l f := by + rintro (x|⟨⟩) _ + · exact Pi.single_eq_of_ne (by simp [i]) _ + exact (‹¬_› trivial).elim + have he := exists_of_pr_pos (spins_law p n).nz + ((scanPrice_pos p).trans_le (scan_fraction (n:=n) l f v hr hn hx)) + obtain ⟨x,h,_⟩ := he + refine ⟨lit f l x,0,fun i d t h k => ite_eq_right (by simp [f,Flavor.keeps]),?_⟩ + rw [←etaScan,h]; simp [v,Digest.sumBit,Digest.diagO,i] + +theorem atom_union (p : Shape) (n : ℕ) (z : Base p.g n) (s : Label p.b) : + ∑ i:Tag p.g,atom p i s z=0 := by + simp_rw [atom,←map_sum (cut p n)] + rw [Finset.univ_sum_single (fun i : Tag p.g => mom p s z)] + funext x + exact char_two (mom p s z) + +set_option maxHeartbeats 800000 in +theorem exact_vat (w : Pdual p n) (E : Finset (Label p.b)) (g : F) + (hE : (E.card:ℝ) w (useAtom p l s Flavor.full x)≠g *dialed p l Flavor.full x)<1/4) : + g=0∧ silent w := by + classical + let Q l := w ∘ₗ fixStar p n l - g • eta p n + have hi (l : Tag p.g) (s : Label p.b) (z : Base p.g n) : + Q l (mom p s z)= w (atom p l s z)-g*eta p n (mom p s z) := rfl + have hh (l s z) (hz : allows l z) : Q l (mom p s z)=0 := by + have he (s) (hs : s∉E) : + pr (spins p n) (fun x=> Q l (mom p s (lit Flavor.full l x))≠0)<1/4 := by + simp_rw [hi,←etaScan p l s Flavor.full] + simpa only [sub_ne_zero,useAtom,dialed] using h l s hs + exact vat_excluded z E (Q l) (fun i h=>vat_erase l i (Q l) (he i h) z hz) hE s + simp_rw [hi] at hh + have he l s z (h : allows l z) : w (atom p l s z) =g*eta p n (mom p s z) := + sub_eq_zero.mp (hh l s z h) + obtain ⟨z,s,hz,hb⟩ := shared_base p hn hr (by obtain ⟨_,hh⟩ := hj; omega) + have h0 : g=0 := by + have ht : w (∑ l:Tag p.g,atom p l s z)=0 := by rw [atom_union,map_zero] + rw [map_sum] at ht + simp_rw [he _ s z (hz _),hb,mul_one] at ht + simpa only [Finset.sum_const, Finset.card_univ,Tag,Fintype.card_fin, + odd_smul_bit hj] using ht + refine ⟨h0,atom_silent (fun i s z h=> (he i s z h).trans ?_)⟩ + rw [h0,zero_mul] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CompatibleOptionRealization.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CompatibleOptionRealization.lean index 94755ad10a0519bb23fa15cc4fc0f60f80a3c8d5..b52b6fa5acf7896c2cd4622e58d9f2759f1ccbee 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CompatibleOptionRealization.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CompatibleOptionRealization.lean @@ -1,130 +1,130 @@ -import OAI.Combinatorics.HadwigerCounterexample.PairedEventBounds - -namespace OAI - -/-! # Compatible Option Realization -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Function Module LinearMap -open scoped BigOperators -variable {p:Shape} {n N M K s0:ℕ} -namespace StatusAnalysis - -variable {q:Format} {d e: Rates} {b:Bool} -abbrev Stalls (p:Shape) := Bool→Finset (Label p.b) - -def booths (p:Shape) (K:ℕ) (s: Plan p n) (H:Stalls p) := - (∀ i,(H i).card≤frameBills p.g K) ∧ - ∀ i j, protectedBy p (sPin s j i) (qorth K) (H i) -theorem buildBooths (K:ℕ) (s:Plan p n) (h:planRank s≤K) - (hj:(K+1)*qorth K≤p.j+1) : - ∃ H,booths p K s H := by - classical - choose H hH hG using fun i : Bool=> pin_protection s i K (qorth K) h hj - exact ⟨H,hH,hG⟩ - -theorem shelter (K :ℕ) (S:Pin p n N) (t : Quill p q d b) (z : Tagging p (Messenger q)) (H:Stalls p) - (h:booths p K S.sp H) (hp : Injective t.sel) - (ht:∀ i:Messenger q,t.sel i∉H (parcel b i)) - (hg : ∀ i,1≤q i ∧ q i≤7) : t.penSpace z S K := by - intro x i - let v:=(t.pen z).draw x - refine ⟨H i,h.2 i,fun j hj=>?_,?_,hp.injOn⟩ - · have he : parcel b j=i := Finset.mem_filter.mp hj|>.2 - rw [←he]; exact ht j - exact (Volley.here_card v (shots_ok b v rfl hg) i).trans (by unfold qorth; omega) - -theorem sizedCharts (K:ℕ) (w:LeafMixture p n N) (t:Station p n N K w) (ht:t.bank) - (i:w.T) (h:planRank (w.pin i.val).sp≤K) : - ∃ d:Stakes K,charted (t.cAxes i (toRates d)) (w.pin i.val).sp := by - let s:=(w.pin i.val).sp - let d (i:Nodes):= dim (effective s i) - have hd i : d i < K^2+1 := Nat.lt_of_le_of_lt - ((effective_dim s i).trans (by gcongr)) (Nat.lt_succ_self _) - exact ⟨fun i=>⟨d i,hd i⟩,ht.1 i⟩ - -structure Fabric (p:Shape) (q:Format) (d:Rates) (b:Bool) where - sel : Messenger q → Label p.b - flav : Messenger q → Flavor p.g - amp : Amounts p q d b - -namespace Fabric -variable (w:Fabric p q d b) (t:Tagging p (Messenger q)) -def hang (s:Script p (Messenger q)) : Quill p q d b := - ⟨w.sel,w.flav,w.amp,s⟩ -def up (w:Fabric p q d b) (t:Tagging p (Messenger q)) (z: Messenger q→F) := - (w.hang 0).moral t z - -end Fabric - -variable {i j:Bool} {L:ℕ} -set_option maxHeartbeats 1200000 in -theorem optionVia (q:Format) (d e : Rates) (s t:Pin p n N) (T:Cross p n) (K:ℕ) - (ha: tableInj s.sp t.sp T) (hb : tableInj t.sp s.sp (reciprocal p T)) - (p':Tagging p (Messenger q)) (x:Charts p n d) (y:Charts p n e) - (hx:charted x s.sp) (hy:charted y t.sp) - (f:Fabric p q d true) (g:Fabric p q e false) - (hs h:Stalls p) (hm:booths p K s.sp hs) (hu : booths p K t.sp h) - (hf:∀ i,f.sel i∉ hs (parcel true i)) (hg:∀ i,g.sel i∉ h (parcel false i)) - (z:Messenger q→F) (hF:f.up p' z)(hG:g.up p' z) - (hj : 1≤p.J) (h2: 2≤p.g) (h₀:∀ i,1≤q i∧q i≤7) - (he:speak _ _ (sendSum z f.amp g.amp)=(hailing p x y T,0)) : - ∃ (a b:Script p (Messenger q)),Typus.chances ⟨p',z,f.hang a,g.hang b⟩ x y s t T K := by - obtain ⟨hQ,hR,hL,hS⟩:= (spoken x y T z f.amp g.amp).mp he - obtain ⟨a,ha'⟩:= proclaim_script true f.amp g.amp p' y (reciprocal p T) hR (fun i=>(h₀ i).1) - hS h2 hj - have hh : rhyme g.amp f.amp := fun i=> (add_comm ..).trans (hR i) - obtain ⟨b,hb'⟩:= proclaim_script false g.amp f.amp p' x T hh (fun i=>(h₀ i).1) - hL h2 hj - exact ⟨a,b, ⟨h₀,hF,hG,hQ,hR,ha',hb'⟩,⟨hx,shelter K s (f.hang a) p' hs hm hF.1 hf h₀,hL,ha⟩, - ⟨hy,shelter K t (g.hang b) p' h hu hG.1 hg h₀,hS,hb⟩⟩ - -def berthTicket (a b:Pin p n N) (T: Cross p n) - (x:UnitType p n N × UnitType p n N) := - tableInj a.sp b.sp T ∧ tableInj b.sp a.sp (reciprocal p T) - ∧ fitsTable a.sp b.sp T (actual p x.1 x.2) - -theorem issueTicket (x y:UnitType p n N) (w : LeafMixture p n N) (t:Station p n N K w) - (i j:w.T) (ha:apart w.T) - (hx:x∈i.val) (hy:y∈j.val) (ht:t.bank) - (he : secureAt p w.rooting (x,y)) : - ∃ k, berthTicket (w.pin i.val) (w.pin j.val) (t.mails i j k) (x,y) := by - obtain ⟨k,hk⟩:=ht.2 i j (actual p x y) - obtain ⟨h1,h2⟩:=he - let a:= w.pin i.val; let b:= w.pin j.val - have hh : w.rooting x=a.sp:= congrArg Pin.sp (LeafMixture.poller_eq w ha i.property hx) - have hg : w.rooting y=b.sp:= congrArg Pin.sp (LeafMixture.poller_eq w ha j.property hy) - change tableInj (w.rooting x) (w.rooting y) (actual p x y) at h1 - change tableInj (w.rooting y) (w.rooting x) (actual p y x) at h2 - rw [hh,hg] at h1 h2 - rw [← reciprocal_actual] at h2 - exact ⟨k, fits_inj hk h1,fits_inj (fits_recip hk) h2,hk⟩ - -theorem berth_flags (a b:Pin p n N) (T:Cross p n) {x:UnitType p n N × UnitType p n N} - (h:berthTicket a b T x) (ha:a.agree x.1) (hb:b.agree x.2) : - tableFlag a b T x.1 ∧ tableFlag b a (reciprocal p T) x.2 := by - have hg:=fits_recip h.2.2; rw [reciprocal_actual] at hg - exact ⟨fits_flag T _ a b x.1 h.2.2 (flag_actual _ _ hb), - fits_flag _ _ b a x.2 hg (flag_actual _ _ ha)⟩ - -def cardTone (m:BMark p n N) (x:UnitType p n N) (T:Cross p n) (j:Bool) : F := - ∑ i:Bool,contract p T i j (m x i) - -theorem actualTone (m:BMark p n N) (a b : UnitType p n N) (j:Bool) : - cardTone m a (actual p a b) j = tone p b (unary j) (delta m a) := by - rw [lone] - unfold cardTone delta - rw [map_add,Fintype.sum_bool] - simp_rw [contract_actual]; rfl -theorem fitsTone {w v: Plan p n} {T U:Cross p n} - (m:BMark p n N) (x:UnitType p n N) - (h:fitsTable w v T U) (hx:∀ i,m x i∈effective w i) (j) : - cardTone m x T j=cardTone m x U j := - Finset.sum_congr rfl (fun i _=>fits_contract h i j _ (hx i)) -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PairedEventBounds + +namespace OAI + +/-! # Compatible Option Realization -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Function Module LinearMap +open scoped BigOperators +variable {p:Shape} {n N M K s0:ℕ} +namespace StatusAnalysis + +variable {q:Format} {d e: Rates} {b:Bool} +abbrev Stalls (p:Shape) := Bool→Finset (Label p.b) + +def booths (p:Shape) (K:ℕ) (s: Plan p n) (H:Stalls p) := + (∀ i,(H i).card≤frameBills p.g K) ∧ + ∀ i j, protectedBy p (sPin s j i) (qorth K) (H i) +theorem buildBooths (K:ℕ) (s:Plan p n) (h:planRank s≤K) + (hj:(K+1)*qorth K≤p.j+1) : + ∃ H,booths p K s H := by + classical + choose H hH hG using fun i : Bool=> pin_protection s i K (qorth K) h hj + exact ⟨H,hH,hG⟩ + +theorem shelter (K :ℕ) (S:Pin p n N) (t : Quill p q d b) (z : Tagging p (Messenger q)) (H:Stalls p) + (h:booths p K S.sp H) (hp : Injective t.sel) + (ht:∀ i:Messenger q,t.sel i∉H (parcel b i)) + (hg : ∀ i,1≤q i ∧ q i≤7) : t.penSpace z S K := by + intro x i + let v:=(t.pen z).draw x + refine ⟨H i,h.2 i,fun j hj=>?_,?_,hp.injOn⟩ + · have he : parcel b j=i := Finset.mem_filter.mp hj|>.2 + rw [←he]; exact ht j + exact (Volley.here_card v (shots_ok b v rfl hg) i).trans (by unfold qorth; omega) + +theorem sizedCharts (K:ℕ) (w:LeafMixture p n N) (t:Station p n N K w) (ht:t.bank) + (i:w.T) (h:planRank (w.pin i.val).sp≤K) : + ∃ d:Stakes K,charted (t.cAxes i (toRates d)) (w.pin i.val).sp := by + let s:=(w.pin i.val).sp + let d (i:Nodes):= dim (effective s i) + have hd i : d i < K^2+1 := Nat.lt_of_le_of_lt + ((effective_dim s i).trans (by gcongr)) (Nat.lt_succ_self _) + exact ⟨fun i=>⟨d i,hd i⟩,ht.1 i⟩ + +structure Fabric (p:Shape) (q:Format) (d:Rates) (b:Bool) where + sel : Messenger q → Label p.b + flav : Messenger q → Flavor p.g + amp : Amounts p q d b + +namespace Fabric +variable (w:Fabric p q d b) (t:Tagging p (Messenger q)) +def hang (s:Script p (Messenger q)) : Quill p q d b := + ⟨w.sel,w.flav,w.amp,s⟩ +def up (w:Fabric p q d b) (t:Tagging p (Messenger q)) (z: Messenger q→F) := + (w.hang 0).moral t z + +end Fabric + +variable {i j:Bool} {L:ℕ} +set_option maxHeartbeats 1200000 in +theorem optionVia (q:Format) (d e : Rates) (s t:Pin p n N) (T:Cross p n) (K:ℕ) + (ha: tableInj s.sp t.sp T) (hb : tableInj t.sp s.sp (reciprocal p T)) + (p':Tagging p (Messenger q)) (x:Charts p n d) (y:Charts p n e) + (hx:charted x s.sp) (hy:charted y t.sp) + (f:Fabric p q d true) (g:Fabric p q e false) + (hs h:Stalls p) (hm:booths p K s.sp hs) (hu : booths p K t.sp h) + (hf:∀ i,f.sel i∉ hs (parcel true i)) (hg:∀ i,g.sel i∉ h (parcel false i)) + (z:Messenger q→F) (hF:f.up p' z)(hG:g.up p' z) + (hj : 1≤p.J) (h2: 2≤p.g) (h₀:∀ i,1≤q i∧q i≤7) + (he:speak _ _ (sendSum z f.amp g.amp)=(hailing p x y T,0)) : + ∃ (a b:Script p (Messenger q)),Typus.chances ⟨p',z,f.hang a,g.hang b⟩ x y s t T K := by + obtain ⟨hQ,hR,hL,hS⟩:= (spoken x y T z f.amp g.amp).mp he + obtain ⟨a,ha'⟩:= proclaim_script true f.amp g.amp p' y (reciprocal p T) hR (fun i=>(h₀ i).1) + hS h2 hj + have hh : rhyme g.amp f.amp := fun i=> (add_comm ..).trans (hR i) + obtain ⟨b,hb'⟩:= proclaim_script false g.amp f.amp p' x T hh (fun i=>(h₀ i).1) + hL h2 hj + exact ⟨a,b, ⟨h₀,hF,hG,hQ,hR,ha',hb'⟩,⟨hx,shelter K s (f.hang a) p' hs hm hF.1 hf h₀,hL,ha⟩, + ⟨hy,shelter K t (g.hang b) p' h hu hG.1 hg h₀,hS,hb⟩⟩ + +def berthTicket (a b:Pin p n N) (T: Cross p n) + (x:UnitType p n N × UnitType p n N) := + tableInj a.sp b.sp T ∧ tableInj b.sp a.sp (reciprocal p T) + ∧ fitsTable a.sp b.sp T (actual p x.1 x.2) + +theorem issueTicket (x y:UnitType p n N) (w : LeafMixture p n N) (t:Station p n N K w) + (i j:w.T) (ha:apart w.T) + (hx:x∈i.val) (hy:y∈j.val) (ht:t.bank) + (he : secureAt p w.rooting (x,y)) : + ∃ k, berthTicket (w.pin i.val) (w.pin j.val) (t.mails i j k) (x,y) := by + obtain ⟨k,hk⟩:=ht.2 i j (actual p x y) + obtain ⟨h1,h2⟩:=he + let a:= w.pin i.val; let b:= w.pin j.val + have hh : w.rooting x=a.sp:= congrArg Pin.sp (LeafMixture.poller_eq w ha i.property hx) + have hg : w.rooting y=b.sp:= congrArg Pin.sp (LeafMixture.poller_eq w ha j.property hy) + change tableInj (w.rooting x) (w.rooting y) (actual p x y) at h1 + change tableInj (w.rooting y) (w.rooting x) (actual p y x) at h2 + rw [hh,hg] at h1 h2 + rw [← reciprocal_actual] at h2 + exact ⟨k, fits_inj hk h1,fits_inj (fits_recip hk) h2,hk⟩ + +theorem berth_flags (a b:Pin p n N) (T:Cross p n) {x:UnitType p n N × UnitType p n N} + (h:berthTicket a b T x) (ha:a.agree x.1) (hb:b.agree x.2) : + tableFlag a b T x.1 ∧ tableFlag b a (reciprocal p T) x.2 := by + have hg:=fits_recip h.2.2; rw [reciprocal_actual] at hg + exact ⟨fits_flag T _ a b x.1 h.2.2 (flag_actual _ _ hb), + fits_flag _ _ b a x.2 hg (flag_actual _ _ ha)⟩ + +def cardTone (m:BMark p n N) (x:UnitType p n N) (T:Cross p n) (j:Bool) : F := + ∑ i:Bool,contract p T i j (m x i) + +theorem actualTone (m:BMark p n N) (a b : UnitType p n N) (j:Bool) : + cardTone m a (actual p a b) j = tone p b (unary j) (delta m a) := by + rw [lone] + unfold cardTone delta + rw [map_add,Fintype.sum_bool] + simp_rw [contract_actual]; rfl +theorem fitsTone {w v: Plan p n} {T U:Cross p n} + (m:BMark p n N) (x:UnitType p n N) + (h:fitsTable w v T U) (hx:∀ i,m x i∈effective w i) (j) : + cardTone m x T j=cardTone m x U j := + Finset.sum_congr rfl (fun i _=>fits_contract h i j _ (hx i)) +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CompatiblePairTests.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CompatiblePairTests.lean index f30cfd3d5b964387ee5876c315cd9e09241abe07..fd059217f362f12ce8651970f3a7dff9ae31c3b1 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CompatiblePairTests.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CompatiblePairTests.lean @@ -1,105 +1,105 @@ -import OAI.Combinatorics.HadwigerCounterexample.PredictionClassBounds - -namespace OAI - -/-! # Compatible Pair Tests -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Function Module LinearMap Matrix -open scoped BigOperators Topology -open Template -namespace StatusAnalysis -open PreparationParameters Station PredictionClass Club Guild DualAnalysis -variable {p:Shape} {n N M r s0:ℕ} - {w:rhythms p M} {b:PreparationParameters} - -set_option maxHeartbeats 1800000 in -theorem foretold (w:rhythms p M) (m:cycleM p) (x:Sketch p M) - (v:Station p n (M*n) b.pins (w n)) (hv:v.bank) - (U:Wgt (UnitType p n (M*n))) (h:Lead U (w n) (m n) b) - (hE:AnalyticParameters p M b s0) - (hm:(w n).within (engrave x b m w n)) - (hn:2*p.r≤n) (Y:Silhouette p (M*n) r) (f:Bool→Pulsar p r) - {τ ε δ η a d0:ℝ} (hh: hue x.c Y f (fun i=>x.g i n) x.α τ) - (hε:0<ε) (hp:Jubilee p b.pins ε η) - (hB:supportBudget p b.pins η a) - (hz:x.ε n ≤scanPrice p*ε) (ht:10*ε≤τ) (hT:2*τ<1) - (hF:Beams b (m n) Y (w n) U v a ε δ d0) (i : ViewPair p n (M*n) (w n)) - (hx:cirque (w n) U i ≠0) - (hg1:gauze p δ δ Y (m n) b.pins i.1.2) (hg2:gauze p δ δ Y (m n) b.pins i.2.2) - (hC:matchProg x n (i.1.2,i.2.2)) - (hS:secureAt p (w n).rooting (i.1.2,i.2.2)) : - eligiblePair v (m n) i.1 i.2 Y a := by - classical - let s:=w n; let μ:= U; let K:=b.pins - let X:=i.1.2; let Z:=i.2.2 - let j:=i.1.1; let k:=i.2.1 - let L:=troupe s μ - have hs : L i.1≠0:=left_ne_zero_of_mul hx - have hl : L i.2 ≠0:=right_ne_zero_of_mul hx - have hX := troupe_home h i.1 hs - have hZ:= troupe_home h i.2 hl - have hL i:= (h.strength.leaf _ (Subtype.prop (show s.T from i))).bound - obtain ⟨g,hg⟩:= ready_loupe s v hv hE hL - let d:= g.r j; let e:=g.r k - let t:=v.cAxes j (toRates d); let u:=v.cAxes k (toRates e) - let A:=g.H j; let B:=g.H k - let m':=x.m n - let F:=x.L n X; let H:=x.L n Z - let P:= A⊔F; let Q:=B⊔ H - obtain ⟨⟨h1,h2⟩,h3,h4⟩:=hm _ j.property X hX.1 - obtain ⟨⟨h1',h2'⟩,h3',h4'⟩:=hm _ k.property Z hZ.1 - let M0:=s.pin j.val; let M1:=s.pin k.val - have he (i):m' X i∈ effective M0.sp i:= (hX.2.1 ▸ (h1 i).2) - have he' i:m' Z i∈effective M1.sp i:= (hZ.2.1 ▸ (h1' i).2) - choose T hP using fun i=> show m' X i∈LinearMap.range (t i) from - (hg.charts j i).1.symm ▸ he i - choose S hQ using fun i=> show m' Z i∈ LinearMap.range (u i) from - (hg.charts k i).1.symm ▸ he' i - let Γ:PredictionData p (toRates d) (toRates e) r := ⟨x.α,f,T,S⟩ - have ht0:= hE.enter.first - let M' := m n - let D:=wisp p Y; let X0:=wake p Y M' X t; let X1:=wake p Y M' Z u - let β:=trimBeta p K - let C:=stellar D X0 X1 η P Q - have hk0 i t:=Nat.lt_succ_iff.mp (g.r i t).isLt - have hA: reports p r D X0 β δ:=routeLive s g v hg M' hE hn i.1 Y δ hF.haze.1 (hL _) hg1 - have hB1: reports p r D X1 β δ:=routeLive s g v hg M' hE hn i.2 Y δ hF.haze.1 (hL _) hg2 - have hR := boothseek b _ (g.H j) F (hg.baseline j) hE (fun i=>(h1 i).1) - have hR' := boothseek b _ (g.H k) H (hg.baseline k) hE (fun i=>(h1' i).1) - have hG: rich C:= plenitude hF.soft hA hB1 ht0.hG P Q hR hR' (trimBeta_pos ..) hp.pos - hp.sturdyR (hk0 _) (hk0 _) - obtain ⟨E,hE0,hr⟩:=stable C hG - obtain ⟨y,hy⟩:= issueTicket X Z s v j k h.strength.part hX.1 hZ.1 hv hS - let U0:=v.mails j k y - have hQ': x.c.compatible x.α (glint p (m' X)) (cardTone m' X U0,cardTone m' Z - (reciprocal p U0)) := by - change glint p _=_ at h3 - have he1 l: cardTone m' X U0 l=(quench p (delta m') (X,Z)).1 l:= - (fitsTone m' X hy.2.2 he l).trans (actualTone m' X Z l) - have he2 l:cardTone m' Z (reciprocal p U0) l=(quench p (delta m') (X,Z)).2 l:= by - have hg := fits_recip hy.2.2; rw [reciprocal_actual] at hg - exact (fitsTone m' Z hg he' l).trans (actualTone m' Z X l) - rw [funext he1,funext he2,h3]; exact hC - have hc: countStory p K η δ ε β D:=⟨hF.soft,(trimBeta_pos ..).le,hε.le,hp.pos.le, - hp.book,hp.low⟩ - have hv : Γ.colored D X0 X1 P Q (2*ε):= by - constructor - · exact crew_praise p x.c Y f (fun i=>x.g i n) x.α τ hh (m n) t T m' X F P le_sup_right - hP hε.le hF.haze.2 hE hn (fun i j hj k f=>(h2 i j hj k f).trans hz) h4 hg1 - exact crew_praise p x.c Y f (fun i=>x.g i n) x.α τ hh (m n) u S m' Z H Q le_sup_right - hQ hε.le hF.haze.2 hE hn (fun i j hj k f=>(h2' i j hj k f).trans hz) h4' hg2 - have hZ0 := laysScore p K Y (m n) D X Z m' (toRates d) (toRates e) t u x.c Γ P Q - E η ε β δ τ hP hQ (paintChorus _ _ f _ x.α τ hh T S) (by linarith only [hε,ht]) hT hc - hA hB1 hv (hk0 _) (hk0 _) ht0.hG ht hR hR' hE0 U0 (h3.trans h3'.symm) hQ' hG - exact inform (w n) v _ Y i.1 i.2 hX.2.2.1 hZ.2.2.1 hX.2.2.2 hZ.2.2.2 d e (hg.charts _) - (hg.charts _) hB A B (hg.baseline _) (hg.baseline _) P Q le_sup_left le_sup_left ht0.hG - hE.jump hp.pos y hy E hr hZ0 - -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PredictionClassBounds + +namespace OAI + +/-! # Compatible Pair Tests -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Function Module LinearMap Matrix +open scoped BigOperators Topology +open Template +namespace StatusAnalysis +open PreparationParameters Station PredictionClass Club Guild DualAnalysis +variable {p:Shape} {n N M r s0:ℕ} + {w:rhythms p M} {b:PreparationParameters} + +set_option maxHeartbeats 1800000 in +theorem foretold (w:rhythms p M) (m:cycleM p) (x:Sketch p M) + (v:Station p n (M*n) b.pins (w n)) (hv:v.bank) + (U:Wgt (UnitType p n (M*n))) (h:Lead U (w n) (m n) b) + (hE:AnalyticParameters p M b s0) + (hm:(w n).within (engrave x b m w n)) + (hn:2*p.r≤n) (Y:Silhouette p (M*n) r) (f:Bool→Pulsar p r) + {τ ε δ η a d0:ℝ} (hh: hue x.c Y f (fun i=>x.g i n) x.α τ) + (hε:0<ε) (hp:Jubilee p b.pins ε η) + (hB:supportBudget p b.pins η a) + (hz:x.ε n ≤scanPrice p*ε) (ht:10*ε≤τ) (hT:2*τ<1) + (hF:Beams b (m n) Y (w n) U v a ε δ d0) (i : ViewPair p n (M*n) (w n)) + (hx:cirque (w n) U i ≠0) + (hg1:gauze p δ δ Y (m n) b.pins i.1.2) (hg2:gauze p δ δ Y (m n) b.pins i.2.2) + (hC:matchProg x n (i.1.2,i.2.2)) + (hS:secureAt p (w n).rooting (i.1.2,i.2.2)) : + eligiblePair v (m n) i.1 i.2 Y a := by + classical + let s:=w n; let μ:= U; let K:=b.pins + let X:=i.1.2; let Z:=i.2.2 + let j:=i.1.1; let k:=i.2.1 + let L:=troupe s μ + have hs : L i.1≠0:=left_ne_zero_of_mul hx + have hl : L i.2 ≠0:=right_ne_zero_of_mul hx + have hX := troupe_home h i.1 hs + have hZ:= troupe_home h i.2 hl + have hL i:= (h.strength.leaf _ (Subtype.prop (show s.T from i))).bound + obtain ⟨g,hg⟩:= ready_loupe s v hv hE hL + let d:= g.r j; let e:=g.r k + let t:=v.cAxes j (toRates d); let u:=v.cAxes k (toRates e) + let A:=g.H j; let B:=g.H k + let m':=x.m n + let F:=x.L n X; let H:=x.L n Z + let P:= A⊔F; let Q:=B⊔ H + obtain ⟨⟨h1,h2⟩,h3,h4⟩:=hm _ j.property X hX.1 + obtain ⟨⟨h1',h2'⟩,h3',h4'⟩:=hm _ k.property Z hZ.1 + let M0:=s.pin j.val; let M1:=s.pin k.val + have he (i):m' X i∈ effective M0.sp i:= (hX.2.1 ▸ (h1 i).2) + have he' i:m' Z i∈effective M1.sp i:= (hZ.2.1 ▸ (h1' i).2) + choose T hP using fun i=> show m' X i∈LinearMap.range (t i) from + (hg.charts j i).1.symm ▸ he i + choose S hQ using fun i=> show m' Z i∈ LinearMap.range (u i) from + (hg.charts k i).1.symm ▸ he' i + let Γ:PredictionData p (toRates d) (toRates e) r := ⟨x.α,f,T,S⟩ + have ht0:= hE.enter.first + let M' := m n + let D:=wisp p Y; let X0:=wake p Y M' X t; let X1:=wake p Y M' Z u + let β:=trimBeta p K + let C:=stellar D X0 X1 η P Q + have hk0 i t:=Nat.lt_succ_iff.mp (g.r i t).isLt + have hA: reports p r D X0 β δ:=routeLive s g v hg M' hE hn i.1 Y δ hF.haze.1 (hL _) hg1 + have hB1: reports p r D X1 β δ:=routeLive s g v hg M' hE hn i.2 Y δ hF.haze.1 (hL _) hg2 + have hR := boothseek b _ (g.H j) F (hg.baseline j) hE (fun i=>(h1 i).1) + have hR' := boothseek b _ (g.H k) H (hg.baseline k) hE (fun i=>(h1' i).1) + have hG: rich C:= plenitude hF.soft hA hB1 ht0.hG P Q hR hR' (trimBeta_pos ..) hp.pos + hp.sturdyR (hk0 _) (hk0 _) + obtain ⟨E,hE0,hr⟩:=stable C hG + obtain ⟨y,hy⟩:= issueTicket X Z s v j k h.strength.part hX.1 hZ.1 hv hS + let U0:=v.mails j k y + have hQ': x.c.compatible x.α (glint p (m' X)) (cardTone m' X U0,cardTone m' Z + (reciprocal p U0)) := by + change glint p _=_ at h3 + have he1 l: cardTone m' X U0 l=(quench p (delta m') (X,Z)).1 l:= + (fitsTone m' X hy.2.2 he l).trans (actualTone m' X Z l) + have he2 l:cardTone m' Z (reciprocal p U0) l=(quench p (delta m') (X,Z)).2 l:= by + have hg := fits_recip hy.2.2; rw [reciprocal_actual] at hg + exact (fitsTone m' Z hg he' l).trans (actualTone m' Z X l) + rw [funext he1,funext he2,h3]; exact hC + have hc: countStory p K η δ ε β D:=⟨hF.soft,(trimBeta_pos ..).le,hε.le,hp.pos.le, + hp.book,hp.low⟩ + have hv : Γ.colored D X0 X1 P Q (2*ε):= by + constructor + · exact crew_praise p x.c Y f (fun i=>x.g i n) x.α τ hh (m n) t T m' X F P le_sup_right + hP hε.le hF.haze.2 hE hn (fun i j hj k f=>(h2 i j hj k f).trans hz) h4 hg1 + exact crew_praise p x.c Y f (fun i=>x.g i n) x.α τ hh (m n) u S m' Z H Q le_sup_right + hQ hε.le hF.haze.2 hE hn (fun i j hj k f=>(h2' i j hj k f).trans hz) h4' hg2 + have hZ0 := laysScore p K Y (m n) D X Z m' (toRates d) (toRates e) t u x.c Γ P Q + E η ε β δ τ hP hQ (paintChorus _ _ f _ x.α τ hh T S) (by linarith only [hε,ht]) hT hc + hA hB1 hv (hk0 _) (hk0 _) ht0.hG ht hR hR' hE0 U0 (h3.trans h3'.symm) hQ' hG + exact inform (w n) v _ Y i.1 i.2 hX.2.2.1 hZ.2.2.1 hX.2.2.2 hZ.2.2.2 d e (hg.charts _) + (hg.charts _) hB A B (hg.baseline _) (hg.baseline _) P Q le_sup_left le_sup_left ht0.hG + hE.jump hp.pos y hy E hr hZ0 + +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CompatibleTableEvents.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CompatibleTableEvents.lean index a6ce626a8807337093233d3ceecfa0dd20569331..959cfd2297d04e5e45e855339a912d0c60e1c627 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CompatibleTableEvents.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CompatibleTableEvents.lean @@ -1,149 +1,149 @@ -import OAI.Combinatorics.HadwigerCounterexample.RareTestEvents - -namespace OAI - -/-! # Compatible Table Events -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix LinearMap Function -open scoped BigOperators Topology -open Template -namespace StatusAnalysis -open PreparationParameters PredictionClass - -variable {p:Shape} {n M K s0 N :ℕ} {w:LeafMixture p n N} {q:PreparationParameters} - -structure Settled (t: LeafMixture p n N) (m:Mixer p n) (q:PreparationParameters) - (U : Wgt (UnitType p n N)) (z:BMark p n N) (k:F) : Prop where - readyC : - IsLaw U ∧ t.strength U (usual p m N) q.leafNew (2*q.ζ) q.pins ∧ - t.within (fun o=>frameSide p m o ∧ exactInk p m z o ∧ - (∀ i,z o i∈effective (t.rooting o) i) ∧ glint p (z o)=k) - hard : q.hardened p N t z - -def shimmer (z:BMark p n N) (r:F) (x:UnitType p n N× UnitType p n N) := - quench p (delta z) x=repeatQ r - -variable (v: Station p n N q.pins w) (i j:w.T) - (U:Wgt (UnitType p n N)) (m:Mixer p n) (z:BMark p n N) - -private theorem chartKnown {r : F} (q:PreparationParameters) (x:w.T) (d: Stakes q.pins) - (hw:Settled w m q U z r) - {v : Charts p n (toRates d)} (hc:charted v (w.pin x.val).sp) - (o : UnitType p n N) (hx:o∈x.val) : - (∀ i,totalRank (z o i)≤ q.pins) ∧ ∃ y,∀ i∈x.val,coordSpec z i v y := by - obtain ⟨h1,h2,h3⟩:=hw.readyC - let A:=(w.pin x.val).sp - have hi j : z o j∈effective A j := by - have hh : w.rooting o=A:=congrArg Pin.sp (LeafMixture.poller_eq w h2.part x.property hx) - rw [←hh]; exact (h3 x.val x.property o hx).2.2.1 j - obtain ⟨T,hK,hB,hG⟩:=hw.hard - obtain ⟨b,hb,hf⟩:=hG x.val x.property - choose y hy using fun j=> show z o j∈LinearMap.range (v j) from (hc j).1.symm ▸ hi j - refine ⟨fun i=>(effective_rank (hi i)).trans (h2.leaf x.val x.property).bound,y, - fun i hh j=>?_⟩ - exact (hy j).trans (congr_fun (hb.2.2 _ hx _ hh).1 j) - -set_option maxHeartbeats 1800000 in -theorem invoke (k:Fin (2^deckMax p q.pins)) - (r:F) (a:ℝ) (hα:0 shimmer z r x∧ berthTicket (w.pin i.val) (w.pin j.val) (v.mails i j k) x)) : - ∃ x:Scrip p q.pins, v.charter x.2.2 m x.2.1 U a (i,j) := by - classical - let K:=q.pins - let T:=v.mails i j k - have hq:=h.enter.first - let a0:= w.pin i.val; let b0:= w.pin j.val - let μ i:=partW U (Subtype.val (show w.T from i)) - let S:=pairW (μ i) (μ j) - obtain ⟨hm,hv,hC⟩:=hw.readyC - have hu x:=show IsLaw (μ x) from on_law hm.nz (hv.leaf x.val x.property).pos - have hμ: IsLaw S:= pairW_law (hu _) (hu _) - have hK x : planRank (w.pin (Subtype.val (show w.T from x))).sp ≤ K := - (hv.leaf _ (Subtype.prop x)).bound - obtain ⟨f,hF⟩:=sizedCharts q.pins w v ht i (hK i) - obtain ⟨g,hG⟩:=sizedCharts q.pins w v ht j (hK j) - let A:= toRates f; let B:=toRates g; let X:=v.cAxes i A; let Y:=v.cAxes j B - let P x:= shimmer z r x∧ berthTicket a0 b0 T x - obtain ⟨o,⟨hop,hOK⟩,ho⟩:= exists_of_pr_pos hμ.nz (lt_of_lt_of_le - (show 0<2*a by positivity) hk) - let x:=o.1; let y:=o.2 - have hcol i x (hx:μ i x≠0) : x∈ i.val := (onW_ne hx).1 - have hx : x∈ i.val:= hcol i x (left_ne_zero_of_mul ho.ne') - have hy : y∈ j.val:= hcol j y (right_ne_zero_of_mul ho.ne') - obtain ⟨hχ,l,hl⟩:= chartKnown (v:=X) U m z q i f hw hF x hx - obtain ⟨hξ,t,ht'⟩:= chartKnown (v:=Y) U m z q j g hw hG y hy - have he (i : w.T) x (hx:x∈ i.val) : ∀ j,z x j∈effective (w.pin i.val).sp j := by - have hi : w.rooting x=(w.pin i.val).sp:=congrArg Pin.sp (LeafMixture.poller_eq w hv.part i.property hx) - rw [← hi]; exact (hC _ i.property _ hx).2.2.1 - let kappa : Tag p.g:= ⟨0,by linarith only [hq.hG]⟩ - let tt : Tagging p (Messenger singles):=fun _=>kappa - let ref := show Messenger singles→F from fun _=>1 - obtain ⟨E,h1,h2,h3⟩:= generic_summary p hq.hG kappa 1 0 - obtain ⟨H,h4,h5,h6⟩:= generic_summary p hq.hG kappa 1 1 - obtain ⟨L,hLa⟩:= buildBooths K a0.sp (hK i) h.penRoom - obtain ⟨O,hLb⟩:= buildBooths K b0.sp (hK j) h.penRoom - have hh : 2*frameBills p.g K+4 ≤ Fintype.card (Label p.b) := by - have hl : frameBills p.g K + 1000 ≤ q.B:=h.forbid - have he:= h.spare; omega - obtain ⟨J,hJ,hJ'⟩:= fourPens _ K L hLa hh - obtain ⟨I,hI,hI'⟩:= fourPens _ K O hLb hh - let F0:Fabric p singles A true:=⟨J,fun _ => Flavor.full,beacon p X l true T E⟩ - let T':= reciprocal p T - let G0:Fabric p singles B false:=⟨I,fun _=> Flavor.full,beacon p Y t false T' H⟩ - have hs : speak A B (sendSum ref F0.amp G0.amp)=(hailing p X Y T,0) := by - apply (spoken X Y T ref F0.amp G0.amp).mpr - have hFq a : fullq ref a=1 := by - unfold fullq - change (∑ _:Fin 1,(1:F))=1; rw [Fintype.sum_unique] - have hR : rhyme F0.amp G0.amp := by - intro i; have hf : (funds F0.amp i).1.1=E.diagO := congrArg (fun x=> x.1.1) (funds_one F0 i) - have hg : (funds G0.amp i).1.1=H.diagO := congrArg (fun x=> x.1.1) (funds_one G0 i) - change (funds (b:=true) F0.amp i).1.1+(funds (b:=false) G0.amp i).1.1=_; rw [hf,hg,h3,h6,zero_add] - refine ⟨hFq,hR, stillBeacon z x X l true T E (hl _ hx) (fun k=>?_),stillBeacon z y Y t false - T' H (ht' _ hy) (fun k=>?_)⟩ - · rw [fitsTone z x hOK.2.2 (he _ _ hx), actualTone,(hC _ i.property _ hx).2.2.2] - exact congr_fun (congrArg Prod.fst hop) k - have hg:=fits_recip hOK.2.2; rw [reciprocal_actual] at hg - rw [fitsTone z y hg (he _ _ hy), actualTone,(hC _ j.property _ hy).2.2.2] - exact congr_fun (congrArg Prod.snd hop) k - obtain ⟨P0,Q0,hf⟩:= optionVia singles A B a0 b0 T K hOK.1 hOK.2.1 tt X Y hF hG F0 G0 L O hLa hLb - (fun i=>hJ' i _) (fun i=> hI' i _) ref ⟨hJ,fun i=>h2,fun i=>h1⟩ - ⟨hI,fun i=>h5,fun i=>h4⟩ h.jump (by linarith only [hq.hG]) singles_short hs - let τ:Typus p singles A B:= ⟨tt,ref,F0.hang P0,G0.hang Q0⟩ - let Front:=v.frontPage τ m i j k; let Back:=v.backPage τ m i j k - have hi a (ha:a∈ i.val): a0.agree a := (hv.leaf _ i.property).fixpin _ ha - have hi' a (ha:a∈ j.val): b0.agree a := (hv.leaf _ j.property).fixpin _ ha - have hm : 2*a≤ (pr (μ i) Front)*(pr (μ j) Back) := by - rw [←pairW_pr] - apply hk.trans - refine pr_on_mono hμ.nz (fun x hx he=>?_) - have h1 := hcol i x.1 (left_ne_zero_of_mul hx) - have h2 := hcol j x.2 (right_ne_zero_of_mul hx) - obtain ⟨ha,hb⟩:= berth_flags a0 b0 T he.2 (hi _ h1) (hi' _ h2) - exact ⟨⟨hf,hi _ h1,(hC _ i.property x.1 h1).1, ha⟩, - ⟨hf,hi' _ h2,(hC _ j.property _ h2).1,hb⟩⟩ - refine ⟨⟨(volume1,f,g),k,show OnFile p _ from τ⟩,hf.1,⟨?_,fun o ho hx=>?_⟩, - ⟨?_,fun o ho hx=>?_⟩⟩ - · exact hm.trans ((mul_le_mul_of_nonneg_left ((pr_le_tot (hu _).nz).trans (hu j).total.le) - (pr_nonneg (hu _).nz)).trans_eq (mul_one _)) - · have hv := hcol i o hx - exact steadyBeacon z o X l true T τ.qA tt m E K - (fun x=> Nat.lt_succ_iff.mp (f x).isLt) rfl (hK i) hF (hl _ hv) ho.2.2.1 - (hC _ i.property _ hv).2.1 - · exact hm.trans ((mul_le_mul_of_nonneg_right ((pr_le_tot (hu _).nz).trans (hu i).total.le) - (pr_nonneg (hu _).nz)).trans_eq (one_mul _)) - have hv:=hcol j o hx - exact steadyBeacon z o Y t false T' τ.qB tt m H K - (fun x=> Nat.lt_succ_iff.mp (g x).isLt) rfl (hK j) hG (ht' _ hv) ho.2.2.1 - (hC _ j.property _ hv).2.1 - -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RareTestEvents + +namespace OAI + +/-! # Compatible Table Events -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix LinearMap Function +open scoped BigOperators Topology +open Template +namespace StatusAnalysis +open PreparationParameters PredictionClass + +variable {p:Shape} {n M K s0 N :ℕ} {w:LeafMixture p n N} {q:PreparationParameters} + +structure Settled (t: LeafMixture p n N) (m:Mixer p n) (q:PreparationParameters) + (U : Wgt (UnitType p n N)) (z:BMark p n N) (k:F) : Prop where + readyC : + IsLaw U ∧ t.strength U (usual p m N) q.leafNew (2*q.ζ) q.pins ∧ + t.within (fun o=>frameSide p m o ∧ exactInk p m z o ∧ + (∀ i,z o i∈effective (t.rooting o) i) ∧ glint p (z o)=k) + hard : q.hardened p N t z + +def shimmer (z:BMark p n N) (r:F) (x:UnitType p n N× UnitType p n N) := + quench p (delta z) x=repeatQ r + +variable (v: Station p n N q.pins w) (i j:w.T) + (U:Wgt (UnitType p n N)) (m:Mixer p n) (z:BMark p n N) + +private theorem chartKnown {r : F} (q:PreparationParameters) (x:w.T) (d: Stakes q.pins) + (hw:Settled w m q U z r) + {v : Charts p n (toRates d)} (hc:charted v (w.pin x.val).sp) + (o : UnitType p n N) (hx:o∈x.val) : + (∀ i,totalRank (z o i)≤ q.pins) ∧ ∃ y,∀ i∈x.val,coordSpec z i v y := by + obtain ⟨h1,h2,h3⟩:=hw.readyC + let A:=(w.pin x.val).sp + have hi j : z o j∈effective A j := by + have hh : w.rooting o=A:=congrArg Pin.sp (LeafMixture.poller_eq w h2.part x.property hx) + rw [←hh]; exact (h3 x.val x.property o hx).2.2.1 j + obtain ⟨T,hK,hB,hG⟩:=hw.hard + obtain ⟨b,hb,hf⟩:=hG x.val x.property + choose y hy using fun j=> show z o j∈LinearMap.range (v j) from (hc j).1.symm ▸ hi j + refine ⟨fun i=>(effective_rank (hi i)).trans (h2.leaf x.val x.property).bound,y, + fun i hh j=>?_⟩ + exact (hy j).trans (congr_fun (hb.2.2 _ hx _ hh).1 j) + +set_option maxHeartbeats 1800000 in +theorem invoke (k:Fin (2^deckMax p q.pins)) + (r:F) (a:ℝ) (hα:0 shimmer z r x∧ berthTicket (w.pin i.val) (w.pin j.val) (v.mails i j k) x)) : + ∃ x:Scrip p q.pins, v.charter x.2.2 m x.2.1 U a (i,j) := by + classical + let K:=q.pins + let T:=v.mails i j k + have hq:=h.enter.first + let a0:= w.pin i.val; let b0:= w.pin j.val + let μ i:=partW U (Subtype.val (show w.T from i)) + let S:=pairW (μ i) (μ j) + obtain ⟨hm,hv,hC⟩:=hw.readyC + have hu x:=show IsLaw (μ x) from on_law hm.nz (hv.leaf x.val x.property).pos + have hμ: IsLaw S:= pairW_law (hu _) (hu _) + have hK x : planRank (w.pin (Subtype.val (show w.T from x))).sp ≤ K := + (hv.leaf _ (Subtype.prop x)).bound + obtain ⟨f,hF⟩:=sizedCharts q.pins w v ht i (hK i) + obtain ⟨g,hG⟩:=sizedCharts q.pins w v ht j (hK j) + let A:= toRates f; let B:=toRates g; let X:=v.cAxes i A; let Y:=v.cAxes j B + let P x:= shimmer z r x∧ berthTicket a0 b0 T x + obtain ⟨o,⟨hop,hOK⟩,ho⟩:= exists_of_pr_pos hμ.nz (lt_of_lt_of_le + (show 0<2*a by positivity) hk) + let x:=o.1; let y:=o.2 + have hcol i x (hx:μ i x≠0) : x∈ i.val := (onW_ne hx).1 + have hx : x∈ i.val:= hcol i x (left_ne_zero_of_mul ho.ne') + have hy : y∈ j.val:= hcol j y (right_ne_zero_of_mul ho.ne') + obtain ⟨hχ,l,hl⟩:= chartKnown (v:=X) U m z q i f hw hF x hx + obtain ⟨hξ,t,ht'⟩:= chartKnown (v:=Y) U m z q j g hw hG y hy + have he (i : w.T) x (hx:x∈ i.val) : ∀ j,z x j∈effective (w.pin i.val).sp j := by + have hi : w.rooting x=(w.pin i.val).sp:=congrArg Pin.sp (LeafMixture.poller_eq w hv.part i.property hx) + rw [← hi]; exact (hC _ i.property _ hx).2.2.1 + let kappa : Tag p.g:= ⟨0,by linarith only [hq.hG]⟩ + let tt : Tagging p (Messenger singles):=fun _=>kappa + let ref := show Messenger singles→F from fun _=>1 + obtain ⟨E,h1,h2,h3⟩:= generic_summary p hq.hG kappa 1 0 + obtain ⟨H,h4,h5,h6⟩:= generic_summary p hq.hG kappa 1 1 + obtain ⟨L,hLa⟩:= buildBooths K a0.sp (hK i) h.penRoom + obtain ⟨O,hLb⟩:= buildBooths K b0.sp (hK j) h.penRoom + have hh : 2*frameBills p.g K+4 ≤ Fintype.card (Label p.b) := by + have hl : frameBills p.g K + 1000 ≤ q.B:=h.forbid + have he:= h.spare; omega + obtain ⟨J,hJ,hJ'⟩:= fourPens _ K L hLa hh + obtain ⟨I,hI,hI'⟩:= fourPens _ K O hLb hh + let F0:Fabric p singles A true:=⟨J,fun _ => Flavor.full,beacon p X l true T E⟩ + let T':= reciprocal p T + let G0:Fabric p singles B false:=⟨I,fun _=> Flavor.full,beacon p Y t false T' H⟩ + have hs : speak A B (sendSum ref F0.amp G0.amp)=(hailing p X Y T,0) := by + apply (spoken X Y T ref F0.amp G0.amp).mpr + have hFq a : fullq ref a=1 := by + unfold fullq + change (∑ _:Fin 1,(1:F))=1; rw [Fintype.sum_unique] + have hR : rhyme F0.amp G0.amp := by + intro i; have hf : (funds F0.amp i).1.1=E.diagO := congrArg (fun x=> x.1.1) (funds_one F0 i) + have hg : (funds G0.amp i).1.1=H.diagO := congrArg (fun x=> x.1.1) (funds_one G0 i) + change (funds (b:=true) F0.amp i).1.1+(funds (b:=false) G0.amp i).1.1=_; rw [hf,hg,h3,h6,zero_add] + refine ⟨hFq,hR, stillBeacon z x X l true T E (hl _ hx) (fun k=>?_),stillBeacon z y Y t false + T' H (ht' _ hy) (fun k=>?_)⟩ + · rw [fitsTone z x hOK.2.2 (he _ _ hx), actualTone,(hC _ i.property _ hx).2.2.2] + exact congr_fun (congrArg Prod.fst hop) k + have hg:=fits_recip hOK.2.2; rw [reciprocal_actual] at hg + rw [fitsTone z y hg (he _ _ hy), actualTone,(hC _ j.property _ hy).2.2.2] + exact congr_fun (congrArg Prod.snd hop) k + obtain ⟨P0,Q0,hf⟩:= optionVia singles A B a0 b0 T K hOK.1 hOK.2.1 tt X Y hF hG F0 G0 L O hLa hLb + (fun i=>hJ' i _) (fun i=> hI' i _) ref ⟨hJ,fun i=>h2,fun i=>h1⟩ + ⟨hI,fun i=>h5,fun i=>h4⟩ h.jump (by linarith only [hq.hG]) singles_short hs + let τ:Typus p singles A B:= ⟨tt,ref,F0.hang P0,G0.hang Q0⟩ + let Front:=v.frontPage τ m i j k; let Back:=v.backPage τ m i j k + have hi a (ha:a∈ i.val): a0.agree a := (hv.leaf _ i.property).fixpin _ ha + have hi' a (ha:a∈ j.val): b0.agree a := (hv.leaf _ j.property).fixpin _ ha + have hm : 2*a≤ (pr (μ i) Front)*(pr (μ j) Back) := by + rw [←pairW_pr] + apply hk.trans + refine pr_on_mono hμ.nz (fun x hx he=>?_) + have h1 := hcol i x.1 (left_ne_zero_of_mul hx) + have h2 := hcol j x.2 (right_ne_zero_of_mul hx) + obtain ⟨ha,hb⟩:= berth_flags a0 b0 T he.2 (hi _ h1) (hi' _ h2) + exact ⟨⟨hf,hi _ h1,(hC _ i.property x.1 h1).1, ha⟩, + ⟨hf,hi' _ h2,(hC _ j.property _ h2).1,hb⟩⟩ + refine ⟨⟨(volume1,f,g),k,show OnFile p _ from τ⟩,hf.1,⟨?_,fun o ho hx=>?_⟩, + ⟨?_,fun o ho hx=>?_⟩⟩ + · exact hm.trans ((mul_le_mul_of_nonneg_left ((pr_le_tot (hu _).nz).trans (hu j).total.le) + (pr_nonneg (hu _).nz)).trans_eq (mul_one _)) + · have hv := hcol i o hx + exact steadyBeacon z o X l true T τ.qA tt m E K + (fun x=> Nat.lt_succ_iff.mp (f x).isLt) rfl (hK i) hF (hl _ hv) ho.2.2.1 + (hC _ i.property _ hv).2.1 + · exact hm.trans ((mul_le_mul_of_nonneg_right ((pr_le_tot (hu _).nz).trans (hu i).total.le) + (pr_nonneg (hu _).nz)).trans_eq (one_mul _)) + have hv:=hcol j o hx + exact steadyBeacon z o Y t false T' τ.qB tt m H K + (fun x=> Nat.lt_succ_iff.mp (g x).isLt) rfl (hK j) hG (ht' _ hv) ho.2.2.1 + (hC _ j.property _ hv).2.1 + +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ComponentIndices.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ComponentIndices.lean index b49d63c52f9b7f4845aa5bb0422359606b82207b..158a16c27f482eb047e55debf76c99836e0c38f5 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ComponentIndices.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ComponentIndices.lean @@ -1,115 +1,115 @@ -import Mathlib.Algebra.Group.Fin.Basic -import Mathlib.Data.Fintype.Card -import Mathlib.Data.Fintype.Prod - -namespace OAI - -/-! # Component Indices -/ - -noncomputable section -namespace HadwigerCounterexample - -abbrev Tag := Fin -abbrev Comp (g : ℕ) := { p : Tag g × Tag g // p.1 < p.2 } - -variable {g : ℕ} - -def edge (l d : Tag g) (h : l ≠ d) : Comp g := - if hl : l < d then ⟨(l,d),hl⟩ else ⟨(d,l),lt_of_le_of_ne (le_of_not_gt hl) h.symm⟩ - -theorem edge_eq {l d : Tag g} (h : l < d) : edge l d (ne_of_lt h) = ⟨(l,d),h⟩ := by - simp [edge,h] - -theorem edge_symm {l d : Tag g} (h : l ≠ d) : edge l d h = edge d l h.symm := by - rcases lt_or_gt_of_ne h with e|e - · simp [edge,e,not_lt.mpr e.le] - · simp [edge,e,not_lt.mpr e.le] - -def inc (e : Comp g) (l : Tag g) : Prop := e.val.1 = l ∨ e.val.2 = l -instance (e : Comp g) (l : Tag g) : Decidable (inc e l) := inferInstanceAs (Decidable (_ ∨ _)) - -theorem inc_edge_fst {l d : Tag g} (h : l ≠ d) : inc (edge l d h) l := by - by_cases e : l < d <;> simp [inc,edge,e] - -theorem inc_edge_iff {l d x : Tag g} (h : l ≠ d) : inc (edge l d h) x ↔ (l=x ∨ d=x) := by - by_cases e : l < d <;> simp [inc,edge,e,or_comm] - -abbrev TagStar (l : Tag g) := {e : Comp g // inc e l} - -def starEquiv (l : Tag g) : {d : Tag g // l ≠ d} ≃ TagStar l := by - let f (d : {d : Tag g // l ≠ d}) : TagStar l := ⟨edge l d d.property,inc_edge_fst _⟩ - apply Equiv.ofBijective f - constructor - · intro i j h - have hi : inc (edge l i i.property) i := (inc_edge_iff _).mpr (Or.inr rfl) - change inc (f i).val i at hi - rw [h] at hi - exact Subtype.ext (((inc_edge_iff j.property).mp hi).resolve_left i.property).symm - · rintro ⟨⟨⟨i,j⟩,hij⟩,he⟩ - rcases he with g|g - · change i = l at g - subst l - refine ⟨⟨j,hij.ne⟩,Subtype.ext ?_⟩ - exact edge_eq hij - · change j = l at g - subst l - refine ⟨⟨i,hij.ne.symm⟩,Subtype.ext ?_⟩ - dsimp only [f] - rw [edge_symm,edge_eq hij] - -theorem card_star (l : Tag g) : Fintype.card (TagStar l) = g - 1 := by - rw [← Fintype.card_congr (starEquiv l)] - exact (Fintype.card_subtype_compl (fun d => l=d)).trans (by simp) - -/-- l in I_d. -/ -def allowed (d l : Tag g) := - 0 < (l-d).val ∧ (l-d).val ≤ (g-1)/2 - -instance (d l : Tag g) : Decidable (allowed d l) := - inferInstanceAs (Decidable (_ ∧ _)) - -theorem not_allowed (d : Tag g) : ¬allowed d d := by - have : NeZero g := ⟨by have := d.isLt; omega⟩ - simp [allowed] - -theorem card_allowed (d : Tag g) : Fintype.card {l : Tag g // allowed d l} = (g-1)/2 := by - have : NeZero g := ⟨by have := d.isLt; omega⟩ - let T := {l : Tag g // allowed d l} - let f (i : Fin ((g-1)/2)) : Tag g := ⟨i.val+1,by have := i.isLt; omega⟩ - have hf (i) : allowed d (f i + d) := by - have := i.isLt - simp only [allowed,add_sub_cancel_right,f] - omega - let h : Fin ((g-1)/2) → T := fun i => ⟨f i + d,hf i⟩ - have hh : Function.Bijective h := by - constructor - · intro i j hij - have he : f i = f j := add_right_cancel (congrArg Subtype.val hij) - have he' := congrArg Fin.val he - exact Fin.ext (Nat.add_right_cancel he') - · intro l - have hl := l.property - unfold allowed at hl - let i : Fin ((g-1)/2) := ⟨(l.val-d).val-1,by omega⟩ - have hi : f i = l.val-d := Fin.ext (by dsimp only [i,f]; omega) - refine ⟨i,Subtype.ext ?_⟩ - change f i + d = _ - rw [hi,sub_add_cancel] - simpa using (Fintype.card_congr (Equiv.ofBijective h hh)).symm - -theorem card_allowed' (l : Tag g) : - Fintype.card {d : Tag g // allowed d l} = (g-1)/2 := by - have : NeZero g := ⟨by have := l.isLt; omega⟩ - let h : {d : Tag g // allowed d l} ≃ {x : Tag g // allowed 0 x} := { - toFun := fun d => ⟨l-d.val, by simpa only [allowed,sub_zero] using d.property⟩ - invFun := fun x => ⟨l-x.val, by simpa only [allowed,sub_sub_cancel,sub_zero] using - x.property⟩ - left_inv := fun d => Subtype.ext (sub_sub_cancel _ _) - right_inv := fun x => Subtype.ext (sub_sub_cancel _ _) } - exact (Fintype.card_congr h).trans (card_allowed _) - -end HadwigerCounterexample - -end - -end OAI +import Mathlib.Algebra.Group.Fin.Basic +import Mathlib.Data.Fintype.Card +import Mathlib.Data.Fintype.Prod + +namespace OAI + +/-! # Component Indices -/ + +noncomputable section +namespace HadwigerCounterexample + +abbrev Tag := Fin +abbrev Comp (g : ℕ) := { p : Tag g × Tag g // p.1 < p.2 } + +variable {g : ℕ} + +def edge (l d : Tag g) (h : l ≠ d) : Comp g := + if hl : l < d then ⟨(l,d),hl⟩ else ⟨(d,l),lt_of_le_of_ne (le_of_not_gt hl) h.symm⟩ + +theorem edge_eq {l d : Tag g} (h : l < d) : edge l d (ne_of_lt h) = ⟨(l,d),h⟩ := by + simp [edge,h] + +theorem edge_symm {l d : Tag g} (h : l ≠ d) : edge l d h = edge d l h.symm := by + rcases lt_or_gt_of_ne h with e|e + · simp [edge,e,not_lt.mpr e.le] + · simp [edge,e,not_lt.mpr e.le] + +def inc (e : Comp g) (l : Tag g) : Prop := e.val.1 = l ∨ e.val.2 = l +instance (e : Comp g) (l : Tag g) : Decidable (inc e l) := inferInstanceAs (Decidable (_ ∨ _)) + +theorem inc_edge_fst {l d : Tag g} (h : l ≠ d) : inc (edge l d h) l := by + by_cases e : l < d <;> simp [inc,edge,e] + +theorem inc_edge_iff {l d x : Tag g} (h : l ≠ d) : inc (edge l d h) x ↔ (l=x ∨ d=x) := by + by_cases e : l < d <;> simp [inc,edge,e,or_comm] + +abbrev TagStar (l : Tag g) := {e : Comp g // inc e l} + +def starEquiv (l : Tag g) : {d : Tag g // l ≠ d} ≃ TagStar l := by + let f (d : {d : Tag g // l ≠ d}) : TagStar l := ⟨edge l d d.property,inc_edge_fst _⟩ + apply Equiv.ofBijective f + constructor + · intro i j h + have hi : inc (edge l i i.property) i := (inc_edge_iff _).mpr (Or.inr rfl) + change inc (f i).val i at hi + rw [h] at hi + exact Subtype.ext (((inc_edge_iff j.property).mp hi).resolve_left i.property).symm + · rintro ⟨⟨⟨i,j⟩,hij⟩,he⟩ + rcases he with g|g + · change i = l at g + subst l + refine ⟨⟨j,hij.ne⟩,Subtype.ext ?_⟩ + exact edge_eq hij + · change j = l at g + subst l + refine ⟨⟨i,hij.ne.symm⟩,Subtype.ext ?_⟩ + dsimp only [f] + rw [edge_symm,edge_eq hij] + +theorem card_star (l : Tag g) : Fintype.card (TagStar l) = g - 1 := by + rw [← Fintype.card_congr (starEquiv l)] + exact (Fintype.card_subtype_compl (fun d => l=d)).trans (by simp) + +/-- l in I_d. -/ +def allowed (d l : Tag g) := + 0 < (l-d).val ∧ (l-d).val ≤ (g-1)/2 + +instance (d l : Tag g) : Decidable (allowed d l) := + inferInstanceAs (Decidable (_ ∧ _)) + +theorem not_allowed (d : Tag g) : ¬allowed d d := by + have : NeZero g := ⟨by have := d.isLt; omega⟩ + simp [allowed] + +theorem card_allowed (d : Tag g) : Fintype.card {l : Tag g // allowed d l} = (g-1)/2 := by + have : NeZero g := ⟨by have := d.isLt; omega⟩ + let T := {l : Tag g // allowed d l} + let f (i : Fin ((g-1)/2)) : Tag g := ⟨i.val+1,by have := i.isLt; omega⟩ + have hf (i) : allowed d (f i + d) := by + have := i.isLt + simp only [allowed,add_sub_cancel_right,f] + omega + let h : Fin ((g-1)/2) → T := fun i => ⟨f i + d,hf i⟩ + have hh : Function.Bijective h := by + constructor + · intro i j hij + have he : f i = f j := add_right_cancel (congrArg Subtype.val hij) + have he' := congrArg Fin.val he + exact Fin.ext (Nat.add_right_cancel he') + · intro l + have hl := l.property + unfold allowed at hl + let i : Fin ((g-1)/2) := ⟨(l.val-d).val-1,by omega⟩ + have hi : f i = l.val-d := Fin.ext (by dsimp only [i,f]; omega) + refine ⟨i,Subtype.ext ?_⟩ + change f i + d = _ + rw [hi,sub_add_cancel] + simpa using (Fintype.card_congr (Equiv.ofBijective h hh)).symm + +theorem card_allowed' (l : Tag g) : + Fintype.card {d : Tag g // allowed d l} = (g-1)/2 := by + have : NeZero g := ⟨by have := l.isLt; omega⟩ + let h : {d : Tag g // allowed d l} ≃ {x : Tag g // allowed 0 x} := { + toFun := fun d => ⟨l-d.val, by simpa only [allowed,sub_zero] using d.property⟩ + invFun := fun x => ⟨l-x.val, by simpa only [allowed,sub_sub_cancel,sub_zero] using + x.property⟩ + left_inv := fun d => Subtype.ext (sub_sub_cancel _ _) + right_inv := fun x => Subtype.ext (sub_sub_cancel _ _) } + exact (Fintype.card_congr h).trans (card_allowed _) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ConcentrationScales.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ConcentrationScales.lean index 2c3a37564e5187c93dfebad73f88d45e17594de2..015f72a50d17d8f44476f95bf554d3a4fd650bca 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ConcentrationScales.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ConcentrationScales.lean @@ -1,169 +1,169 @@ -import OAI.Combinatorics.HadwigerCounterexample.DependentPairConcentration - -namespace OAI - -/-! # Concentration Scales -/ - -noncomputable section -namespace HadwigerCounterexample - -open Matrix LinearMap Module Finset Filter Real Function -open scoped BigOperators Topology -variable {X : Type*} - -/-- pay slack for any fixed multiple of exponentially smaller term. -/ -theorem pay_nat {a b : ℝ} (c : ℝ) (hab : b < a) : - ∀ᶠ n : ℕ in atTop,c * bp (-a*n) ≤ bp (-b*n) := by - have h := (bp_tendsto (sub_pos.mpr hab)).comp (tendsto_natCast_atTop_atTop (R:=ℝ)) - filter_upwards [h.eventually (eventually_ge_atTop c)] with n hn - change c ≤ bp ((a-b)*n) at hn - refine (mul_le_mul_of_nonneg_right hn (bp_pos _).le).trans_eq ?_ - rw [← bp_add, show (a-b)*n + -a*n= -b*n by ring] - -theorem pay_div_nat {a b : ℝ} (c u : ℝ) (hu : 0 < u) (hab : b < a) : - ∀ᶠ n : ℕ in atTop,c * bp (-a*n) ≤ u*bp (-b*n) := by - filter_upwards [pay_nat (c/u) hab] with n hn - calc _ = u*(c/u*bp (-a*n)) := by field_simp - _ ≤ _ := mul_le_mul_of_nonneg_left hn hu.le - -theorem cast_tops (M : ℕ) (hM : 1≤M) : - Tendsto (fun n : ℕ => (↑(M*n):ℝ)) atTop atTop := by - simp_rw [Nat.cast_mul]; exact - (tendsto_const_mul_atTop_of_pos (show 0<(M:ℝ) from by - exact_mod_cast (show 0 < M from hM))).mpr tendsto_natCast_atTop_atTop - -variable {p : Shape} {M n N : ℕ} -variable {I J K G A B : Type} [Fintype I] [Fintype J] [Fintype K] [Fintype G] -variable [DecidableEq I] [DecidableEq J] [DecidableEq K] [DecidableEq G] -variable [Fintype A] [Fintype B] -variable {g : Route J G} - -omit [Fintype G] [DecidableEq J] in -theorem port_limit (g : Route J G) (i : G) : - num (Port g i) ≤ num J := by - exact_mod_cast Fintype.card_subtype_le _ - -namespace Program -variable {s : Program p n g A} - -/-- empirical input-and-image law -/ -def makeData (s : Program p n g A) (w : Wgt A) (o : Forum p n N G) : - Wgt (A×Rack J N) := - mapW w (fun x => (x,s.showKey x o)) -omit [Fintype G] [DecidableEq G] in -theorem data_law (s : Program p n g A) (w : Wgt A) (o : Forum p n N G) - (hw : IsLaw w) : IsLaw (s.makeData w o) := mapW_law hw _ -omit [Fintype G] [DecidableEq G] in -theorem view_data (s : Program p n g A) (w : Wgt A) (o : Forum p n N G) - (f : Wgt (A×Rack J N)) : - avg (s.makeData w o) f=s.oexpect w (fun a b => f (a,b)) o := mapW_avg .. -omit [Fintype G] [DecidableEq G] in -theorem freq_data (s : Program p n g A) (w : Wgt A) (o : Forum p n N G) - (P : A×Rack J N→Prop) : - pr (s.makeData w o) P = oFreq w (fun a b => P (a,b)) o s := mapW_pr .. - -set_option maxHeartbeats 600000 in -theorem variance_calendar (p : Shape) (M : ℕ) (g : Route J G) - (r u : ℝ) (hu : 0 < u) (hM : 1≤M) : - ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n) - (A : Type) [Fintype A] (s : Program p n g A) - (T : A→ Wgt (Rack J N)) (w : Wgt A), IsLaw w → - (∀ x y, |T x y|≤1) →2*num (Full p n) ¬ s.free x) ≤ bp (r-n) → - (let v := forumLaw m N - let f := s.oexpect w T - avg v (fun x => (f x-avg v f)^2)) ≤ u*bp (-(1/4:ℝ)*n) := by - let t := tied g Bool - let k := num (Bool×J) - let b := 2*netFact t - let c := num G* (2*bp k)+1 - filter_upwards [pay_div_nat (a:=1) (2*bp r) (u/2) (by positivity) (b:=1/4) (by norm_num), - pay_div_nat (a:=1/2) (b*c) (u/2) (by positivity) (b:=1/4) (by norm_num), - (cast_tops M hM).eventually (eventually_ge_atTop (2*k+1))] - with n hn hh hk N m A _ s T w hw hT hN h - change (2*k+1) ≤ (↑(M*n) : ℝ) at hk - have he := oVar m hN T w hw hT k (fun i => port_limit _ i) (by linarith only [hk]) - (bp (r-n)) h - apply he.trans - subst N - have hv : (n:ℝ) ≤ (M*n:ℕ) := by exact_mod_cast (show n ≤ M*n from by nlinarith) - let P := bp (-(1/2:ℝ)*n) - have ht : twinkle t k (M*n) ≤ c*P := by - have hq : bp (k-(M*n:ℕ)) ≤ bp k*P := by - unfold P; rw [← bp_add]; apply bp_le; linarith only [hv,Nat.cast_nonneg (α:=ℝ) n] - have hr : bp (-(↑(M*n):ℝ)/2)≤P := bp_le (by linarith only [hv]) - calc _ ≤ num G*(2*(bp k * P))+P := add_le_add - (mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hq (by norm_num)) - (Nat.cast_nonneg _)) hr - _ = _ := by unfold c; ring - have h1 : 2*bp (r-n) ≤ u/2*bp (-(1/4:ℝ)*n) := by - simpa only [mul_assoc,← bp_add,neg_mul,one_mul,←sub_eq_add_neg] using hn - have h2 : 2*netFact t* twinkle t k (M*n)≤ u/2*bp (-(1/4:ℝ)*n) := - (mul_le_mul_of_nonneg_left ht (by apply mul_nonneg (by norm_num) netFact_pos.le)).trans - (le_trans (le_of_eq (Eq.symm (mul_assoc b c P))) hh) - exact (add_le_add h1 h2).trans_eq (by ring) - -theorem approx_calendar (p : Shape) (M : ℕ) (g : Route J G) - (r η : ℝ) (hη : 0<η) (hM : 1 ≤ M) : - ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n) - (A : Type) [Fintype A] (s : Program p n g A) - (w : Wgt A), IsLaw w → - 2*num (Full p n) ¬ s.free x) ≤ bp (r-n) → - approxData (forumLaw m N) (s.makeData w) η (bp (-(1/4:ℝ)*n)) := by - filter_upwards [variance_calendar p M g r (η^2) (by positivity) hM] - with n hn N m A _ s w hw hN he F hF - subst N - let T (x : A) (y : Rack J (M*n)) := F (x,y) - rw [mixW_avg]; simp_rw [view_data] - refine (outlier (forum_law m hN).nz _ η hη - (hn m _ s T w hw (fun x y => hF _) hN he)).trans_eq ?_ - field_simp - -theorem thin_calendar (p : Shape) (M : ℕ) (g : Route J G) - (b η c : ℝ) (hc : 0 < c) (hη : 0<η) (hM : 1≤M) : - ∃ l : ℕ, ∀ r : ℝ, ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n) - (A : Type) [Fintype A] (s : Program p n g A) - (w : Wgt A), IsLaw w → - 2*num (Full p n) ¬ s.free x) ≤ bp (r-n) → - thinData (forumLaw m N) (s.makeData w) (bp (-c*n)) η (bp (-b*n)) := by - obtain ⟨l,hl⟩ := exists_nat_gt (b/c) - let d := η^l/2 - have hd : 0 ?_⟩ - filter_upwards [pay_div_nat (a:=1) (bp r) d hd (b:=0) (by norm_num), - pay_div_nat (a:=c*l) (netFact t) d hd (b:=b) - (by rwa [div_lt_iff₀ hc,mul_comm] at hl), - (cast_tops M hM).eventually (eventually_ge_atTop (2*k+1))] - with n hn hh hk N m A _ s w hw hN hr P hP - subst N; let N := M*n - change 2*k+1 ≤ (N:ℝ) at hk - let T (x : A) (y : Rack J N) := P (x,y) - let v := forumLaw (G:=G) m N - let f := fun o => oFreq w T o s - rw [show pr (mixW v (s.makeData w)) P=avg v (fun x => pr (s.makeData w x) P) from mixW_avg ..] at hP - simp_rw [freq_data] at * - have hi : bp (r-n) ≤ d := by - simpa only [neg_zero,zero_mul,bp_zero,mul_one,← bp_add,neg_mul,one_mul, ← sub_eq_add_neg] - using hn - have hj : η^l=d+d := by unfold d; ring - have he := oTail m hN T w hw (k:=k) (fun i => port_limit _ i) (by linarith only [hk]) - (bp (r-n)) hr hη.le - have hv := forum_law (G:=G) m hN - apply le_of_mul_le_mul_left _ hd - calc d*pr v (fun x => η ≤ f x) - _ ≤ _ := mul_le_mul_of_nonneg_right (show d≤η^l-bp (r-n) from by - rw [hj]; linarith only [hi]) (pr_nonneg hv.nz) - _ ≤ _ := he - _ ≤ netFact t * bp (-c*n)^l := mul_le_mul_of_nonneg_left - (pow_le_pow_left₀ (avg_nonneg hv.nz fun x => pr_nonneg hw.nz) hP l) netFact_pos.le - _ ≤ _ := by rw [← bp_mul_nat,show -c*n*l= -(c*l)*n by ring]; exact hh -end Program -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.DependentPairConcentration + +namespace OAI + +/-! # Concentration Scales -/ + +noncomputable section +namespace HadwigerCounterexample + +open Matrix LinearMap Module Finset Filter Real Function +open scoped BigOperators Topology +variable {X : Type*} + +/-- pay slack for any fixed multiple of exponentially smaller term. -/ +theorem pay_nat {a b : ℝ} (c : ℝ) (hab : b < a) : + ∀ᶠ n : ℕ in atTop,c * bp (-a*n) ≤ bp (-b*n) := by + have h := (bp_tendsto (sub_pos.mpr hab)).comp (tendsto_natCast_atTop_atTop (R:=ℝ)) + filter_upwards [h.eventually (eventually_ge_atTop c)] with n hn + change c ≤ bp ((a-b)*n) at hn + refine (mul_le_mul_of_nonneg_right hn (bp_pos _).le).trans_eq ?_ + rw [← bp_add, show (a-b)*n + -a*n= -b*n by ring] + +theorem pay_div_nat {a b : ℝ} (c u : ℝ) (hu : 0 < u) (hab : b < a) : + ∀ᶠ n : ℕ in atTop,c * bp (-a*n) ≤ u*bp (-b*n) := by + filter_upwards [pay_nat (c/u) hab] with n hn + calc _ = u*(c/u*bp (-a*n)) := by field_simp + _ ≤ _ := mul_le_mul_of_nonneg_left hn hu.le + +theorem cast_tops (M : ℕ) (hM : 1≤M) : + Tendsto (fun n : ℕ => (↑(M*n):ℝ)) atTop atTop := by + simp_rw [Nat.cast_mul]; exact + (tendsto_const_mul_atTop_of_pos (show 0<(M:ℝ) from by + exact_mod_cast (show 0 < M from hM))).mpr tendsto_natCast_atTop_atTop + +variable {p : Shape} {M n N : ℕ} +variable {I J K G A B : Type} [Fintype I] [Fintype J] [Fintype K] [Fintype G] +variable [DecidableEq I] [DecidableEq J] [DecidableEq K] [DecidableEq G] +variable [Fintype A] [Fintype B] +variable {g : Route J G} + +omit [Fintype G] [DecidableEq J] in +theorem port_limit (g : Route J G) (i : G) : + num (Port g i) ≤ num J := by + exact_mod_cast Fintype.card_subtype_le _ + +namespace Program +variable {s : Program p n g A} + +/-- empirical input-and-image law -/ +def makeData (s : Program p n g A) (w : Wgt A) (o : Forum p n N G) : + Wgt (A×Rack J N) := + mapW w (fun x => (x,s.showKey x o)) +omit [Fintype G] [DecidableEq G] in +theorem data_law (s : Program p n g A) (w : Wgt A) (o : Forum p n N G) + (hw : IsLaw w) : IsLaw (s.makeData w o) := mapW_law hw _ +omit [Fintype G] [DecidableEq G] in +theorem view_data (s : Program p n g A) (w : Wgt A) (o : Forum p n N G) + (f : Wgt (A×Rack J N)) : + avg (s.makeData w o) f=s.oexpect w (fun a b => f (a,b)) o := mapW_avg .. +omit [Fintype G] [DecidableEq G] in +theorem freq_data (s : Program p n g A) (w : Wgt A) (o : Forum p n N G) + (P : A×Rack J N→Prop) : + pr (s.makeData w o) P = oFreq w (fun a b => P (a,b)) o s := mapW_pr .. + +set_option maxHeartbeats 600000 in +theorem variance_calendar (p : Shape) (M : ℕ) (g : Route J G) + (r u : ℝ) (hu : 0 < u) (hM : 1≤M) : + ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n) + (A : Type) [Fintype A] (s : Program p n g A) + (T : A→ Wgt (Rack J N)) (w : Wgt A), IsLaw w → + (∀ x y, |T x y|≤1) →2*num (Full p n) ¬ s.free x) ≤ bp (r-n) → + (let v := forumLaw m N + let f := s.oexpect w T + avg v (fun x => (f x-avg v f)^2)) ≤ u*bp (-(1/4:ℝ)*n) := by + let t := tied g Bool + let k := num (Bool×J) + let b := 2*netFact t + let c := num G* (2*bp k)+1 + filter_upwards [pay_div_nat (a:=1) (2*bp r) (u/2) (by positivity) (b:=1/4) (by norm_num), + pay_div_nat (a:=1/2) (b*c) (u/2) (by positivity) (b:=1/4) (by norm_num), + (cast_tops M hM).eventually (eventually_ge_atTop (2*k+1))] + with n hn hh hk N m A _ s T w hw hT hN h + change (2*k+1) ≤ (↑(M*n) : ℝ) at hk + have he := oVar m hN T w hw hT k (fun i => port_limit _ i) (by linarith only [hk]) + (bp (r-n)) h + apply he.trans + subst N + have hv : (n:ℝ) ≤ (M*n:ℕ) := by exact_mod_cast (show n ≤ M*n from by nlinarith) + let P := bp (-(1/2:ℝ)*n) + have ht : twinkle t k (M*n) ≤ c*P := by + have hq : bp (k-(M*n:ℕ)) ≤ bp k*P := by + unfold P; rw [← bp_add]; apply bp_le; linarith only [hv,Nat.cast_nonneg (α:=ℝ) n] + have hr : bp (-(↑(M*n):ℝ)/2)≤P := bp_le (by linarith only [hv]) + calc _ ≤ num G*(2*(bp k * P))+P := add_le_add + (mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hq (by norm_num)) + (Nat.cast_nonneg _)) hr + _ = _ := by unfold c; ring + have h1 : 2*bp (r-n) ≤ u/2*bp (-(1/4:ℝ)*n) := by + simpa only [mul_assoc,← bp_add,neg_mul,one_mul,←sub_eq_add_neg] using hn + have h2 : 2*netFact t* twinkle t k (M*n)≤ u/2*bp (-(1/4:ℝ)*n) := + (mul_le_mul_of_nonneg_left ht (by apply mul_nonneg (by norm_num) netFact_pos.le)).trans + (le_trans (le_of_eq (Eq.symm (mul_assoc b c P))) hh) + exact (add_le_add h1 h2).trans_eq (by ring) + +theorem approx_calendar (p : Shape) (M : ℕ) (g : Route J G) + (r η : ℝ) (hη : 0<η) (hM : 1 ≤ M) : + ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n) + (A : Type) [Fintype A] (s : Program p n g A) + (w : Wgt A), IsLaw w → + 2*num (Full p n) ¬ s.free x) ≤ bp (r-n) → + approxData (forumLaw m N) (s.makeData w) η (bp (-(1/4:ℝ)*n)) := by + filter_upwards [variance_calendar p M g r (η^2) (by positivity) hM] + with n hn N m A _ s w hw hN he F hF + subst N + let T (x : A) (y : Rack J (M*n)) := F (x,y) + rw [mixW_avg]; simp_rw [view_data] + refine (outlier (forum_law m hN).nz _ η hη + (hn m _ s T w hw (fun x y => hF _) hN he)).trans_eq ?_ + field_simp + +theorem thin_calendar (p : Shape) (M : ℕ) (g : Route J G) + (b η c : ℝ) (hc : 0 < c) (hη : 0<η) (hM : 1≤M) : + ∃ l : ℕ, ∀ r : ℝ, ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n) + (A : Type) [Fintype A] (s : Program p n g A) + (w : Wgt A), IsLaw w → + 2*num (Full p n) ¬ s.free x) ≤ bp (r-n) → + thinData (forumLaw m N) (s.makeData w) (bp (-c*n)) η (bp (-b*n)) := by + obtain ⟨l,hl⟩ := exists_nat_gt (b/c) + let d := η^l/2 + have hd : 0 ?_⟩ + filter_upwards [pay_div_nat (a:=1) (bp r) d hd (b:=0) (by norm_num), + pay_div_nat (a:=c*l) (netFact t) d hd (b:=b) + (by rwa [div_lt_iff₀ hc,mul_comm] at hl), + (cast_tops M hM).eventually (eventually_ge_atTop (2*k+1))] + with n hn hh hk N m A _ s w hw hN hr P hP + subst N; let N := M*n + change 2*k+1 ≤ (N:ℝ) at hk + let T (x : A) (y : Rack J N) := P (x,y) + let v := forumLaw (G:=G) m N + let f := fun o => oFreq w T o s + rw [show pr (mixW v (s.makeData w)) P=avg v (fun x => pr (s.makeData w x) P) from mixW_avg ..] at hP + simp_rw [freq_data] at * + have hi : bp (r-n) ≤ d := by + simpa only [neg_zero,zero_mul,bp_zero,mul_one,← bp_add,neg_mul,one_mul, ← sub_eq_add_neg] + using hn + have hj : η^l=d+d := by unfold d; ring + have he := oTail m hN T w hw (k:=k) (fun i => port_limit _ i) (by linarith only [hk]) + (bp (r-n)) hr hη.le + have hv := forum_law (G:=G) m hN + apply le_of_mul_le_mul_left _ hd + calc d*pr v (fun x => η ≤ f x) + _ ≤ _ := mul_le_mul_of_nonneg_right (show d≤η^l-bp (r-n) from by + rw [hj]; linarith only [hi]) (pr_nonneg hv.nz) + _ ≤ _ := he + _ ≤ netFact t * bp (-c*n)^l := mul_le_mul_of_nonneg_left + (pow_le_pow_left₀ (avg_nonneg hv.nz fun x => pr_nonneg hw.nz) hP l) netFact_pos.le + _ ≤ _ := by rw [← bp_mul_nat,show -c*n*l= -(c*l)*n by ring]; exact hh +end Program +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalCellEntropy.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalCellEntropy.lean index 936811656f9f608f872a09f89f00929c76ac812e..0e341e18f03a72a3a4460638683605f836286a6a 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalCellEntropy.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalCellEntropy.lean @@ -1,156 +1,156 @@ -import OAI.Combinatorics.HadwigerCounterexample.GradientRealization -import OAI.Combinatorics.HadwigerCounterexample.WalshBounds - -namespace OAI - -/-! # Conditional Cell Entropy -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Submodule Module Finset -open scoped BigOperators -variable {p : Shape} {n N : ℕ} - -theorem plan_add_disjoint (a b : Plan p n) (h : ∀ z, Disjoint (a z) (b z)) : - planRank (a⊔b)=planRank a+planRank b := by - unfold planRank - rw [← Finset.sum_add_distrib] - refine Finset.sum_congr rfl fun i _ => ?_ - have he := Submodule.finrank_sup_add_finrank_inf_eq (a i) (b i) - rw [(h i).eq_bot,finrank_bot,add_zero] at he - exact he - -theorem plan_new_disjoint (a b : Plan p n) (h : ∀ z,Disjoint (a z) (b z)) : - planNew a b=planRank b := by rw [planNew,plan_add_disjoint a b h,Nat.add_sub_cancel_left] - -variable {I : Type} [Fintype I] - -def kslots (p : Shape) (I : Type) [Fintype I] := - Fintype.card I*(p.g-1)*2 -def kmax (p : Shape) := 56*(p.g-1) -theorem slots_budget {w : I→Bool} (v : Volley p n I) - (hb : v.bounded w) : kslots p I ≤ kmax p := by - classical - have h := v.call_count hb - unfold kslots kmax; nlinarith - -instance instFKeys (t : Tagging p I) (N : ℕ) : Fintype (Keys (p:=p) t N) := - by classical exact inferInstance - -theorem dim_keys (t : Tagging p I) : - dim (Keys (p:=p) t N) = kslots p I * N := by - have h (l : Tag p.g) : - dim (AtomKey (p:=p) l N)=(p.g-1)*(2*N) := by - unfold AtomKey dim - - rw [finrank_pi_fintype] - have he : finrank F (Bool → Vec (Fin N))=2*N := by - rw [finrank_pi_fintype] - simp_rw [show finrank F (Vec (Fin N))=_ from dim_vec _] - simp - simp_rw [he] - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,card_star]; rfl - unfold dim Keys kslots - rw [finrank_pi_fintype] - have hx i : finrank F (AtomKey (p:=p) (t i) N)=(p.g-1)*(2*N) := h (t i) - simp_rw [hx] - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,Nat.cast_id] - ring - -namespace Volley -variable {v : Volley p n I} - -theorem key_slots (t : Tagging p I) {q} {a : Plan p n} - (h : v.avoids a q) : - planNew a (v.keyPlan t) = kslots p I := by - classical - let Y := visits p t - have hh i := key_independent v t h i - have he (z : Place p) : dim (keyPlan v t z)=Fintype.card (Y z.1) := - mrk_inj.mp (hh z).1 - rw [plan_new_disjoint a _ (fun i => Disjoint.mono_left (pin_le_table a i) - (hh i).2.symm), planRank,Fintype.sum_prod_type] - simp_rw [Fintype.sum_bool,he,←two_mul,←Finset.mul_sum] - have hE : ∑ i : Comp p.g,Fintype.card (Y i)=Fintype.card I*(p.g-1) := by - have hf {A : Type} [Fintype A] (p : A → Prop) [DecidablePred p] : - Fintype.card {i:A//p i}=∑ i:A, if p i then (1:ℕ) else 0 := by - rw [Fintype.card_subtype,←Finset.sum_filter]; simp - - have hY (i) : Fintype.card (Y i)=∑ j:I,if inc i (t j) then (1:ℕ) else 0 := hf _ - simp_rw [hY] - rw [Finset.sum_comm] - simp_rw [← hf (fun i => inc i _)] - have hz (j) : Fintype.card {i:Comp p.g//inc i (t j)}=p.g-1 := card_star (t j) - simp_rw [hz] - simp - rw [hE]; unfold kslots; ring - -/-- chosen reference x fixes the pin made of a and all key directions -for every y in the same pin which agrees on query key. -/ -theorem key_pin (t : Tagging p I) {a : Pin p n N} {x y : UnitType p n N} - (hx : a.agree x) (hy : a.agree y) (h : v.keys t x=v.keys t y) : - (Pin.make (v.frozen a.sp t) x).agree y := by - classical - intro i u hu - obtain ⟨l,hl,r,⟨z,rfl⟩,rfl⟩ := Submodule.mem_sup.mp - (show u∈a.sp i⊔v.keyPlan t i from hu) - have hZ : images y i * v.keyM t i.1 = images x i * v.keyM t i.1 := by - ext b j - obtain ⟨k,hk⟩ := j - have ht := congr_fun (congr_fun (congr_fun h k) (⟨i.1,hk⟩ : TagStar _)) i.2 - rw [v.keys_loc,v.keys_loc] at ht - exact congr_fun ht.symm b - change images y i *ᵥ _ = images x i *ᵥ _ - rw [Matrix.mulVec_add,Matrix.mulVec_add,hx _ _ hl,hy _ _ hl] - rw [mulVecLin_apply,mulVec_mulVec,mulVec_mulVec,hZ] -end Volley - -def tau (N k : ℕ) := bp (-((k:ℝ)+0.01)*N) -def hit (N : ℕ) := bp (-0.02*N) - -theorem in_clear {a f : Pin p n N} {k : ℕ} {ζ : ℝ} {w : Wgt (UnitType p n N)} - (hz : ζ ≤ 0.004) (hkz : ζ*k ≤ 0.004) - (hw : SubLaw w) (h : a.clear ζ w) (hF : a.sp≤f.sp) (hk : planRank f.sp=planRank a.sp+k) - (S : UnitType p n N → Prop) - (hS : ∀ x,S x → f.agree x) (ht : tau N k ≤ pr w S) : - IsLaw (onW w S) ∧ f.clear 0.05 (onW w S) := by - classical - have hpos : 0 < pr w S := lt_of_lt_of_le (bp_pos _) ht - have hh : IsLaw (onW w S) := normW_law (subW_nonneg hw.nz _) hpos - refine ⟨hh,fun b => ?_⟩ - let t := planNew f.sp b.sp - by_cases he : t=0 - · change pr _ _ ≤ fee N _ t - rw [he,fee] - simp only [Nat.cast_zero,mul_zero,zero_mul,bp_zero] - exact (pr_le_tot hh.nz).trans hh.total.le - let R := fun x => S x ∧ b.agree x - by_cases hf : 0 < pr w R - · obtain ⟨x,⟨hx,hB⟩,_⟩ := exists_of_pr_pos hw.nz hf - let c := Pin.make (f.sp⊔b.sp) x - have hc : pr w R≤ fee N ζ (planNew a.sp c.sp) := (pr_mono hw.nz (q:=c.agree) - (fun y hy => ((Pin.combine (hS x hx) hB).mpr ⟨hS _ hy.1,hy.2⟩))).trans (h c) - have hN : planNew a.sp c.sp=k+t := by - have hh : planNew a.sp f.sp+t=planNew a.sp c.sp := planNew_mono_add hF - rw [← hh] - rw [planNew, sup_eq_right.mpr hF,hk, Nat.add_sub_cancel_left] - rw [hN] at hc - rw [pr_on] - refine ((div_le_div₀ (bp_pos _).le hc (bp_pos _) ht)).trans ?_ - unfold fee - rw [←bp_sub] - refine bp_le ?_ - have h1 : 1 ≤ (t:ℝ) := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr he - have hg := mul_le_mul_of_nonneg_right hz (show 0≤(t:ℝ) from Nat.cast_nonneg _) - rw [Nat.cast_add] - change _ ≤ -(1-0.05)*(t : ℝ)*N - rw [← sub_mul] - exact mul_le_mul_of_nonneg_right (by linarith only [hkz,h1,hg]) (Nat.cast_nonneg _) - · rw [pr_on] - exact (div_nonpos_of_nonpos_of_nonneg (not_lt.mp hf) hpos.le).trans (bp_pos _).le - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.GradientRealization +import OAI.Combinatorics.HadwigerCounterexample.WalshBounds + +namespace OAI + +/-! # Conditional Cell Entropy -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Submodule Module Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} + +theorem plan_add_disjoint (a b : Plan p n) (h : ∀ z, Disjoint (a z) (b z)) : + planRank (a⊔b)=planRank a+planRank b := by + unfold planRank + rw [← Finset.sum_add_distrib] + refine Finset.sum_congr rfl fun i _ => ?_ + have he := Submodule.finrank_sup_add_finrank_inf_eq (a i) (b i) + rw [(h i).eq_bot,finrank_bot,add_zero] at he + exact he + +theorem plan_new_disjoint (a b : Plan p n) (h : ∀ z,Disjoint (a z) (b z)) : + planNew a b=planRank b := by rw [planNew,plan_add_disjoint a b h,Nat.add_sub_cancel_left] + +variable {I : Type} [Fintype I] + +def kslots (p : Shape) (I : Type) [Fintype I] := + Fintype.card I*(p.g-1)*2 +def kmax (p : Shape) := 56*(p.g-1) +theorem slots_budget {w : I→Bool} (v : Volley p n I) + (hb : v.bounded w) : kslots p I ≤ kmax p := by + classical + have h := v.call_count hb + unfold kslots kmax; nlinarith + +instance instFKeys (t : Tagging p I) (N : ℕ) : Fintype (Keys (p:=p) t N) := + by classical exact inferInstance + +theorem dim_keys (t : Tagging p I) : + dim (Keys (p:=p) t N) = kslots p I * N := by + have h (l : Tag p.g) : + dim (AtomKey (p:=p) l N)=(p.g-1)*(2*N) := by + unfold AtomKey dim + + rw [finrank_pi_fintype] + have he : finrank F (Bool → Vec (Fin N))=2*N := by + rw [finrank_pi_fintype] + simp_rw [show finrank F (Vec (Fin N))=_ from dim_vec _] + simp + simp_rw [he] + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,card_star]; rfl + unfold dim Keys kslots + rw [finrank_pi_fintype] + have hx i : finrank F (AtomKey (p:=p) (t i) N)=(p.g-1)*(2*N) := h (t i) + simp_rw [hx] + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,Nat.cast_id] + ring + +namespace Volley +variable {v : Volley p n I} + +theorem key_slots (t : Tagging p I) {q} {a : Plan p n} + (h : v.avoids a q) : + planNew a (v.keyPlan t) = kslots p I := by + classical + let Y := visits p t + have hh i := key_independent v t h i + have he (z : Place p) : dim (keyPlan v t z)=Fintype.card (Y z.1) := + mrk_inj.mp (hh z).1 + rw [plan_new_disjoint a _ (fun i => Disjoint.mono_left (pin_le_table a i) + (hh i).2.symm), planRank,Fintype.sum_prod_type] + simp_rw [Fintype.sum_bool,he,←two_mul,←Finset.mul_sum] + have hE : ∑ i : Comp p.g,Fintype.card (Y i)=Fintype.card I*(p.g-1) := by + have hf {A : Type} [Fintype A] (p : A → Prop) [DecidablePred p] : + Fintype.card {i:A//p i}=∑ i:A, if p i then (1:ℕ) else 0 := by + rw [Fintype.card_subtype,←Finset.sum_filter]; simp + + have hY (i) : Fintype.card (Y i)=∑ j:I,if inc i (t j) then (1:ℕ) else 0 := hf _ + simp_rw [hY] + rw [Finset.sum_comm] + simp_rw [← hf (fun i => inc i _)] + have hz (j) : Fintype.card {i:Comp p.g//inc i (t j)}=p.g-1 := card_star (t j) + simp_rw [hz] + simp + rw [hE]; unfold kslots; ring + +/-- chosen reference x fixes the pin made of a and all key directions +for every y in the same pin which agrees on query key. -/ +theorem key_pin (t : Tagging p I) {a : Pin p n N} {x y : UnitType p n N} + (hx : a.agree x) (hy : a.agree y) (h : v.keys t x=v.keys t y) : + (Pin.make (v.frozen a.sp t) x).agree y := by + classical + intro i u hu + obtain ⟨l,hl,r,⟨z,rfl⟩,rfl⟩ := Submodule.mem_sup.mp + (show u∈a.sp i⊔v.keyPlan t i from hu) + have hZ : images y i * v.keyM t i.1 = images x i * v.keyM t i.1 := by + ext b j + obtain ⟨k,hk⟩ := j + have ht := congr_fun (congr_fun (congr_fun h k) (⟨i.1,hk⟩ : TagStar _)) i.2 + rw [v.keys_loc,v.keys_loc] at ht + exact congr_fun ht.symm b + change images y i *ᵥ _ = images x i *ᵥ _ + rw [Matrix.mulVec_add,Matrix.mulVec_add,hx _ _ hl,hy _ _ hl] + rw [mulVecLin_apply,mulVec_mulVec,mulVec_mulVec,hZ] +end Volley + +def tau (N k : ℕ) := bp (-((k:ℝ)+0.01)*N) +def hit (N : ℕ) := bp (-0.02*N) + +theorem in_clear {a f : Pin p n N} {k : ℕ} {ζ : ℝ} {w : Wgt (UnitType p n N)} + (hz : ζ ≤ 0.004) (hkz : ζ*k ≤ 0.004) + (hw : SubLaw w) (h : a.clear ζ w) (hF : a.sp≤f.sp) (hk : planRank f.sp=planRank a.sp+k) + (S : UnitType p n N → Prop) + (hS : ∀ x,S x → f.agree x) (ht : tau N k ≤ pr w S) : + IsLaw (onW w S) ∧ f.clear 0.05 (onW w S) := by + classical + have hpos : 0 < pr w S := lt_of_lt_of_le (bp_pos _) ht + have hh : IsLaw (onW w S) := normW_law (subW_nonneg hw.nz _) hpos + refine ⟨hh,fun b => ?_⟩ + let t := planNew f.sp b.sp + by_cases he : t=0 + · change pr _ _ ≤ fee N _ t + rw [he,fee] + simp only [Nat.cast_zero,mul_zero,zero_mul,bp_zero] + exact (pr_le_tot hh.nz).trans hh.total.le + let R := fun x => S x ∧ b.agree x + by_cases hf : 0 < pr w R + · obtain ⟨x,⟨hx,hB⟩,_⟩ := exists_of_pr_pos hw.nz hf + let c := Pin.make (f.sp⊔b.sp) x + have hc : pr w R≤ fee N ζ (planNew a.sp c.sp) := (pr_mono hw.nz (q:=c.agree) + (fun y hy => ((Pin.combine (hS x hx) hB).mpr ⟨hS _ hy.1,hy.2⟩))).trans (h c) + have hN : planNew a.sp c.sp=k+t := by + have hh : planNew a.sp f.sp+t=planNew a.sp c.sp := planNew_mono_add hF + rw [← hh] + rw [planNew, sup_eq_right.mpr hF,hk, Nat.add_sub_cancel_left] + rw [hN] at hc + rw [pr_on] + refine ((div_le_div₀ (bp_pos _).le hc (bp_pos _) ht)).trans ?_ + unfold fee + rw [←bp_sub] + refine bp_le ?_ + have h1 : 1 ≤ (t:ℝ) := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr he + have hg := mul_le_mul_of_nonneg_right hz (show 0≤(t:ℝ) from Nat.cast_nonneg _) + rw [Nat.cast_add] + change _ ≤ -(1-0.05)*(t : ℝ)*N + rw [← sub_mul] + exact mul_le_mul_of_nonneg_right (by linarith only [hkz,h1,hg]) (Nat.cast_nonneg _) + · rw [pr_on] + exact (div_nonpos_of_nonpos_of_nonneg (not_lt.mp hf) hpos.le).trans (bp_pos _).le + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalFlags.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalFlags.lean index 3417359e3abafdd2bd3b1bfe67c76ee75af0de93..5de58c52f021b71b5a805fbe678f724feeec38f8 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalFlags.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalFlags.lean @@ -1,107 +1,107 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteProjectionCenters - -namespace OAI - -/-! # Conditional Flags -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real -open scoped BigOperators -variable {A B C X Y : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype X] [Fintype Y] -variable {w : Wgt X} - -def stained (w : Wgt X) (f : X→Y) (i : Y) : Wgt X := by - classical exact if mapW w f i≠0 then onW w (fun x => f x=i) else w -theorem stained_law (f : X→Y) (hw : IsLaw w) (i : Y) : IsLaw (stained w f i) := by - unfold stained; split - next h => exact on_law hw.nz (lt_of_le_of_ne ((mapW_law hw f).nz _) (Ne.symm h)) - next => exact hw - -theorem stain_rebuild (f : X→Y) (P : Y→Prop) (hw : IsLaw w) : - subW w (P∘f) = mixW (subW (mapW w f) P) (stained w f) := by - classical - have hh := disintegrate hw.nz f - funext i - have hi (y) : - mapW w f y * stained w f y i= - mapW w f y * onW w (fun x => f x=y) i := by - by_cases h : mapW w f y=0 <;> simp [stained,h] - have he := congr_fun hh i - unfold subW mixW Function.comp - unfold mixW at he - rw [he,avg,Finset.sum_mul] - unfold avg at * - apply sum_congr rfl - intro j _ - rw [mul_right_comm _ (ind _), hi] - by_cases hx : f i=j - · rw [hx] - simp only [onW_val,ind_zero hx,mul_zero,zero_div,zero_mul] - -theorem stain_inputs (f : X→Y) (hw : IsLaw w) : - w=mixW (mapW w f) (stained w f) := by - have ht := stain_rebuild f (fun _ => True) hw - unfold subW at ht - simpa only [Function.comp_apply,ind_true,mul_one] using ht - -variable {μ : Wgt A} - -def colored (μ : Wgt A) (w : Wgt X) (v : A→ X→ Y) := - semi μ (fun i => mapW w (v i)) -def coloredP (w : Wgt X) (v : A→ X→Y) (K : A→X→B) := - fun i : A×Y => mapW (stained w (v i.1) i.2) (K i.1) -def flaggedW (μ : Wgt A) (w : Wgt X) (v : A→X→Y) (K : A→X→B) (P : A→Y→Prop) := - mixW μ (fun i => mapW (subW w (P i ∘ v i)) (K i)) - -theorem semi_total (μ : Wgt A) (v : A → Wgt Y) : - tot (semi μ v)=avg μ (fun i=>tot (v i)) := by - simpa only [avg_const,mul_one] using semi_avg μ v (fun i=>1) - -theorem colored_ultra (hμ : IsLaw μ) (hw : IsLaw w) (K : A→X→B) (v : A→X→Y) : - Ultra (colored μ w v) (coloredP w v K) := by - have ht (i) := mapW_law hw (v i) - refine ⟨⟨fun x => mul_nonneg (hμ.nz _) ((ht _).nz _),?_⟩, - fun i => mapW_law (stained_law _ hw _) (K i.1)⟩ - unfold colored; rw [semi_total] - simp_rw [(ht _).total] - exact hμ.avg_const _ - -theorem flag_catalog (K : A→ X→B) (v : A→ X→ Y) (P : A→ Y→ Prop) - (hw : IsLaw w) (hμ : IsLaw μ) : - catalog (colored μ w v) (coloredP w v K) - (flaggedW μ w v K P) := by - classical - let W := colored μ w v - have hh := (colored_ultra hμ hw K v).law - refine ⟨subW W (fun i => P i.1 i.2),subW_nonneg hh.nz _,subW_le hh.nz _,?_⟩ - unfold flaggedW - simp_rw [stain_rebuild (v _) (P _) hw,map_mix] - funext x - simp only [mixW,coloredP,colored,W,avg,subW,semi,Finset.mul_sum,Fintype.sum_prod_type] - exact sum_congr rfl fun i _ => sum_congr rfl fun j _ => by ring - -theorem colored_budget [Nonempty Y] (K : A→ X→B) (v : A→ X→ Y) (f : B→C) - (hw : IsLaw w) (hμ : IsLaw μ) : - budget (colored μ w v) (coloredP w v K) f ≤ - budget μ (fun i => mapW w (K i)) f + Real.log (num Y) := by - unfold budget colored coloredP - rw [semi_avg,← hμ.avg_const (Real.log _),← avg_add] - apply avg_mono hμ.nz - intro i - let u := mapW w (v i) - have he : IsLaw u := mapW_law hw (v i) - let q (j : Y) := mapW (mapW (stained w (v i) j) (K i)) f - have hq (j) : IsLaw (q j) := mapW_law (mapW_law (stained_law _ hw _) _) _ - have ht : mapW (mapW w (K i)) f=mixW u q := by - calc mapW _ _ = mapW (mapW (mixW u (stained w (v i))) (K i)) f := - congrArg (fun z => mapW (mapW z (K i)) f) (stain_inputs (v i) hw) - _ = _ := by rw [map_mix,map_mix] - change avg u (fun j => tension (q j) _)≤ tension _ _+_ - rw [tension_mix,add_comm _ (log _),ht] - exact add_le_add_left (mix_charge he hq) _ -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteProjectionCenters + +namespace OAI + +/-! # Conditional Flags -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real +open scoped BigOperators +variable {A B C X Y : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype X] [Fintype Y] +variable {w : Wgt X} + +def stained (w : Wgt X) (f : X→Y) (i : Y) : Wgt X := by + classical exact if mapW w f i≠0 then onW w (fun x => f x=i) else w +theorem stained_law (f : X→Y) (hw : IsLaw w) (i : Y) : IsLaw (stained w f i) := by + unfold stained; split + next h => exact on_law hw.nz (lt_of_le_of_ne ((mapW_law hw f).nz _) (Ne.symm h)) + next => exact hw + +theorem stain_rebuild (f : X→Y) (P : Y→Prop) (hw : IsLaw w) : + subW w (P∘f) = mixW (subW (mapW w f) P) (stained w f) := by + classical + have hh := disintegrate hw.nz f + funext i + have hi (y) : + mapW w f y * stained w f y i= + mapW w f y * onW w (fun x => f x=y) i := by + by_cases h : mapW w f y=0 <;> simp [stained,h] + have he := congr_fun hh i + unfold subW mixW Function.comp + unfold mixW at he + rw [he,avg,Finset.sum_mul] + unfold avg at * + apply sum_congr rfl + intro j _ + rw [mul_right_comm _ (ind _), hi] + by_cases hx : f i=j + · rw [hx] + simp only [onW_val,ind_zero hx,mul_zero,zero_div,zero_mul] + +theorem stain_inputs (f : X→Y) (hw : IsLaw w) : + w=mixW (mapW w f) (stained w f) := by + have ht := stain_rebuild f (fun _ => True) hw + unfold subW at ht + simpa only [Function.comp_apply,ind_true,mul_one] using ht + +variable {μ : Wgt A} + +def colored (μ : Wgt A) (w : Wgt X) (v : A→ X→ Y) := + semi μ (fun i => mapW w (v i)) +def coloredP (w : Wgt X) (v : A→ X→Y) (K : A→X→B) := + fun i : A×Y => mapW (stained w (v i.1) i.2) (K i.1) +def flaggedW (μ : Wgt A) (w : Wgt X) (v : A→X→Y) (K : A→X→B) (P : A→Y→Prop) := + mixW μ (fun i => mapW (subW w (P i ∘ v i)) (K i)) + +theorem semi_total (μ : Wgt A) (v : A → Wgt Y) : + tot (semi μ v)=avg μ (fun i=>tot (v i)) := by + simpa only [avg_const,mul_one] using semi_avg μ v (fun i=>1) + +theorem colored_ultra (hμ : IsLaw μ) (hw : IsLaw w) (K : A→X→B) (v : A→X→Y) : + Ultra (colored μ w v) (coloredP w v K) := by + have ht (i) := mapW_law hw (v i) + refine ⟨⟨fun x => mul_nonneg (hμ.nz _) ((ht _).nz _),?_⟩, + fun i => mapW_law (stained_law _ hw _) (K i.1)⟩ + unfold colored; rw [semi_total] + simp_rw [(ht _).total] + exact hμ.avg_const _ + +theorem flag_catalog (K : A→ X→B) (v : A→ X→ Y) (P : A→ Y→ Prop) + (hw : IsLaw w) (hμ : IsLaw μ) : + catalog (colored μ w v) (coloredP w v K) + (flaggedW μ w v K P) := by + classical + let W := colored μ w v + have hh := (colored_ultra hμ hw K v).law + refine ⟨subW W (fun i => P i.1 i.2),subW_nonneg hh.nz _,subW_le hh.nz _,?_⟩ + unfold flaggedW + simp_rw [stain_rebuild (v _) (P _) hw,map_mix] + funext x + simp only [mixW,coloredP,colored,W,avg,subW,semi,Finset.mul_sum,Fintype.sum_prod_type] + exact sum_congr rfl fun i _ => sum_congr rfl fun j _ => by ring + +theorem colored_budget [Nonempty Y] (K : A→ X→B) (v : A→ X→ Y) (f : B→C) + (hw : IsLaw w) (hμ : IsLaw μ) : + budget (colored μ w v) (coloredP w v K) f ≤ + budget μ (fun i => mapW w (K i)) f + Real.log (num Y) := by + unfold budget colored coloredP + rw [semi_avg,← hμ.avg_const (Real.log _),← avg_add] + apply avg_mono hμ.nz + intro i + let u := mapW w (v i) + have he : IsLaw u := mapW_law hw (v i) + let q (j : Y) := mapW (mapW (stained w (v i) j) (K i)) f + have hq (j) : IsLaw (q j) := mapW_law (mapW_law (stained_law _ hw _) _) _ + have ht : mapW (mapW w (K i)) f=mixW u q := by + calc mapW _ _ = mapW (mapW (mixW u (stained w (v i))) (K i)) f := + congrArg (fun z => mapW (mapW z (K i)) f) (stain_inputs (v i) hw) + _ = _ := by rw [map_mix,map_mix] + change avg u (fun j => tension (q j) _)≤ tension _ _+_ + rw [tension_mix,add_comm _ (log _),ht] + exact add_le_add_left (mix_charge he hq) _ +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalFourCorners.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalFourCorners.lean index c3b6142bf90b66960e0ae3e5796ec2051c00e6e6..e71ea590d5e82d91f0b36c706a3c7d9b36f66c62 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalFourCorners.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalFourCorners.lean @@ -1,101 +1,101 @@ -import OAI.Combinatorics.HadwigerCounterexample.UnseenCrossingFactorization -import OAI.Combinatorics.HadwigerCounterexample.GramConditionedLaws - -namespace OAI - -/-! # Conditional Four Corners -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module LinearMap Function Filter -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I J : Type} [Fintype I] [DecidableEq I] -set_option maxHeartbeats 600000 in -private theorem stip_mask (E : Rail I) (t : Vec E) (p : Wgt (Rack I N)) (δ : ℝ) - (hδ : 0≤δ) (hh : |avg unif p|≤δ) (h : ∀ f:Vec E,f≠0 → - |avg unif (fun i=>phasedBy (ledgerM E f) i*p i)|≤bp (-(N:ℝ)/2)) : - |partMean (fun x=>traced x E t) p|≤δ+bp (-(N:ℝ)/2) := by - classical - have he (f : Vec E) : - |vectorPhase f t*avg unif (fun i : Rack I N=>phasedBy (ledgerM E f) i*p i)|≤ δ+bp (-(N:ℝ)/2) := by - rw [abs_mul,vectorPhase,wsign_abs,one_mul] - by_cases hz : f=0 - · subst f; simpa only [ledger_zero,layer_zero,one_mul] using hh.trans (le_add_of_nonneg_right (bp_pos (-(N:ℝ)/2)).le) - exact (h f hz).trans (le_add_of_nonneg_left hδ) - have hf : partMean (fun x=>traced x E t) p=avg unif (fun f:Vec E => vectorPhase f t*avg unif - (fun i:Rack I N=>phasedBy (ledgerM E f) i*p i)) := by - unfold partMean; simp_rw [rail_expand,←avg_mul] - rw [avg_avg]; simp_rw [←avg_mul']; exact avg_congr (fun i _=>avg_congr fun j _=>by ring) - rw [hf] - exact (abs_avg_le unif_law.nz).trans (unif_law.avg_le he) -namespace Template -variable (v : Template p I) - -theorem pack_bound (v : Template p I) (j : I) (U : Wgt (Keys (p:=p) v.t N)) - (hU : ∀ i, |U i|≤1) (i) : |packSecs v j U i| ≤1 := by - unfold packSecs; rw [Finset.abs_prod] - exact (Finset.prod_le_prod₀ (fun i _=>abs_nonneg _) (fun i _ => hU _)).trans_eq (by simp) - -set_option maxHeartbeats 800000 in -theorem lopsided (v : Template p I) (j : I) (q : I→F) - (U : Wgt (Keys (p:=p) v.t N)) (δ : ℝ) (hδ : 0≤δ) - (hU : ∀ x,|U x|≤1) (h : chairCut v j U δ) - (hW : carried U (ownPart (p:=p) v.t q)) - (Z : GeoM v.seam) : - |partMean (gramPart Z) (packSecs v j U)|≤δ+bp (-(N:ℝ)/2) := by - classical - let P := packSecs v j U - let Q := gramPart Z (N:=N) - have hb := bp_pos (-(N:ℝ)/2) - by_cases hp : ∃ x,Q x∧P x≠0 - · obtain ⟨x,hx,hP⟩ := hp - let E := cantRail v j - let T (y : v.PackStack N) := traced y E (cantVec v j Z) - have hg i : ind (Q i)*P i=ind (T i)*P i := by - by_cases hh : P i=0 - · rw [hh,mul_zero,mul_zero] - rw [show Q i=T i from propext - (cant_bridge v j q Z x i (pack_gate v j q U hW hP) (pack_gate v j q U hW hh) hx)] - change |avg unif (fun x => ind (Q x)*P x)|≤_ - simp_rw [hg] - exact stip_mask E (cantVec v j Z) P δ hδ (global_quart v j U hU δ h) (cant_leak v j U hU) - have hh (x) : ind (Q x)*P x=0 := by - by_cases he : Q x <;> simp only [he,ind_true,ind_false,one_mul,zero_mul] - exact not_ne_iff.mp (fun hx => hp ⟨x,he,hx⟩) - change |avg unif (fun x=>ind (Q x)*P x)|≤_ - simp_rw [hh,avg_zero,abs_zero] - exact add_nonneg hδ hb.le - -set_option maxHeartbeats 800000 in -theorem pack_hot (v : Template p I) (j : I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) - (δ : ℝ) (hδ : 0≤δ) (hU : ∀ x, |U x|≤1) (h : chairCut v j U δ) - (hW : carried U (ownPart (p:=p) v.t q)) - (Z : GeoM v.seam) (k : ℝ) (hk : ∀ i,num (Port v.seam i)≤ k) - (hN : 2*k-(N:ℝ) ≤ -1) : - let W := netFact v.seam - |avg (rackStation Z N) (packSecs v j U)|≤ - 2*W*(num (Ports p)*(2*bp (k-N)))+W*(δ+bp (-(N:ℝ)/2)) := by - classical - intro W - let B := pr unif (gramPart Z (N:=N)) - have hb := wave_norm Z N (fun i => by linarith only [hN,hk i]) - have h0 : 0phasedBy (ledgerM E f) i*p i)|≤bp (-(N:ℝ)/2)) : + |partMean (fun x=>traced x E t) p|≤δ+bp (-(N:ℝ)/2) := by + classical + have he (f : Vec E) : + |vectorPhase f t*avg unif (fun i : Rack I N=>phasedBy (ledgerM E f) i*p i)|≤ δ+bp (-(N:ℝ)/2) := by + rw [abs_mul,vectorPhase,wsign_abs,one_mul] + by_cases hz : f=0 + · subst f; simpa only [ledger_zero,layer_zero,one_mul] using hh.trans (le_add_of_nonneg_right (bp_pos (-(N:ℝ)/2)).le) + exact (h f hz).trans (le_add_of_nonneg_left hδ) + have hf : partMean (fun x=>traced x E t) p=avg unif (fun f:Vec E => vectorPhase f t*avg unif + (fun i:Rack I N=>phasedBy (ledgerM E f) i*p i)) := by + unfold partMean; simp_rw [rail_expand,←avg_mul] + rw [avg_avg]; simp_rw [←avg_mul']; exact avg_congr (fun i _=>avg_congr fun j _=>by ring) + rw [hf] + exact (abs_avg_le unif_law.nz).trans (unif_law.avg_le he) +namespace Template +variable (v : Template p I) + +theorem pack_bound (v : Template p I) (j : I) (U : Wgt (Keys (p:=p) v.t N)) + (hU : ∀ i, |U i|≤1) (i) : |packSecs v j U i| ≤1 := by + unfold packSecs; rw [Finset.abs_prod] + exact (Finset.prod_le_prod₀ (fun i _=>abs_nonneg _) (fun i _ => hU _)).trans_eq (by simp) + +set_option maxHeartbeats 800000 in +theorem lopsided (v : Template p I) (j : I) (q : I→F) + (U : Wgt (Keys (p:=p) v.t N)) (δ : ℝ) (hδ : 0≤δ) + (hU : ∀ x,|U x|≤1) (h : chairCut v j U δ) + (hW : carried U (ownPart (p:=p) v.t q)) + (Z : GeoM v.seam) : + |partMean (gramPart Z) (packSecs v j U)|≤δ+bp (-(N:ℝ)/2) := by + classical + let P := packSecs v j U + let Q := gramPart Z (N:=N) + have hb := bp_pos (-(N:ℝ)/2) + by_cases hp : ∃ x,Q x∧P x≠0 + · obtain ⟨x,hx,hP⟩ := hp + let E := cantRail v j + let T (y : v.PackStack N) := traced y E (cantVec v j Z) + have hg i : ind (Q i)*P i=ind (T i)*P i := by + by_cases hh : P i=0 + · rw [hh,mul_zero,mul_zero] + rw [show Q i=T i from propext + (cant_bridge v j q Z x i (pack_gate v j q U hW hP) (pack_gate v j q U hW hh) hx)] + change |avg unif (fun x => ind (Q x)*P x)|≤_ + simp_rw [hg] + exact stip_mask E (cantVec v j Z) P δ hδ (global_quart v j U hU δ h) (cant_leak v j U hU) + have hh (x) : ind (Q x)*P x=0 := by + by_cases he : Q x <;> simp only [he,ind_true,ind_false,one_mul,zero_mul] + exact not_ne_iff.mp (fun hx => hp ⟨x,he,hx⟩) + change |avg unif (fun x=>ind (Q x)*P x)|≤_ + simp_rw [hh,avg_zero,abs_zero] + exact add_nonneg hδ hb.le + +set_option maxHeartbeats 800000 in +theorem pack_hot (v : Template p I) (j : I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) + (δ : ℝ) (hδ : 0≤δ) (hU : ∀ x, |U x|≤1) (h : chairCut v j U δ) + (hW : carried U (ownPart (p:=p) v.t q)) + (Z : GeoM v.seam) (k : ℝ) (hk : ∀ i,num (Port v.seam i)≤ k) + (hN : 2*k-(N:ℝ) ≤ -1) : + let W := netFact v.seam + |avg (rackStation Z N) (packSecs v j U)|≤ + 2*W*(num (Ports p)*(2*bp (k-N)))+W*(δ+bp (-(N:ℝ)/2)) := by + classical + intro W + let B := pr unif (gramPart Z (N:=N)) + have hb := wave_norm Z N (fun i => by linarith only [hN,hk i]) + have h0 : 0 w.sameInk i (x.profile j o m (s j) y) → - x.profile j o m (s j) y=w.amp i) - -set_option maxHeartbeats 800000 in -theorem thinGlaze (Y : Silhouette p N r) (o : UnitType p n N) (i : Messenger q) - (s : Charts p n d) (k:AtomKey (p:=p) (t i) N) - {δ : ℝ} (hd:0<δ) - (hw:w.moral t z) (hp : w.steady t z m K s o) - (he : gauze p δ δ Y m K o) (ht : 1≤p.r) (hn : 2*p.r≤n) : - let x:=w.allure t z i - δ ≤ x.reference Y (Y (t i) (z i) k) → - basebeta p K/2 ≤ w.seraph t z o m s Y i k := by - classical - intro x h - let j:=parcel b i - let z':= w.amp i; let a:=Y (t i) (z i) k - let μ:=x.reflected Y j o m (s j) a - have hx : x.apt := w.allure_apt t z hw i - have hm : IsLaw μ:= x.reflectedLaw Y (Appearance.witLaw hx ht hn) _ _ _ _ _ - obtain ⟨h1,h2,h3⟩:=hp.steadyAxes i - have hh := x.demonstrates Y o (m:=m) (s j) K j a δ hd z'.1 z'.2.1.2 (hw.2.2 i) - (hw.2.1 i) ht hn h (he _) h1 h2 h3 - have hq (y) (h:μ y≠0) (hz:w.sameInk i y): y=w.amp i := by - let P := fun x=>w.sameInk i x → x=w.amp i - have hb : carried μ P:= x.reflection_exact Y j o m (s j) a P (hp.sufficesP i) - exact (show P y from not_not.mp fun hi=>h (hb y hi)) hz - have h4 : (z'.1.diagO,z'.2.1.2)=z'.2.1 := Prod.ext (hp.enough i) rfl - rw [h4] at hh - exact hh.trans ((pr_on_mono hm.nz hq).trans_eq (pr_point' ..)) - -theorem tinyCell_loss (Y:Silhouette p N r) {δ:ℝ} (hd:0≤δ) (i : Messenger q) - (hN: 2*num (Messenger q×Toast p)-(N:ℝ)≤ -1) - (hh:2*num (Toast p)-(N:ℝ)≤ -1) : - let x:= w.allure t z i - let μ:=lawNu p N t z - pr μ (fun y=> x.reference Y (Y (t i) (z i) (y i)) < δ) ≤ - r*δ+2*netFact (trayPort p t)*bp (-(N:ℝ)/2) := by - classical - intro a μ - let I:=Messenger q - let Ω:=fun i=> lawOmega p N (t i) (z i) - let S:=fun y=>a.reference Y (Y (t i) (z i) y)<δ - let f : ∀ i:Messenger q,Wgt (AtomKey (p:=p) (t i) N) := fun j=> - if h:j=i then h ▸ (fun x : AtomKey (p:=p) (t i) N=> ind (S x)) else fun _=>1 - have hi : f i=fun x=>ind (S x) := by unfold f; simp - have hf j (h:j≠i) : f j=fun _ => 1 := by unfold f; simp [h] - have hg j x : |f j x| ≤ 1 := by - by_cases h:j=i - · subst j; rw [hi]; exact (abs_of_nonneg (ind_nonneg _)).le.trans (ind_le_one _) - rw [hf j h]; simp - have he x : prodW f x= ind (S (x i)) := by - unfold prodW; rw [Finset.prod_eq_single i _ (by simp),hi] - intro b _ hb; rw [hf _ hb] - have hR : - ∏ i,avg (Ω i) (f i) = pr (Ω i) S := by - rw [Finset.prod_eq_single i _ (by simp),hi]; rfl - intro b _ hb; rw [hf _ hb,(omegaLaw _ _ _ hh).avg_const] - let L:=2*netFact (trayPort p t)*bp (-(N:ℝ)/2) - have hM : pr μ (fun x=> S (x i)) ≤ pr (Ω i) S+L := by - have hm := reference_product t z f hg hN - change |avg μ (prodW f)-∏ i,avg (Ω i) (f i)|≤L at hm - rw [show prodW f=(fun x=>ind (S (x i))) from funext he,hR] at hm - exact sub_le_iff_le_add'.mp ((abs_le.mp hm).2) - have hZ : pr (Ω i) S ≤ r*δ := by - let Q:=fun x=> a.reference Y x < δ - rw [show pr (Ω i) S= pr (a.reference Y) Q from (mapW_pr (Ω i) (Y (t i) (z i)) Q).symm] - exact haze_small _ δ hd - exact hM.trans (add_le_add_left hZ _) - -end Quill -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SimultaneousProjection + +namespace OAI + +/-! # Conditional Large Set Hits -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix LinearMap Function +open scoped BigOperators Topology +open Template +variable {p:Shape} {M n N K r s0:ℕ} +namespace StatusAnalysis +namespace Quill +variable {q:Format} {d:Rates} {b:Bool} (w:Quill p q d b) (t : Tagging p (Messenger q)) + (z:Messenger q→F) (m:Mixer p n) + +def prelim (K:ℕ) (s:Charts p n d) (i:Messenger q) := + d (parcel b i)≤ K^2 ∧ Injective (s (parcel b i)) ∧ + ∀ x,totalRank (s (parcel b i) x)≤ K + +def sameInk (i:Messenger q) (v: Magazine p (d (parcel b i))) := + Appearance.nearly p (w.amp i).1 (w.amp i).2.1 v + +structure steady (K:ℕ) (s:Charts p n d) (o: UnitType p n N) : Prop where + frame : PreparationParameters.frameSide p m o + steadyAxes (i:Messenger q) : prelim (b:=b) K s i + enough i : (w.amp i).1.diagO=(w.amp i).2.1.1 + sufficesP i : + let j:= parcel b i; let x:=w.allure t z i + carried (w.policies t z n i) (fun y=> w.sameInk i (x.profile j o m (s j) y) → + x.profile j o m (s j) y=w.amp i) + +set_option maxHeartbeats 800000 in +theorem thinGlaze (Y : Silhouette p N r) (o : UnitType p n N) (i : Messenger q) + (s : Charts p n d) (k:AtomKey (p:=p) (t i) N) + {δ : ℝ} (hd:0<δ) + (hw:w.moral t z) (hp : w.steady t z m K s o) + (he : gauze p δ δ Y m K o) (ht : 1≤p.r) (hn : 2*p.r≤n) : + let x:=w.allure t z i + δ ≤ x.reference Y (Y (t i) (z i) k) → + basebeta p K/2 ≤ w.seraph t z o m s Y i k := by + classical + intro x h + let j:=parcel b i + let z':= w.amp i; let a:=Y (t i) (z i) k + let μ:=x.reflected Y j o m (s j) a + have hx : x.apt := w.allure_apt t z hw i + have hm : IsLaw μ:= x.reflectedLaw Y (Appearance.witLaw hx ht hn) _ _ _ _ _ + obtain ⟨h1,h2,h3⟩:=hp.steadyAxes i + have hh := x.demonstrates Y o (m:=m) (s j) K j a δ hd z'.1 z'.2.1.2 (hw.2.2 i) + (hw.2.1 i) ht hn h (he _) h1 h2 h3 + have hq (y) (h:μ y≠0) (hz:w.sameInk i y): y=w.amp i := by + let P := fun x=>w.sameInk i x → x=w.amp i + have hb : carried μ P:= x.reflection_exact Y j o m (s j) a P (hp.sufficesP i) + exact (show P y from not_not.mp fun hi=>h (hb y hi)) hz + have h4 : (z'.1.diagO,z'.2.1.2)=z'.2.1 := Prod.ext (hp.enough i) rfl + rw [h4] at hh + exact hh.trans ((pr_on_mono hm.nz hq).trans_eq (pr_point' ..)) + +theorem tinyCell_loss (Y:Silhouette p N r) {δ:ℝ} (hd:0≤δ) (i : Messenger q) + (hN: 2*num (Messenger q×Toast p)-(N:ℝ)≤ -1) + (hh:2*num (Toast p)-(N:ℝ)≤ -1) : + let x:= w.allure t z i + let μ:=lawNu p N t z + pr μ (fun y=> x.reference Y (Y (t i) (z i) (y i)) < δ) ≤ + r*δ+2*netFact (trayPort p t)*bp (-(N:ℝ)/2) := by + classical + intro a μ + let I:=Messenger q + let Ω:=fun i=> lawOmega p N (t i) (z i) + let S:=fun y=>a.reference Y (Y (t i) (z i) y)<δ + let f : ∀ i:Messenger q,Wgt (AtomKey (p:=p) (t i) N) := fun j=> + if h:j=i then h ▸ (fun x : AtomKey (p:=p) (t i) N=> ind (S x)) else fun _=>1 + have hi : f i=fun x=>ind (S x) := by unfold f; simp + have hf j (h:j≠i) : f j=fun _ => 1 := by unfold f; simp [h] + have hg j x : |f j x| ≤ 1 := by + by_cases h:j=i + · subst j; rw [hi]; exact (abs_of_nonneg (ind_nonneg _)).le.trans (ind_le_one _) + rw [hf j h]; simp + have he x : prodW f x= ind (S (x i)) := by + unfold prodW; rw [Finset.prod_eq_single i _ (by simp),hi] + intro b _ hb; rw [hf _ hb] + have hR : + ∏ i,avg (Ω i) (f i) = pr (Ω i) S := by + rw [Finset.prod_eq_single i _ (by simp),hi]; rfl + intro b _ hb; rw [hf _ hb,(omegaLaw _ _ _ hh).avg_const] + let L:=2*netFact (trayPort p t)*bp (-(N:ℝ)/2) + have hM : pr μ (fun x=> S (x i)) ≤ pr (Ω i) S+L := by + have hm := reference_product t z f hg hN + change |avg μ (prodW f)-∏ i,avg (Ω i) (f i)|≤L at hm + rw [show prodW f=(fun x=>ind (S (x i))) from funext he,hR] at hm + exact sub_le_iff_le_add'.mp ((abs_le.mp hm).2) + have hZ : pr (Ω i) S ≤ r*δ := by + let Q:=fun x=> a.reference Y x < δ + rw [show pr (Ω i) S= pr (a.reference Y) Q from (mapW_pr (Ω i) (Y (t i) (z i)) Q).symm] + exact haze_small _ δ hd + exact hM.trans (add_le_add_left hZ _) + +end Quill +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalProductLaws.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalProductLaws.lean index b40a9100a81a12c8712f12ffd8c1abc624add5ee..f9f94109bce9a891e296b7737cfbd5939996d796 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalProductLaws.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalProductLaws.lean @@ -1,125 +1,125 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteConditioning - -namespace OAI - -/-! # Conditional Product Laws -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators - -variable {A B I : Type} [Fintype A] [Fintype B] - -theorem subLaw_pair {w : Wgt A} {v : Wgt B} (hw : SubLaw w) (hv : SubLaw v) : - SubLaw (pairW w v) := by - refine ⟨fun x => mul_nonneg (hw.nz _) (hv.nz _),?_⟩ - rw [pairW_tot] - exact (mul_le_mul hw.total hv.total (tot_nonneg hv.nz) (by norm_num)).trans_eq (one_mul _) - -theorem pair_unif : - unif (α:=A×B) = pairW unif unif := by - funext x; simp [pairW,unif_apply,mul_comm] - -theorem unifOn_slice (p : A × B → Prop) (x : A) (y : B) : - unifOn p (x,y) = - mapW (unifOn p) Prod.fst x * unifOn (fun y => p (x,y)) y := by - classical - have hm : mapW (unifOn p) Prod.fst x = - nbr (fun y => p (x,y)) / nbr p := by - simp only [mapW,pr,avg,Fintype.sum_prod_type,unifOn_val, nbr,tot] - rw [Finset.sum_eq_single x] - · simp [ind_true,div_eq_mul_inv,Finset.sum_mul] - · intro b _ hb - simp [ind,hb] - · simp - rw [hm,unifOn_val,unifOn_val] - by_cases h : p (x,y) - · have hh {A : Type} [Fintype A] (p : A → Prop) (x : A) (hx : p x) : 0 < nbr p := by - have hp := weight_le_tot (fun y => ind_nonneg (p y)) x - exact lt_of_lt_of_le (ind_one hx ▸ zero_lt_one) hp - rw [ind_one h] - have hv := hh _ _ h - have hw := hh (fun y => p (x,y)) _ h - field_simp - · rw [ind_zero h] - ring - -theorem unifOn_and (p q : A → Prop) : - onW (unifOn p) q = unifOn (fun x => p x ∧ q x) := by - classical - have hp : pr (unifOn p) q = nbr (fun x => p x ∧ q x) / nbr p := by - simp only [pr,avg,unifOn_val,div_eq_mul_inv,ind_and,nbr,tot,Finset.sum_mul] - refine Finset.sum_congr rfl fun i _ => ?_ - ring - funext x - rw [onW_val,hp,unifOn_val,unifOn_val,ind_and] - by_cases h : p x - · by_cases g : q x - · have hl (p : A → Prop) (h : p x) : 0 < nbr p := - lt_of_lt_of_le (ind_one h ▸ zero_lt_one) (weight_le_tot (fun y => ind_nonneg (p y)) x) - have hh := hl p h - have hg := hl (fun x => p x ∧ q x) ⟨h,g⟩ - field_simp - · rw [ind_zero g] - ring - · rw [ind_zero h] - ring - -theorem unifOn_and_prod (p : A → Prop) (q : B → Prop) : - unifOn (fun x : A × B => p x.1 ∧ q x.2) = pairW (unifOn p) (unifOn q) := by - have h : - nbr (fun x : A × B => p x.1 ∧ q x.2) = nbr p * nbr q := by - change tot _ = _ * _ - simp_rw [ind_and] - exact pairW_tot (fun x => ind (p x)) (fun y => ind (q y)) - funext x - simp only [pairW,unifOn_val,h,ind_and] - ring_nf - -theorem pr_cap {w v : Wgt A} {c : ℝ} (h : ∀ x, w x ≤ c*v x) (p : A → Prop) : - pr w p ≤ c*pr v p := calc - _ ≤ pr (fun x => c*v x) p := pr_mono_left (w:=w) (v:=fun x => c*v x) h _ - _ = _ := by simp only [pr,avg,Finset.mul_sum,mul_assoc] - -def semi (w : Wgt A) (k : A → Wgt B) : Wgt (A × B) := fun x => w x.1 * k x.1 x.2 - -theorem semi_avg (w : Wgt A) (k : A → Wgt B) (f : A × B → ℝ) : - avg (semi w k) f = avg w (fun x => avg (k x) (fun y => f (x,y))) := by - simp only [avg,semi,Fintype.sum_prod_type,Finset.mul_sum,mul_assoc] - -theorem pair_semi_avg (w w' : Wgt A) (k k' : A → Wgt B) (f : (A × B) × (A × B) → ℝ) : - avg (pairW (semi w k) (semi w' k')) f = - avg (pairW w w') (fun x => - avg (pairW (k x.1) (k' x.2)) (fun y => f ((x.1,y.1), (x.2,y.2)))) := by - simp only [pairW_avg, semi_avg] - refine avg_congr fun x _ => ?_ - exact avg_avg _ _ _ - -theorem pair_semi_pr (w w' : Wgt A) (k k' : A → Wgt B) (p : A × A → Prop) (q : B × B → Prop) : - pr (pairW (semi w k) (semi w' k')) (fun x => p (x.1.1,x.2.1) ∧ q (x.1.2,x.2.2)) = - avg (pairW w w') (fun x => ind (p x) * pr (pairW (k x.1) (k' x.2)) q) := by - unfold pr - rw [pair_semi_avg] - simp_rw [ind_and] - refine avg_congr fun x _ => ?_ - exact avg_mul' _ _ _ - -variable [Fintype I] [DecidableEq I] - -/-- Reassociate two arrays of independent columns into componentwise independent pairs. -/ -theorem prodW_pair_pr (w v : I → Wgt A) (p : I → A × A → Prop) : - pr (pairW (prodW w) (prodW v)) (fun x => ∀ i, p i (x.1 i,x.2 i)) = - ∏ i, pr (pairW (w i) (v i)) (p i) := by - simp_rw [pr,ind_all,pairW_avg] - have hx (x : I → A) : - avg (prodW v) (fun y => ∏ i, ind (p i (x i,y i))) = - ∏ i, avg (v i) (fun y => ind (p i (x i,y))) := - prodW_avg _ (fun i y => ind (p i (x i,y))) - simp_rw [hx] - exact prodW_avg w (fun i x => avg (v i) (fun y => ind (p i (x,y)))) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteConditioning + +namespace OAI + +/-! # Conditional Product Laws -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators + +variable {A B I : Type} [Fintype A] [Fintype B] + +theorem subLaw_pair {w : Wgt A} {v : Wgt B} (hw : SubLaw w) (hv : SubLaw v) : + SubLaw (pairW w v) := by + refine ⟨fun x => mul_nonneg (hw.nz _) (hv.nz _),?_⟩ + rw [pairW_tot] + exact (mul_le_mul hw.total hv.total (tot_nonneg hv.nz) (by norm_num)).trans_eq (one_mul _) + +theorem pair_unif : + unif (α:=A×B) = pairW unif unif := by + funext x; simp [pairW,unif_apply,mul_comm] + +theorem unifOn_slice (p : A × B → Prop) (x : A) (y : B) : + unifOn p (x,y) = + mapW (unifOn p) Prod.fst x * unifOn (fun y => p (x,y)) y := by + classical + have hm : mapW (unifOn p) Prod.fst x = + nbr (fun y => p (x,y)) / nbr p := by + simp only [mapW,pr,avg,Fintype.sum_prod_type,unifOn_val, nbr,tot] + rw [Finset.sum_eq_single x] + · simp [ind_true,div_eq_mul_inv,Finset.sum_mul] + · intro b _ hb + simp [ind,hb] + · simp + rw [hm,unifOn_val,unifOn_val] + by_cases h : p (x,y) + · have hh {A : Type} [Fintype A] (p : A → Prop) (x : A) (hx : p x) : 0 < nbr p := by + have hp := weight_le_tot (fun y => ind_nonneg (p y)) x + exact lt_of_lt_of_le (ind_one hx ▸ zero_lt_one) hp + rw [ind_one h] + have hv := hh _ _ h + have hw := hh (fun y => p (x,y)) _ h + field_simp + · rw [ind_zero h] + ring + +theorem unifOn_and (p q : A → Prop) : + onW (unifOn p) q = unifOn (fun x => p x ∧ q x) := by + classical + have hp : pr (unifOn p) q = nbr (fun x => p x ∧ q x) / nbr p := by + simp only [pr,avg,unifOn_val,div_eq_mul_inv,ind_and,nbr,tot,Finset.sum_mul] + refine Finset.sum_congr rfl fun i _ => ?_ + ring + funext x + rw [onW_val,hp,unifOn_val,unifOn_val,ind_and] + by_cases h : p x + · by_cases g : q x + · have hl (p : A → Prop) (h : p x) : 0 < nbr p := + lt_of_lt_of_le (ind_one h ▸ zero_lt_one) (weight_le_tot (fun y => ind_nonneg (p y)) x) + have hh := hl p h + have hg := hl (fun x => p x ∧ q x) ⟨h,g⟩ + field_simp + · rw [ind_zero g] + ring + · rw [ind_zero h] + ring + +theorem unifOn_and_prod (p : A → Prop) (q : B → Prop) : + unifOn (fun x : A × B => p x.1 ∧ q x.2) = pairW (unifOn p) (unifOn q) := by + have h : + nbr (fun x : A × B => p x.1 ∧ q x.2) = nbr p * nbr q := by + change tot _ = _ * _ + simp_rw [ind_and] + exact pairW_tot (fun x => ind (p x)) (fun y => ind (q y)) + funext x + simp only [pairW,unifOn_val,h,ind_and] + ring_nf + +theorem pr_cap {w v : Wgt A} {c : ℝ} (h : ∀ x, w x ≤ c*v x) (p : A → Prop) : + pr w p ≤ c*pr v p := calc + _ ≤ pr (fun x => c*v x) p := pr_mono_left (w:=w) (v:=fun x => c*v x) h _ + _ = _ := by simp only [pr,avg,Finset.mul_sum,mul_assoc] + +def semi (w : Wgt A) (k : A → Wgt B) : Wgt (A × B) := fun x => w x.1 * k x.1 x.2 + +theorem semi_avg (w : Wgt A) (k : A → Wgt B) (f : A × B → ℝ) : + avg (semi w k) f = avg w (fun x => avg (k x) (fun y => f (x,y))) := by + simp only [avg,semi,Fintype.sum_prod_type,Finset.mul_sum,mul_assoc] + +theorem pair_semi_avg (w w' : Wgt A) (k k' : A → Wgt B) (f : (A × B) × (A × B) → ℝ) : + avg (pairW (semi w k) (semi w' k')) f = + avg (pairW w w') (fun x => + avg (pairW (k x.1) (k' x.2)) (fun y => f ((x.1,y.1), (x.2,y.2)))) := by + simp only [pairW_avg, semi_avg] + refine avg_congr fun x _ => ?_ + exact avg_avg _ _ _ + +theorem pair_semi_pr (w w' : Wgt A) (k k' : A → Wgt B) (p : A × A → Prop) (q : B × B → Prop) : + pr (pairW (semi w k) (semi w' k')) (fun x => p (x.1.1,x.2.1) ∧ q (x.1.2,x.2.2)) = + avg (pairW w w') (fun x => ind (p x) * pr (pairW (k x.1) (k' x.2)) q) := by + unfold pr + rw [pair_semi_avg] + simp_rw [ind_and] + refine avg_congr fun x _ => ?_ + exact avg_mul' _ _ _ + +variable [Fintype I] [DecidableEq I] + +/-- Reassociate two arrays of independent columns into componentwise independent pairs. -/ +theorem prodW_pair_pr (w v : I → Wgt A) (p : I → A × A → Prop) : + pr (pairW (prodW w) (prodW v)) (fun x => ∀ i, p i (x.1 i,x.2 i)) = + ∏ i, pr (pairW (w i) (v i)) (p i) := by + simp_rw [pr,ind_all,pairW_avg] + have hx (x : I → A) : + avg (prodW v) (fun y => ∏ i, ind (p i (x i,y i))) = + ∏ i, avg (v i) (fun y => ind (p i (x i,y))) := + prodW_avg _ (fun i y => ind (p i (x i,y))) + simp_rw [hx] + exact prodW_avg w (fun i x => avg (v i) (fun y => ind (p i (x,y)))) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalProjection.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalProjection.lean index c573be637dedd7e0cdac17517e9a5ccf67e81ea5..7409a7eb48848315807a3f8d30535beef02c2bdb 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalProjection.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalProjection.lean @@ -1,96 +1,96 @@ -import OAI.Combinatorics.HadwigerCounterexample.HistogramBounds - -namespace OAI - -/-! # Conditional Projection -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real Function -open scoped BigOperators -variable {A B C K : Type} [Fintype A] [Fintype B] [Fintype C] - -def dip (μ f g : Wgt A) := avg μ (fun i => f i*g i) -def ode (μ f : Wgt A) := dip μ f f -def cashbook (μ : Wgt A) (f : A→B) (g : Wgt A) := - fun i => mapW (fun x => μ x*g x) f i / mapW μ f i -def banner (μ : Wgt A) (f : A→B) (g : Wgt A) := cashbook μ f g ∘ f - -theorem ode_nonneg {μ : Wgt A} (hμ : ∀ i,0 ≤ μ i) (f : Wgt A) : 0≤ ode μ f := - avg_nonneg hμ (fun _ => mul_self_nonneg _) -theorem ode_upper {μ : Wgt A} (hμ : SubLaw μ) (f : Wgt A) (B : ℝ) - (hf : ∀ i,|f i|≤B) : ode μ f ≤ B^2 := by - apply hμ.avg_le (sq_nonneg _) - intro i - exact (le_of_eq (Eq.symm (pow_two _))).trans - ((le_of_eq (sq_abs (f i)).symm).trans (pow_le_pow_left₀ (abs_nonneg _) (hf i) 2)) - -theorem dip_sym (μ f g : Wgt A) : dip μ f g=dip μ g f := by unfold dip; simp only [mul_comm] -theorem dip_sub (μ f g h : Wgt A) : - dip μ (fun i=> f i-g i) h=dip μ f h-dip μ g h := by - unfold dip; simp only [sub_mul,avg_sub] - -omit [Fintype B] in -theorem cashbook_bound (μ : Wgt A) (hμ : ∀ i,0≤ μ i) (f : A→B) (g : Wgt A) - (b : ℝ) (hb : 0≤b) (h : ∀ i,|g i|≤b) (i) : |cashbook μ f g i| ≤ b := by - have he : cashbook μ f g i=avg (onW μ (fun x=>f x=i)) g := by - unfold cashbook onW - rw [avg_norm,subW_tot] - unfold mapW pr avg subW; congr 1 - exact Finset.sum_congr rfl fun j _ => by ring - have hw : SubLaw (onW μ (fun x=>f x=i)) := normW_subLaw (subW_nonneg hμ _) - rw [he] - exact (abs_avg_le hw.nz).trans (hw.avg_le hb h) - -theorem cash_orth (μ : Wgt A) (hμ : ∀ i,0≤ μ i) (f : A→B) (g : Wgt A) (h : Wgt B) : - dip μ (banner μ f g) (h ∘ f)=dip μ g (h ∘ f) := by - classical - let w := fun x=> μ x*g x - have he : pour μ f (mapW w f) = fun i => μ i*banner μ f g i := rfl - have hz : lsupp w μ := fun _ hi => left_ne_zero_of_mul hi - have ht := map_pour μ f _ (hz.map hμ f) - rw [he] at ht - have hi := congrArg (fun w' => avg w' h) ht - simp_rw [mapW_avg] at hi - simpa only [w,dip,avg,mul_assoc,Function.comp_apply] using hi - -theorem ode_step (μ : Wgt A) (hμ : ∀ i,0≤ μ i) (f : Wgt A) - (p : A→B) (q : B→C) : - ode μ (banner μ p f)=ode μ (banner μ (q∘p) f)+ - ode μ (fun i => banner μ p f i - banner μ (q∘p) f i) := by - classical - let g := banner μ p f; let h := banner μ (q ∘ p) f - have hh : ode μ h=dip μ g h := - (cash_orth μ hμ (q∘p) f (cashbook μ (q∘p) f)).trans - (cash_orth μ hμ p f (cashbook μ (q∘p) f ∘ q)).symm - have hi i : (g i - h i)*(g i-h i)=g i*g i - 2*(g i*h i)+h i*h i := by ring - change ode μ g=ode μ h+dip μ (fun i => g i-h i) (fun i=>g i-h i) - unfold dip - simp_rw [hi,avg_add,avg_sub,avg_mul'] - change ode μ g=ode μ h+(ode μ g-2*dip μ g h + ode μ h) - linarith only [hh] - -theorem archive_gain {μ : Wgt A} (hw : SubLaw μ) (f : Wgt A) - (p : A→B) (q : B→ C) - (h : Wgt B) (hh : ∀ i:A,|h (p i)| ≤1) : - (dip μ (fun i => f i - banner μ (q∘p) f i) (h ∘ p))^2 ≤ - ode μ (banner μ p f)-ode μ (banner μ (q∘p) f) := by - let u := banner μ p f; let v := banner μ (q∘p) f - let w i := u i-v i - rw [ode_step μ hw.nz f p q] - have he : dip μ (fun i=> f i - banner μ (q∘p) f i) (h∘p)=dip μ w (h∘p) := by - unfold w - rw [dip_sub,dip_sub,cash_orth μ hw.nz p f h] - have ht : ode μ (h∘p) ≤ 1 := (ode_upper hw (h∘p) 1 hh).trans_eq (by ring) - have hq : dip μ w (h∘p)^2≤ode μ w*ode μ (h∘p) := by - simpa only [ode,dip,pow_two] using avg_CS hw.nz w (h∘p) - rw [he] - apply le_trans hq - refine (mul_le_mul_of_nonneg_left ht (ode_nonneg hw.nz w)).trans_eq ?_ - unfold w u v - ring -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.HistogramBounds + +namespace OAI + +/-! # Conditional Projection -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real Function +open scoped BigOperators +variable {A B C K : Type} [Fintype A] [Fintype B] [Fintype C] + +def dip (μ f g : Wgt A) := avg μ (fun i => f i*g i) +def ode (μ f : Wgt A) := dip μ f f +def cashbook (μ : Wgt A) (f : A→B) (g : Wgt A) := + fun i => mapW (fun x => μ x*g x) f i / mapW μ f i +def banner (μ : Wgt A) (f : A→B) (g : Wgt A) := cashbook μ f g ∘ f + +theorem ode_nonneg {μ : Wgt A} (hμ : ∀ i,0 ≤ μ i) (f : Wgt A) : 0≤ ode μ f := + avg_nonneg hμ (fun _ => mul_self_nonneg _) +theorem ode_upper {μ : Wgt A} (hμ : SubLaw μ) (f : Wgt A) (B : ℝ) + (hf : ∀ i,|f i|≤B) : ode μ f ≤ B^2 := by + apply hμ.avg_le (sq_nonneg _) + intro i + exact (le_of_eq (Eq.symm (pow_two _))).trans + ((le_of_eq (sq_abs (f i)).symm).trans (pow_le_pow_left₀ (abs_nonneg _) (hf i) 2)) + +theorem dip_sym (μ f g : Wgt A) : dip μ f g=dip μ g f := by unfold dip; simp only [mul_comm] +theorem dip_sub (μ f g h : Wgt A) : + dip μ (fun i=> f i-g i) h=dip μ f h-dip μ g h := by + unfold dip; simp only [sub_mul,avg_sub] + +omit [Fintype B] in +theorem cashbook_bound (μ : Wgt A) (hμ : ∀ i,0≤ μ i) (f : A→B) (g : Wgt A) + (b : ℝ) (hb : 0≤b) (h : ∀ i,|g i|≤b) (i) : |cashbook μ f g i| ≤ b := by + have he : cashbook μ f g i=avg (onW μ (fun x=>f x=i)) g := by + unfold cashbook onW + rw [avg_norm,subW_tot] + unfold mapW pr avg subW; congr 1 + exact Finset.sum_congr rfl fun j _ => by ring + have hw : SubLaw (onW μ (fun x=>f x=i)) := normW_subLaw (subW_nonneg hμ _) + rw [he] + exact (abs_avg_le hw.nz).trans (hw.avg_le hb h) + +theorem cash_orth (μ : Wgt A) (hμ : ∀ i,0≤ μ i) (f : A→B) (g : Wgt A) (h : Wgt B) : + dip μ (banner μ f g) (h ∘ f)=dip μ g (h ∘ f) := by + classical + let w := fun x=> μ x*g x + have he : pour μ f (mapW w f) = fun i => μ i*banner μ f g i := rfl + have hz : lsupp w μ := fun _ hi => left_ne_zero_of_mul hi + have ht := map_pour μ f _ (hz.map hμ f) + rw [he] at ht + have hi := congrArg (fun w' => avg w' h) ht + simp_rw [mapW_avg] at hi + simpa only [w,dip,avg,mul_assoc,Function.comp_apply] using hi + +theorem ode_step (μ : Wgt A) (hμ : ∀ i,0≤ μ i) (f : Wgt A) + (p : A→B) (q : B→C) : + ode μ (banner μ p f)=ode μ (banner μ (q∘p) f)+ + ode μ (fun i => banner μ p f i - banner μ (q∘p) f i) := by + classical + let g := banner μ p f; let h := banner μ (q ∘ p) f + have hh : ode μ h=dip μ g h := + (cash_orth μ hμ (q∘p) f (cashbook μ (q∘p) f)).trans + (cash_orth μ hμ p f (cashbook μ (q∘p) f ∘ q)).symm + have hi i : (g i - h i)*(g i-h i)=g i*g i - 2*(g i*h i)+h i*h i := by ring + change ode μ g=ode μ h+dip μ (fun i => g i-h i) (fun i=>g i-h i) + unfold dip + simp_rw [hi,avg_add,avg_sub,avg_mul'] + change ode μ g=ode μ h+(ode μ g-2*dip μ g h + ode μ h) + linarith only [hh] + +theorem archive_gain {μ : Wgt A} (hw : SubLaw μ) (f : Wgt A) + (p : A→B) (q : B→ C) + (h : Wgt B) (hh : ∀ i:A,|h (p i)| ≤1) : + (dip μ (fun i => f i - banner μ (q∘p) f i) (h ∘ p))^2 ≤ + ode μ (banner μ p f)-ode μ (banner μ (q∘p) f) := by + let u := banner μ p f; let v := banner μ (q∘p) f + let w i := u i-v i + rw [ode_step μ hw.nz f p q] + have he : dip μ (fun i=> f i - banner μ (q∘p) f i) (h∘p)=dip μ w (h∘p) := by + unfold w + rw [dip_sub,dip_sub,cash_orth μ hw.nz p f h] + have ht : ode μ (h∘p) ≤ 1 := (ode_upper hw (h∘p) 1 hh).trans_eq (by ring) + have hq : dip μ w (h∘p)^2≤ode μ w*ode μ (h∘p) := by + simpa only [ode,dip,pow_two] using avg_CS hw.nz w (h∘p) + rw [he] + apply le_trans hq + refine (mul_le_mul_of_nonneg_left ht (ode_nonneg hw.nz w)).trans_eq ?_ + unfold w u v + ring +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalSignaturePositivity.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalSignaturePositivity.lean index b6013a23c3a2dba17f2f9d8b6a13b85d602f09ec..95937935c445bf951855a5d84a380c8055a49fe9 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalSignaturePositivity.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionalSignaturePositivity.lean @@ -1,110 +1,110 @@ -import OAI.Combinatorics.HadwigerCounterexample.CellPositivityScales - -namespace OAI - -/-! # Conditional Signature Positivity -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix Function -open scoped BigOperators Topology -variable {p:Shape} {n N K r d : ℕ} -namespace StatusAnalysis -open Template - -namespace Appearance -variable (x : Appearance p) (Y : Silhouette p N r) - -theorem smudges (o : UnitType p n N) (m:Mixer p n) (v : Ax p n d) (i:Nodes) (j : Knobs p.g n) : - (x.profile i o m v j).2.1=((scan p x.l x.f j).diagO,stains x.trot m v j) := by - apply Prod.ext - · exact role_scan p _ _ _ _ - funext i; exact T_swap m _ _ - -def nearly (p: Shape) (z: Digest p.g) (u: Par d) (x: Magazine p d) := - x.1=z∧ x.2.1=u - -set_option maxHeartbeats 800000 in -theorem demonstrates (o : UnitType p n N) {m : Mixer p n} - (v : Ax p n d) (K:ℕ) (i:Nodes) (j:Fin r) (δ : ℝ) (hd:0<δ) - (z : Digest p.g) (u:Cell d) - (he : z.feasible x.l x.f) (hf : z.sumBit=x.q) (ht : 1≤p.r) (hn : 2*p.r≤n) - (hh : δ≤ x.reference Y j) - (hs : smoothSilk p δ δ Y m K (onSide o i)) (hK : d≤K^2) - (hV : Injective v) (hv : ∀ x,totalRank (v x) ≤ K) : - basebeta p K/2 ≤ pr (x.reflected Y i o m v j) (nearly p z (z.diagO,u)) := by - classical - have ha : x.apt := ⟨z,he,hf⟩ - let μ:= x.reference Y j - let f := onSide o i - obtain ⟨hM,hB⟩:= hs x - specialize hM ha - specialize hB z j he hf hh - let U (y:AtomKey (p:=p) (x.trot.t ()) N) := Y x.l x.q y=j - have hm : basebeta p K*μ ≤ - pr (x.wit n) (fun y=> (scan p x.l x.f y=z∧Y x.l x.q (x.face f y)=j) ∧ - stains x.trot m v y=u) := by - let h := patrol_beta x.trot U m K z he ht hn f - dsimp only at h - rw [hf] at h - exact h hB d hK v hV hv u - let w := nearly p z (z.diagO,u) - have hq (y : Knobs p.g n) : - (scan p x.l x.f y=z ∧ Y x.l x.q (x.face f y)=j) ∧ stains x.trot m v y=u → - x.showTag Y (onSide o i) y=j∧ w (x.profile i o m v y) := by - rintro ⟨⟨h,h1⟩,h2⟩ - refine ⟨h1,h,?_⟩; rw [smudges,h,h2] - have hW := witLaw ha ht hn - have heq := (hm.trans (pr_mono hW.nz hq)).trans_eq (x.show_pr Y i o m v hW j w) - let ν:= x.empirical Y f j - have h2 : ν ≤ 2*μ := by - have hz : |μ-ν|≤δ := le_trans - (Finset.single_le_sum (fun k _ => abs_nonneg (x.reference Y k-x.empirical Y f k)) - (Finset.mem_univ j)) hM - change δ≤ μ at hh - linarith [(abs_le.mp hz).1] - let Q := pr (x.reflected Y i o m v j) w - have h3 : basebeta p K*μ≤ ν*Q := heq - have ht := mul_le_mul_of_nonneg_right h2 - (show 0≤ Q from pr_nonneg (x.reflectedLaw Y hW i o m v j).nz) - apply le_of_mul_le_mul_right _ (hd.trans_le hh) - change _*μ ≤ Q*μ - linarith only [h3,ht] - -def fitsink (x : Appearance p) (w : Magazine p d) := - w.1.feasible x.l x.f ∧ w.1.sumBit=x.q ∧ w.1.diagO=w.2.1.1 -theorem rawink (x : Appearance p) (m : Mixer p n) (i : Nodes) (o : UnitType p n N) - (v : Ax p n d) : - carried (x.wit n) (x.fitsink ∘ x.profile i o m v) := by - let w:=x.wit n - have hC : carried w (fun y=>dialed p x.l x.f y=x.q) := - normW_carried (subW_carried (spins p n) _) - intro y hi - refine hC y (fun h=>?_); apply hi - refine ⟨?_,h, (role_scan p _ _ _ _).symm⟩ - intro j hj - unfold profile; change scan p x.l x.f y j=0 - unfold scan - simp [hj] -theorem refInk (i : Nodes) (o : UnitType p n N) (m:Mixer p n) (v : Ax p n d) - (j:Fin r) : carried (x.reflected Y i o m v j) x.fitsink := - reflection_exact x Y i o m v j _ (rawink x m i o v) - -end Appearance - -theorem haze_small (w : Wgt (Fin r)) (δ : ℝ) (hδ : 0≤δ) : - pr w (fun x=> w x < δ) ≤ r*δ := by - classical - unfold pr avg - refine (Finset.sum_le_sum (s:=Finset.univ) (g:=fun _=>δ) (fun i _=>?_)).trans_eq (by simp) - dsimp only - by_cases h:w i<δ - · rw [ind_one h,mul_one]; exact h.le - rw [ind_zero h,mul_zero]; exact hδ - -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CellPositivityScales + +namespace OAI + +/-! # Conditional Signature Positivity -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix Function +open scoped BigOperators Topology +variable {p:Shape} {n N K r d : ℕ} +namespace StatusAnalysis +open Template + +namespace Appearance +variable (x : Appearance p) (Y : Silhouette p N r) + +theorem smudges (o : UnitType p n N) (m:Mixer p n) (v : Ax p n d) (i:Nodes) (j : Knobs p.g n) : + (x.profile i o m v j).2.1=((scan p x.l x.f j).diagO,stains x.trot m v j) := by + apply Prod.ext + · exact role_scan p _ _ _ _ + funext i; exact T_swap m _ _ + +def nearly (p: Shape) (z: Digest p.g) (u: Par d) (x: Magazine p d) := + x.1=z∧ x.2.1=u + +set_option maxHeartbeats 800000 in +theorem demonstrates (o : UnitType p n N) {m : Mixer p n} + (v : Ax p n d) (K:ℕ) (i:Nodes) (j:Fin r) (δ : ℝ) (hd:0<δ) + (z : Digest p.g) (u:Cell d) + (he : z.feasible x.l x.f) (hf : z.sumBit=x.q) (ht : 1≤p.r) (hn : 2*p.r≤n) + (hh : δ≤ x.reference Y j) + (hs : smoothSilk p δ δ Y m K (onSide o i)) (hK : d≤K^2) + (hV : Injective v) (hv : ∀ x,totalRank (v x) ≤ K) : + basebeta p K/2 ≤ pr (x.reflected Y i o m v j) (nearly p z (z.diagO,u)) := by + classical + have ha : x.apt := ⟨z,he,hf⟩ + let μ:= x.reference Y j + let f := onSide o i + obtain ⟨hM,hB⟩:= hs x + specialize hM ha + specialize hB z j he hf hh + let U (y:AtomKey (p:=p) (x.trot.t ()) N) := Y x.l x.q y=j + have hm : basebeta p K*μ ≤ + pr (x.wit n) (fun y=> (scan p x.l x.f y=z∧Y x.l x.q (x.face f y)=j) ∧ + stains x.trot m v y=u) := by + let h := patrol_beta x.trot U m K z he ht hn f + dsimp only at h + rw [hf] at h + exact h hB d hK v hV hv u + let w := nearly p z (z.diagO,u) + have hq (y : Knobs p.g n) : + (scan p x.l x.f y=z ∧ Y x.l x.q (x.face f y)=j) ∧ stains x.trot m v y=u → + x.showTag Y (onSide o i) y=j∧ w (x.profile i o m v y) := by + rintro ⟨⟨h,h1⟩,h2⟩ + refine ⟨h1,h,?_⟩; rw [smudges,h,h2] + have hW := witLaw ha ht hn + have heq := (hm.trans (pr_mono hW.nz hq)).trans_eq (x.show_pr Y i o m v hW j w) + let ν:= x.empirical Y f j + have h2 : ν ≤ 2*μ := by + have hz : |μ-ν|≤δ := le_trans + (Finset.single_le_sum (fun k _ => abs_nonneg (x.reference Y k-x.empirical Y f k)) + (Finset.mem_univ j)) hM + change δ≤ μ at hh + linarith [(abs_le.mp hz).1] + let Q := pr (x.reflected Y i o m v j) w + have h3 : basebeta p K*μ≤ ν*Q := heq + have ht := mul_le_mul_of_nonneg_right h2 + (show 0≤ Q from pr_nonneg (x.reflectedLaw Y hW i o m v j).nz) + apply le_of_mul_le_mul_right _ (hd.trans_le hh) + change _*μ ≤ Q*μ + linarith only [h3,ht] + +def fitsink (x : Appearance p) (w : Magazine p d) := + w.1.feasible x.l x.f ∧ w.1.sumBit=x.q ∧ w.1.diagO=w.2.1.1 +theorem rawink (x : Appearance p) (m : Mixer p n) (i : Nodes) (o : UnitType p n N) + (v : Ax p n d) : + carried (x.wit n) (x.fitsink ∘ x.profile i o m v) := by + let w:=x.wit n + have hC : carried w (fun y=>dialed p x.l x.f y=x.q) := + normW_carried (subW_carried (spins p n) _) + intro y hi + refine hC y (fun h=>?_); apply hi + refine ⟨?_,h, (role_scan p _ _ _ _).symm⟩ + intro j hj + unfold profile; change scan p x.l x.f y j=0 + unfold scan + simp [hj] +theorem refInk (i : Nodes) (o : UnitType p n N) (m:Mixer p n) (v : Ax p n d) + (j:Fin r) : carried (x.reflected Y i o m v j) x.fitsink := + reflection_exact x Y i o m v j _ (rawink x m i o v) + +end Appearance + +theorem haze_small (w : Wgt (Fin r)) (δ : ℝ) (hδ : 0≤δ) : + pr w (fun x=> w x < δ) ≤ r*δ := by + classical + unfold pr avg + refine (Finset.sum_le_sum (s:=Finset.univ) (g:=fun _=>δ) (fun i _=>?_)).trans_eq (by simp) + dsimp only + by_cases h:w i<δ + · rw [ind_one h,mul_one]; exact h.le + rw [ind_zero h,mul_zero]; exact hδ + +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionedBatchLaws.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionedBatchLaws.lean index df48416fae4e09457326a5b519c3f53292e2472c..cd2530cc038d4a1750d4db0c1e7168bb20ab36c1 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionedBatchLaws.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionedBatchLaws.lean @@ -1,198 +1,198 @@ -import OAI.Combinatorics.HadwigerCounterexample.IndependentWeightCorrelation - -namespace OAI - -/-! # Conditioned Batch Laws -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Module LinearMap Submodule Function Finset -variable {I J G H : Type} [Fintype I] [Fintype J] [Fintype G] [Fintype H] -variable [DecidableEq I] [DecidableEq J] [DecidableEq G] -variable {N : ℕ} - -def street (g : Route (I×J) G) (i : I) : Route J G := fun j => g (i,j) -def condLane (g : Route (I×J) G) (i : I) (z : G) (k : Port (street g i) z) : - Port g z := ⟨(i,k.val),k.property⟩ -def laneM {g : Route (I×J) G} (Z : GeoM g) (i : I) : - GeoM (street g i) := - fun z => (Z z).submatrix (condLane g i z) (condLane g i z) - -private theorem cut_inj {I J : Type} [Fintype I] [Fintype J] [DecidableEq I] - (A : PlusRack I N) (h : Injective A.mulVec) {g : J→I} (hg : Injective g) : - Injective (A.submatrix _root_.id g).mulVec := by - rw [← mul_embedMat] - exact inj_comp_mat _ _ h (embedMat_inj hg) - -variable {g : Route (I×J) G} - -omit [Fintype G] in -set_option maxHeartbeats 600000 in -theorem laneGram (Z : GeoM g) (x : Rack (I × J) N) (h : bothPart Z x) (i : I) : - bothPart (laneM Z i) (led i x) := by - classical - obtain ⟨hh,hj⟩ := (both_test ..).mp h - apply (both_test ..).mpr - constructor - · refine (part_scores ..).mpr fun q a b => ?_ - exact (part_scores ..).mp hh q (condLane g i q a) (condLane g i q b) - intro j - let f := condLane g i j - have he : Injective f := by intro a b h; exact Subtype.ext (congrArg - (fun x : Port g j => x.val.2) h) - exact ⟨cut_inj (rackEquiv g N x j).1 (hj j).1 he, - cut_inj (rackEquiv g N x j).2 (hj j).2 he⟩ - -def crossroads (g : Route (I×J) G) := - (crowded g)\(cInside g) -def outsideZ (Z : GeoM g) : Vec (crossroads g) := - fun x => directions g Z ⟨x.val,Finset.sdiff_subset x.property⟩ - -omit [Fintype G] in -private theorem road_iff (Z : GeoM g) (x : Rack (I×J) N) : - bothPart Z x ↔ (traced x (crossroads g) (outsideZ Z) ∧ - (∀ i,bothPart (laneM Z i) (led i x))) ∧injPart g x := by - classical - constructor - · intro h - have ht := (both_test ..).mp h - refine ⟨⟨?_,laneGram Z x h⟩,ht.2⟩ - funext i - exact congr_fun ((match_crowd x g Z).mpr ht.1) (⟨i.val,Finset.sdiff_subset i.property⟩ : - ↑(crowded g)) - rintro ⟨⟨ht,hH⟩,hf⟩ - refine (both_test ..).mpr ⟨(part_scores ..).mpr ?_,hf⟩ - intro i a b - rcases a with ⟨⟨l,x'⟩,hl⟩ - rcases b with ⟨⟨t,y⟩,hr⟩ - subst i - let j := g (l,x') - by_cases hh : l=t - · subst t - let a : Port (street g l) j := ⟨x',rfl⟩ - let b : Port (street g l) j := ⟨y,hr⟩ - exact (part_scores ..).mp ((both_test ..).mp (hH l)).1 j a b - let z : I×J := (l,x') - let v : I×J := (t,y) - have hv : (z,v)∈crossroads g := Finset.mem_sdiff.mpr - ⟨Finset.mem_filter.mpr ⟨mem_univ _,hr.symm⟩,fun h => hh (mem_filter.mp h).2⟩ - exact congr_fun ht (⟨(z,v),hv⟩ : ↑(crossroads g)) - -private def condMean (p : H→Prop) (f : Wgt H) := - avg unif (fun x => ind (p x)*f x) -private theorem cond_reset [Nonempty H] (p : H→Prop) (f : Wgt H) (h : 0 simp only [h,ind_true,ind_false,one_mul, - zero_mul]; exact hf i x; norm_num - have hE i (h : i∈E) : i.1.1≠i.2.1 := fun he => - (mem_sdiff.mp h).2 (mem_filter.mpr ⟨(mem_sdiff.mp h).1,he⟩) - have ht := speed_expand F hF E (outsideZ Z) hE - have hP : avg unif (brightProd F)=∏ i, condMean (bothPart (laneM Z i)) (f i) := - (led_uniform (prodW F)).trans (prodW_avg _ _) - let A x := ind (traced x E (outsideZ Z))*brightProd F x - have hA x : |A x|≤1 := by - by_cases h : traced x E (outsideZ Z) - · unfold A; rw [ind_one h,one_mul]; exact lane_abs F hF _ x - unfold A; rw [ind_zero h,zero_mul]; norm_num - have hi x : - ind (bothPart Z x) * brightProd f x= ind (injPart g x) * A x := by - rw [road_iff]; unfold A F - simp only [ind_and, ind_all,brightProd,Finset.prod_mul_distrib] - ring - have hg : - |condMean (bothPart Z) (brightProd f) - avg unif A|≤ num G*(2*bp (k-N)) := by - unfold condMean - simp_rw [hi] - rw [← avg_sub] - refine (abs_avg_le unif_law.nz).trans ((avg_mono unif_law.nz (g:=fun x => - ind (¬injPart g x)) fun i => ?_).trans (injPart_failure g N k hk)) - by_cases h : injPart g i <;> - simp only [h,ind_true,not_true,ind_false,one_mul,sub_self,abs_zero,zero_mul,zero_sub, - abs_neg,not_false_eq_true]; exact le_rfl; exact hA _ - rw [hP] at ht - unfold twinkle - apply le_trans _ (add_le_add hg ht) - exact abs_sub_le .. - -omit [DecidableEq I] in -theorem lane_norm (Z : GeoM g) (hN : ∀ i, 2*num (Port g i)-(N:ℝ)≤ -1) - (i : I) : 0 x.val.2) h) - have hx j : num (Port (street g i) j)≤num (Port g j) := by - exact_mod_cast Fintype.card_le_of_injective _ (he j) - refine lt_of_lt_of_le (inv_pos_of_pos netFact_pos) (net_norm (laneM Z i) N (fun j => ?_)).1 - linarith only [hx j,hN j] - -set_option maxHeartbeats 800000 in -theorem compare_lanes (Z : GeoM g) (f : I→ Wgt (Rack J N)) (hf : ∀ i x,|f i x|≤1) - (k : ℝ) (hk : ∀ i,num (Port g i)≤k) (hN : ∀ i,2*num (Port g i)-(N:ℝ)≤ -1) : - |avg (rackStation Z N) (brightProd f)- ∏ i,avg (rackStation (laneM Z i) N) (f i)|≤ - 2*netFact g*twinkle g k N := by - classical - let A := pr unif (bothPart (N:=N) Z) - let B i := pr unif (bothPart (N:=N) (laneM Z i)) - let u := avg (rackStation Z N) (brightProd f) - let v i := avg (rackStation (laneM Z i) N) (f i) - let P := bp (- ((crossroads g).card:ℝ))*(∏ i, B i) - let V := ∏ i,v i - have hV : |V|≤1 := by - unfold V - rw [Finset.abs_prod] - have he (i) : - SubLaw (rackStation (laneM Z i) N) := unifOn_sub _ - refine (Finset.prod_le_prod₀ (fun i _ => abs_nonneg _) - (fun i _ => (abs_avg_le (he i).nz).trans ((he i).avg_le zero_le_one (hf i)))).trans_eq ?_ - simp - have hh := net_norm Z N hN - have h0 : 0 (1:ℝ) - have ht := lane_means Z F (by intro i x; simp [F]) k hk - have he (i : I) : - condMean (bothPart (laneM Z i)) (F i)=B i := by simp only [F,condMean,mul_one]; rfl - have hx : - condMean (bothPart (N:=N) Z) (brightProd F)=A := by - simp only [F,brightProd,condMean,Finset.prod_const_one,mul_one,A,pr] - simp_rw [he,hx] at ht; exact ht - have hg : A * |u-V|≤2*twinkle g k N := by - have hh : |(A-P)*V|≤twinkle g k N := by - rw [abs_mul]; exact ((mul_le_mul_of_nonneg_left hV (abs_nonneg _)).trans_eq (mul_one _)).trans h2 - calc A*|u-V|= |(A*u-P*V)-(A-P)*V| := by - rw [show A*u-P*V-(A-P)*V=(A*(u-V)) by ring,abs_mul,abs_of_nonneg h0.le] - _ ≤ _ := ((abs_sub ..).trans (add_le_add h1 hh)).trans_eq (two_mul _).symm - apply le_of_mul_le_mul_left _ (inv_pos_of_pos (netFact_pos (f:=g))) - exact ((mul_le_mul_of_nonneg_right hh.1 (abs_nonneg _)).trans hg).trans_eq (by - have h := netFact_pos (f:=g) - field_simp) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.IndependentWeightCorrelation + +namespace OAI + +/-! # Conditioned Batch Laws -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Module LinearMap Submodule Function Finset +variable {I J G H : Type} [Fintype I] [Fintype J] [Fintype G] [Fintype H] +variable [DecidableEq I] [DecidableEq J] [DecidableEq G] +variable {N : ℕ} + +def street (g : Route (I×J) G) (i : I) : Route J G := fun j => g (i,j) +def condLane (g : Route (I×J) G) (i : I) (z : G) (k : Port (street g i) z) : + Port g z := ⟨(i,k.val),k.property⟩ +def laneM {g : Route (I×J) G} (Z : GeoM g) (i : I) : + GeoM (street g i) := + fun z => (Z z).submatrix (condLane g i z) (condLane g i z) + +private theorem cut_inj {I J : Type} [Fintype I] [Fintype J] [DecidableEq I] + (A : PlusRack I N) (h : Injective A.mulVec) {g : J→I} (hg : Injective g) : + Injective (A.submatrix _root_.id g).mulVec := by + rw [← mul_embedMat] + exact inj_comp_mat _ _ h (embedMat_inj hg) + +variable {g : Route (I×J) G} + +omit [Fintype G] in +set_option maxHeartbeats 600000 in +theorem laneGram (Z : GeoM g) (x : Rack (I × J) N) (h : bothPart Z x) (i : I) : + bothPart (laneM Z i) (led i x) := by + classical + obtain ⟨hh,hj⟩ := (both_test ..).mp h + apply (both_test ..).mpr + constructor + · refine (part_scores ..).mpr fun q a b => ?_ + exact (part_scores ..).mp hh q (condLane g i q a) (condLane g i q b) + intro j + let f := condLane g i j + have he : Injective f := by intro a b h; exact Subtype.ext (congrArg + (fun x : Port g j => x.val.2) h) + exact ⟨cut_inj (rackEquiv g N x j).1 (hj j).1 he, + cut_inj (rackEquiv g N x j).2 (hj j).2 he⟩ + +def crossroads (g : Route (I×J) G) := + (crowded g)\(cInside g) +def outsideZ (Z : GeoM g) : Vec (crossroads g) := + fun x => directions g Z ⟨x.val,Finset.sdiff_subset x.property⟩ + +omit [Fintype G] in +private theorem road_iff (Z : GeoM g) (x : Rack (I×J) N) : + bothPart Z x ↔ (traced x (crossroads g) (outsideZ Z) ∧ + (∀ i,bothPart (laneM Z i) (led i x))) ∧injPart g x := by + classical + constructor + · intro h + have ht := (both_test ..).mp h + refine ⟨⟨?_,laneGram Z x h⟩,ht.2⟩ + funext i + exact congr_fun ((match_crowd x g Z).mpr ht.1) (⟨i.val,Finset.sdiff_subset i.property⟩ : + ↑(crowded g)) + rintro ⟨⟨ht,hH⟩,hf⟩ + refine (both_test ..).mpr ⟨(part_scores ..).mpr ?_,hf⟩ + intro i a b + rcases a with ⟨⟨l,x'⟩,hl⟩ + rcases b with ⟨⟨t,y⟩,hr⟩ + subst i + let j := g (l,x') + by_cases hh : l=t + · subst t + let a : Port (street g l) j := ⟨x',rfl⟩ + let b : Port (street g l) j := ⟨y,hr⟩ + exact (part_scores ..).mp ((both_test ..).mp (hH l)).1 j a b + let z : I×J := (l,x') + let v : I×J := (t,y) + have hv : (z,v)∈crossroads g := Finset.mem_sdiff.mpr + ⟨Finset.mem_filter.mpr ⟨mem_univ _,hr.symm⟩,fun h => hh (mem_filter.mp h).2⟩ + exact congr_fun ht (⟨(z,v),hv⟩ : ↑(crossroads g)) + +private def condMean (p : H→Prop) (f : Wgt H) := + avg unif (fun x => ind (p x)*f x) +private theorem cond_reset [Nonempty H] (p : H→Prop) (f : Wgt H) (h : 0 simp only [h,ind_true,ind_false,one_mul, + zero_mul]; exact hf i x; norm_num + have hE i (h : i∈E) : i.1.1≠i.2.1 := fun he => + (mem_sdiff.mp h).2 (mem_filter.mpr ⟨(mem_sdiff.mp h).1,he⟩) + have ht := speed_expand F hF E (outsideZ Z) hE + have hP : avg unif (brightProd F)=∏ i, condMean (bothPart (laneM Z i)) (f i) := + (led_uniform (prodW F)).trans (prodW_avg _ _) + let A x := ind (traced x E (outsideZ Z))*brightProd F x + have hA x : |A x|≤1 := by + by_cases h : traced x E (outsideZ Z) + · unfold A; rw [ind_one h,one_mul]; exact lane_abs F hF _ x + unfold A; rw [ind_zero h,zero_mul]; norm_num + have hi x : + ind (bothPart Z x) * brightProd f x= ind (injPart g x) * A x := by + rw [road_iff]; unfold A F + simp only [ind_and, ind_all,brightProd,Finset.prod_mul_distrib] + ring + have hg : + |condMean (bothPart Z) (brightProd f) - avg unif A|≤ num G*(2*bp (k-N)) := by + unfold condMean + simp_rw [hi] + rw [← avg_sub] + refine (abs_avg_le unif_law.nz).trans ((avg_mono unif_law.nz (g:=fun x => + ind (¬injPart g x)) fun i => ?_).trans (injPart_failure g N k hk)) + by_cases h : injPart g i <;> + simp only [h,ind_true,not_true,ind_false,one_mul,sub_self,abs_zero,zero_mul,zero_sub, + abs_neg,not_false_eq_true]; exact le_rfl; exact hA _ + rw [hP] at ht + unfold twinkle + apply le_trans _ (add_le_add hg ht) + exact abs_sub_le .. + +omit [DecidableEq I] in +theorem lane_norm (Z : GeoM g) (hN : ∀ i, 2*num (Port g i)-(N:ℝ)≤ -1) + (i : I) : 0 x.val.2) h) + have hx j : num (Port (street g i) j)≤num (Port g j) := by + exact_mod_cast Fintype.card_le_of_injective _ (he j) + refine lt_of_lt_of_le (inv_pos_of_pos netFact_pos) (net_norm (laneM Z i) N (fun j => ?_)).1 + linarith only [hx j,hN j] + +set_option maxHeartbeats 800000 in +theorem compare_lanes (Z : GeoM g) (f : I→ Wgt (Rack J N)) (hf : ∀ i x,|f i x|≤1) + (k : ℝ) (hk : ∀ i,num (Port g i)≤k) (hN : ∀ i,2*num (Port g i)-(N:ℝ)≤ -1) : + |avg (rackStation Z N) (brightProd f)- ∏ i,avg (rackStation (laneM Z i) N) (f i)|≤ + 2*netFact g*twinkle g k N := by + classical + let A := pr unif (bothPart (N:=N) Z) + let B i := pr unif (bothPart (N:=N) (laneM Z i)) + let u := avg (rackStation Z N) (brightProd f) + let v i := avg (rackStation (laneM Z i) N) (f i) + let P := bp (- ((crossroads g).card:ℝ))*(∏ i, B i) + let V := ∏ i,v i + have hV : |V|≤1 := by + unfold V + rw [Finset.abs_prod] + have he (i) : + SubLaw (rackStation (laneM Z i) N) := unifOn_sub _ + refine (Finset.prod_le_prod₀ (fun i _ => abs_nonneg _) + (fun i _ => (abs_avg_le (he i).nz).trans ((he i).avg_le zero_le_one (hf i)))).trans_eq ?_ + simp + have hh := net_norm Z N hN + have h0 : 0 (1:ℝ) + have ht := lane_means Z F (by intro i x; simp [F]) k hk + have he (i : I) : + condMean (bothPart (laneM Z i)) (F i)=B i := by simp only [F,condMean,mul_one]; rfl + have hx : + condMean (bothPart (N:=N) Z) (brightProd F)=A := by + simp only [F,brightProd,condMean,Finset.prod_const_one,mul_one,A,pr] + simp_rw [he,hx] at ht; exact ht + have hg : A * |u-V|≤2*twinkle g k N := by + have hh : |(A-P)*V|≤twinkle g k N := by + rw [abs_mul]; exact ((mul_le_mul_of_nonneg_left hV (abs_nonneg _)).trans_eq (mul_one _)).trans h2 + calc A*|u-V|= |(A*u-P*V)-(A-P)*V| := by + rw [show A*u-P*V-(A-P)*V=(A*(u-V)) by ring,abs_mul,abs_of_nonneg h0.le] + _ ≤ _ := ((abs_sub ..).trans (add_le_add h1 hh)).trans_eq (two_mul _).symm + apply le_of_mul_le_mul_left _ (inv_pos_of_pos (netFact_pos (f:=g))) + exact ((mul_le_mul_of_nonneg_right hh.1 (abs_nonneg _)).trans hg).trans_eq (by + have h := netFact_pos (f:=g) + field_simp) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionedCorrelations.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionedCorrelations.lean index 440b42f9847fd48104ee2a4e720e3258f24e3971..0e329217eb8d80fd0a64aa05de0363efa14ff7ca 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionedCorrelations.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ConditionedCorrelations.lean @@ -1,97 +1,97 @@ -import OAI.Combinatorics.HadwigerCounterexample.BilinearBlockCorrelation - -namespace OAI - -/-! # Conditioned Correlations -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real Filter Matrix LinearMap Function -open scoped BigOperators -variable {p : Shape} {I A : Type} [Fintype I] [Fintype A] -variable {n : ℕ} - -set_option maxHeartbeats 600000 in -theorem spark_condition (p : Shape) (M : Moment p n) (s t : Label p.b) (l j : Tag p.g) - (f g : Flavor p.g) (B) (hB : f.keeps l B) (hB' : g.keeps j B) - (w u : Wgt (Knobs p.g n)) (hw : ∀ i,|w i|≤1) (hu : ∀ i,|u i|≤1) - (μ δ : Wgt (Knobs p.g n)) (hμ : IsLaw μ) (hδ : IsLaw δ) - (C : ℝ) (hC : 0 wsign (Q x.1 x.2)*(w x.1*u x.2))|≤ - C^2*bp (-(n:ℝ)/10) := by - classical - intro Q - let V := Knobs p.g n - let fit (f p : Wgt V) := fun i => p i*f i/(C*unif i) - have h0 (i : V) : 0 ?_ - unfold Z F fit pairW - have h1 := h0 i.1; have h2 := h0 i.2 - have h3 : unif i.1 ≠ 0 := by rw [unif_apply]; positivity - have h4 : unif i.2 ≠ 0 := by rw [unif_apply]; positivity - field_simp - change |avg (pairW μ δ) F|≤_ - rw [he,abs_mul,abs_of_nonneg (sq_nonneg _)] - have hi : (n:ℝ)≤5*blockRank B s t M := by exact_mod_cast hM - exact mul_le_mul_of_nonneg_left ((spark_uncap p M s t l j f g B hB hB' - _ _ (hh w μ hw hμ hc) (hh u δ hu hδ hc')).trans (bp_le (by linarith only [hi]))) (sq_nonneg _) - -def litFire (p : Shape) {n N : ℕ} (x : UnitType p n N) := - ∀ (s t : Label p.b) (c : Vec (Notches p)), c≠0 → - n≤5*blockRank Block.Z s t (issue p c x) - -theorem litFire_calendar (p : Shape) (C : ℝ) (M : ℕ) (hM : 4≤M) : - ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n), 2*num (Full p n) ¬litFire p i) ≤ bp (-(n:ℝ)*n/8) := by - classical - let I := Label p.b × Label p.b × Vec (Notches p) - have ht := bp_poly_dom_nat (a:=1) zero_lt_one (num I) 0 - filter_upwards [issue_live p,ht,(tendsto_natCast_atTop_atTop (R:=ℝ)).eventually - (eventually_ge_atTop (8*(C*M+1)))] - with n hn hp hab N m hN w h - change 8*(C*M+1)≤ (n:ℝ) at hab - refine (pr_cap h _).trans ?_ - let Q (i : I) (x : UnitType p n N) := - i.2.2≠0 ∧ 5*blockRank Block.Z i.1 i.2.1 (issue p i.2.2 x) h.2).trans - (hn N (by unfold N; nlinarith only [Nat.mul_le_mul_right n hM]) hN m _ _ i.2.2 h) - have hh (x : UnitType p n N) (h : ¬litFire p x) : ∃ i,Q i x := by - unfold litFire at h - push Not at h - obtain ⟨s,t,c,hc,h⟩ := h; exact ⟨(s,t,c),hc,h⟩ - have hi : pr v (fun x=> ¬litFire p x) ≤ num I*bp (-(n:ℝ)*n/4) := - (le_trans (pr_mono hv.nz hh) (pr_exists_le hv.nz Q)).trans ((sum_le_sum - fun i _ => he i).trans_eq (by simp [num])) - refine (mul_le_mul_of_nonneg_left hi (bp_pos _).le).trans ?_ - simp only [pow_zero,mul_one,one_mul] at hp - apply (mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_right hp.le - (bp_pos (-(n:ℝ)*n/4)).le) (bp_pos (C*N)).le).trans - rw [← bp_add,← bp_add] - apply bp_le - unfold N; push_cast - nlinarith only [mul_le_mul_of_nonneg_right hab (Nat.cast_nonneg n : 0≤(n:ℝ))] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BilinearBlockCorrelation + +namespace OAI + +/-! # Conditioned Correlations -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real Filter Matrix LinearMap Function +open scoped BigOperators +variable {p : Shape} {I A : Type} [Fintype I] [Fintype A] +variable {n : ℕ} + +set_option maxHeartbeats 600000 in +theorem spark_condition (p : Shape) (M : Moment p n) (s t : Label p.b) (l j : Tag p.g) + (f g : Flavor p.g) (B) (hB : f.keeps l B) (hB' : g.keeps j B) + (w u : Wgt (Knobs p.g n)) (hw : ∀ i,|w i|≤1) (hu : ∀ i,|u i|≤1) + (μ δ : Wgt (Knobs p.g n)) (hμ : IsLaw μ) (hδ : IsLaw δ) + (C : ℝ) (hC : 0 wsign (Q x.1 x.2)*(w x.1*u x.2))|≤ + C^2*bp (-(n:ℝ)/10) := by + classical + intro Q + let V := Knobs p.g n + let fit (f p : Wgt V) := fun i => p i*f i/(C*unif i) + have h0 (i : V) : 0 ?_ + unfold Z F fit pairW + have h1 := h0 i.1; have h2 := h0 i.2 + have h3 : unif i.1 ≠ 0 := by rw [unif_apply]; positivity + have h4 : unif i.2 ≠ 0 := by rw [unif_apply]; positivity + field_simp + change |avg (pairW μ δ) F|≤_ + rw [he,abs_mul,abs_of_nonneg (sq_nonneg _)] + have hi : (n:ℝ)≤5*blockRank B s t M := by exact_mod_cast hM + exact mul_le_mul_of_nonneg_left ((spark_uncap p M s t l j f g B hB hB' + _ _ (hh w μ hw hμ hc) (hh u δ hu hδ hc')).trans (bp_le (by linarith only [hi]))) (sq_nonneg _) + +def litFire (p : Shape) {n N : ℕ} (x : UnitType p n N) := + ∀ (s t : Label p.b) (c : Vec (Notches p)), c≠0 → + n≤5*blockRank Block.Z s t (issue p c x) + +theorem litFire_calendar (p : Shape) (C : ℝ) (M : ℕ) (hM : 4≤M) : + ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n), 2*num (Full p n) ¬litFire p i) ≤ bp (-(n:ℝ)*n/8) := by + classical + let I := Label p.b × Label p.b × Vec (Notches p) + have ht := bp_poly_dom_nat (a:=1) zero_lt_one (num I) 0 + filter_upwards [issue_live p,ht,(tendsto_natCast_atTop_atTop (R:=ℝ)).eventually + (eventually_ge_atTop (8*(C*M+1)))] + with n hn hp hab N m hN w h + change 8*(C*M+1)≤ (n:ℝ) at hab + refine (pr_cap h _).trans ?_ + let Q (i : I) (x : UnitType p n N) := + i.2.2≠0 ∧ 5*blockRank Block.Z i.1 i.2.1 (issue p i.2.2 x) h.2).trans + (hn N (by unfold N; nlinarith only [Nat.mul_le_mul_right n hM]) hN m _ _ i.2.2 h) + have hh (x : UnitType p n N) (h : ¬litFire p x) : ∃ i,Q i x := by + unfold litFire at h + push Not at h + obtain ⟨s,t,c,hc,h⟩ := h; exact ⟨(s,t,c),hc,h⟩ + have hi : pr v (fun x=> ¬litFire p x) ≤ num I*bp (-(n:ℝ)*n/4) := + (le_trans (pr_mono hv.nz hh) (pr_exists_le hv.nz Q)).trans ((sum_le_sum + fun i _ => he i).trans_eq (by simp [num])) + refine (mul_le_mul_of_nonneg_left hi (bp_pos _).le).trans ?_ + simp only [pow_zero,mul_one,one_mul] at hp + apply (mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_right hp.le + (bp_pos (-(n:ℝ)*n/4)).le) (bp_pos (C*N)).le).trans + rw [← bp_add,← bp_add] + apply bp_le + unfold N; push_cast + nlinarith only [mul_le_mul_of_nonneg_right hab (Nat.cast_nonneg n : 0≤(n:ℝ))] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ConstructionScales.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ConstructionScales.lean index 913d1af970de40cd021a9d60c079b77fbfa3eb8b..3df6e179b9d926720b296ace7946e59364107835 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ConstructionScales.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ConstructionScales.lean @@ -1,100 +1,100 @@ -import OAI.Combinatorics.HadwigerCounterexample.RawFrameLaws - -namespace OAI - -/-! # Construction Scales -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Filter - -theorem card_full (p : Shape) (n : ℕ) : - Fintype.card (Full p n) = psize p * (1+(p.g*p.g+3)*n) + p.h := by - calc - _ = Fintype.card (Row p n) + Fintype.card (Fin p.h) := - Fintype.card_sum .. - _ = _ := by rw [card_row, Fintype.card_fin] - -theorem full_linear (p : Shape) : ∃ B : ℝ, 0 ≤ B ∧ ∀ n : ℕ, 0 < n → - num (Full p n) ≤ B*n := by - let b := psize p*(1+(p.g*p.g+3)) + p.h - refine ⟨↑b,Nat.cast_nonneg b, fun n hn => ?_⟩ - have h1 : 1 ≤ n := hn - have h2 : Fintype.card (Full p n) ≤ b*n := by - rw [card_full] - unfold b - calc _ ≤ psize p * (n+(p.g*p.g+3)*n) + p.h*n := - add_le_add (Nat.mul_le_mul_left _ (by omega)) (by nlinarith) - _ = _ := by ring - exact_mod_cast h2 - -theorem unit_size (p : Shape) (n N : ℕ) : - num (UnitType p n N) = bp (num (Comp p.g) * 4 * N * num (Full p n)) := by - have hc : - (Fintype.card (UnitType p n N)) = - ((Fintype.card (Mat (Fin N) (Full p n)))^2)^(Fintype.card (Comp p.g)) * - ((Fintype.card (Mat (Fin N) (Full p n)))^2)^(Fintype.card (Comp p.g)) := by - simp [UnitType, Orient, Oframe, RawFrame, pow_two] - unfold num - rw [hc] - push_cast - rw [card_space,dim_mat,Fintype.card_fin] - push_cast - simp only [← bp_mul_nat,← bp_add] - push_cast; ring_nf - -/-- Fixed linear and constant expenses become any fixed small fraction of N. -/ -theorem have_budget {δ : ℝ} (hd : 0 < δ) (a b : ℝ) (hb : 0 ≤ b) : - ∀ᶠ M : ℕ in atTop, ∀ n : ℕ, 1 ≤ n → a*n+b ≤ δ*(M*n : ℕ) := by - have h : Tendsto (fun M : ℕ => δ*M) atTop atTop := - (tendsto_const_mul_atTop_of_pos hd).mpr tendsto_natCast_atTop_atTop - filter_upwards [h.eventually (eventually_ge_atTop (a+b))] with M hM n hn - change a+b ≤ δ*M at hM - push_cast - have hn' : 1 ≤ (n:ℝ) := by exact_mod_cast hn - nlinarith only [mul_le_mul_of_nonneg_right hM (Nat.cast_nonneg n : (0:ℝ)≤n), - mul_le_mul_of_nonneg_right hn' hb] - -theorem columns_budget (p : Shape) {δ : ℝ} (hd : 0 < δ) (a b : ℝ) - (ha : 0 ≤ a) (hb : 0 ≤ b) : - ∀ᶠ M : ℕ in atTop, ∀ n : ℕ, 1 ≤ n → - a*num (Full p n) + b ≤ δ*(M*n:ℕ) := by - obtain ⟨B,hB,h⟩ := full_linear p - filter_upwards [have_budget hd (a*B) b hb] with M hM n hn - refine le_trans ?_ (hM n hn) - rw [mul_assoc] - exact add_le_add_left (mul_le_mul_of_nonneg_left (h _ hn) ha) _ - -theorem raw_ready (p : Shape) {δ : ℝ} (hd : 0 < δ) : - ∀ᶠ M : ℕ in atTop, ∀ᶠ n : ℕ in atTop, let N := M*n; - num (UnitType p n N) ≤ bp ((4*num (Comp p.g))*N^ (2 : ℕ)) ∧ - ∀ m : Mixer p n, IsLaw (raw m N) ∧ ∀ a : Pin p n N, - pr (pairW (raw m N) (raw m N)) a.agree ≤ bp (-(1-δ)*(planRank a.sp)*N) := by - have hd' : 0 < δ/2 := by positivity - filter_upwards [columns_budget p hd' 2 (4*num (Comp p.g)) (by norm_num) - (by unfold num; positivity), - columns_budget p (δ:=1) (by norm_num) 2 1 (by norm_num) (by norm_num)] with M ha hb - filter_upwards [eventually_ge_atTop 1] with n hn - specialize ha n hn - specialize hb n hn - let N := M*n - have hi : 0 ≤ num (Comp p.g) := Nat.cast_nonneg _ - have hj : 0 ≤ num (Full p n) := Nat.cast_nonneg _ - rw [one_mul] at hb - have hh : 2*num (Full p n) reference_cap _ a hd ?_ ?_ ?_⟩ <;> linarith -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RawFrameLaws + +namespace OAI + +/-! # Construction Scales -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Filter + +theorem card_full (p : Shape) (n : ℕ) : + Fintype.card (Full p n) = psize p * (1+(p.g*p.g+3)*n) + p.h := by + calc + _ = Fintype.card (Row p n) + Fintype.card (Fin p.h) := + Fintype.card_sum .. + _ = _ := by rw [card_row, Fintype.card_fin] + +theorem full_linear (p : Shape) : ∃ B : ℝ, 0 ≤ B ∧ ∀ n : ℕ, 0 < n → + num (Full p n) ≤ B*n := by + let b := psize p*(1+(p.g*p.g+3)) + p.h + refine ⟨↑b,Nat.cast_nonneg b, fun n hn => ?_⟩ + have h1 : 1 ≤ n := hn + have h2 : Fintype.card (Full p n) ≤ b*n := by + rw [card_full] + unfold b + calc _ ≤ psize p * (n+(p.g*p.g+3)*n) + p.h*n := + add_le_add (Nat.mul_le_mul_left _ (by omega)) (by nlinarith) + _ = _ := by ring + exact_mod_cast h2 + +theorem unit_size (p : Shape) (n N : ℕ) : + num (UnitType p n N) = bp (num (Comp p.g) * 4 * N * num (Full p n)) := by + have hc : + (Fintype.card (UnitType p n N)) = + ((Fintype.card (Mat (Fin N) (Full p n)))^2)^(Fintype.card (Comp p.g)) * + ((Fintype.card (Mat (Fin N) (Full p n)))^2)^(Fintype.card (Comp p.g)) := by + simp [UnitType, Orient, Oframe, RawFrame, pow_two] + unfold num + rw [hc] + push_cast + rw [card_space,dim_mat,Fintype.card_fin] + push_cast + simp only [← bp_mul_nat,← bp_add] + push_cast; ring_nf + +/-- Fixed linear and constant expenses become any fixed small fraction of N. -/ +theorem have_budget {δ : ℝ} (hd : 0 < δ) (a b : ℝ) (hb : 0 ≤ b) : + ∀ᶠ M : ℕ in atTop, ∀ n : ℕ, 1 ≤ n → a*n+b ≤ δ*(M*n : ℕ) := by + have h : Tendsto (fun M : ℕ => δ*M) atTop atTop := + (tendsto_const_mul_atTop_of_pos hd).mpr tendsto_natCast_atTop_atTop + filter_upwards [h.eventually (eventually_ge_atTop (a+b))] with M hM n hn + change a+b ≤ δ*M at hM + push_cast + have hn' : 1 ≤ (n:ℝ) := by exact_mod_cast hn + nlinarith only [mul_le_mul_of_nonneg_right hM (Nat.cast_nonneg n : (0:ℝ)≤n), + mul_le_mul_of_nonneg_right hn' hb] + +theorem columns_budget (p : Shape) {δ : ℝ} (hd : 0 < δ) (a b : ℝ) + (ha : 0 ≤ a) (hb : 0 ≤ b) : + ∀ᶠ M : ℕ in atTop, ∀ n : ℕ, 1 ≤ n → + a*num (Full p n) + b ≤ δ*(M*n:ℕ) := by + obtain ⟨B,hB,h⟩ := full_linear p + filter_upwards [have_budget hd (a*B) b hb] with M hM n hn + refine le_trans ?_ (hM n hn) + rw [mul_assoc] + exact add_le_add_left (mul_le_mul_of_nonneg_left (h _ hn) ha) _ + +theorem raw_ready (p : Shape) {δ : ℝ} (hd : 0 < δ) : + ∀ᶠ M : ℕ in atTop, ∀ᶠ n : ℕ in atTop, let N := M*n; + num (UnitType p n N) ≤ bp ((4*num (Comp p.g))*N^ (2 : ℕ)) ∧ + ∀ m : Mixer p n, IsLaw (raw m N) ∧ ∀ a : Pin p n N, + pr (pairW (raw m N) (raw m N)) a.agree ≤ bp (-(1-δ)*(planRank a.sp)*N) := by + have hd' : 0 < δ/2 := by positivity + filter_upwards [columns_budget p hd' 2 (4*num (Comp p.g)) (by norm_num) + (by unfold num; positivity), + columns_budget p (δ:=1) (by norm_num) 2 1 (by norm_num) (by norm_num)] with M ha hb + filter_upwards [eventually_ge_atTop 1] with n hn + specialize ha n hn + specialize hb n hn + let N := M*n + have hi : 0 ≤ num (Comp p.g) := Nat.cast_nonneg _ + have hj : 0 ≤ num (Full p n) := Nat.cast_nonneg _ + rw [one_mul] at hb + have hh : 2*num (Full p n) reference_cap _ a hd ?_ ?_ ?_⟩ <;> linarith +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CoordinateBlocks.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CoordinateBlocks.lean index 59d898199cb6177b2fbb15b81db3f48508b1cf8b..6e717e57a73413d432520f2a53d138367365ab3a 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CoordinateBlocks.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CoordinateBlocks.lean @@ -1,147 +1,147 @@ -import OAI.Combinatorics.HadwigerCounterexample.BooleanLabels -import OAI.Combinatorics.HadwigerCounterexample.QuadraticTesters -import OAI.Combinatorics.HadwigerCounterexample.CoordinateEmbeddings - -namespace OAI - -/-! # Coordinate Blocks -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix -open scoped BigOperators -variable {p : Shape} {n : ℕ} - -def blockA (p : Shape) (n : ℕ) (B : Block p.g) : Mat (AIdx p.g n) (Fin n) := - embedMat (fun i => some (B,i)) - -def blockRay (p : Shape) (n : ℕ) (s : Label p.b) (B : Block p.g) : Mat (Row p n) (Fin n) := - labMat p n s * blockA p n B - -theorem lab_inj (s : Label p.b) : Function.Injective (labMat p n s).mulVec := by - intro x y he - funext i - rw [labMat_act,labMat_act] at he - have h := congr_fun he (emptySel,i) - simpa [putLab,selV,emptySel] using h - -theorem joined_lab_inj {s t : Label p.b} (hj : 1≤p.j) (hs : s≠t) : - Function.Injective (fromCols (labMat p n s) (labMat p n t)).mulVec := by - apply inj_fromCols (lab_inj _) (lab_inj _) - classical - rw [disjoint_iff_inf_le] - rintro x ⟨⟨v,rfl⟩,w,h⟩ - simp only [mulVecLin_apply,labMat_act] at h - let Z : Label p.b → Vec (AIdx p.g n) := fun i => if i=s then v else -w - have he : ∑ i ∈ ({s,t} : Finset _), putLab p n i (Z i)=0 := by - simp [Z,hs,hs.symm,map_neg,h] - have hi : ({s,t}:Finset _).card ≤ p.j+1 := by - have hh : ({s,t}:Finset _).card=2 := by simp [hs] - omega - have hg := ray_indep _ _ hi he s (by simp) - have hv : v=0 := by simpa [Z] using hg - rw [hv,map_zero]; exact Submodule.zero_mem _ - -theorem block_inj (B : Block p.g) : Function.Injective (blockA p n B).mulVec := - embedMat_inj (show Function.Injective (fun i => some (B,i)) from - fun _ _ h => congrArg Prod.snd (Option.some.inj h)) - -theorem blockRay_inj (p : Shape) (n) (s) (B) : - Function.Injective (blockRay p n s B).mulVec := - inj_comp_mat _ _ (lab_inj _) (block_inj B) - -theorem joined_block_inj {s t : Label p.b} (hj : 1 ≤ p.j) (hs : s ≠ t) (B : Block p.g) : - Function.Injective (fromCols (blockRay p n s B) (blockRay p n t B)).mulVec := by - classical - apply inj_fromCols (blockRay_inj ..) (blockRay_inj ..) - rw [disjoint_iff_inf_le] - rintro x ⟨⟨v,rfl⟩,w,h⟩ - simp only [Matrix.mulVecLin_apply,blockRay,← Matrix.mulVec_mulVec] at h - let a := Sum.elim (blockA p n B *ᵥ v) (0 : Vec (AIdx p.g n)) - let b := Sum.elim (0 : Vec (AIdx p.g n)) (blockA p n B *ᵥ w) - have heq : a=b := joined_lab_inj hj hs (by - dsimp only [a,b] - rw [fromCols_mulVec_sumElim,fromCols_mulVec_sumElim,Matrix.mulVec_zero, - Matrix.mulVec_zero,zero_add,add_zero,h]) - have hg : blockA p n B *ᵥ v = 0 := funext (fun x => congr_fun heq (.inl x)) - change blockRay p n s B *ᵥ v ∈ _ - rw [blockRay,← Matrix.mulVec_mulVec,hg,Matrix.mulVec_zero] - exact Submodule.zero_mem _ - -theorem blockRay_eval (p : Shape) (s : Label p.b) (B) (i) (j : Fin n) : - blockRay p n s B i j = if i.2=some (B,j) then monoBit s i.1.val else 0 := by - rw [blockRay,blockA,mul_embedMat]; rfl - -theorem project_pick {d B : Block p.g} (hd : d ≠ B) (a) (s) (i) : - (blockRay p n s B)ᵀ *ᵥ pick p n a d i = 0 := by - classical - unfold pick - split - · rename_i hi - rw [Matrix.mulVec_single_one] - ext j - change blockRay p n s B (a,some (d,⟨i,hi⟩)) j=0 - simp [blockRay_eval,hd] - rw [Matrix.mulVec_zero] - -theorem project_same (B : Block p.g) (a s) (i : Fin n) : - (blockRay p n s B)ᵀ *ᵥ pick p n a B i.val = Pi.single i (monoBit s a.val) := by - classical - rw [pick,dite_eq_left i.isLt,Matrix.mulVec_single_one] - ext j - change blockRay p n s B _ j=_ - rw [blockRay_eval] - simp [Pi.single_apply, eq_comm] - -def pullM {I J V U : Type} [Fintype V] [Fintype U] (P : Mat V I) (Q : Mat U J) : - Mat V U →ₗ[F] Mat I J := liftM Pᵀ Qᵀ -theorem pullM_def {I J V U : Type} [Fintype V] [Fintype U] (P : Mat V I) - (Q : Mat U J) (M : Mat V U) : pullM P Q M=Pᵀ*M*Q := rfl - -theorem pull_test {d B : Block p.g} (h : d≠B) (s s') : - pullM (blockRay p n s B) (blockRay p n s' B) (testM p n d) = 0 := by - unfold testM pullM - simp only [map_sum,liftM_outer,project_pick h] - simp - -theorem pull_self_Z (M) (s s' : Label p.b) : - pullM (blockRay p n s Block.Z) (blockRay p n s' Block.Z) (selfM p n M)=0 := by - let L := pullM (blockRay p n s Block.Z) (blockRay p n s' Block.Z) - have hx (i j : Tag p.g) := pull_test (n:=n) (d:=Block.O i j) - (B:=Block.Z) (by simp [Block.O,Block.Z]) s s' - have hs := pull_test (p:=p) (n:=n) (d:=Block.S) (B:=Block.Z) (by simp [Block.S,Block.Z]) s s' - have h (a : SelIdx p.b p.j) (s : Label p.b) (i) := - project_pick (n:=n) (p:=p) (d:=Block.sharp) (B:=Block.Z) (by simp [Block.sharp,Block.Z]) a s i - rw [selfM]; simp only [map_add,map_sum,hx,hs,Finset.sum_const_zero,zero_add] - unfold sharpM sharpPick pullM - by_cases he : 1 ≤ p.j - · simp only [map_sum,map_smul,map_add, dite_eq_left he,liftM_outer,h] - simp - · simp only [dite_eq_right he]; simp - -theorem pull_self_sharp (M) (s s' : Label p.b) (hj : 1≤p.j) : - pullM (blockRay p n s Block.sharp) (blockRay p n s' Block.sharp) (selfM p n M) = - ∑ i, (s i+s' i) • M i := by - classical - have hx (i j : Tag p.g) := pull_test (n:=n) (d:=Block.O i j) - (B:=Block.sharp) (by simp [Block.O,Block.sharp]) s s' - have hs := pull_test (p:=p) (n:=n) (d:=Block.S) (B:=Block.sharp) (by simp [Block.S,Block.sharp]) s s' - rw [selfM]; simp only [map_add,map_sum,hx,hs,Finset.sum_const_zero,zero_add] - unfold sharpM sharpPick pullM - simp only [map_sum,map_add,map_smul, dite_eq_left hj,liftM_outer,project_same] - refine Finset.sum_congr rfl fun i _ => ?_ - ext a b - simp only [Matrix.sum_apply,Matrix.add_apply,Matrix.smul_apply,smul_eq_mul, - vecMulVec_apply,monoBit,emptySel,Finset.prod_empty,Finset.prod_singleton,Pi.single_apply] - rw [Finset.sum_eq_single a] - · rw [Finset.sum_eq_single b] - · simp; ring - · intro j _ h; simp [h.symm] - · simp - · intro j _ h; simp [h.symm] - simp -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BooleanLabels +import OAI.Combinatorics.HadwigerCounterexample.QuadraticTesters +import OAI.Combinatorics.HadwigerCounterexample.CoordinateEmbeddings + +namespace OAI + +/-! # Coordinate Blocks -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix +open scoped BigOperators +variable {p : Shape} {n : ℕ} + +def blockA (p : Shape) (n : ℕ) (B : Block p.g) : Mat (AIdx p.g n) (Fin n) := + embedMat (fun i => some (B,i)) + +def blockRay (p : Shape) (n : ℕ) (s : Label p.b) (B : Block p.g) : Mat (Row p n) (Fin n) := + labMat p n s * blockA p n B + +theorem lab_inj (s : Label p.b) : Function.Injective (labMat p n s).mulVec := by + intro x y he + funext i + rw [labMat_act,labMat_act] at he + have h := congr_fun he (emptySel,i) + simpa [putLab,selV,emptySel] using h + +theorem joined_lab_inj {s t : Label p.b} (hj : 1≤p.j) (hs : s≠t) : + Function.Injective (fromCols (labMat p n s) (labMat p n t)).mulVec := by + apply inj_fromCols (lab_inj _) (lab_inj _) + classical + rw [disjoint_iff_inf_le] + rintro x ⟨⟨v,rfl⟩,w,h⟩ + simp only [mulVecLin_apply,labMat_act] at h + let Z : Label p.b → Vec (AIdx p.g n) := fun i => if i=s then v else -w + have he : ∑ i ∈ ({s,t} : Finset _), putLab p n i (Z i)=0 := by + simp [Z,hs,hs.symm,map_neg,h] + have hi : ({s,t}:Finset _).card ≤ p.j+1 := by + have hh : ({s,t}:Finset _).card=2 := by simp [hs] + omega + have hg := ray_indep _ _ hi he s (by simp) + have hv : v=0 := by simpa [Z] using hg + rw [hv,map_zero]; exact Submodule.zero_mem _ + +theorem block_inj (B : Block p.g) : Function.Injective (blockA p n B).mulVec := + embedMat_inj (show Function.Injective (fun i => some (B,i)) from + fun _ _ h => congrArg Prod.snd (Option.some.inj h)) + +theorem blockRay_inj (p : Shape) (n) (s) (B) : + Function.Injective (blockRay p n s B).mulVec := + inj_comp_mat _ _ (lab_inj _) (block_inj B) + +theorem joined_block_inj {s t : Label p.b} (hj : 1 ≤ p.j) (hs : s ≠ t) (B : Block p.g) : + Function.Injective (fromCols (blockRay p n s B) (blockRay p n t B)).mulVec := by + classical + apply inj_fromCols (blockRay_inj ..) (blockRay_inj ..) + rw [disjoint_iff_inf_le] + rintro x ⟨⟨v,rfl⟩,w,h⟩ + simp only [Matrix.mulVecLin_apply,blockRay,← Matrix.mulVec_mulVec] at h + let a := Sum.elim (blockA p n B *ᵥ v) (0 : Vec (AIdx p.g n)) + let b := Sum.elim (0 : Vec (AIdx p.g n)) (blockA p n B *ᵥ w) + have heq : a=b := joined_lab_inj hj hs (by + dsimp only [a,b] + rw [fromCols_mulVec_sumElim,fromCols_mulVec_sumElim,Matrix.mulVec_zero, + Matrix.mulVec_zero,zero_add,add_zero,h]) + have hg : blockA p n B *ᵥ v = 0 := funext (fun x => congr_fun heq (.inl x)) + change blockRay p n s B *ᵥ v ∈ _ + rw [blockRay,← Matrix.mulVec_mulVec,hg,Matrix.mulVec_zero] + exact Submodule.zero_mem _ + +theorem blockRay_eval (p : Shape) (s : Label p.b) (B) (i) (j : Fin n) : + blockRay p n s B i j = if i.2=some (B,j) then monoBit s i.1.val else 0 := by + rw [blockRay,blockA,mul_embedMat]; rfl + +theorem project_pick {d B : Block p.g} (hd : d ≠ B) (a) (s) (i) : + (blockRay p n s B)ᵀ *ᵥ pick p n a d i = 0 := by + classical + unfold pick + split + · rename_i hi + rw [Matrix.mulVec_single_one] + ext j + change blockRay p n s B (a,some (d,⟨i,hi⟩)) j=0 + simp [blockRay_eval,hd] + rw [Matrix.mulVec_zero] + +theorem project_same (B : Block p.g) (a s) (i : Fin n) : + (blockRay p n s B)ᵀ *ᵥ pick p n a B i.val = Pi.single i (monoBit s a.val) := by + classical + rw [pick,dite_eq_left i.isLt,Matrix.mulVec_single_one] + ext j + change blockRay p n s B _ j=_ + rw [blockRay_eval] + simp [Pi.single_apply, eq_comm] + +def pullM {I J V U : Type} [Fintype V] [Fintype U] (P : Mat V I) (Q : Mat U J) : + Mat V U →ₗ[F] Mat I J := liftM Pᵀ Qᵀ +theorem pullM_def {I J V U : Type} [Fintype V] [Fintype U] (P : Mat V I) + (Q : Mat U J) (M : Mat V U) : pullM P Q M=Pᵀ*M*Q := rfl + +theorem pull_test {d B : Block p.g} (h : d≠B) (s s') : + pullM (blockRay p n s B) (blockRay p n s' B) (testM p n d) = 0 := by + unfold testM pullM + simp only [map_sum,liftM_outer,project_pick h] + simp + +theorem pull_self_Z (M) (s s' : Label p.b) : + pullM (blockRay p n s Block.Z) (blockRay p n s' Block.Z) (selfM p n M)=0 := by + let L := pullM (blockRay p n s Block.Z) (blockRay p n s' Block.Z) + have hx (i j : Tag p.g) := pull_test (n:=n) (d:=Block.O i j) + (B:=Block.Z) (by simp [Block.O,Block.Z]) s s' + have hs := pull_test (p:=p) (n:=n) (d:=Block.S) (B:=Block.Z) (by simp [Block.S,Block.Z]) s s' + have h (a : SelIdx p.b p.j) (s : Label p.b) (i) := + project_pick (n:=n) (p:=p) (d:=Block.sharp) (B:=Block.Z) (by simp [Block.sharp,Block.Z]) a s i + rw [selfM]; simp only [map_add,map_sum,hx,hs,Finset.sum_const_zero,zero_add] + unfold sharpM sharpPick pullM + by_cases he : 1 ≤ p.j + · simp only [map_sum,map_smul,map_add, dite_eq_left he,liftM_outer,h] + simp + · simp only [dite_eq_right he]; simp + +theorem pull_self_sharp (M) (s s' : Label p.b) (hj : 1≤p.j) : + pullM (blockRay p n s Block.sharp) (blockRay p n s' Block.sharp) (selfM p n M) = + ∑ i, (s i+s' i) • M i := by + classical + have hx (i j : Tag p.g) := pull_test (n:=n) (d:=Block.O i j) + (B:=Block.sharp) (by simp [Block.O,Block.sharp]) s s' + have hs := pull_test (p:=p) (n:=n) (d:=Block.S) (B:=Block.sharp) (by simp [Block.S,Block.sharp]) s s' + rw [selfM]; simp only [map_add,map_sum,hx,hs,Finset.sum_const_zero,zero_add] + unfold sharpM sharpPick pullM + simp only [map_sum,map_add,map_smul, dite_eq_left hj,liftM_outer,project_same] + refine Finset.sum_congr rfl fun i _ => ?_ + ext a b + simp only [Matrix.sum_apply,Matrix.add_apply,Matrix.smul_apply,smul_eq_mul, + vecMulVec_apply,monoBit,emptySel,Finset.prod_empty,Finset.prod_singleton,Pi.single_apply] + rw [Finset.sum_eq_single a] + · rw [Finset.sum_eq_single b] + · simp; ring + · intro j _ h; simp [h.symm] + · simp + · intro j _ h; simp [h.symm] + simp +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CoordinateDuality.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CoordinateDuality.lean index 459678f59d36912e46a470f5a58330f024653be4..4bb97077105f9b3bbedc2cc5f5e98f253bb1ac80 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CoordinateDuality.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CoordinateDuality.lean @@ -1,87 +1,87 @@ -import OAI.Combinatorics.HadwigerCounterexample.ScalarStatusAlgebra - -namespace OAI - -/-! # Coordinate Duality -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module LinearMap Submodule Function -open scoped BigOperators -namespace StatusAnalysis -variable {A B : Rates} {d e : ℕ} - -structure DualCoefficients (A B : Rates) where - left : Quota - right : Quota - gam : Grid→F - hed : Grid→F - north : (i:Grid)→ Cell (A i.1) - south : (i:Grid)→ Cell (B i.2) -def DualCoefficients.bet (p : DualCoefficients A B) (i : Grid) (x : LedgerS A B i) := - p.gam i * x.1 + p.hed i * x.2.1 + (dotProduct (p.north i) x.2.2.1+ - dotProduct (p.south i) x.2.2.2) -def DualCoefficients.law (p : DualCoefficients A B) (V : StatusSp A B) := - ∀ i:Grid,∀ v∈V i, p.bet i (want _ _ v) = - p.left i.2 * couple _ v.2.1 + p.right i.1 * couple _ v.2.2 - -private theorem coordinates (f : Question d e →ₗ[F] F) : - ∃ a b : F,∃ (u : Cell d) (v : Cell e),∀ (x:Question d e), - f x=a*x.1+b*x.2.1 + (dotProduct u x.2.2.1+dotProduct v x.2.2.2) := by - let g := f ∘ₗ LinearMap.inr F F _ ∘ₗ LinearMap.inr F F _ - obtain ⟨u,hu⟩:=dotL_surj (g ∘ₗ LinearMap.inl F _ _) - obtain ⟨v,hv⟩:=dotL_surj (g ∘ₗ LinearMap.inr F _ _) - let a : Question d e := (1,0); let b : Question d e := (0,1,0) - refine ⟨f a,f b,u,v,?_⟩ - rintro ⟨x,y,z,w⟩ - have he : ((x,y,z,w):Question d e)=x • a +y • b+((0,0,z,0)+(0,0,0,w)) := by - unfold a b; ext <;> simp - have h1 : f (0,0,z,0)=dotProduct u z := LinearMap.congr_fun hu z - have h2 : f (0,0,0,w)=dotProduct v w := LinearMap.congr_fun hv w - change f (x,y,z,w)=f a*x + f b*y + _ - conv_lhs => rw [he] - rw [map_add,map_add,map_add,map_smul,map_smul,h1,h2]; simp [mul_comm] - -theorem jargon_score (V : StatusSp A B) (T : Cabinet A B) - (h : ¬scorecard V T) (hh : ∀ i,coverBase (V i)) : - ∃ p : DualCoefficients A B, (p.left≠0 ∨ p.right≠0) ∧ p.law V ∧ ∑ i,p.bet i (T i)≠0 := by - obtain ⟨p,hp,hf⟩:= counter_score V T h - choose a b u v he using fun i=>coordinates (p.alf i) - let g : DualCoefficients A B:=⟨p.altL,p.altR,a,b,u,v⟩ - have hz i x : g.bet i x=p.alf i x := (he i x).symm - refine ⟨g,critic_nz V T hh p hp hf,fun i x hx=>?_,?_⟩ - · rw [hz]; exact hp i x hx - simp_rw [hz]; exact hf - -abbrev excessK (V : Space (Signal d e)) := V ⊓ LinearMap.ker (view d e) -theorem signal_dim : - dim (Signal d e) = dim (View d e)+2 := by - simp only [Signal,View,Whole,dim,finrank_prod,finrank_self] - omega -theorem ker_two (V : Space (Signal d e)) : - dim (excessK V) ≤ 2 := by - have he : Surjective (view d e) := by - rintro ⟨i,j,k⟩; exact ⟨(i,(j,0),(k,0)),rfl⟩ - have ht := LinearMap.finrank_range_add_finrank_ker (view d e) - change rk (view _ _) + dim _=dim (Signal d e) at ht - rw [rk_surj.mp he,signal_dim] at ht - exact (Submodule.finrank_mono (show excessK V≤_ from inf_le_right)).trans - (by omega : dim (LinearMap.ker (view d e)) ≤ 2) - -def overage (V : Space (Signal d e)) := dim V - dim (View d e) -theorem overage_two (V : Space (Signal d e)) : overage V≤2 := by - have hi : dim V ≤ dim (Signal d e) := finrank_le _ - rw [signal_dim] at hi; unfold overage; omega -theorem overage_mono {V W : Space (Signal d e)} (h : V≤W) : - overage V≤overage W := Nat.sub_le_sub_right (finrank_mono h) _ -theorem overage_lt {V W : Space (Signal d e)} (h : V simp + have h1 : f (0,0,z,0)=dotProduct u z := LinearMap.congr_fun hu z + have h2 : f (0,0,0,w)=dotProduct v w := LinearMap.congr_fun hv w + change f (x,y,z,w)=f a*x + f b*y + _ + conv_lhs => rw [he] + rw [map_add,map_add,map_add,map_smul,map_smul,h1,h2]; simp [mul_comm] + +theorem jargon_score (V : StatusSp A B) (T : Cabinet A B) + (h : ¬scorecard V T) (hh : ∀ i,coverBase (V i)) : + ∃ p : DualCoefficients A B, (p.left≠0 ∨ p.right≠0) ∧ p.law V ∧ ∑ i,p.bet i (T i)≠0 := by + obtain ⟨p,hp,hf⟩:= counter_score V T h + choose a b u v he using fun i=>coordinates (p.alf i) + let g : DualCoefficients A B:=⟨p.altL,p.altR,a,b,u,v⟩ + have hz i x : g.bet i x=p.alf i x := (he i x).symm + refine ⟨g,critic_nz V T hh p hp hf,fun i x hx=>?_,?_⟩ + · rw [hz]; exact hp i x hx + simp_rw [hz]; exact hf + +abbrev excessK (V : Space (Signal d e)) := V ⊓ LinearMap.ker (view d e) +theorem signal_dim : + dim (Signal d e) = dim (View d e)+2 := by + simp only [Signal,View,Whole,dim,finrank_prod,finrank_self] + omega +theorem ker_two (V : Space (Signal d e)) : + dim (excessK V) ≤ 2 := by + have he : Surjective (view d e) := by + rintro ⟨i,j,k⟩; exact ⟨(i,(j,0),(k,0)),rfl⟩ + have ht := LinearMap.finrank_range_add_finrank_ker (view d e) + change rk (view _ _) + dim _=dim (Signal d e) at ht + rw [rk_surj.mp he,signal_dim] at ht + exact (Submodule.finrank_mono (show excessK V≤_ from inf_le_right)).trans + (by omega : dim (LinearMap.ker (view d e)) ≤ 2) + +def overage (V : Space (Signal d e)) := dim V - dim (View d e) +theorem overage_two (V : Space (Signal d e)) : overage V≤2 := by + have hi : dim V ≤ dim (Signal d e) := finrank_le _ + rw [signal_dim] at hi; unfold overage; omega +theorem overage_mono {V W : Space (Signal d e)} (h : V≤W) : + overage V≤overage W := Nat.sub_le_sub_right (finrank_mono h) _ +theorem overage_lt {V W : Space (Signal d e)} (h : V if i=f j then 1 else 0) - -omit [Fintype I] in -theorem embedMatT [DecidableEq U] (f : I → U) (x : Vec U) : - (embedMat f)ᵀ *ᵥ x = fun i => x (f i) := by - classical funext i - simp [embedMat,Matrix.mulVec,dotProduct] - -omit [Fintype V] [Fintype I] in -theorem mul_embedMat [DecidableEq U] (f : I → U) (M : Mat V U) : - M*embedMat f = M.submatrix _root_.id f := by - ext i j - simp [Matrix.mul_apply,embedMat] - -omit [Fintype V] [Fintype I] in -theorem embedMat_mul [DecidableEq U] (f : I → U) (M : Mat U V) : - (embedMat f)ᵀ*M = M.submatrix f _root_.id := by - ext i j - simp [Matrix.mul_apply,embedMat] - -omit [Fintype I] in -theorem embedMat_self [DecidableEq I] [DecidableEq U] {f : I → U} (h : Injective f) : - (embedMat f)ᵀ * embedMat f = 1 := by - ext i j - rw [embedMat_mul] - simp only [embedMat,Matrix.submatrix_apply,Matrix.of_apply,id_eq, - Matrix.one_apply,h.eq_iff] - -theorem embedMat_inj [DecidableEq U] {f : I → U} (h : Injective f) : - Injective (embedMat f).mulVec := by - classical - intro x y g - change embedMat f *ᵥ x = embedMat f *ᵥ y at g - have he (x : Vec I) : (embedMat f)ᵀ *ᵥ (embedMat f *ᵥ x) = x := by - rw [Matrix.mulVec_mulVec,embedMat_self h,Matrix.one_mulVec] - rw [← he x,g,he] - -omit [Fintype U] in -theorem inj_fromCols {A : Mat U I} {B : Mat U J} (hA : Injective A.mulVec) - (hB : Injective B.mulVec) (h : Disjoint (colSp A) (colSp B)) : - Injective (fromCols A B).mulVec := by - rw [← Matrix.coe_mulVecLin,← LinearMap.ker_eq_bot, Matrix.ker_mulVecLin_eq_bot_iff] - intro x hx - let a := fun i => x (Sum.inl i) - let b := fun j => x (Sum.inr j) - rw [fromCols_mulVec] at hx - have he : A*ᵥa=B*ᵥb := add_right_cancel (hx.trans (char_two (B*ᵥb)).symm) - have hi : A*ᵥa ∈ colSp A ⊓ colSp B := - ⟨⟨a,rfl⟩, he.symm ▸ (show B*ᵥb∈colSp B from ⟨b,rfl⟩)⟩ - rw [h.eq_bot] at hi - have hg : A*ᵥa=0 := by simpa using hi - have ha : a=0 := hA (hg.trans (Matrix.mulVec_zero A).symm) - rw [he] at hg - have hb : b=0 := hB (hg.trans (Matrix.mulVec_zero B).symm) - funext i - cases i - · exact congr_fun ha _ - · exact congr_fun hb _ - -/-- Specify an arbitrary cross Gram bilinear form between independent columns. -/ -theorem prescribe_between {A : Mat U I} {B : Mat V J} - (hA : Injective A.mulVec) (hB : Injective B.mulVec) (M : Mat I J) : - ∃ L : Mat U V, Aᵀ*L*B=M := by - classical - obtain ⟨a,ha⟩ := mat_left_inv hA - obtain ⟨b,hb⟩ := mat_left_inv hB - refine ⟨aᵀ*(M*b),?_⟩ - rw [← Matrix.mul_assoc Aᵀ,←transpose_mul,ha,transpose_one,Matrix.one_mul, - Matrix.mul_assoc,hb,Matrix.mul_one] - -/-- Two opposite-direction restrictions are specifiable on disjoint bases. -/ -theorem prescribe_opposite {A : Mat U I} {B : Mat V J} {C : Mat U K} {D : Mat V T} - (hc : Injective (fromCols A C).mulVec) (hd : Injective (fromCols B D).mulVec) - (M : Mat I J) (N : Mat T K) : - ∃ L : Mat U V, Aᵀ*L*B=M ∧ Dᵀ*Lᵀ*C=N := by - obtain ⟨L,hL⟩ := prescribe_between hc hd (fromBlocks M 0 0 Nᵀ) - rw [transpose_fromCols, fromRows_mul, fromRows_mul_fromCols] at hL - have hi : Cᵀ*L*D=Nᵀ := congrArg Matrix.toBlocks₂₂ hL - refine ⟨L, congrArg Matrix.toBlocks₁₁ hL, ?_⟩ - have hg := congrArg Matrix.transpose hi - rwa [transpose_mul,transpose_mul,transpose_transpose,transpose_transpose,← Matrix.mul_assoc] at hg - -omit [Fintype I] in -theorem rank_ge_mul (A : Mat I J) (B : Mat J K) : - A.rank+B.rank ≤ (A*B).rank+Fintype.card J := by - let f := A.mulVecLin - let g := f ∘ₗ (colSp B).subtype - have he : LinearMap.range g = colSp (A*B) := by - change LinearMap.range g = LinearMap.range ((A*B).mulVecLin) - rw [mulVecLin_mul] - unfold g - rw [LinearMap.range_comp,LinearMap.range_comp] - simp [f,colSp] - have hi : dim (LinearMap.ker g) ≤ dim (LinearMap.ker f) := by - let q := ((colSp B).subtype ∘ₗ (LinearMap.ker g).subtype) - have hq (x : LinearMap.ker g) : q x ∈ LinearMap.ker f := x.property - let k := q.codRestrict (LinearMap.ker f) hq - have hk : Injective k := by - intro x y h - have heq := congrArg (fun b : LinearMap.ker f => b.val) h - exact Subtype.ext (Subtype.ext heq) - exact LinearMap.finrank_le_finrank_of_injective hk - have h1 := g.finrank_range_add_finrank_ker - rw [he] at h1 - have h2 := f.finrank_range_add_finrank_ker - change (A*B).rank + dim (LinearMap.ker g)=B.rank at h1 - change A.rank + dim (LinearMap.ker f)=dim (Vec J) at h2 - rw [dim_vec] at h2; omega - -theorem rank_ge_congr (A : Mat I I) (B : Mat J I) : - A.rank + 2*B.rank ≤ (liftM B B A).rank + 2*Fintype.card I := by - have h1 := rank_ge_mul B A - have h2 := rank_ge_mul (B*A) Bᵀ - rw [Matrix.rank_transpose] at h2 - rw [liftM_def]; omega - -/-- Choose a large space in the domain which becomes disjoint from S in the target. -/ -theorem choose_free {A : Mat I J} (hA : Injective A.mulVec) (S : Space (Vec I)) : - ∃ T : Space (Vec J), Fintype.card J ≤ dim T+dim S ∧ - Disjoint S (colSp (A*pack T)) := by - let U := S.comap A.mulVecLin - obtain ⟨T,hT⟩ := U.exists_isCompl - refine ⟨T,?_,?_⟩ - · have hi : dim U ≤ dim S := by - let q := A.mulVecLin ∘ₗ U.subtype - have he (x : U) : q x∈S := x.property - let B := q.codRestrict S he - have hb : Injective B := fun x y h => Subtype.ext (hA - (show q x=q y from congrArg Subtype.val h)) - exact LinearMap.finrank_le_finrank_of_injective hb - have he := (U.prodEquivOfIsCompl T hT).finrank_eq - rw [finrank_prod,show finrank F (Vec J)=Fintype.card J from dim_vec _] at he - change dim U + dim T = Fintype.card J at he - rw [← he] - exact (Nat.add_le_add_right hi _).trans_eq (Nat.add_comm _ _) - rw [colSp,mulVecLin_mul,LinearMap.range_comp,show LinearMap.range (pack T).mulVecLin = T from - colSp_pack T] - rw [disjoint_iff_inf_le] - rintro x ⟨hx,y,hy,rfl⟩ - have hh : y∈U⊓T := ⟨hx,hy⟩ - rw [hT.inf_eq_bot] at hh - have he : y=0 := by simpa using hh - rw [he,map_zero]; exact Submodule.zero_mem _ - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.MatrixRanks +import Mathlib.Data.Matrix.ColumnRowPartitioned + +namespace OAI + +/-! # Coordinate Embeddings -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module Function +open scoped BigOperators +variable {U V I J K T : Type} [Fintype U] [Fintype V] [Fintype I] [Fintype J] + [Fintype K] [Fintype T] + +def embedMat [DecidableEq U] (f : I → U) : Mat U I := Matrix.of (fun i j => if i=f j then 1 else 0) + +omit [Fintype I] in +theorem embedMatT [DecidableEq U] (f : I → U) (x : Vec U) : + (embedMat f)ᵀ *ᵥ x = fun i => x (f i) := by + classical funext i + simp [embedMat,Matrix.mulVec,dotProduct] + +omit [Fintype V] [Fintype I] in +theorem mul_embedMat [DecidableEq U] (f : I → U) (M : Mat V U) : + M*embedMat f = M.submatrix _root_.id f := by + ext i j + simp [Matrix.mul_apply,embedMat] + +omit [Fintype V] [Fintype I] in +theorem embedMat_mul [DecidableEq U] (f : I → U) (M : Mat U V) : + (embedMat f)ᵀ*M = M.submatrix f _root_.id := by + ext i j + simp [Matrix.mul_apply,embedMat] + +omit [Fintype I] in +theorem embedMat_self [DecidableEq I] [DecidableEq U] {f : I → U} (h : Injective f) : + (embedMat f)ᵀ * embedMat f = 1 := by + ext i j + rw [embedMat_mul] + simp only [embedMat,Matrix.submatrix_apply,Matrix.of_apply,id_eq, + Matrix.one_apply,h.eq_iff] + +theorem embedMat_inj [DecidableEq U] {f : I → U} (h : Injective f) : + Injective (embedMat f).mulVec := by + classical + intro x y g + change embedMat f *ᵥ x = embedMat f *ᵥ y at g + have he (x : Vec I) : (embedMat f)ᵀ *ᵥ (embedMat f *ᵥ x) = x := by + rw [Matrix.mulVec_mulVec,embedMat_self h,Matrix.one_mulVec] + rw [← he x,g,he] + +omit [Fintype U] in +theorem inj_fromCols {A : Mat U I} {B : Mat U J} (hA : Injective A.mulVec) + (hB : Injective B.mulVec) (h : Disjoint (colSp A) (colSp B)) : + Injective (fromCols A B).mulVec := by + rw [← Matrix.coe_mulVecLin,← LinearMap.ker_eq_bot, Matrix.ker_mulVecLin_eq_bot_iff] + intro x hx + let a := fun i => x (Sum.inl i) + let b := fun j => x (Sum.inr j) + rw [fromCols_mulVec] at hx + have he : A*ᵥa=B*ᵥb := add_right_cancel (hx.trans (char_two (B*ᵥb)).symm) + have hi : A*ᵥa ∈ colSp A ⊓ colSp B := + ⟨⟨a,rfl⟩, he.symm ▸ (show B*ᵥb∈colSp B from ⟨b,rfl⟩)⟩ + rw [h.eq_bot] at hi + have hg : A*ᵥa=0 := by simpa using hi + have ha : a=0 := hA (hg.trans (Matrix.mulVec_zero A).symm) + rw [he] at hg + have hb : b=0 := hB (hg.trans (Matrix.mulVec_zero B).symm) + funext i + cases i + · exact congr_fun ha _ + · exact congr_fun hb _ + +/-- Specify an arbitrary cross Gram bilinear form between independent columns. -/ +theorem prescribe_between {A : Mat U I} {B : Mat V J} + (hA : Injective A.mulVec) (hB : Injective B.mulVec) (M : Mat I J) : + ∃ L : Mat U V, Aᵀ*L*B=M := by + classical + obtain ⟨a,ha⟩ := mat_left_inv hA + obtain ⟨b,hb⟩ := mat_left_inv hB + refine ⟨aᵀ*(M*b),?_⟩ + rw [← Matrix.mul_assoc Aᵀ,←transpose_mul,ha,transpose_one,Matrix.one_mul, + Matrix.mul_assoc,hb,Matrix.mul_one] + +/-- Two opposite-direction restrictions are specifiable on disjoint bases. -/ +theorem prescribe_opposite {A : Mat U I} {B : Mat V J} {C : Mat U K} {D : Mat V T} + (hc : Injective (fromCols A C).mulVec) (hd : Injective (fromCols B D).mulVec) + (M : Mat I J) (N : Mat T K) : + ∃ L : Mat U V, Aᵀ*L*B=M ∧ Dᵀ*Lᵀ*C=N := by + obtain ⟨L,hL⟩ := prescribe_between hc hd (fromBlocks M 0 0 Nᵀ) + rw [transpose_fromCols, fromRows_mul, fromRows_mul_fromCols] at hL + have hi : Cᵀ*L*D=Nᵀ := congrArg Matrix.toBlocks₂₂ hL + refine ⟨L, congrArg Matrix.toBlocks₁₁ hL, ?_⟩ + have hg := congrArg Matrix.transpose hi + rwa [transpose_mul,transpose_mul,transpose_transpose,transpose_transpose,← Matrix.mul_assoc] at hg + +omit [Fintype I] in +theorem rank_ge_mul (A : Mat I J) (B : Mat J K) : + A.rank+B.rank ≤ (A*B).rank+Fintype.card J := by + let f := A.mulVecLin + let g := f ∘ₗ (colSp B).subtype + have he : LinearMap.range g = colSp (A*B) := by + change LinearMap.range g = LinearMap.range ((A*B).mulVecLin) + rw [mulVecLin_mul] + unfold g + rw [LinearMap.range_comp,LinearMap.range_comp] + simp [f,colSp] + have hi : dim (LinearMap.ker g) ≤ dim (LinearMap.ker f) := by + let q := ((colSp B).subtype ∘ₗ (LinearMap.ker g).subtype) + have hq (x : LinearMap.ker g) : q x ∈ LinearMap.ker f := x.property + let k := q.codRestrict (LinearMap.ker f) hq + have hk : Injective k := by + intro x y h + have heq := congrArg (fun b : LinearMap.ker f => b.val) h + exact Subtype.ext (Subtype.ext heq) + exact LinearMap.finrank_le_finrank_of_injective hk + have h1 := g.finrank_range_add_finrank_ker + rw [he] at h1 + have h2 := f.finrank_range_add_finrank_ker + change (A*B).rank + dim (LinearMap.ker g)=B.rank at h1 + change A.rank + dim (LinearMap.ker f)=dim (Vec J) at h2 + rw [dim_vec] at h2; omega + +theorem rank_ge_congr (A : Mat I I) (B : Mat J I) : + A.rank + 2*B.rank ≤ (liftM B B A).rank + 2*Fintype.card I := by + have h1 := rank_ge_mul B A + have h2 := rank_ge_mul (B*A) Bᵀ + rw [Matrix.rank_transpose] at h2 + rw [liftM_def]; omega + +/-- Choose a large space in the domain which becomes disjoint from S in the target. -/ +theorem choose_free {A : Mat I J} (hA : Injective A.mulVec) (S : Space (Vec I)) : + ∃ T : Space (Vec J), Fintype.card J ≤ dim T+dim S ∧ + Disjoint S (colSp (A*pack T)) := by + let U := S.comap A.mulVecLin + obtain ⟨T,hT⟩ := U.exists_isCompl + refine ⟨T,?_,?_⟩ + · have hi : dim U ≤ dim S := by + let q := A.mulVecLin ∘ₗ U.subtype + have he (x : U) : q x∈S := x.property + let B := q.codRestrict S he + have hb : Injective B := fun x y h => Subtype.ext (hA + (show q x=q y from congrArg Subtype.val h)) + exact LinearMap.finrank_le_finrank_of_injective hb + have he := (U.prodEquivOfIsCompl T hT).finrank_eq + rw [finrank_prod,show finrank F (Vec J)=Fintype.card J from dim_vec _] at he + change dim U + dim T = Fintype.card J at he + rw [← he] + exact (Nat.add_le_add_right hi _).trans_eq (Nat.add_comm _ _) + rw [colSp,mulVecLin_mul,LinearMap.range_comp,show LinearMap.range (pack T).mulVecLin = T from + colSp_pack T] + rw [disjoint_iff_inf_le] + rintro x ⟨hx,y,hy,rfl⟩ + have hh : y∈U⊓T := ⟨hx,hy⟩ + rw [hT.inf_eq_bot] at hh + have he : y=0 := by simpa using hh + rw [he,map_zero]; exact Submodule.zero_mem _ + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CoverAlternatives.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CoverAlternatives.lean index b5607c467935ca7233510e557187ca17f771ada7..266e21a3231583b8e411ad1984d09cd4808aa6f2 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CoverAlternatives.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CoverAlternatives.lean @@ -1,86 +1,86 @@ -import OAI.Combinatorics.HadwigerCounterexample.PhaseClassCompatibility -import OAI.Combinatorics.HadwigerCounterexample.LowRankKernelAlternative - -namespace OAI - -/-! # Cover Alternatives -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Finset Filter -open scoped BigOperators Topology -open PredictionClass -variable {p : Shape} {n N M : ℕ} -theorem longStory (T : Cov p N) (d : ℕ) (hd : cdim p T≤d) - (c : PredictionClass) (α : Party) (r : F) (Δ : UnitType p n N → Ambient p N) - (w : Wgt (UnitType p n N)) (hh : ∀ x,w x≠ 0 → covered p T (Δ x)) : - ∃ P : UnitType p n N×UnitType p n N→Prop,named P (bp (3*d*(N:ℝ))) ∧ - named (P ∘ Prod.swap) (bp (3*d*(N:ℝ))) ∧ - ∀ x,pairW w w x≠0→ (P x↔ matchUp Δ α r c x) := by - classical - let Q (x : Daypair p T×Daypair p T) : Prop := - c.compatible α r (fun i=>x.2.2 i x.1.1, fun i => x.1.2 i x.2.1) - let f := daypair p T Δ w - refine ⟨fun x=>Q (f x.1,f x.2),day_named p T Δ w d hd Q,day_named p T Δ w d hd (Q∘Prod.swap), - fun x hx=>?_⟩ - have hs (x y : UnitType p n N) (hz : w x≠0) (i) : - (f y).2 i (f x).1=tone p y (unary i) (Δ x) := - shadow_valid p T Δ hh x y (unary i) hz - unfold Q matchUp quench - dsimp only - simp_rw [hs _ _ (left_ne_zero_of_mul hx), hs _ _ (right_ne_zero_of_mul hx)] - -theorem matSeason (T : Cov p N) (d : ℕ) (hd : cdim p T≤d) - (α : Party) (r : F) (Δ : UnitType p n N → Ambient p N) - (w : Wgt (UnitType p n N)) (hh : ∀ x,w x≠ 0 → covered p T (Δ x)) : - ∃ F : Mat (UnitType p n N) (UnitType p n N), F.rank ≤ 2*d*N ∧ - (∀ x, F x x=0) ∧ ∀ x,pairW w w x≠0→ (F x.1 x.2=0 ↔ matchUp Δ α r twinned x) := by - let F := circus p T Δ w - have he : F.rank ≤ N*d := (circus_rank ..).trans (Nat.mul_le_mul_left _ hd) - refine ⟨F+Fᵀ, (mrk_add_le F Fᵀ).trans ?_,fun x=>char_two _,fun x hx=>?_⟩ - · rw [Matrix.rank_transpose]; nlinarith - · unfold matchUp compatible quench - dsimp only; rw [←tone_vec,←tone_vec] - have h x y (hx : w x ≠ 0) : F x y = tone p y allSide (Δ x) := - shadow_valid p T Δ hh x y allSide hx - change (F x.1 x.2+F x.2 x.1=0) ↔ _ - rw [h _ _ (left_ne_zero_of_mul hx),h _ _ (right_ne_zero_of_mul hx)] - -set_option maxHeartbeats 1000000 in -theorem coFiber (l : Filter ℕ) (hz : l≤atTop) {M : ℕ} (hM : 1≤ M) (d : ℕ) - (p : Shape) (w : ∀ n,Wgt (UnitType p n (M*n))) - (α : Party) (r : F) (Δ : ∀ n, UnitType p n (M*n) → Ambient p (M*n)) - (h : ∀ᶠ n in l, IsLaw (w n) ∧ - ∃ T : Cov p (M*n),cdim p T≤d∧∀ x,w n x≠0 → covered p T (Δ n x)) - (he : slight l (fun n=>pr (pairW (w n) (w n)) (matchUp (Δ n) α r twinned))) : - ∃ S : ∀ n, UnitType p n (M*n)→Prop,warm l (fun n=>((M*n:ℕ):ℝ)) (fun n=>pr (w n) (S n)) ∧ - ∀ᶠ n in l, ∀ x,S n x.1 → S n x.2 → matchUp (Δ n) α r twinned x := by - classical - let X n:= UnitType p n (M*n) - let q n:= matchUp (Δ n) α r twinned - let c (k : ℕ) := ((k:ℝ)+1)⁻¹ - let P n (S : X n→Prop) (k : ℕ) := - bp (-(c k)*((M*n:ℕ):ℝ)) ≤ pr (w n) S ∧ ∀ x,S x.1 → S x.2 → q n x - have hf (k : ℕ) : ∀ᶠ n in l,∃ S : X n→Prop,P n S k := by - obtain ⟨θ,hθ,hg⟩:= fiber_growth (2*d) (c k) (by unfold c; positivity) (by positivity) - filter_upwards [h,he θ hθ, (trend_sizes l hz hM).1.eventually hg] with n hn hh hF - obtain ⟨hv,T,hT,h⟩:=hn - obtain ⟨F,hf,hz,hc⟩:= matSeason T d hT α r (Δ n) (w n) h - have ht : pr (pairW (w n) (w n)) (fun x => F x.1 x.2=0) ≤ θ := - (avg_congr (fun x hx => show ind _=ind _ from congrArg ind (propext (hc x hx)))).trans_le hh - have hr : (F.rank:ℝ)≤ 2*d*(M*n:ℕ) := by exact_mod_cast hf - obtain ⟨S,hS,ht⟩:= hF (X n) F (w n) hv hr hz ht - let Y (x:X n) := S x∧ w n x≠0 - have he : pr (w n) Y=pr (w n) S := avg_congr (fun x hx=>by simp [Y, hx]) - refine ⟨Y, hS.trans_eq he.symm, fun x hx hy => - (hc x (mul_ne_zero hx.2 hy.2)).mp (ht x.1 hx.1 x.2 hy.1)⟩ - obtain ⟨k,hk,hf⟩:= diagonal_gains l hz (fun n k => ∃ S : X n→Prop,P n S k) hf - obtain ⟨S,h⟩:= taking hf - refine ⟨S,fun ε he=>?_, h.mono fun i hi=>hi.2⟩ - filter_upwards [h,slight_inv_stage hk ε he] with n hn hh - exact (bp_le (mul_le_mul_of_nonneg_right (neg_le_neg hh) (Nat.cast_nonneg _))).trans hn.1 -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PhaseClassCompatibility +import OAI.Combinatorics.HadwigerCounterexample.LowRankKernelAlternative + +namespace OAI + +/-! # Cover Alternatives -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Finset Filter +open scoped BigOperators Topology +open PredictionClass +variable {p : Shape} {n N M : ℕ} +theorem longStory (T : Cov p N) (d : ℕ) (hd : cdim p T≤d) + (c : PredictionClass) (α : Party) (r : F) (Δ : UnitType p n N → Ambient p N) + (w : Wgt (UnitType p n N)) (hh : ∀ x,w x≠ 0 → covered p T (Δ x)) : + ∃ P : UnitType p n N×UnitType p n N→Prop,named P (bp (3*d*(N:ℝ))) ∧ + named (P ∘ Prod.swap) (bp (3*d*(N:ℝ))) ∧ + ∀ x,pairW w w x≠0→ (P x↔ matchUp Δ α r c x) := by + classical + let Q (x : Daypair p T×Daypair p T) : Prop := + c.compatible α r (fun i=>x.2.2 i x.1.1, fun i => x.1.2 i x.2.1) + let f := daypair p T Δ w + refine ⟨fun x=>Q (f x.1,f x.2),day_named p T Δ w d hd Q,day_named p T Δ w d hd (Q∘Prod.swap), + fun x hx=>?_⟩ + have hs (x y : UnitType p n N) (hz : w x≠0) (i) : + (f y).2 i (f x).1=tone p y (unary i) (Δ x) := + shadow_valid p T Δ hh x y (unary i) hz + unfold Q matchUp quench + dsimp only + simp_rw [hs _ _ (left_ne_zero_of_mul hx), hs _ _ (right_ne_zero_of_mul hx)] + +theorem matSeason (T : Cov p N) (d : ℕ) (hd : cdim p T≤d) + (α : Party) (r : F) (Δ : UnitType p n N → Ambient p N) + (w : Wgt (UnitType p n N)) (hh : ∀ x,w x≠ 0 → covered p T (Δ x)) : + ∃ F : Mat (UnitType p n N) (UnitType p n N), F.rank ≤ 2*d*N ∧ + (∀ x, F x x=0) ∧ ∀ x,pairW w w x≠0→ (F x.1 x.2=0 ↔ matchUp Δ α r twinned x) := by + let F := circus p T Δ w + have he : F.rank ≤ N*d := (circus_rank ..).trans (Nat.mul_le_mul_left _ hd) + refine ⟨F+Fᵀ, (mrk_add_le F Fᵀ).trans ?_,fun x=>char_two _,fun x hx=>?_⟩ + · rw [Matrix.rank_transpose]; nlinarith + · unfold matchUp compatible quench + dsimp only; rw [←tone_vec,←tone_vec] + have h x y (hx : w x ≠ 0) : F x y = tone p y allSide (Δ x) := + shadow_valid p T Δ hh x y allSide hx + change (F x.1 x.2+F x.2 x.1=0) ↔ _ + rw [h _ _ (left_ne_zero_of_mul hx),h _ _ (right_ne_zero_of_mul hx)] + +set_option maxHeartbeats 1000000 in +theorem coFiber (l : Filter ℕ) (hz : l≤atTop) {M : ℕ} (hM : 1≤ M) (d : ℕ) + (p : Shape) (w : ∀ n,Wgt (UnitType p n (M*n))) + (α : Party) (r : F) (Δ : ∀ n, UnitType p n (M*n) → Ambient p (M*n)) + (h : ∀ᶠ n in l, IsLaw (w n) ∧ + ∃ T : Cov p (M*n),cdim p T≤d∧∀ x,w n x≠0 → covered p T (Δ n x)) + (he : slight l (fun n=>pr (pairW (w n) (w n)) (matchUp (Δ n) α r twinned))) : + ∃ S : ∀ n, UnitType p n (M*n)→Prop,warm l (fun n=>((M*n:ℕ):ℝ)) (fun n=>pr (w n) (S n)) ∧ + ∀ᶠ n in l, ∀ x,S n x.1 → S n x.2 → matchUp (Δ n) α r twinned x := by + classical + let X n:= UnitType p n (M*n) + let q n:= matchUp (Δ n) α r twinned + let c (k : ℕ) := ((k:ℝ)+1)⁻¹ + let P n (S : X n→Prop) (k : ℕ) := + bp (-(c k)*((M*n:ℕ):ℝ)) ≤ pr (w n) S ∧ ∀ x,S x.1 → S x.2 → q n x + have hf (k : ℕ) : ∀ᶠ n in l,∃ S : X n→Prop,P n S k := by + obtain ⟨θ,hθ,hg⟩:= fiber_growth (2*d) (c k) (by unfold c; positivity) (by positivity) + filter_upwards [h,he θ hθ, (trend_sizes l hz hM).1.eventually hg] with n hn hh hF + obtain ⟨hv,T,hT,h⟩:=hn + obtain ⟨F,hf,hz,hc⟩:= matSeason T d hT α r (Δ n) (w n) h + have ht : pr (pairW (w n) (w n)) (fun x => F x.1 x.2=0) ≤ θ := + (avg_congr (fun x hx => show ind _=ind _ from congrArg ind (propext (hc x hx)))).trans_le hh + have hr : (F.rank:ℝ)≤ 2*d*(M*n:ℕ) := by exact_mod_cast hf + obtain ⟨S,hS,ht⟩:= hF (X n) F (w n) hv hr hz ht + let Y (x:X n) := S x∧ w n x≠0 + have he : pr (w n) Y=pr (w n) S := avg_congr (fun x hx=>by simp [Y, hx]) + refine ⟨Y, hS.trans_eq he.symm, fun x hx hy => + (hc x (mul_ne_zero hx.2 hy.2)).mp (ht x.1 hx.1 x.2 hy.1)⟩ + obtain ⟨k,hk,hf⟩:= diagonal_gains l hz (fun n k => ∃ S : X n→Prop,P n S k) hf + obtain ⟨S,h⟩:= taking hf + refine ⟨S,fun ε he=>?_, h.mono fun i hi=>hi.2⟩ + filter_upwards [h,slight_inv_stage hk ε he] with n hn hh + exact (bp_le (mul_le_mul_of_nonneg_right (neg_le_neg hh) (Nat.cast_nonneg _))).trans hn.1 +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CoverSpaces.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CoverSpaces.lean index 639d46a4822fd804ebe56ba2293f06b40ba7f07f..803038b83cf220cb7765e85f4cae5772e0986e79 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CoverSpaces.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CoverSpaces.lean @@ -1,207 +1,207 @@ -import OAI.Combinatorics.HadwigerCounterexample.AttackCutDecomposition - -namespace OAI - -/-! # Cover Spaces -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Submodule Module -open scoped BigOperators -variable {p : Shape} {N : ℕ} -variable {I J : Type} [Fintype I] [Fintype J] - -noncomputable def prj (S : Space (Vec I)) : Mat I I := - (proj_exists S ⊥ disjoint_bot_right).choose - -theorem prj_data (S : Space (Vec I)) : ProjData S ⊥ (prj S) := - (proj_exists S ⊥ disjoint_bot_right).choose_spec - -variable [DecidableEq I] [DecidableEq J] -def chop (S : Space (Vec I)) := 1-prj S - -theorem chop_ker (S : Space (Vec I)) (x : Vec I) : - chop S *ᵥ x=0 ↔ x∈S := by - rw [chop,Matrix.sub_mulVec,Matrix.one_mulVec,sub_eq_zero] - constructor - · intro h; exact h.symm ▸ (prj_data S).onto x - exact fun h => ((prj_data S).fixes x h).symm - -theorem chop_colT (S : Space (Vec I)) : colSp (chop S)ᵀ=annih S := by - have hi : colSp (chop S)ᵀ ≤annih S := (colSp_kill ..).mpr (fun x hx => by - rw [transpose_transpose]; exact (chop_ker S x).mpr hx) - apply Submodule.eq_of_le_of_finrank_eq hi - have h := (chop S).mulVecLin.finrank_range_add_finrank_ker - rw [show ker (chop S).mulVecLin=S from (by ext x; exact chop_ker S x)] at h - change (chop S).rank + dim S = dim (Vec I) at h - have he := annih_dim S - rw [dim_vec,← he, add_comm] at h - exact (Matrix.rank_transpose _).trans (Nat.add_left_cancel h) - -theorem vanish_chop {S : Space (Vec I)} {T : Space (Vec J)} (M : Mat I J) : - vanish S T M ↔ liftM (chop S) (chop T) M=0 := by - let A := (chop S)ᵀ - let B := (chop T)ᵀ - have h1 : liftM (chop S) (chop T) M=pullM A B M := by - simp only [A,B,pullM,Matrix.transpose_transpose] - have h2 : colSp A=annih S := chop_colT _ - have h3 : colSp B=annih T := chop_colT _ - rw [h1] - unfold vanish - rw [←h2,←h3] - constructor - · intro h - refine evmat_ext fun x y => ?_ - rw [evmat_pull, h (A *ᵥ x) ⟨_,rfl⟩ (B *ᵥ y) ⟨_,rfl⟩] - simp [evmat] - rintro h x ⟨x,rfl⟩ y ⟨y,rfl⟩ - rw [mulVecLin_apply,mulVecLin_apply,←evmat_pull,h] - simp [evmat] - -def chopSpace (S T : Space (Vec I)) := T.map (chop S).mulVecLin - -theorem chopSpace_join (S T : Space (Vec I)) : - S ⊔ chopSpace S T=S⊔ T := by - classical - refine le_antisymm (sup_le le_sup_left ?_) (sup_le le_sup_left ?_) - · rintro t ⟨x,h,rfl⟩ - rw [mulVecLin_apply,chop,Matrix.sub_mulVec,Matrix.one_mulVec] - exact Submodule.sub_mem _ (Submodule.mem_sup_right h) - (Submodule.mem_sup_left ((prj_data S).onto x)) - intro x hx - have he : x=prj S *ᵥ x+chop S *ᵥ x := by - rw [chop,Matrix.sub_mulVec,Matrix.one_mulVec,add_sub_cancel] - exact he.symm ▸ Submodule.add_mem_sup ((prj_data S).onto x) - (show chop S *ᵥ x∈chopSpace S T from ⟨x,hx,rfl⟩) - -theorem chopSpace_disjoint (S T : Space (Vec I)) : Disjoint S (chopSpace S T) := by - rw [disjoint_iff_inf_le] - rintro x ⟨hx,y,hy,rfl⟩ - rw [mulVecLin_apply,chop,Matrix.sub_mulVec,Matrix.one_mulVec] at hx ⊢ - have hi := (prj_data S).fixes _ hx - rw [Matrix.mulVec_sub,(prj_data S).fixes _ ((prj_data S).onto y),sub_self] at hi - rw [←hi]; exact Submodule.zero_mem _ - -theorem chopSpace_rank (S T : Space (Vec I)) : - dim S+dim (chopSpace S T) = dim (S⊔T : Submodule _ _) := by - have h := Submodule.finrank_sup_add_finrank_inf_eq S (chopSpace S T) - rw [chopSpace_join,(chopSpace_disjoint S T).eq_bot,finrank_bot,add_zero] at h - exact h.symm - -abbrev Cov (p : Shape) (N : ℕ) := Place p → Space (Vec (Fin N)) -def cdSign (p : Shape) {N} (S : Cov p N) (i : Bool) := - ∑ e : Comp p.g,dim (S (e,i)) -def cdim (p : Shape) {N} (S : Cov p N) := ∑ i : Place p,dim (S i) -theorem cdim_sign (p : Shape) {N} (S : Cov p N) : - cdim p S=cdSign p S true+cdSign p S false := by - simp only [cdim,cdSign,Fintype.sum_prod_type,Fintype.sum_bool,Finset.sum_add_distrib] - -def epoch (p : Shape) {N} (x : Ambient p N) := ∑ e : Comp p.g,(x e).rank - -def matter (p : Shape) {N} (x : Ambient p N) : Cov p N := - fun z => colSp (if z.2 then x z.1 else (x z.1)ᵀ) - -theorem matter_dim (x : Ambient p N) (b : Bool) : cdSign p (matter p x) b=epoch p x := - Finset.sum_congr rfl fun i _ => by cases b; exact Matrix.rank_transpose _; rfl - -def erased (p : Shape) {N} (S : Cov p N) : Ambient p N →ₗ[F] Ambient p N := - LinearMap.pi (fun i => liftM (chop (S (i,true))) (chop (S (i,false))) ∘ₗ LinearMap.proj i) - -def covered (p : Shape) {N} (S : Cov p N) (x : Ambient p N) := - erased p S x=0 - -theorem covered_iff (S : Cov p N) (x) : covered p S x ↔ - ∀ e,vanish (S (e,true)) (S (e,false)) (x e) := by - constructor - · intro h e - apply (vanish_chop _).mpr - exact congr_fun h e - intro h - exact funext fun e => (vanish_chop _).mp (h e) - -theorem covered_part {S : Cov p N} {x : Ambient p N} (h : matter p x ≤ S) : - covered p S x := by - refine (covered_iff ..).mpr (fun e a ha b _ => ?_) - change dotProduct a (x e *ᵥ b)=0 - apply (annih_mem ..).mp ha - exact h (e,true) ⟨b,rfl⟩ - -/-- Cover as a tensor space; used to count tiny-cover span. -/ -def coverX (p : Shape) {N} (S : Cov p N) := ker (erased p S) - -private theorem vanish_sum {S : Space (Vec I)} {T : Space (Vec J)} - (M : Mat I J) : - vanish S T M ↔ M∈box S ⊤ ⊔ box ⊤ T := by - classical - constructor - · intro h - let A := prj S - let B := prj T - let D := A*M - let E := (1-A)*M*Bᵀ - have hh : colSp D≤S := by - rintro x ⟨y,rfl⟩ - rw [mulVecLin_apply,show D=_*_ from rfl,←mulVec_mulVec] - exact (prj_data S).onto _ - have he : colSp Eᵀ ≤ T := by - rintro x ⟨y,rfl⟩ - rw [mulVecLin_apply,show E=_*_ from rfl,transpose_mul,transpose_transpose,←mulVec_mulVec] - exact (prj_data T).onto _ - have hx : M=D+E := by - have hg := (vanish_chop _).mp h - change (1-A)*M*(1-B)ᵀ = 0 at hg - rw [transpose_sub,transpose_one,Matrix.mul_sub,Matrix.mul_one] at hg - unfold D E - rw [← sub_eq_zero.mp hg,Matrix.sub_mul,Matrix.one_mul,add_sub_cancel] - rw [hx]; exact Submodule.add_mem_sup ((box_mem ..).mpr ⟨hh,le_top⟩) - ((box_mem ..).mpr ⟨le_top,he⟩) - · intro h - obtain ⟨A,hA,B,hB,rfl⟩ := Submodule.mem_sup.mp h - intro x hx y hy - have hi : colSp A≤ S := ((box_mem ..).mp hA).1 - have hj : colSp Bᵀ≤ T := ((box_mem ..).mp hB).2 - rw [evmat_addM,show evmat A x y=0 from - (annih_mem ..).mp hx _ (hi ⟨_,rfl⟩),zero_add,← evmat_transpose B] - exact (annih_mem ..).mp hy _ (hj ⟨_,rfl⟩) - -theorem cover_mem (S : Cov p N) (x : Ambient p N) : - x∈coverX p S ↔ ∀ e,x e∈box (S (e,true)) ⊤ ⊔ box ⊤ (S (e,false)) := - (covered_iff ..).trans (forall_congr' fun e => vanish_sum (x e)) - -private theorem cov_pi_bound {V J : Type} [AddCommGroup V] [Module F V] [FiniteDimensional F V] - [Fintype J] (s : J→ Submodule F V) : - dim (Submodule.pi Set.univ s) ≤ ∑ i, dim (s i) := by - let T := Submodule.pi Set.univ s - have h (i : J) (x : T) : x.val i∈ s i := x.property i (Set.mem_univ i) - let f : T →ₗ[F] (∀ i,s i) := { - toFun := fun x i => ⟨_,h i x⟩ - map_add' := by intro x y; rfl - map_smul' := by intro x y; rfl } - have hf : Function.Injective f := fun x y e => Subtype.ext (funext (fun i => - show x.val i=y.val i from congrArg (fun t:s i => t.val) (congr_fun e i))) - exact (LinearMap.finrank_le_finrank_of_injective hf).trans_eq - (Module.finrank_pi_fintype _) - -theorem cover_dim (p : Shape) {N} (S : Cov p N) : - dim (coverX p S)≤ N*cdim p S := by - let A (i : Comp p.g) : Space (Mat (Fin N) (Fin N)) := - box (S (i,true)) ⊤ ⊔ box ⊤ (S (i,false)) - have he : coverX p S≤ Submodule.pi Set.univ A := by - intro x hx i _ - exact (cover_mem ..).mp hx i - refine ((Submodule.finrank_mono he).trans (cov_pi_bound ..)).trans ?_ - unfold cdim - rw [Fintype.sum_prod_type, Finset.mul_sum] - have ht : dim (⊤ : Space (Vec (Fin N)))=N := (finrank_top ..).trans - ((dim_vec _).trans (Fintype.card_fin _)) - refine Finset.sum_le_sum fun i _ => ?_ - apply (Submodule.finrank_add_le_finrank_add_finrank ..).trans - change dim (box (S (i,true)) _)+dim (box _ (S (i,false)))≤_ - rw [box_dim,box_dim,ht,Fintype.sum_bool,Nat.mul_add,Nat.mul_comm N _] - rw [Nat.mul_comm N _] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.AttackCutDecomposition + +namespace OAI + +/-! # Cover Spaces -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Submodule Module +open scoped BigOperators +variable {p : Shape} {N : ℕ} +variable {I J : Type} [Fintype I] [Fintype J] + +noncomputable def prj (S : Space (Vec I)) : Mat I I := + (proj_exists S ⊥ disjoint_bot_right).choose + +theorem prj_data (S : Space (Vec I)) : ProjData S ⊥ (prj S) := + (proj_exists S ⊥ disjoint_bot_right).choose_spec + +variable [DecidableEq I] [DecidableEq J] +def chop (S : Space (Vec I)) := 1-prj S + +theorem chop_ker (S : Space (Vec I)) (x : Vec I) : + chop S *ᵥ x=0 ↔ x∈S := by + rw [chop,Matrix.sub_mulVec,Matrix.one_mulVec,sub_eq_zero] + constructor + · intro h; exact h.symm ▸ (prj_data S).onto x + exact fun h => ((prj_data S).fixes x h).symm + +theorem chop_colT (S : Space (Vec I)) : colSp (chop S)ᵀ=annih S := by + have hi : colSp (chop S)ᵀ ≤annih S := (colSp_kill ..).mpr (fun x hx => by + rw [transpose_transpose]; exact (chop_ker S x).mpr hx) + apply Submodule.eq_of_le_of_finrank_eq hi + have h := (chop S).mulVecLin.finrank_range_add_finrank_ker + rw [show ker (chop S).mulVecLin=S from (by ext x; exact chop_ker S x)] at h + change (chop S).rank + dim S = dim (Vec I) at h + have he := annih_dim S + rw [dim_vec,← he, add_comm] at h + exact (Matrix.rank_transpose _).trans (Nat.add_left_cancel h) + +theorem vanish_chop {S : Space (Vec I)} {T : Space (Vec J)} (M : Mat I J) : + vanish S T M ↔ liftM (chop S) (chop T) M=0 := by + let A := (chop S)ᵀ + let B := (chop T)ᵀ + have h1 : liftM (chop S) (chop T) M=pullM A B M := by + simp only [A,B,pullM,Matrix.transpose_transpose] + have h2 : colSp A=annih S := chop_colT _ + have h3 : colSp B=annih T := chop_colT _ + rw [h1] + unfold vanish + rw [←h2,←h3] + constructor + · intro h + refine evmat_ext fun x y => ?_ + rw [evmat_pull, h (A *ᵥ x) ⟨_,rfl⟩ (B *ᵥ y) ⟨_,rfl⟩] + simp [evmat] + rintro h x ⟨x,rfl⟩ y ⟨y,rfl⟩ + rw [mulVecLin_apply,mulVecLin_apply,←evmat_pull,h] + simp [evmat] + +def chopSpace (S T : Space (Vec I)) := T.map (chop S).mulVecLin + +theorem chopSpace_join (S T : Space (Vec I)) : + S ⊔ chopSpace S T=S⊔ T := by + classical + refine le_antisymm (sup_le le_sup_left ?_) (sup_le le_sup_left ?_) + · rintro t ⟨x,h,rfl⟩ + rw [mulVecLin_apply,chop,Matrix.sub_mulVec,Matrix.one_mulVec] + exact Submodule.sub_mem _ (Submodule.mem_sup_right h) + (Submodule.mem_sup_left ((prj_data S).onto x)) + intro x hx + have he : x=prj S *ᵥ x+chop S *ᵥ x := by + rw [chop,Matrix.sub_mulVec,Matrix.one_mulVec,add_sub_cancel] + exact he.symm ▸ Submodule.add_mem_sup ((prj_data S).onto x) + (show chop S *ᵥ x∈chopSpace S T from ⟨x,hx,rfl⟩) + +theorem chopSpace_disjoint (S T : Space (Vec I)) : Disjoint S (chopSpace S T) := by + rw [disjoint_iff_inf_le] + rintro x ⟨hx,y,hy,rfl⟩ + rw [mulVecLin_apply,chop,Matrix.sub_mulVec,Matrix.one_mulVec] at hx ⊢ + have hi := (prj_data S).fixes _ hx + rw [Matrix.mulVec_sub,(prj_data S).fixes _ ((prj_data S).onto y),sub_self] at hi + rw [←hi]; exact Submodule.zero_mem _ + +theorem chopSpace_rank (S T : Space (Vec I)) : + dim S+dim (chopSpace S T) = dim (S⊔T : Submodule _ _) := by + have h := Submodule.finrank_sup_add_finrank_inf_eq S (chopSpace S T) + rw [chopSpace_join,(chopSpace_disjoint S T).eq_bot,finrank_bot,add_zero] at h + exact h.symm + +abbrev Cov (p : Shape) (N : ℕ) := Place p → Space (Vec (Fin N)) +def cdSign (p : Shape) {N} (S : Cov p N) (i : Bool) := + ∑ e : Comp p.g,dim (S (e,i)) +def cdim (p : Shape) {N} (S : Cov p N) := ∑ i : Place p,dim (S i) +theorem cdim_sign (p : Shape) {N} (S : Cov p N) : + cdim p S=cdSign p S true+cdSign p S false := by + simp only [cdim,cdSign,Fintype.sum_prod_type,Fintype.sum_bool,Finset.sum_add_distrib] + +def epoch (p : Shape) {N} (x : Ambient p N) := ∑ e : Comp p.g,(x e).rank + +def matter (p : Shape) {N} (x : Ambient p N) : Cov p N := + fun z => colSp (if z.2 then x z.1 else (x z.1)ᵀ) + +theorem matter_dim (x : Ambient p N) (b : Bool) : cdSign p (matter p x) b=epoch p x := + Finset.sum_congr rfl fun i _ => by cases b; exact Matrix.rank_transpose _; rfl + +def erased (p : Shape) {N} (S : Cov p N) : Ambient p N →ₗ[F] Ambient p N := + LinearMap.pi (fun i => liftM (chop (S (i,true))) (chop (S (i,false))) ∘ₗ LinearMap.proj i) + +def covered (p : Shape) {N} (S : Cov p N) (x : Ambient p N) := + erased p S x=0 + +theorem covered_iff (S : Cov p N) (x) : covered p S x ↔ + ∀ e,vanish (S (e,true)) (S (e,false)) (x e) := by + constructor + · intro h e + apply (vanish_chop _).mpr + exact congr_fun h e + intro h + exact funext fun e => (vanish_chop _).mp (h e) + +theorem covered_part {S : Cov p N} {x : Ambient p N} (h : matter p x ≤ S) : + covered p S x := by + refine (covered_iff ..).mpr (fun e a ha b _ => ?_) + change dotProduct a (x e *ᵥ b)=0 + apply (annih_mem ..).mp ha + exact h (e,true) ⟨b,rfl⟩ + +/-- Cover as a tensor space; used to count tiny-cover span. -/ +def coverX (p : Shape) {N} (S : Cov p N) := ker (erased p S) + +private theorem vanish_sum {S : Space (Vec I)} {T : Space (Vec J)} + (M : Mat I J) : + vanish S T M ↔ M∈box S ⊤ ⊔ box ⊤ T := by + classical + constructor + · intro h + let A := prj S + let B := prj T + let D := A*M + let E := (1-A)*M*Bᵀ + have hh : colSp D≤S := by + rintro x ⟨y,rfl⟩ + rw [mulVecLin_apply,show D=_*_ from rfl,←mulVec_mulVec] + exact (prj_data S).onto _ + have he : colSp Eᵀ ≤ T := by + rintro x ⟨y,rfl⟩ + rw [mulVecLin_apply,show E=_*_ from rfl,transpose_mul,transpose_transpose,←mulVec_mulVec] + exact (prj_data T).onto _ + have hx : M=D+E := by + have hg := (vanish_chop _).mp h + change (1-A)*M*(1-B)ᵀ = 0 at hg + rw [transpose_sub,transpose_one,Matrix.mul_sub,Matrix.mul_one] at hg + unfold D E + rw [← sub_eq_zero.mp hg,Matrix.sub_mul,Matrix.one_mul,add_sub_cancel] + rw [hx]; exact Submodule.add_mem_sup ((box_mem ..).mpr ⟨hh,le_top⟩) + ((box_mem ..).mpr ⟨le_top,he⟩) + · intro h + obtain ⟨A,hA,B,hB,rfl⟩ := Submodule.mem_sup.mp h + intro x hx y hy + have hi : colSp A≤ S := ((box_mem ..).mp hA).1 + have hj : colSp Bᵀ≤ T := ((box_mem ..).mp hB).2 + rw [evmat_addM,show evmat A x y=0 from + (annih_mem ..).mp hx _ (hi ⟨_,rfl⟩),zero_add,← evmat_transpose B] + exact (annih_mem ..).mp hy _ (hj ⟨_,rfl⟩) + +theorem cover_mem (S : Cov p N) (x : Ambient p N) : + x∈coverX p S ↔ ∀ e,x e∈box (S (e,true)) ⊤ ⊔ box ⊤ (S (e,false)) := + (covered_iff ..).trans (forall_congr' fun e => vanish_sum (x e)) + +private theorem cov_pi_bound {V J : Type} [AddCommGroup V] [Module F V] [FiniteDimensional F V] + [Fintype J] (s : J→ Submodule F V) : + dim (Submodule.pi Set.univ s) ≤ ∑ i, dim (s i) := by + let T := Submodule.pi Set.univ s + have h (i : J) (x : T) : x.val i∈ s i := x.property i (Set.mem_univ i) + let f : T →ₗ[F] (∀ i,s i) := { + toFun := fun x i => ⟨_,h i x⟩ + map_add' := by intro x y; rfl + map_smul' := by intro x y; rfl } + have hf : Function.Injective f := fun x y e => Subtype.ext (funext (fun i => + show x.val i=y.val i from congrArg (fun t:s i => t.val) (congr_fun e i))) + exact (LinearMap.finrank_le_finrank_of_injective hf).trans_eq + (Module.finrank_pi_fintype _) + +theorem cover_dim (p : Shape) {N} (S : Cov p N) : + dim (coverX p S)≤ N*cdim p S := by + let A (i : Comp p.g) : Space (Mat (Fin N) (Fin N)) := + box (S (i,true)) ⊤ ⊔ box ⊤ (S (i,false)) + have he : coverX p S≤ Submodule.pi Set.univ A := by + intro x hx i _ + exact (cover_mem ..).mp hx i + refine ((Submodule.finrank_mono he).trans (cov_pi_bound ..)).trans ?_ + unfold cdim + rw [Fintype.sum_prod_type, Finset.mul_sum] + have ht : dim (⊤ : Space (Vec (Fin N)))=N := (finrank_top ..).trans + ((dim_vec _).trans (Fintype.card_fin _)) + refine Finset.sum_le_sum fun i _ => ?_ + apply (Submodule.finrank_add_le_finrank_add_finrank ..).trans + change dim (box (S (i,true)) _)+dim (box _ (S (i,false)))≤_ + rw [box_dim,box_dim,ht,Fintype.sum_bool,Nat.mul_add,Nat.mul_comm N _] + rw [Nat.mul_comm N _] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CrossForms.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CrossForms.lean index 24f75f2580902819df20f35b8c746426a404db44..7aa7f768ee5c13cbbb9e92573e33449fef5bcf18 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CrossForms.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CrossForms.lean @@ -1,106 +1,106 @@ -import OAI.Combinatorics.HadwigerCounterexample.NominalSpaces - -namespace OAI - -/-! # Cross Forms -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix -open scoped BigOperators -variable {p : Shape} {n N : ℕ} - -def flipZ (p : Shape) (z : Place p) : Place p := (z.1,!z.2) -@[simp] theorem flipZ_flip (z : Place p) : flipZ p (flipZ p z)=z := by cases z; simp [flipZ] - -abbrev Cross (p : Shape) (n : ℕ) := Place p → Mat (JointIdx p n) (JointIdx p n) -def reciprocal (p : Shape) {n} (M : Cross p n) : Cross p n := fun z => (M (flipZ p z))ᵀ -@[simp] theorem reciprocal_twice (M : Cross p n) : reciprocal p (reciprocal p M)=M := by - funext i; simp [reciprocal] - -def actual (p : Shape) {n N} (x y : UnitType p n N) : Cross p n := - fun z => (images x z)ᵀ * images y (flipZ p z) - -@[simp] theorem reciprocal_actual (x y : UnitType p n N) : - reciprocal p (actual p x y)=actual p y x := by - funext z; simp only [reciprocal,actual,transpose_mul,flipZ_flip,transpose_transpose] - -/-- two abstract cross sets agree at every row coming from these frozen -directions. Also apply this notion reciprocally to check columns. -/ -def rowAgree (q : Plan p n) (A B : Cross p n) := - ∀ z, ∀ x∈ q z,∀ y, evmat (A z) x y=evmat (B z) x y - -/-- The flag on an orientation of A. Test all entries on the table spaces -with column in the B pins. Test the other entries by the reciprocal flag. -Together these are §5 admissibility (when units are in the pin leaves). -/ -def tableFlag (a b : Pin p n N) (M : Cross p n) (x : UnitType p n N) := - ∀ z,∀ v∈tabSpace a.sp z,∀ w∈b.sp (flipZ p z), - evmat (M z) v w=dotProduct (images x z *ᵥ v) (b.target (flipZ p z) *ᵥ w) - -private theorem ev_gram {I J W : Type} [Fintype I] [Fintype J] [Fintype W] - (P : Mat W I) (Q : Mat W J) (v : Vec I) (w : Vec J) : - evmat (Pᵀ*Q) v w = dotProduct (P *ᵥ v) (Q *ᵥ w) := by - rw [evmat,← Matrix.mulVec_mulVec,dotProduct_transpose_mulVec,dotProduct_comm] - -theorem flag_actual {a b : Pin p n N} (x y : UnitType p n N) (h : b.agree y) : - tableFlag a b (actual p x y) x := by - intro z v hv w hw - rw [actual,ev_gram,h _ _ hw] - -def channelOut (p : Shape) {n} (M : Cross p n) (j : Bool) (z : Place p) : - Mat (Chan p) (JointIdx p n) := (M z * IH p n j)ᵀ - -/-- small table injecting condition, at this role. Row directions are in -a.sp and wholly in the indicated primal block; output is viewed modulo -*hPin at the same sign*, not the sign of the tested columns. -/ -def tableInj (a b : Plan p n) (M : Cross p n) := - ∀ (z : Place p) (i j : Bool) (v : Ray p n), (IP p n i)*ᵥv ∈ a z → - channelOut p M j z *ᵥ (IP p n i *ᵥ v) ∈ hPin b z j → v=0 - -/-- Contraction on x, computed in full table coordinates; at the small -table only its restriction to C_i is initially meaningful. -/ -def contract (p : Shape) {n} (M : Cross p n) (i j : Bool) : - Profile p n →ₗ[F] F where - toFun x := ∑ e : Comp p.g, mpair - ((channelOut p M j (e,true))ᵀ * channelOut p M j (e,false)) - (liftM (IP p n i) (IP p n i) (x e)) - map_add' x y := by simp only [Pi.add_apply,map_add,Finset.sum_add_distrib] - map_smul' a x := by simp only [Pi.smul_apply,map_smul,RingHom.id_apply, - smul_eq_mul, Finset.mul_sum] - -theorem contract_actual (x y : UnitType p n N) (i j : Bool) : - contract p (actual p x y) i j = (ufun (onSide y j)) ∘ₗ (Uembed (onSide x i)) := by - let A := onSide x i - let B := onSide y j - have he (z : Place p) : actual p x y z * IH p n j = (images x z)ᵀ * - channel (takeSign (B z.1) !z.2) := by rw [actual,Matrix.mul_assoc,images_ih]; rfl - apply LinearMap.ext - intro w - change ∑ e : Comp p.g, _ = ∑ e : Comp p.g, _ - refine Finset.sum_congr rfl fun e _ => ?_ - - let P := images x (e,true) - let Q := images x (e,false) - let Y := channel (B e).2 - let X := channel (B e).1 - have hm : (channelOut p (actual p x y) j (e,true))ᵀ * channelOut p (actual p x y) j (e,false) = - liftM Pᵀ Qᵀ (Y*Xᵀ) := by - unfold channelOut - rw [he,he] - simp only [transpose_mul,transpose_transpose,liftM_def] - change (Pᵀ * Y)*(Xᵀ*Q)=_ - simp only [Matrix.mul_assoc] - change mpair _ _ = mpair (Y*Xᵀ) (liftM (primary (A e).1) (primary (A e).2) (w e)) - rw [hm, ← mpair_liftM P Q,liftM_comp] - have hP : P * IP p n i = primary (A e).1 := images_ip x (e,true) _ - have hQ : Q * IP p n i = primary (A e).2 := images_ip x (e,false) _ - rw [hP,hQ] - -def innerP (p : Shape) {n N} (x : UnitType p n N) (i : Bool) := - ufun (onSide x (!i)) ∘ₗ Uembed (onSide x i) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.NominalSpaces + +namespace OAI + +/-! # Cross Forms -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix +open scoped BigOperators +variable {p : Shape} {n N : ℕ} + +def flipZ (p : Shape) (z : Place p) : Place p := (z.1,!z.2) +@[simp] theorem flipZ_flip (z : Place p) : flipZ p (flipZ p z)=z := by cases z; simp [flipZ] + +abbrev Cross (p : Shape) (n : ℕ) := Place p → Mat (JointIdx p n) (JointIdx p n) +def reciprocal (p : Shape) {n} (M : Cross p n) : Cross p n := fun z => (M (flipZ p z))ᵀ +@[simp] theorem reciprocal_twice (M : Cross p n) : reciprocal p (reciprocal p M)=M := by + funext i; simp [reciprocal] + +def actual (p : Shape) {n N} (x y : UnitType p n N) : Cross p n := + fun z => (images x z)ᵀ * images y (flipZ p z) + +@[simp] theorem reciprocal_actual (x y : UnitType p n N) : + reciprocal p (actual p x y)=actual p y x := by + funext z; simp only [reciprocal,actual,transpose_mul,flipZ_flip,transpose_transpose] + +/-- two abstract cross sets agree at every row coming from these frozen +directions. Also apply this notion reciprocally to check columns. -/ +def rowAgree (q : Plan p n) (A B : Cross p n) := + ∀ z, ∀ x∈ q z,∀ y, evmat (A z) x y=evmat (B z) x y + +/-- The flag on an orientation of A. Test all entries on the table spaces +with column in the B pins. Test the other entries by the reciprocal flag. +Together these are §5 admissibility (when units are in the pin leaves). -/ +def tableFlag (a b : Pin p n N) (M : Cross p n) (x : UnitType p n N) := + ∀ z,∀ v∈tabSpace a.sp z,∀ w∈b.sp (flipZ p z), + evmat (M z) v w=dotProduct (images x z *ᵥ v) (b.target (flipZ p z) *ᵥ w) + +private theorem ev_gram {I J W : Type} [Fintype I] [Fintype J] [Fintype W] + (P : Mat W I) (Q : Mat W J) (v : Vec I) (w : Vec J) : + evmat (Pᵀ*Q) v w = dotProduct (P *ᵥ v) (Q *ᵥ w) := by + rw [evmat,← Matrix.mulVec_mulVec,dotProduct_transpose_mulVec,dotProduct_comm] + +theorem flag_actual {a b : Pin p n N} (x y : UnitType p n N) (h : b.agree y) : + tableFlag a b (actual p x y) x := by + intro z v hv w hw + rw [actual,ev_gram,h _ _ hw] + +def channelOut (p : Shape) {n} (M : Cross p n) (j : Bool) (z : Place p) : + Mat (Chan p) (JointIdx p n) := (M z * IH p n j)ᵀ + +/-- small table injecting condition, at this role. Row directions are in +a.sp and wholly in the indicated primal block; output is viewed modulo +*hPin at the same sign*, not the sign of the tested columns. -/ +def tableInj (a b : Plan p n) (M : Cross p n) := + ∀ (z : Place p) (i j : Bool) (v : Ray p n), (IP p n i)*ᵥv ∈ a z → + channelOut p M j z *ᵥ (IP p n i *ᵥ v) ∈ hPin b z j → v=0 + +/-- Contraction on x, computed in full table coordinates; at the small +table only its restriction to C_i is initially meaningful. -/ +def contract (p : Shape) {n} (M : Cross p n) (i j : Bool) : + Profile p n →ₗ[F] F where + toFun x := ∑ e : Comp p.g, mpair + ((channelOut p M j (e,true))ᵀ * channelOut p M j (e,false)) + (liftM (IP p n i) (IP p n i) (x e)) + map_add' x y := by simp only [Pi.add_apply,map_add,Finset.sum_add_distrib] + map_smul' a x := by simp only [Pi.smul_apply,map_smul,RingHom.id_apply, + smul_eq_mul, Finset.mul_sum] + +theorem contract_actual (x y : UnitType p n N) (i j : Bool) : + contract p (actual p x y) i j = (ufun (onSide y j)) ∘ₗ (Uembed (onSide x i)) := by + let A := onSide x i + let B := onSide y j + have he (z : Place p) : actual p x y z * IH p n j = (images x z)ᵀ * + channel (takeSign (B z.1) !z.2) := by rw [actual,Matrix.mul_assoc,images_ih]; rfl + apply LinearMap.ext + intro w + change ∑ e : Comp p.g, _ = ∑ e : Comp p.g, _ + refine Finset.sum_congr rfl fun e _ => ?_ + + let P := images x (e,true) + let Q := images x (e,false) + let Y := channel (B e).2 + let X := channel (B e).1 + have hm : (channelOut p (actual p x y) j (e,true))ᵀ * channelOut p (actual p x y) j (e,false) = + liftM Pᵀ Qᵀ (Y*Xᵀ) := by + unfold channelOut + rw [he,he] + simp only [transpose_mul,transpose_transpose,liftM_def] + change (Pᵀ * Y)*(Xᵀ*Q)=_ + simp only [Matrix.mul_assoc] + change mpair _ _ = mpair (Y*Xᵀ) (liftM (primary (A e).1) (primary (A e).2) (w e)) + rw [hm, ← mpair_liftM P Q,liftM_comp] + have hP : P * IP p n i = primary (A e).1 := images_ip x (e,true) _ + have hQ : Q * IP p n i = primary (A e).2 := images_ip x (e,false) _ + rw [hP,hQ] + +def innerP (p : Shape) {n N} (x : UnitType p n N) (i : Bool) := + ufun (onSide x (!i)) ∘ₗ Uembed (onSide x i) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CrossPatternCorrelation.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CrossPatternCorrelation.lean index 00a4d927f0ac761bf505b9867b410dd18e291802..590b736143c22f39d10157cc572db6d9c4e2b809 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CrossPatternCorrelation.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CrossPatternCorrelation.lean @@ -1,159 +1,159 @@ -import OAI.Combinatorics.HadwigerCounterexample.BoundedQueryTemplates - -namespace OAI - -/-! # Cross Pattern Correlation -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Module LinearMap Submodule Finset Function -variable {p : Shape} {n N : ℕ} -variable {I J K A B : Type} [Fintype I] [Fintype J] [Fintype K] -variable [DecidableEq I] [DecidableEq J] [DecidableEq K] - -def layerPhase (M : Mat I J) (N : ℕ) : - PlusRack I N →ₗ[F] (PlusRack J N →ₗ[F] F) where - toFun X := mpair (X*M) - map_add' X Y := LinearMap.ext fun Z => by rw [Matrix.add_mul,mpair_add,LinearMap.add_apply] - map_smul' a X := LinearMap.ext fun Z => by rw [Matrix.smul_mul,mpair_smul,LinearMap.smul_apply]; rfl - -omit [DecidableEq I] [DecidableEq J] in -theorem layer_form (M : Mat I J) (X : PlusRack I N) (Y : PlusRack J N) : - layerPhase M N X Y=mpair M (Xᵀ*Y) := by - change (X*M*Yᵀ).trace=(M*(Xᵀ*Y)ᵀ).trace - rw [Matrix.transpose_mul,Matrix.transpose_transpose, - ← Matrix.mul_assoc M,Matrix.trace_mul_comm _ X,Matrix.mul_assoc] - -omit [DecidableEq I] [DecidableEq J] in -theorem layer_rank (M : Mat I J) (N : ℕ) : - rk (layerPhase M N)=N*M.rank := by - classical - obtain ⟨A,B,hA,hB,hM⟩ := rank_product M - let t := M.rank - let P := layerPhase B N - let X := rmult (Fin N) A - have h1 : P ∘ₗ X=layerPhase M N := by - refine LinearMap.ext fun W => ?_ - change mpair ((W*A)*B)=mpair (W*M) - rw [Matrix.mul_assoc,hM] - have hp : Injective P := by - rw [←LinearMap.ker_eq_bot] - refine le_bot_iff.mp (fun V hV => ?_) - change mpair (V*B)=0 at hV - have hg := mpair_nondeg _ hV - have hh : Injective Bᵀ.mulVec := transpose_surj_iff.mp (by rwa [transpose_transpose]) - obtain ⟨D,hD⟩ := mat_left_inv hh - have hf : B*Dᵀ=1 := by - rw [←transpose_transpose B,← transpose_mul,hD,transpose_one] - have he : V=0 := calc - V = V*1 := (Matrix.mul_one _).symm - _ = _ := by rw [←hf,←Matrix.mul_assoc,hg,Matrix.zero_mul] - rw [he]; exact Submodule.zero_mem _ - have hx : Surjective X := by - obtain ⟨D,hD⟩ := mat_left_inv hA - intro v - exact ⟨v*D,by change v*D*A=v; rw [Matrix.mul_assoc,hD,Matrix.mul_one]⟩ - have hf : rk (P ∘ₗ X)=rk P := by - unfold rk; rw [LinearMap.range_comp,LinearMap.range_eq_top.mpr hx,Submodule.map_top] - rw [←h1,hf] - exact (rk_inj.mp hp).trans ((dim_mat _ _).trans (by simp)) - -def phasedBy (M : Mat I I) (x : Rack I N) : ℝ := wsign (layerPhase M N x.1 x.2) -def upliftR (f : J→I) (x : PlusRack J N) : PlusRack I N := x * (embedMat f)ᵀ - -omit [DecidableEq J] [DecidableEq K] in -theorem shifted_sub (M : Mat I I) (f : J→I) (g : K→I) (x : PlusRack J N) (y : PlusRack K N) : - layerPhase M N (upliftR f x) (upliftR g y)=layerPhase (M.submatrix f g) N x y := by - rw [layer_form,layer_form] - let X := embedMat f - let Y := embedMat g - have he : (upliftR f x)ᵀ* upliftR g y=liftM X Y (xᵀ*y) := by - simp only [upliftR,transpose_mul,transpose_transpose,liftM_def,X,Y,Matrix.mul_assoc] - rw [he,mpair_liftM] - rw [show liftM Xᵀ Yᵀ M=M.submatrix f g from (by - unfold X Y; rw [liftM_def,transpose_transpose,embedMat_mul,mul_embedMat]; rfl)] - -private theorem uniform_shift {A : Type} [AddGroup A] [Fintype A] (f : Wgt A) (x : A) : - avg unif f=avg unif (fun y => f (y+x)) := by - let e : A≃ A := - { toFun := (·+x) - invFun := (·-x) - left_inv a := add_sub_cancel_right .. - right_inv a := sub_add_cancel .. } - have h := avg_bij e unif f - rw [show (fun y => unif (e y))=unif from (by ext; simp [unif_apply])] at h - exact h.symm - -def pairedShift {I J K : Type} [Fintype J] [Fintype K] [DecidableEq I] (f : J→I) (g : K→I) - (P : PlusRack J N) (Q : PlusRack K N) := (upliftR f P,upliftR g Q) - -set_option maxHeartbeats 600000 in -theorem layerLeak (M : Mat I I) (f g r : Wgt (Rack I N)) (U : J→I) (V : K→I) - (hf : ∀ x, |f x|≤1) (hg : ∀ x,|g x|≤1) - (h1 : ∀ x y, f (x+(0,upliftR V y))=f x) - (h2 : ∀ x y,g (x+(upliftR U y,0))=g x) - (h3 : ∀ x y z,r (x+(upliftR U y,upliftR V z))=r x) : - |avg unif (fun x => phasedBy M x*f x*g x*r x)| ≤ - bp (- (N:ℝ)*(M.submatrix U V).rank / 2) * avg unif (fun x => |r x|) := by - classical - let A x := phasedBy M x*f x*g x*r x - let D : Wgt (PlusRack J N × PlusRack K N) := pairW unif unif - have hD : IsLaw D := pairW_law unif_law unif_law - have he : - avg unif A=avg unif (fun x => avg D (fun q => A (x+pairedShift U V q.1 q.2))) := by - rw [avg_avg]; refine (hD.avg_const (avg unif A)).symm.trans - (avg_congr fun q _ => uniform_shift A _) - let E := bp (- (N:ℝ)*(M.submatrix U V).rank /2) - let c (x : Rack I N) := layerPhase M N x.1 x.2 - have hQ (x) : |avg D (fun q => A (x+pairedShift U V q.1 q.2))|≤E*|r x| := by - let S (y : PlusRack J N) := f (x+(upliftR U y,0))*wsign (layerPhase M N (upliftR U y) x.2) - let T (y : PlusRack K N) := g (x+(0,upliftR V y))*wsign (layerPhase M N x.1 (upliftR V y)) - let L (q : PlusRack J N × PlusRack K N) := - S q.1*(T q.2*wsign (layerPhase (M.submatrix U V) N q.1 q.2)) - have hx q : A (x+pairedShift U V q.1 q.2)=L q*(r x*wsign (c x)) := by - rcases q with ⟨y,z⟩ - let Y := upliftR U y - let Z := upliftR V z - have hfg : f (x+(Y,Z))=f (x+(Y,0)) := by - rw [show x+(Y,Z)=x+(Y,0)+(0,Z) from by - rw [add_assoc]; apply congrArg - apply Prod.ext <;> simp,h1] - have hgg : g (x+(Y,Z))=g (x+(0,Z)) := by - rw [show x+(Y,Z)=x+(0,Z)+(Y,0) from by - rw [add_assoc]; apply congrArg - apply Prod.ext <;> simp,h2] - unfold A L phasedBy; dsimp only - change wsign (layerPhase M N (x.1+Y) (x.2+Z))*f (x+(Y,Z))*g (x+(Y,Z))*r (x+(Y,Z))=_ - rw [hfg,hgg,h3] - unfold S T c - simp only [map_add,LinearMap.add_apply,wsign_add] - rw [show layerPhase M N Y Z=_ from shifted_sub M U V y z] - dsimp only [Y,Z]; ring - have hs x : |S x|≤ 1 := by simpa only [S,abs_mul,wsign_abs,mul_one] using hf _ - have ht x : |T x|≤ 1 := by simpa only [T,abs_mul,wsign_abs,mul_one] using hg _ - have hl : |avg D L|≤ E := by - unfold D L - rw [pairW_avg,avg_avg] - simp_rw [mul_left_comm (S _),avg_mul'] - refine (walsh_bound _ S T hs ht).trans_eq ?_ - unfold E; rw [layer_rank,Nat.cast_mul,neg_mul] - simp_rw [hx] - rw [avg_mul,abs_mul,abs_mul,wsign_abs,mul_one] - exact mul_le_mul_of_nonneg_right hl (abs_nonneg _) - change |avg unif A| ≤_ - rw [he] - exact ((abs_avg_le unif_law.nz).trans (avg_mono unif_law.nz hQ)).trans_eq (avg_mul' ..) - -omit [DecidableEq I] in -theorem layer_zero (x : Rack I N) : phasedBy 0 x=1 := by unfold phasedBy; simp [layerPhase,mpair] -omit [DecidableEq I] in -theorem layer_add (M T : Mat I I) (x : Rack I N) : phasedBy (M+T) x=phasedBy M x*phasedBy T x := by - unfold phasedBy - rw [layer_form,layer_form,layer_form,mpair_add,wsign_add] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BoundedQueryTemplates + +namespace OAI + +/-! # Cross Pattern Correlation -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Module LinearMap Submodule Finset Function +variable {p : Shape} {n N : ℕ} +variable {I J K A B : Type} [Fintype I] [Fintype J] [Fintype K] +variable [DecidableEq I] [DecidableEq J] [DecidableEq K] + +def layerPhase (M : Mat I J) (N : ℕ) : + PlusRack I N →ₗ[F] (PlusRack J N →ₗ[F] F) where + toFun X := mpair (X*M) + map_add' X Y := LinearMap.ext fun Z => by rw [Matrix.add_mul,mpair_add,LinearMap.add_apply] + map_smul' a X := LinearMap.ext fun Z => by rw [Matrix.smul_mul,mpair_smul,LinearMap.smul_apply]; rfl + +omit [DecidableEq I] [DecidableEq J] in +theorem layer_form (M : Mat I J) (X : PlusRack I N) (Y : PlusRack J N) : + layerPhase M N X Y=mpair M (Xᵀ*Y) := by + change (X*M*Yᵀ).trace=(M*(Xᵀ*Y)ᵀ).trace + rw [Matrix.transpose_mul,Matrix.transpose_transpose, + ← Matrix.mul_assoc M,Matrix.trace_mul_comm _ X,Matrix.mul_assoc] + +omit [DecidableEq I] [DecidableEq J] in +theorem layer_rank (M : Mat I J) (N : ℕ) : + rk (layerPhase M N)=N*M.rank := by + classical + obtain ⟨A,B,hA,hB,hM⟩ := rank_product M + let t := M.rank + let P := layerPhase B N + let X := rmult (Fin N) A + have h1 : P ∘ₗ X=layerPhase M N := by + refine LinearMap.ext fun W => ?_ + change mpair ((W*A)*B)=mpair (W*M) + rw [Matrix.mul_assoc,hM] + have hp : Injective P := by + rw [←LinearMap.ker_eq_bot] + refine le_bot_iff.mp (fun V hV => ?_) + change mpair (V*B)=0 at hV + have hg := mpair_nondeg _ hV + have hh : Injective Bᵀ.mulVec := transpose_surj_iff.mp (by rwa [transpose_transpose]) + obtain ⟨D,hD⟩ := mat_left_inv hh + have hf : B*Dᵀ=1 := by + rw [←transpose_transpose B,← transpose_mul,hD,transpose_one] + have he : V=0 := calc + V = V*1 := (Matrix.mul_one _).symm + _ = _ := by rw [←hf,←Matrix.mul_assoc,hg,Matrix.zero_mul] + rw [he]; exact Submodule.zero_mem _ + have hx : Surjective X := by + obtain ⟨D,hD⟩ := mat_left_inv hA + intro v + exact ⟨v*D,by change v*D*A=v; rw [Matrix.mul_assoc,hD,Matrix.mul_one]⟩ + have hf : rk (P ∘ₗ X)=rk P := by + unfold rk; rw [LinearMap.range_comp,LinearMap.range_eq_top.mpr hx,Submodule.map_top] + rw [←h1,hf] + exact (rk_inj.mp hp).trans ((dim_mat _ _).trans (by simp)) + +def phasedBy (M : Mat I I) (x : Rack I N) : ℝ := wsign (layerPhase M N x.1 x.2) +def upliftR (f : J→I) (x : PlusRack J N) : PlusRack I N := x * (embedMat f)ᵀ + +omit [DecidableEq J] [DecidableEq K] in +theorem shifted_sub (M : Mat I I) (f : J→I) (g : K→I) (x : PlusRack J N) (y : PlusRack K N) : + layerPhase M N (upliftR f x) (upliftR g y)=layerPhase (M.submatrix f g) N x y := by + rw [layer_form,layer_form] + let X := embedMat f + let Y := embedMat g + have he : (upliftR f x)ᵀ* upliftR g y=liftM X Y (xᵀ*y) := by + simp only [upliftR,transpose_mul,transpose_transpose,liftM_def,X,Y,Matrix.mul_assoc] + rw [he,mpair_liftM] + rw [show liftM Xᵀ Yᵀ M=M.submatrix f g from (by + unfold X Y; rw [liftM_def,transpose_transpose,embedMat_mul,mul_embedMat]; rfl)] + +private theorem uniform_shift {A : Type} [AddGroup A] [Fintype A] (f : Wgt A) (x : A) : + avg unif f=avg unif (fun y => f (y+x)) := by + let e : A≃ A := + { toFun := (·+x) + invFun := (·-x) + left_inv a := add_sub_cancel_right .. + right_inv a := sub_add_cancel .. } + have h := avg_bij e unif f + rw [show (fun y => unif (e y))=unif from (by ext; simp [unif_apply])] at h + exact h.symm + +def pairedShift {I J K : Type} [Fintype J] [Fintype K] [DecidableEq I] (f : J→I) (g : K→I) + (P : PlusRack J N) (Q : PlusRack K N) := (upliftR f P,upliftR g Q) + +set_option maxHeartbeats 600000 in +theorem layerLeak (M : Mat I I) (f g r : Wgt (Rack I N)) (U : J→I) (V : K→I) + (hf : ∀ x, |f x|≤1) (hg : ∀ x,|g x|≤1) + (h1 : ∀ x y, f (x+(0,upliftR V y))=f x) + (h2 : ∀ x y,g (x+(upliftR U y,0))=g x) + (h3 : ∀ x y z,r (x+(upliftR U y,upliftR V z))=r x) : + |avg unif (fun x => phasedBy M x*f x*g x*r x)| ≤ + bp (- (N:ℝ)*(M.submatrix U V).rank / 2) * avg unif (fun x => |r x|) := by + classical + let A x := phasedBy M x*f x*g x*r x + let D : Wgt (PlusRack J N × PlusRack K N) := pairW unif unif + have hD : IsLaw D := pairW_law unif_law unif_law + have he : + avg unif A=avg unif (fun x => avg D (fun q => A (x+pairedShift U V q.1 q.2))) := by + rw [avg_avg]; refine (hD.avg_const (avg unif A)).symm.trans + (avg_congr fun q _ => uniform_shift A _) + let E := bp (- (N:ℝ)*(M.submatrix U V).rank /2) + let c (x : Rack I N) := layerPhase M N x.1 x.2 + have hQ (x) : |avg D (fun q => A (x+pairedShift U V q.1 q.2))|≤E*|r x| := by + let S (y : PlusRack J N) := f (x+(upliftR U y,0))*wsign (layerPhase M N (upliftR U y) x.2) + let T (y : PlusRack K N) := g (x+(0,upliftR V y))*wsign (layerPhase M N x.1 (upliftR V y)) + let L (q : PlusRack J N × PlusRack K N) := + S q.1*(T q.2*wsign (layerPhase (M.submatrix U V) N q.1 q.2)) + have hx q : A (x+pairedShift U V q.1 q.2)=L q*(r x*wsign (c x)) := by + rcases q with ⟨y,z⟩ + let Y := upliftR U y + let Z := upliftR V z + have hfg : f (x+(Y,Z))=f (x+(Y,0)) := by + rw [show x+(Y,Z)=x+(Y,0)+(0,Z) from by + rw [add_assoc]; apply congrArg + apply Prod.ext <;> simp,h1] + have hgg : g (x+(Y,Z))=g (x+(0,Z)) := by + rw [show x+(Y,Z)=x+(0,Z)+(Y,0) from by + rw [add_assoc]; apply congrArg + apply Prod.ext <;> simp,h2] + unfold A L phasedBy; dsimp only + change wsign (layerPhase M N (x.1+Y) (x.2+Z))*f (x+(Y,Z))*g (x+(Y,Z))*r (x+(Y,Z))=_ + rw [hfg,hgg,h3] + unfold S T c + simp only [map_add,LinearMap.add_apply,wsign_add] + rw [show layerPhase M N Y Z=_ from shifted_sub M U V y z] + dsimp only [Y,Z]; ring + have hs x : |S x|≤ 1 := by simpa only [S,abs_mul,wsign_abs,mul_one] using hf _ + have ht x : |T x|≤ 1 := by simpa only [T,abs_mul,wsign_abs,mul_one] using hg _ + have hl : |avg D L|≤ E := by + unfold D L + rw [pairW_avg,avg_avg] + simp_rw [mul_left_comm (S _),avg_mul'] + refine (walsh_bound _ S T hs ht).trans_eq ?_ + unfold E; rw [layer_rank,Nat.cast_mul,neg_mul] + simp_rw [hx] + rw [avg_mul,abs_mul,abs_mul,wsign_abs,mul_one] + exact mul_le_mul_of_nonneg_right hl (abs_nonneg _) + change |avg unif A| ≤_ + rw [he] + exact ((abs_avg_le unif_law.nz).trans (avg_mono unif_law.nz hQ)).trans_eq (avg_mul' ..) + +omit [DecidableEq I] in +theorem layer_zero (x : Rack I N) : phasedBy 0 x=1 := by unfold phasedBy; simp [layerPhase,mpair] +omit [DecidableEq I] in +theorem layer_add (M T : Mat I I) (x : Rack I N) : phasedBy (M+T) x=phasedBy M x*phasedBy T x := by + unfold phasedBy + rw [layer_form,layer_form,layer_form,mpair_add,wsign_add] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CrossPatternCounting.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CrossPatternCounting.lean index 7fe87b0b5810290b8ae9672e3702bf229e25b02c..36f4c5f2282cccb547bc8a3c8e568da0e6dd951a 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CrossPatternCounting.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CrossPatternCounting.lean @@ -1,173 +1,173 @@ -import OAI.Combinatorics.HadwigerCounterexample.RankSubrectangles - -namespace OAI - -/-! # Cross Pattern Counting -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Submodule Function Finset -open scoped BigOperators - -variable {I J T L : Type} [Fintype I] [Fintype J] [Fintype T] [Fintype L] - [DecidableEq I] [DecidableEq J] [DecidableEq T] [DecidableEq L] - -abbrev Avenue (I J : Type) := Mat (I×J) (I×J) -def interDraw (M : Avenue I J) := - ∀ i u v,M (i,u) (i,v)=0 - -def disperses (f : T → I × J) (g : L → I × J) := - ∀ i j,(f i).1≠(g j).1 -def arcPeak (M : Avenue I J) (t : ℕ) := - ∃ (f g : Fin t→ I × J), disperses f g ∧ Injective (M.submatrix f g).mulVec - -def peak (M : Avenue I J) : ℕ := sSup {t | arcPeak M t} - -omit [DecidableEq I] [DecidableEq J] in -private theorem peak_bdd (M : Avenue I J) (t : ℕ) (h : arcPeak M t) : - t≤ Fintype.card (I×J) := by - obtain ⟨f,g,hg,h⟩ := h - have hx := ((mrk_inj.mp h).trans (Fintype.card_fin _)).symm - exact hx.trans_le ((M.rank_submatrix_le f g).trans M.rank_le_card_width) - -omit [DecidableEq I] [DecidableEq J] in -theorem real_peak (M : Avenue I J) : arcPeak M (peak M) := by - classical - have he : arcPeak M 0 := ⟨Fin.elim0,Fin.elim0, - fun i => Fin.elim0 i, fun _ _ _ => Subsingleton.elim _ _⟩ - exact Nat.sSup_mem (show Set.Nonempty {t | arcPeak M t} from ⟨0,he⟩) - ⟨Fintype.card (I×J),fun _ => peak_bdd M _⟩ - -omit [DecidableEq I] [DecidableEq J] in -theorem peak_le (M : Avenue I J) : peak M ≤ Fintype.card (I×J) := - peak_bdd M _ (real_peak M) - -omit [DecidableEq I] [DecidableEq J] in -theorem sized_peak (M : Avenue I J) {f : T→I × J} {g : L → I × J} - (h : disperses f g) : (M.submatrix f g).rank ≤ peak M := by - classical - obtain ⟨a,b,hb⟩ := minor_arc (M.submatrix f g) - let W := {t | arcPeak M t} - refine le_csSup ⟨Fintype.card (I×J),fun t => peak_bdd M t⟩ - (show (M.submatrix f g).rank∈W from ?_) - exact ⟨f ∘ a,g ∘ b,fun i j => h _ _,hb⟩ - -omit [DecidableEq I] [DecidableEq J] in -theorem peak_pos (M : Avenue I J) (h : M≠0) (he : interDraw M) : 1≤peak M := by - classical - obtain ⟨⟨x,y⟩,⟨v,w⟩,hx⟩ : - ∃ i j : I×J,M i j≠0 := by by_contra! hn; exact h (Matrix.ext fun i j => hn i j) - let f (_ : Unit) := (x,y) - let g (_ : Unit) := (v,w) - have hv : disperses f g := fun i j h => hx ((show x=v from h).symm ▸ he x y w) - have hh := sized_peak M hv - have h1 : M.submatrix f g=1 := by - ext i j - obtain rfl := Subsingleton.elim i j - rw [Matrix.one_apply_eq] - exact (bit_cases _).resolve_left hx - simpa only [h1,Matrix.rank_one,Fintype.card_unit] using hh - -abbrev Incident (I J : Type) := Mat J (I×J) -def took (M : Avenue I J) (i : I) : Incident I J × Incident I J := - (M.submatrix (fun j => (i,j)) _root_.id, (Mᵀ.submatrix (fun j => (i,j)) _root_.id)) - -private theorem took_same (A B : Avenue I J) {t : ℕ} (f g : Fin t→ I×J) - (hA : peak A=t) (hB : peak B=t) (ha : interDraw A) (hb : interDraw B) - (hd : disperses f g) (hf : Injective (A.submatrix f g).mulVec) - (hL : ∀ i,took A (f i).1=took B (f i).1) - (hR : ∀ i,took A (g i).1=took B (g i).1) : A=B := by - classical - let touched (x : I) := (∃ i,x=(f i).1)∨∃ i,x=(g i).1 - have he {i : I} (h : touched i) (j : J) (k : I × J) : - A (i,j) k=B (i,j) k ∧ A k (i,j)=B k (i,j) := by - have hE : took A i=took B i := by - rcases h with ⟨i,rfl⟩|⟨i,rfl⟩; exact hL i; exact hR i - exact ⟨congr_fun (congr_fun (congrArg Prod.fst hE) j) k, - congr_fun (congr_fun (congrArg Prod.snd hE) j) k⟩ - ext ⟨i,j⟩ ⟨k,l⟩ - by_cases h : i=k - · subst k; rw [ha,hb] - by_cases hi : touched i - · exact (he hi j _).1 - by_cases hj : touched k - · exact (he hj l _).2 - let u := Sum.elim f (fun _ : Unit => (i,j)) - let v := Sum.elim g (fun _ : Unit => (k,l)) - have ht : disperses u v := by - rintro (x|x) (y|y) h' - · exact hd _ _ h' - · exact hj (Or.inl ⟨_,h'.symm⟩) - · exact hi (Or.inr ⟨_,h'⟩) - · exact h h' - have h1 x y : A (f x) y=B (f x) y := - (he (i:=(f x).1) (Or.inl ⟨x,rfl⟩) (f x).2 y).1 - have h2 x y : A x (g y)=B x (g y) := - (he (i:=(g y).1) (Or.inr ⟨y,rfl⟩) (g y).2 x).2 - exact border_same A B f g (i,j) (k,l) hf h1 h2 ((sized_peak A ht).trans_eq hA) - ((sized_peak B ht).trans_eq hB) - -private abbrev Bag (I J : Type) := (I × J) × Incident I J × Incident I J -def peakExpense (I J : Type) [Fintype I] [Fintype J] (t : ℕ) := - 2*t * ((1+2*num J)* num I*num J) - -private theorem bagCount : - num (Bag I J) ≤ bp ((1+2*num J)*num I*num J) := by - classical - have hA : num (I×J) ≤ bp (num (I×J)) := by - let K := I×J - have h : Fintype.card K <2^(Fintype.card K) := Nat.lt_two_pow_self - unfold num - rw [bp_nat] - exact_mod_cast h.le - have he {I J : Type} [Fintype I] [Fintype J] : num (I×J)=num I*num J := by - simp only [num,Fintype.card_prod,Nat.cast_mul] - unfold Bag - rw [he, he (I:=Incident ..)] - simp only [Incident,cast_mat] - calc num (I×J)* _ ≤ bp (num (I×J))* _ := - mul_le_mul_of_nonneg_right hA (mul_nonneg (bp_pos _).le (bp_pos _).le) - _ = _ := by rw [←bp_add,←bp_add,he]; congr 1; ring - -set_option maxHeartbeats 800000 in -theorem price_peak (t : ℕ) : - nbr (fun M : Avenue I J => interDraw M ∧ peak M=t)≤bp (peakExpense I J t) := by - classical - let S := {M : Avenue I J // interDraw M ∧ peak M=t} - have ht (M : S) : arcPeak M.val t := by - have hf {A : Avenue I J} {t : ℕ} (h : peak A=t) : arcPeak A t := h ▸ real_peak A - exact hf M.property.2 - choose f g hD hG using ht - let P := (Fin t → Bag I J) × (Fin t → Bag I J) - let e : S→P := fun M => (fun i => (f M i,took M.val (f M i).1), - fun i => (g M i,took M.val (g M i).1)) - have hf : Injective e := by - intro A B h - have h1 (i) : (f A i,took A.val (f A i).1)=(f B i,took B.val (f B i).1) := - congr_fun (congrArg Prod.fst h) i - have h2 (i) : (g A i,took A.val (g A i).1)=(g B i,took B.val (g B i).1) := - congr_fun (congrArg Prod.snd h) i - refine Subtype.ext (took_same A.val B.val (f A) (g A) A.property.2 B.property.2 - A.property.1 B.property.1 (hD A) (hG A) (fun i => ?_) (fun i => ?_)) - · have he : took A.val (f A i).1=took B.val (f B i).1 := congrArg Prod.snd (h1 i) - rwa [← show f A i=f B i from congrArg Prod.fst (h1 i)] at he - have he : took A.val (g A i).1=took B.val (g B i).1 := congrArg Prod.snd (h2 i) - rwa [← show g A i=g B i from congrArg Prod.fst (h2 i)] at he - rw [nbr_eq_card] - have hZ : (Fintype.card S:ℝ) ≤ Fintype.card P := by exact_mod_cast Fintype.card_le_of_injective e hf - apply hZ.trans - apply le_trans ((show (↑(Fintype.card P):ℝ)=num (Bag I J)^t*num (Bag I J)^t by - simp [P,num]).le) - let V := ((1+2*num J)*num I*num J) - have h1 := @bagCount I J _ _ _ _ - have he := pow_le_pow_left₀ (Nat.cast_nonneg _ : 0 ≤ num (Bag I J)) h1 t - have hz := bp_mul_nat V t - rw [← hz] at he - refine (mul_le_mul he he (pow_nonneg (Nat.cast_nonneg _) _) (bp_pos _).le).trans_eq ?_ - rw [←bp_add]; unfold V peakExpense; congr 1; ring - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RankSubrectangles + +namespace OAI + +/-! # Cross Pattern Counting -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Submodule Function Finset +open scoped BigOperators + +variable {I J T L : Type} [Fintype I] [Fintype J] [Fintype T] [Fintype L] + [DecidableEq I] [DecidableEq J] [DecidableEq T] [DecidableEq L] + +abbrev Avenue (I J : Type) := Mat (I×J) (I×J) +def interDraw (M : Avenue I J) := + ∀ i u v,M (i,u) (i,v)=0 + +def disperses (f : T → I × J) (g : L → I × J) := + ∀ i j,(f i).1≠(g j).1 +def arcPeak (M : Avenue I J) (t : ℕ) := + ∃ (f g : Fin t→ I × J), disperses f g ∧ Injective (M.submatrix f g).mulVec + +def peak (M : Avenue I J) : ℕ := sSup {t | arcPeak M t} + +omit [DecidableEq I] [DecidableEq J] in +private theorem peak_bdd (M : Avenue I J) (t : ℕ) (h : arcPeak M t) : + t≤ Fintype.card (I×J) := by + obtain ⟨f,g,hg,h⟩ := h + have hx := ((mrk_inj.mp h).trans (Fintype.card_fin _)).symm + exact hx.trans_le ((M.rank_submatrix_le f g).trans M.rank_le_card_width) + +omit [DecidableEq I] [DecidableEq J] in +theorem real_peak (M : Avenue I J) : arcPeak M (peak M) := by + classical + have he : arcPeak M 0 := ⟨Fin.elim0,Fin.elim0, + fun i => Fin.elim0 i, fun _ _ _ => Subsingleton.elim _ _⟩ + exact Nat.sSup_mem (show Set.Nonempty {t | arcPeak M t} from ⟨0,he⟩) + ⟨Fintype.card (I×J),fun _ => peak_bdd M _⟩ + +omit [DecidableEq I] [DecidableEq J] in +theorem peak_le (M : Avenue I J) : peak M ≤ Fintype.card (I×J) := + peak_bdd M _ (real_peak M) + +omit [DecidableEq I] [DecidableEq J] in +theorem sized_peak (M : Avenue I J) {f : T→I × J} {g : L → I × J} + (h : disperses f g) : (M.submatrix f g).rank ≤ peak M := by + classical + obtain ⟨a,b,hb⟩ := minor_arc (M.submatrix f g) + let W := {t | arcPeak M t} + refine le_csSup ⟨Fintype.card (I×J),fun t => peak_bdd M t⟩ + (show (M.submatrix f g).rank∈W from ?_) + exact ⟨f ∘ a,g ∘ b,fun i j => h _ _,hb⟩ + +omit [DecidableEq I] [DecidableEq J] in +theorem peak_pos (M : Avenue I J) (h : M≠0) (he : interDraw M) : 1≤peak M := by + classical + obtain ⟨⟨x,y⟩,⟨v,w⟩,hx⟩ : + ∃ i j : I×J,M i j≠0 := by by_contra! hn; exact h (Matrix.ext fun i j => hn i j) + let f (_ : Unit) := (x,y) + let g (_ : Unit) := (v,w) + have hv : disperses f g := fun i j h => hx ((show x=v from h).symm ▸ he x y w) + have hh := sized_peak M hv + have h1 : M.submatrix f g=1 := by + ext i j + obtain rfl := Subsingleton.elim i j + rw [Matrix.one_apply_eq] + exact (bit_cases _).resolve_left hx + simpa only [h1,Matrix.rank_one,Fintype.card_unit] using hh + +abbrev Incident (I J : Type) := Mat J (I×J) +def took (M : Avenue I J) (i : I) : Incident I J × Incident I J := + (M.submatrix (fun j => (i,j)) _root_.id, (Mᵀ.submatrix (fun j => (i,j)) _root_.id)) + +private theorem took_same (A B : Avenue I J) {t : ℕ} (f g : Fin t→ I×J) + (hA : peak A=t) (hB : peak B=t) (ha : interDraw A) (hb : interDraw B) + (hd : disperses f g) (hf : Injective (A.submatrix f g).mulVec) + (hL : ∀ i,took A (f i).1=took B (f i).1) + (hR : ∀ i,took A (g i).1=took B (g i).1) : A=B := by + classical + let touched (x : I) := (∃ i,x=(f i).1)∨∃ i,x=(g i).1 + have he {i : I} (h : touched i) (j : J) (k : I × J) : + A (i,j) k=B (i,j) k ∧ A k (i,j)=B k (i,j) := by + have hE : took A i=took B i := by + rcases h with ⟨i,rfl⟩|⟨i,rfl⟩; exact hL i; exact hR i + exact ⟨congr_fun (congr_fun (congrArg Prod.fst hE) j) k, + congr_fun (congr_fun (congrArg Prod.snd hE) j) k⟩ + ext ⟨i,j⟩ ⟨k,l⟩ + by_cases h : i=k + · subst k; rw [ha,hb] + by_cases hi : touched i + · exact (he hi j _).1 + by_cases hj : touched k + · exact (he hj l _).2 + let u := Sum.elim f (fun _ : Unit => (i,j)) + let v := Sum.elim g (fun _ : Unit => (k,l)) + have ht : disperses u v := by + rintro (x|x) (y|y) h' + · exact hd _ _ h' + · exact hj (Or.inl ⟨_,h'.symm⟩) + · exact hi (Or.inr ⟨_,h'⟩) + · exact h h' + have h1 x y : A (f x) y=B (f x) y := + (he (i:=(f x).1) (Or.inl ⟨x,rfl⟩) (f x).2 y).1 + have h2 x y : A x (g y)=B x (g y) := + (he (i:=(g y).1) (Or.inr ⟨y,rfl⟩) (g y).2 x).2 + exact border_same A B f g (i,j) (k,l) hf h1 h2 ((sized_peak A ht).trans_eq hA) + ((sized_peak B ht).trans_eq hB) + +private abbrev Bag (I J : Type) := (I × J) × Incident I J × Incident I J +def peakExpense (I J : Type) [Fintype I] [Fintype J] (t : ℕ) := + 2*t * ((1+2*num J)* num I*num J) + +private theorem bagCount : + num (Bag I J) ≤ bp ((1+2*num J)*num I*num J) := by + classical + have hA : num (I×J) ≤ bp (num (I×J)) := by + let K := I×J + have h : Fintype.card K <2^(Fintype.card K) := Nat.lt_two_pow_self + unfold num + rw [bp_nat] + exact_mod_cast h.le + have he {I J : Type} [Fintype I] [Fintype J] : num (I×J)=num I*num J := by + simp only [num,Fintype.card_prod,Nat.cast_mul] + unfold Bag + rw [he, he (I:=Incident ..)] + simp only [Incident,cast_mat] + calc num (I×J)* _ ≤ bp (num (I×J))* _ := + mul_le_mul_of_nonneg_right hA (mul_nonneg (bp_pos _).le (bp_pos _).le) + _ = _ := by rw [←bp_add,←bp_add,he]; congr 1; ring + +set_option maxHeartbeats 800000 in +theorem price_peak (t : ℕ) : + nbr (fun M : Avenue I J => interDraw M ∧ peak M=t)≤bp (peakExpense I J t) := by + classical + let S := {M : Avenue I J // interDraw M ∧ peak M=t} + have ht (M : S) : arcPeak M.val t := by + have hf {A : Avenue I J} {t : ℕ} (h : peak A=t) : arcPeak A t := h ▸ real_peak A + exact hf M.property.2 + choose f g hD hG using ht + let P := (Fin t → Bag I J) × (Fin t → Bag I J) + let e : S→P := fun M => (fun i => (f M i,took M.val (f M i).1), + fun i => (g M i,took M.val (g M i).1)) + have hf : Injective e := by + intro A B h + have h1 (i) : (f A i,took A.val (f A i).1)=(f B i,took B.val (f B i).1) := + congr_fun (congrArg Prod.fst h) i + have h2 (i) : (g A i,took A.val (g A i).1)=(g B i,took B.val (g B i).1) := + congr_fun (congrArg Prod.snd h) i + refine Subtype.ext (took_same A.val B.val (f A) (g A) A.property.2 B.property.2 + A.property.1 B.property.1 (hD A) (hG A) (fun i => ?_) (fun i => ?_)) + · have he : took A.val (f A i).1=took B.val (f B i).1 := congrArg Prod.snd (h1 i) + rwa [← show f A i=f B i from congrArg Prod.fst (h1 i)] at he + have he : took A.val (g A i).1=took B.val (g B i).1 := congrArg Prod.snd (h2 i) + rwa [← show g A i=g B i from congrArg Prod.fst (h2 i)] at he + rw [nbr_eq_card] + have hZ : (Fintype.card S:ℝ) ≤ Fintype.card P := by exact_mod_cast Fintype.card_le_of_injective e hf + apply hZ.trans + apply le_trans ((show (↑(Fintype.card P):ℝ)=num (Bag I J)^t*num (Bag I J)^t by + simp [P,num]).le) + let V := ((1+2*num J)*num I*num J) + have h1 := @bagCount I J _ _ _ _ + have he := pow_le_pow_left₀ (Nat.cast_nonneg _ : 0 ≤ num (Bag I J)) h1 t + have hz := bp_mul_nat V t + rw [← hz] at he + refine (mul_le_mul he he (pow_nonneg (Nat.cast_nonneg _) _) (bp_pos _).le).trans_eq ?_ + rw [←bp_add]; unfold V peakExpense; congr 1; ring + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/CutIntegralBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/CutIntegralBounds.lean index 38edd1505bd5da5871bdf92b7134562a7997b424..4f1bab901135496a934aec9539190cff592bc699 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/CutIntegralBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/CutIntegralBounds.lean @@ -1,145 +1,145 @@ -import OAI.Combinatorics.HadwigerCounterexample.FourCornerTrials - -namespace OAI - -/-! # Cut Integral Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real Matrix Function Filter -open scoped BigOperators Topology -variable {p : Shape} {n N M : ℕ} {I A : Type} [Fintype I] [DecidableEq I] [Fintype A] - -def chairpan (p : I→Wgt A) (x : Bool×I) := p x.2 -def reparse (I A : Type) : (Bool×I→ A)≃ (I→A) × (I→A) := - (show (_:Type)≃(Bool→I→A) from ⟨curry,uncurry,fun _=>rfl,fun _=>rfl⟩).trans (wingpair _) - -theorem chairpan_law (p : I→Wgt A) : - mapW (prodW (chairpan p)) (reparse I A)=pairW (prodW p) (prodW p) := by - classical - funext i - obtain ⟨i,rfl⟩ := (reparse I A).surjective i - rw [mapW_equiv_val,Equiv.symm_apply_apply]; unfold pairW prodW - rw [Fintype.prod_prod_type,Fintype.prod_bool]; rfl -namespace Template -variable (v : Template p I) - -def panels (v : Template p I) := collect p v (Prod.snd : Bool × I → I) -def rekeys (v : Template p I) (k : Keys (p:=p) v.panels.t N) : - Keys (p:=p) v.t N ×Keys (p:=p) v.t N := (fun i=>k (true,i),fun i=>k (false,i)) - -def clue (v : Template p I) (j : I) (T : Wgt (Inputs p n I)) (U : Wgt (Keys (p:=p) v.t N)) - (x : Inputs p n (Bool × I)) (y : Keys (p:=p) v.panels.t N) := - quart (chairI v j n) T (reparse _ _ x)*quart (chairK v j N) U (rekeys v y) - -theorem clue_crane (v : Template p I) (j : I) (T : Wgt (Inputs p n I)) (U : Wgt (Keys - (p:=p) v.t N)) (w : I→ Wgt (Knobs p.g n)) : - crane v j T U w=v.panels.sampleAll (chairpan w) (clue v j T U) := by - classical - funext i - unfold crane; dsimp only - rw [←chairpan_law w,mapW_avg]; unfold sampleAll - refine avg_congr fun k hk => ?_ - rw [quart_prot]; rfl - -def scene (v : Template p I) (T : Wgt (Inputs p n I)) (U : Wgt (Keys (p:=p) v.t N)) - (w f : I→ Wgt (Knobs p.g n)) (o : UnitType p n N) := - avg (prodW w) (fun x => protean v T U o x * prodW f x) - -def blackout (v : Template p I) (T : Wgt (Inputs p n I)) (U : Wgt (Keys (p:=p) v.t N)) - (w : I→Wgt (Knobs p.g n)) (ε : ℝ) (o : UnitType p n N) := - ∃ f:I→Wgt (Knobs p.g n),(∀ i j,|f i j|≤1) ∧ ε < |scene v T U w f o| - -theorem shaft (v : Template p I) (j : I) (U : Wgt (Keys (p:=p) v.t N)) - (T : Wgt (Inputs p n I)) (w f : I→ Wgt (Knobs p.g n)) (hw : ∀ i,IsLaw (w i)) - (hf : ∀ i j,|f i j|≤1) (o : UnitType p n N) : - |scene v T U w f o|^4 ≤ crane v j T U w o := by - classical - let D (i : Aside j) := f i.val - have h0 i : |prodW D i|≤1 := by - unfold prodW; rw [abs_prod]; exact (prod_le_prod₀ (fun i _=>abs_nonneg _) (fun i _=>hf _ _)).trans_eq - (by simp) - have he (i : Inputs p n I) : - prodW f i=f j (i j)*prodW D ((chairI v j n i).2) := chair_split f i j - unfold scene; simp_rw [he] - exact quart_CS (chairI v j n) _ _ _ _ (chair_weight w j) (hw j) - (prodW_law fun i:Aside j=> hw i.val) (f j) (prodW D) (hf j) h0 - -set_option maxHeartbeats 1200000 in -theorem shade_calendar (v : Template p I) (j : I) (M : ℕ) (hM : 1≤M) - (C ε : ℝ) (hε : 0<ε) : - ∃ δ : ℝ,0<δ ∧ ∀ᶠ n : ℕ in atTop, - let N := M*n - ∀ (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) (T : Wgt (Inputs p n I)) - (w : I→Wgt (Knobs p.g n)), (∀ x, |U x|≤1) → chairCut v j U δ → - carried U (ownPart (p:=p) v.t q) → - (∀ x, |T x|≤1) → (∀ i,IsLaw (w i)) → - (∀ i,mapW (w i) (freePart p)=unif) → - ∀ (m : Mixer p n), 2*num (Full p n)f (M*n)+z n) atTop (𝓝 (W*d)) := by - have hh (c : ℝ) (C : ℝ) (hC : 0 bp (c-C*v i)) atTop (𝓝 0) := by - simp_rw [sub_eq_add_neg,bp_add, ← neg_mul] - simpa using ((bp_tendsto_zero hC).comp hv).const_mul (bp c) - let N (i : ℕ) := (↑(M*i):ℝ) - have he := cast_tops M hM - have hz := hh (num Bool*num I) 1 zero_lt_one (v:=fun n:ℕ=>(n:ℝ)) tendsto_natCast_atTop_atTop - have h1 := hh k 1 zero_lt_one he - have h2 : Tendsto (fun i => bp (-N i/2)) atTop (𝓝 0) := by - have hq := hh 0 (1/2) (by norm_num) he - refine (tendsto_congr' ?_).mp hq - exact .of_forall (fun n => by unfold N; simp only [zero_sub]; congr 1; ring) - have h3 := (((h1.const_mul 2).const_mul (num (Ports p))).const_mul (2*W)).add - ((h2.const_add d).const_mul W) - simpa only [mul_zero,zero_add,add_zero,f,z,N,one_mul] using h3.add hz - have hh₂ : W*dhw i.2) - (fun i=>hz i.2) _ hi - change pr ρ _ ≤ _ at h4 - have hh (x) : (panels v).sampleAll (chairpan w) (clue v j T U) x=g x := - Eq.symm (congr_fun (clue_crane ..) x) - - have hh' : (panels v).sampleAll (chairpan w) (clue v j T U)=g := funext hh - change pr ρ (fun x => E≤ |(panels v).sampleAll (chairpan w) (clue v j T U) x- - avg (pairW μ μ) ((panels v).sampleAll (chairpan w) (clue v j T U))|)≤_ at h4 - rw [hh'] at h4 - apply (pr_mono hρ.nz ?_).trans h4 - rintro i ⟨b,hb,hv⟩ - have ht := shaft v j U T w b hw hb i - have hG : avg (pairW μ μ) g ≤ E := (le_abs_self _).trans (hm.trans hq.le) - have hy : ε^4 ≤ g i := (pow_le_pow_left₀ hε.le hv.le 4).trans ht - exact le_trans (show E ≤ g i-avg (pairW μ μ) g from by unfold E at *; linarith only [hG,hy]) - (le_abs_self _) -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FourCornerTrials + +namespace OAI + +/-! # Cut Integral Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real Matrix Function Filter +open scoped BigOperators Topology +variable {p : Shape} {n N M : ℕ} {I A : Type} [Fintype I] [DecidableEq I] [Fintype A] + +def chairpan (p : I→Wgt A) (x : Bool×I) := p x.2 +def reparse (I A : Type) : (Bool×I→ A)≃ (I→A) × (I→A) := + (show (_:Type)≃(Bool→I→A) from ⟨curry,uncurry,fun _=>rfl,fun _=>rfl⟩).trans (wingpair _) + +theorem chairpan_law (p : I→Wgt A) : + mapW (prodW (chairpan p)) (reparse I A)=pairW (prodW p) (prodW p) := by + classical + funext i + obtain ⟨i,rfl⟩ := (reparse I A).surjective i + rw [mapW_equiv_val,Equiv.symm_apply_apply]; unfold pairW prodW + rw [Fintype.prod_prod_type,Fintype.prod_bool]; rfl +namespace Template +variable (v : Template p I) + +def panels (v : Template p I) := collect p v (Prod.snd : Bool × I → I) +def rekeys (v : Template p I) (k : Keys (p:=p) v.panels.t N) : + Keys (p:=p) v.t N ×Keys (p:=p) v.t N := (fun i=>k (true,i),fun i=>k (false,i)) + +def clue (v : Template p I) (j : I) (T : Wgt (Inputs p n I)) (U : Wgt (Keys (p:=p) v.t N)) + (x : Inputs p n (Bool × I)) (y : Keys (p:=p) v.panels.t N) := + quart (chairI v j n) T (reparse _ _ x)*quart (chairK v j N) U (rekeys v y) + +theorem clue_crane (v : Template p I) (j : I) (T : Wgt (Inputs p n I)) (U : Wgt (Keys + (p:=p) v.t N)) (w : I→ Wgt (Knobs p.g n)) : + crane v j T U w=v.panels.sampleAll (chairpan w) (clue v j T U) := by + classical + funext i + unfold crane; dsimp only + rw [←chairpan_law w,mapW_avg]; unfold sampleAll + refine avg_congr fun k hk => ?_ + rw [quart_prot]; rfl + +def scene (v : Template p I) (T : Wgt (Inputs p n I)) (U : Wgt (Keys (p:=p) v.t N)) + (w f : I→ Wgt (Knobs p.g n)) (o : UnitType p n N) := + avg (prodW w) (fun x => protean v T U o x * prodW f x) + +def blackout (v : Template p I) (T : Wgt (Inputs p n I)) (U : Wgt (Keys (p:=p) v.t N)) + (w : I→Wgt (Knobs p.g n)) (ε : ℝ) (o : UnitType p n N) := + ∃ f:I→Wgt (Knobs p.g n),(∀ i j,|f i j|≤1) ∧ ε < |scene v T U w f o| + +theorem shaft (v : Template p I) (j : I) (U : Wgt (Keys (p:=p) v.t N)) + (T : Wgt (Inputs p n I)) (w f : I→ Wgt (Knobs p.g n)) (hw : ∀ i,IsLaw (w i)) + (hf : ∀ i j,|f i j|≤1) (o : UnitType p n N) : + |scene v T U w f o|^4 ≤ crane v j T U w o := by + classical + let D (i : Aside j) := f i.val + have h0 i : |prodW D i|≤1 := by + unfold prodW; rw [abs_prod]; exact (prod_le_prod₀ (fun i _=>abs_nonneg _) (fun i _=>hf _ _)).trans_eq + (by simp) + have he (i : Inputs p n I) : + prodW f i=f j (i j)*prodW D ((chairI v j n i).2) := chair_split f i j + unfold scene; simp_rw [he] + exact quart_CS (chairI v j n) _ _ _ _ (chair_weight w j) (hw j) + (prodW_law fun i:Aside j=> hw i.val) (f j) (prodW D) (hf j) h0 + +set_option maxHeartbeats 1200000 in +theorem shade_calendar (v : Template p I) (j : I) (M : ℕ) (hM : 1≤M) + (C ε : ℝ) (hε : 0<ε) : + ∃ δ : ℝ,0<δ ∧ ∀ᶠ n : ℕ in atTop, + let N := M*n + ∀ (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) (T : Wgt (Inputs p n I)) + (w : I→Wgt (Knobs p.g n)), (∀ x, |U x|≤1) → chairCut v j U δ → + carried U (ownPart (p:=p) v.t q) → + (∀ x, |T x|≤1) → (∀ i,IsLaw (w i)) → + (∀ i,mapW (w i) (freePart p)=unif) → + ∀ (m : Mixer p n), 2*num (Full p n)f (M*n)+z n) atTop (𝓝 (W*d)) := by + have hh (c : ℝ) (C : ℝ) (hC : 0 bp (c-C*v i)) atTop (𝓝 0) := by + simp_rw [sub_eq_add_neg,bp_add, ← neg_mul] + simpa using ((bp_tendsto_zero hC).comp hv).const_mul (bp c) + let N (i : ℕ) := (↑(M*i):ℝ) + have he := cast_tops M hM + have hz := hh (num Bool*num I) 1 zero_lt_one (v:=fun n:ℕ=>(n:ℝ)) tendsto_natCast_atTop_atTop + have h1 := hh k 1 zero_lt_one he + have h2 : Tendsto (fun i => bp (-N i/2)) atTop (𝓝 0) := by + have hq := hh 0 (1/2) (by norm_num) he + refine (tendsto_congr' ?_).mp hq + exact .of_forall (fun n => by unfold N; simp only [zero_sub]; congr 1; ring) + have h3 := (((h1.const_mul 2).const_mul (num (Ports p))).const_mul (2*W)).add + ((h2.const_add d).const_mul W) + simpa only [mul_zero,zero_add,add_zero,f,z,N,one_mul] using h3.add hz + have hh₂ : W*dhw i.2) + (fun i=>hz i.2) _ hi + change pr ρ _ ≤ _ at h4 + have hh (x) : (panels v).sampleAll (chairpan w) (clue v j T U) x=g x := + Eq.symm (congr_fun (clue_crane ..) x) + + have hh' : (panels v).sampleAll (chairpan w) (clue v j T U)=g := funext hh + change pr ρ (fun x => E≤ |(panels v).sampleAll (chairpan w) (clue v j T U) x- + avg (pairW μ μ) ((panels v).sampleAll (chairpan w) (clue v j T U))|)≤_ at h4 + rw [hh'] at h4 + apply (pr_mono hρ.nz ?_).trans h4 + rintro i ⟨b,hb,hv⟩ + have ht := shaft v j U T w b hw hb i + have hG : avg (pairW μ μ) g ≤ E := (le_abs_self _).trans (hm.trans hq.le) + have hy : ε^4 ≤ g i := (pow_le_pow_left₀ hε.le hv.le 4).trans ht + exact le_trans (show E ≤ g i-avg (pairW μ μ) g from by unfold E at *; linarith only [hG,hy]) + (le_abs_self _) +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/DependentPairConcentration.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/DependentPairConcentration.lean index 6752f44e7c21bedea3dadc5bb1336d28c8691122..46234a4cab68099546af0066cd22b831b6c83446 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/DependentPairConcentration.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/DependentPairConcentration.lean @@ -1,136 +1,136 @@ -import OAI.Combinatorics.HadwigerCounterexample.QueryConcentration - -namespace OAI - -/-! # Dependent Pair Concentration -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Finset Function -open scoped BigOperators -variable {X Y A B : Type} [Fintype X] [Fintype Y] [Fintype A] [Fintype B] - -theorem outlier {w : Wgt A} (hw : ∀ x, 0 ≤ w x) - {f : Wgt A} (m : ℝ) (c : ℝ) (hc : 0 < c) {d : ℝ} - (h : avg w (fun x => (f x-m)^2)≤d) : - pr w (fun x => c≤|f x-m|) ≤ d/c^2 := by - refine (le_div_iff₀ (pow_pos hc 2)).mpr ?_ - rw [mul_comm] - let g (x : A) := (f x-m)^2 - have hg x (h : c≤ |f x-m|) : c^2 ≤ g x := by - unfold g; exact (pow_le_pow_left₀ hc.le h 2).trans_eq (sq_abs _) - exact ((mul_le_mul_of_nonneg_left (pr_mono hw hg) (sq_nonneg c)).trans - (le_avg_markov hw (fun x => sq_nonneg (f x-m)) _)).trans h - -def approxData (μ : Wgt X) (f : X→ Wgt A) (c d : ℝ) := - ∀ h : Wgt A,(∀ x,|h x|≤1) → - pr μ (fun x => c ≤ |avg (f x) h-avg (mixW μ f) h|)≤d - -def thinData (μ : Wgt X) (f : X→ Wgt A) (τ c d : ℝ) := - ∀ P : A → Prop,pr (mixW μ f) P≤τ → pr μ (fun x => c≤pr (f x) P)≤d - -omit [Fintype A] [Fintype B] in -theorem mix_data (f : X → Wgt A) (g : Y → Wgt B) (u : Wgt X) (v : Wgt Y) : - mixW (pairW u v) (fun x => pairW (f x.1) (g x.2))=pairW (mixW u f) (mixW v g) := by - classical - funext i - unfold mixW - exact pairW_separate u (fun j => f j i.1) v (fun j => g j i.2) - -set_option maxHeartbeats 800000 in -theorem paired_spread {μ : Wgt X} {ν : Wgt Y} {w : Wgt (X×Y)} - (F : Wgt (A×B)) (f : X→ Wgt A) (g : Y→Wgt B) - (hμ : IsLaw μ) (hν : IsLaw ν) (hw : IsLaw w) - (hf : ∀ x, IsLaw (f x)) (hg : ∀ x,IsLaw (g x)) - (hF : ∀ x, |F x|≤1) - (η d e τ : ℝ) (hη : 0<η) (hτ : 0<τ) (he : 0 ≤ e) - (hA : approxData μ f η d) (hB : approxData ν g η d) (hQ : thinData ν g τ η e) - (L H : ℝ) (hL : 0≤L) (hH : 0≤H) - (hwA : ∀ x,mapW w Prod.fst x≤ L*μ x) (hwB : ∀ x,mapW w Prod.snd x≤ L*ν x) - (h : ∀ x,w x≤H *pairW μ ν x) : - let M x := avg (pairW (f x.1) (g x.2)) F - pr w (fun x : X×Y => 5*η ≤|M x-avg (pairW μ ν) M|) ≤ L*(d+d/τ)+H*e := by - classical - let M (x : X × Y) := avg (pairW (f x.1) (g x.2)) F - let pA := mixW μ f; let pB := mixW ν g - have hpB := mixW_law hν hg - let hfun (y : B) (x : A) := F (x,y) - have hf1 y x : |hfun y x|≤1 := hF (x,y) - let Lfun (y : B) := avg pA (hfun y) - let Lx (x : X) (y : B) := avg (f x) (hfun y) - have h1 {w : Wgt A} (hw : IsLaw w) y : - |avg w (hfun y)| ≤1 := avg_bound1 hw _ (hf1 _) - have hLa (x y) : |Lx x y|≤1 := h1 (hf x) y - have hLb (y) : |Lfun y|≤1 := h1 (mixW_law hμ hf) y - let bad (x : X) (y : B) := η ≤ |Lx x y-Lfun y| - let Q (x : X) := τ ≤ pr pB (bad x) - have h2 : pr μ Q≤d/τ := by - have he' : avg μ (fun x => pr pB (bad x)) ≤ d := by - unfold pr - rw [avg_avg] - exact hpB.avg_le (fun i => hA _ (hf1 i)) - apply (le_div_iff₀ hτ).mpr - rw [mul_comm] - exact le_trans (le_avg_markov hμ.nz (fun x => pr_nonneg - (p:=bad x) hpB.nz) _) he' - let R (y : Y) := η≤|avg (g y) Lfun-avg pB Lfun| - have hR : pr ν R ≤ d := hB _ hLb - let S := fun x : X×Y => ¬Q x.1 ∧ η ≤ pr (g x.2) (bad x.1) - have hS : pr (pairW μ ν) S≤ e := by - rw [pr,pairW_avg] - refine hμ.avg_le (fun x => ?_) - by_cases h : Q x - · unfold S; simp only [h,not_true_eq_false,false_and,ind_false,avg_zero] - exact he - unfold S - simp only [h,not_false_eq_true,true_and] - exact hQ (bad x) (le_of_not_ge h) - have ha (x : X × Y) (hh : ¬ (Q x.1 ∨ R x.2 ∨ S x)) : - ¬ (5*η ≤|M x-avg (pairW μ ν) M|) := by - have hy := not_or.mp hh - have ht : pr (g x.2) (bad x.1) < η := lt_of_not_ge fun h => - (not_or.mp hy.2).2 ⟨hy.1,h⟩ - have hW y : |Lx x.1 y-Lfun y| ≤ η+2*ind (bad x.1 y) := by - by_cases he' : bad x.1 y - · rw [ind_one he',mul_one] - exact (abs_sub ..).trans ((add_le_add (hLa ..) (hLb y)).trans (by linarith only [hη])) - · rw [ind_zero he',mul_zero,add_zero]; exact le_of_not_ge he' - have hW' : - |avg (g x.2) (Lx x.1)-avg (g x.2) Lfun|<3*η := by - rw [←avg_sub] - apply lt_of_le_of_lt ((abs_avg_le (hg _).nz).trans (avg_mono (hg _).nz hW)) - rw [avg_add,(hg _).avg_const,avg_mul'] - unfold pr at ht; linarith only [ht] - have hr : |avg (g x.2) Lfun -avg pB Lfun|<η := lt_of_not_ge ((not_or.mp hy.2).1) - have eq1 (x : X×Y) : M x=avg (g x.2) (Lx x.1) := by - unfold M; rw [pairW_avg,avg_avg] - have eq2 : - avg (pairW μ ν) M=avg pB Lfun := by - rw [show avg (pairW μ ν) M= _ from (mixW_avg _ (fun x : X × Y => pairW (f x.1) (g x.2)) F).symm] - rw [mix_data,pairW_avg,avg_avg] - rw [eq1,eq2] - apply not_le_of_gt - exact ((abs_sub_le ..).trans_lt ((add_lt_add hW' hr).trans (by linarith))) - have hh x : - 5*η ≤ |M x-avg (pairW μ ν) M| → Q x.1 ∨ R x.2 ∨ S x := - fun hz => Classical.byContradiction (fun h => ha x h hz) - have hW : pr w (Q ∘ Prod.fst) ≤ L*(d/τ) := by - simp only [comp_def] - rw [show pr w _=pr (mapW w Prod.fst) Q from (mapW_pr w Prod.fst Q).symm] - exact (pr_cap hwA _).trans (mul_le_mul_of_nonneg_left h2 hL) - have hT : pr w (R ∘ Prod.snd) ≤ L*d := by - simp only [comp_def] - rw [show pr w _=pr (mapW w Prod.snd) R from (mapW_pr w Prod.snd R).symm] - exact (pr_cap hwB _).trans (mul_le_mul_of_nonneg_left hR hL) - have hG : pr w S ≤ H*e := (pr_cap h _).trans (mul_le_mul_of_nonneg_left hS hH) - change pr w _ ≤ _ - apply le_trans (pr_mono hw.nz hh) - apply le_trans (pr_or_le (p:=Q ∘ Prod.fst) (q:=fun x => R x.2 ∨ S x) hw.nz) - apply (add_le_add hW ((pr_or_le (p:=R ∘ Prod.snd) (q:=S) hw.nz).trans (add_le_add hT hG))).trans - linarith - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.QueryConcentration + +namespace OAI + +/-! # Dependent Pair Concentration -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Finset Function +open scoped BigOperators +variable {X Y A B : Type} [Fintype X] [Fintype Y] [Fintype A] [Fintype B] + +theorem outlier {w : Wgt A} (hw : ∀ x, 0 ≤ w x) + {f : Wgt A} (m : ℝ) (c : ℝ) (hc : 0 < c) {d : ℝ} + (h : avg w (fun x => (f x-m)^2)≤d) : + pr w (fun x => c≤|f x-m|) ≤ d/c^2 := by + refine (le_div_iff₀ (pow_pos hc 2)).mpr ?_ + rw [mul_comm] + let g (x : A) := (f x-m)^2 + have hg x (h : c≤ |f x-m|) : c^2 ≤ g x := by + unfold g; exact (pow_le_pow_left₀ hc.le h 2).trans_eq (sq_abs _) + exact ((mul_le_mul_of_nonneg_left (pr_mono hw hg) (sq_nonneg c)).trans + (le_avg_markov hw (fun x => sq_nonneg (f x-m)) _)).trans h + +def approxData (μ : Wgt X) (f : X→ Wgt A) (c d : ℝ) := + ∀ h : Wgt A,(∀ x,|h x|≤1) → + pr μ (fun x => c ≤ |avg (f x) h-avg (mixW μ f) h|)≤d + +def thinData (μ : Wgt X) (f : X→ Wgt A) (τ c d : ℝ) := + ∀ P : A → Prop,pr (mixW μ f) P≤τ → pr μ (fun x => c≤pr (f x) P)≤d + +omit [Fintype A] [Fintype B] in +theorem mix_data (f : X → Wgt A) (g : Y → Wgt B) (u : Wgt X) (v : Wgt Y) : + mixW (pairW u v) (fun x => pairW (f x.1) (g x.2))=pairW (mixW u f) (mixW v g) := by + classical + funext i + unfold mixW + exact pairW_separate u (fun j => f j i.1) v (fun j => g j i.2) + +set_option maxHeartbeats 800000 in +theorem paired_spread {μ : Wgt X} {ν : Wgt Y} {w : Wgt (X×Y)} + (F : Wgt (A×B)) (f : X→ Wgt A) (g : Y→Wgt B) + (hμ : IsLaw μ) (hν : IsLaw ν) (hw : IsLaw w) + (hf : ∀ x, IsLaw (f x)) (hg : ∀ x,IsLaw (g x)) + (hF : ∀ x, |F x|≤1) + (η d e τ : ℝ) (hη : 0<η) (hτ : 0<τ) (he : 0 ≤ e) + (hA : approxData μ f η d) (hB : approxData ν g η d) (hQ : thinData ν g τ η e) + (L H : ℝ) (hL : 0≤L) (hH : 0≤H) + (hwA : ∀ x,mapW w Prod.fst x≤ L*μ x) (hwB : ∀ x,mapW w Prod.snd x≤ L*ν x) + (h : ∀ x,w x≤H *pairW μ ν x) : + let M x := avg (pairW (f x.1) (g x.2)) F + pr w (fun x : X×Y => 5*η ≤|M x-avg (pairW μ ν) M|) ≤ L*(d+d/τ)+H*e := by + classical + let M (x : X × Y) := avg (pairW (f x.1) (g x.2)) F + let pA := mixW μ f; let pB := mixW ν g + have hpB := mixW_law hν hg + let hfun (y : B) (x : A) := F (x,y) + have hf1 y x : |hfun y x|≤1 := hF (x,y) + let Lfun (y : B) := avg pA (hfun y) + let Lx (x : X) (y : B) := avg (f x) (hfun y) + have h1 {w : Wgt A} (hw : IsLaw w) y : + |avg w (hfun y)| ≤1 := avg_bound1 hw _ (hf1 _) + have hLa (x y) : |Lx x y|≤1 := h1 (hf x) y + have hLb (y) : |Lfun y|≤1 := h1 (mixW_law hμ hf) y + let bad (x : X) (y : B) := η ≤ |Lx x y-Lfun y| + let Q (x : X) := τ ≤ pr pB (bad x) + have h2 : pr μ Q≤d/τ := by + have he' : avg μ (fun x => pr pB (bad x)) ≤ d := by + unfold pr + rw [avg_avg] + exact hpB.avg_le (fun i => hA _ (hf1 i)) + apply (le_div_iff₀ hτ).mpr + rw [mul_comm] + exact le_trans (le_avg_markov hμ.nz (fun x => pr_nonneg + (p:=bad x) hpB.nz) _) he' + let R (y : Y) := η≤|avg (g y) Lfun-avg pB Lfun| + have hR : pr ν R ≤ d := hB _ hLb + let S := fun x : X×Y => ¬Q x.1 ∧ η ≤ pr (g x.2) (bad x.1) + have hS : pr (pairW μ ν) S≤ e := by + rw [pr,pairW_avg] + refine hμ.avg_le (fun x => ?_) + by_cases h : Q x + · unfold S; simp only [h,not_true_eq_false,false_and,ind_false,avg_zero] + exact he + unfold S + simp only [h,not_false_eq_true,true_and] + exact hQ (bad x) (le_of_not_ge h) + have ha (x : X × Y) (hh : ¬ (Q x.1 ∨ R x.2 ∨ S x)) : + ¬ (5*η ≤|M x-avg (pairW μ ν) M|) := by + have hy := not_or.mp hh + have ht : pr (g x.2) (bad x.1) < η := lt_of_not_ge fun h => + (not_or.mp hy.2).2 ⟨hy.1,h⟩ + have hW y : |Lx x.1 y-Lfun y| ≤ η+2*ind (bad x.1 y) := by + by_cases he' : bad x.1 y + · rw [ind_one he',mul_one] + exact (abs_sub ..).trans ((add_le_add (hLa ..) (hLb y)).trans (by linarith only [hη])) + · rw [ind_zero he',mul_zero,add_zero]; exact le_of_not_ge he' + have hW' : + |avg (g x.2) (Lx x.1)-avg (g x.2) Lfun|<3*η := by + rw [←avg_sub] + apply lt_of_le_of_lt ((abs_avg_le (hg _).nz).trans (avg_mono (hg _).nz hW)) + rw [avg_add,(hg _).avg_const,avg_mul'] + unfold pr at ht; linarith only [ht] + have hr : |avg (g x.2) Lfun -avg pB Lfun|<η := lt_of_not_ge ((not_or.mp hy.2).1) + have eq1 (x : X×Y) : M x=avg (g x.2) (Lx x.1) := by + unfold M; rw [pairW_avg,avg_avg] + have eq2 : + avg (pairW μ ν) M=avg pB Lfun := by + rw [show avg (pairW μ ν) M= _ from (mixW_avg _ (fun x : X × Y => pairW (f x.1) (g x.2)) F).symm] + rw [mix_data,pairW_avg,avg_avg] + rw [eq1,eq2] + apply not_le_of_gt + exact ((abs_sub_le ..).trans_lt ((add_lt_add hW' hr).trans (by linarith))) + have hh x : + 5*η ≤ |M x-avg (pairW μ ν) M| → Q x.1 ∨ R x.2 ∨ S x := + fun hz => Classical.byContradiction (fun h => ha x h hz) + have hW : pr w (Q ∘ Prod.fst) ≤ L*(d/τ) := by + simp only [comp_def] + rw [show pr w _=pr (mapW w Prod.fst) Q from (mapW_pr w Prod.fst Q).symm] + exact (pr_cap hwA _).trans (mul_le_mul_of_nonneg_left h2 hL) + have hT : pr w (R ∘ Prod.snd) ≤ L*d := by + simp only [comp_def] + rw [show pr w _=pr (mapW w Prod.snd) R from (mapW_pr w Prod.snd R).symm] + exact (pr_cap hwB _).trans (mul_le_mul_of_nonneg_left hR hL) + have hG : pr w S ≤ H*e := (pr_cap h _).trans (mul_le_mul_of_nonneg_left hS hH) + change pr w _ ≤ _ + apply le_trans (pr_mono hw.nz hh) + apply le_trans (pr_or_le (p:=Q ∘ Prod.fst) (q:=fun x => R x.2 ∨ S x) hw.nz) + apply (add_le_add hW ((pr_or_le (p:=R ∘ Prod.snd) (q:=S) hw.nz).trans (add_le_add hT hG))).trans + linarith + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/DerivativeCompression.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/DerivativeCompression.lean index 97ad967b09369becc15146196cfad4615b1189dc..d078f96718a8c212374d36ed7e4d4bc963dbdbb5 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/DerivativeCompression.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/DerivativeCompression.lean @@ -1,150 +1,150 @@ -import OAI.Combinatorics.HadwigerCounterexample.ResponseSolvability - -namespace OAI - -/-! # Derivative Compression -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule -open scoped BigOperators -variable {I J : Type} [Fintype I] [Fintype J] - -theorem mat_mul_fix {A : Mat I I} {B : Mat I J} (h : ∀ x∈colSp B,A *ᵥ x=x) : - A*B=B := by - apply coe_mv_inj - refine LinearMap.ext fun x => ?_ - change _ *ᵥ x=_ *ᵥ _ - rw [← Matrix.mulVec_mulVec]; exact h (B *ᵥ x) ⟨x,rfl⟩ - -/-- Endomorphism taking V into V, preserving dot product against S, -of rank bounded by the observer space S. -/ -private theorem compress_observer (V S : Space (Vec I)) : - ∃ A : Mat I I,(∀ v∈V,A *ᵥ v∈V) ∧ - (∀ v∈V,∀ y∈S, dotProduct y (A *ᵥ v) = dotProduct y v) ∧ - A.rank≤dim S := by - classical - obtain ⟨Q,hQ⟩ := mat_left_inv (pack_inj V) - let P := (pack S)ᵀ * pack V - obtain ⟨B,hB⟩ := proj_exists (colSp Pᵀ) ⊥ disjoint_bot_right - let A := pack V * Bᵀ * Q - have hh (t) : A *ᵥ (pack V *ᵥ t)=pack V *ᵥ (Bᵀ *ᵥ t) := by - simp only [A,← Matrix.mulVec_mulVec] - rw [Matrix.mulVec_mulVec t Q,hQ, Matrix.one_mulVec] - refine ⟨A,fun x hx => ?_,fun x hx y hy => ?_,?_⟩ - · obtain ⟨t,rfl⟩ := (pack_mem_iff x _).mp hx - rw [hh] - exact (pack_mem_iff ..).mpr ⟨_,rfl⟩ - · obtain ⟨t,rfl⟩ := (pack_mem_iff x _).mp hx - obtain ⟨u,rfl⟩ := (pack_mem_iff y _).mp hy - rw [hh] - have he : P * Bᵀ=P := by - have h1 := congrArg Matrix.transpose (mat_mul_fix (A:=B) hB.fixes) - simpa only [transpose_mul,transpose_transpose] using h1 - have hg (t') : dotProduct (pack S *ᵥ u) (pack V *ᵥ t')=dotProduct u (P *ᵥ t') := by - rw [show P=_*_ from rfl,← Matrix.mulVec_mulVec,dotProduct_transpose_mulVec,dotProduct_comm] - rw [hg,hg,Matrix.mulVec_mulVec,he] - · refine ((Matrix.rank_mul_le_left ..).trans (Matrix.rank_mul_le_right ..)).trans ?_ - rw [Matrix.rank_transpose] - exact (rank_maps (colSp Pᵀ) hB.onto).trans (by - rw [colSp_dim,Matrix.rank_transpose] - exact P.rank_le_card_height.trans_eq (Fintype.card_fin _)) - -variable {p : Shape} {n : ℕ} -def priOut (p : Shape) {n} (C : ChanOut p n) (z : Place p) : Space (Vec (Chan p)) := - colSp (C z * IP p n true) ⊔ colSp (C z * IP p n false) -def outSmall (H : ℕ) {p : Shape} {n} (C : ChanOut p n) := - ∀ (z : Place p) i,(C z * IP p n i).rank≤H - -theorem le_priOut (C : ChanOut p n) (z : Place p) (i) : - colSp (C z * IP p n i)≤priOut p C z := by - cases i; exact le_sup_right; exact le_sup_left -theorem dim_priOut {C : ChanOut p n} {H} (h : outSmall H C) (z : Place p) : - dim (priOut p C z) ≤2*H := by - rw [two_mul] - exact (Submodule.finrank_add_le_finrank_add_finrank ..).trans (Nat.add_le_add (h z true) (h z false)) - -theorem outSmall_low {B : Cross p n} {H} (h : lowCross H B) (j : Bool) : - outSmall H (channelOut p B j) := by - intro z i - rw [channelOut, Matrix.transpose_mul,Matrix.mul_assoc] - exact (Matrix.rank_mul_le_right ..).trans (h z i) - -theorem ev_duom {K : Type} [Fintype K] (P : Mat K I) (Q : Mat K J) (v : Vec I) - (w : Vec J) : - evmat (Pᵀ*Q) v w = dotProduct (P *ᵥ v) (Q *ᵥ w) := by - rw [evmat,← Matrix.mulVec_mulVec,dotProduct_transpose_mulVec,dotProduct_comm] - -theorem deriv_compress {C D : ChanOut p n} {f b : Plan p n} {j : Bool} {H} - (h : outSmall H C) (hd : D∈deltaSpace p f b j) : - ∃ B∈deltaSpace p f b j,(∀ z,(B z).rank ≤2*H) ∧ - obsPair p (chanDeriv p C D)=obsPair p (chanDeriv p C B) := by - classical - let S (z) := priOut p C (flipZ p z) - let V (z) := annih (hPin b (flipZ p z) j) - choose A hA hS hT using fun z => compress_observer (V z) (S z) - let B := fun z : Place p => A z * D z - have he z : colSp (D z) ≤ V z ∧ colSp (D z)ᵀ≤ annih (f z) := - (box_mem ..).mp ((deltaSpace_mem _).mp hd z) - refine ⟨B,(deltaSpace_mem _).mpr ?_,fun z => ?_,?_⟩ - · intro z - rw [box_mem] - constructor - · rintro x ⟨y,rfl⟩ - rw [mulVecLin_apply] - unfold B; rw [← mulVec_mulVec] - exact hA z _ ((he z).1 ⟨y,rfl⟩) - · rw [colSp_kill,transpose_transpose] - intro x hx - have h1 : D z *ᵥ x=0 := (box_kill.mp ((deltaSpace_mem _).mp hd z)).2 _ hx - rw [show B z=A z * D z from rfl,←mulVec_mulVec,h1,Matrix.mulVec_zero] - · exact (Matrix.rank_mul_le_left ..).trans ((hT z).trans (dim_priOut h (flipZ p z))) - · rw [obsPair_each,obsPair_each] - have hE (z : Place p) (i l : Bool) (x y : Ray p n) : - dotProduct ((C (flipZ p z) * IP p n i) *ᵥ x) ((B z * IP p n l) *ᵥ y)= - dotProduct ((C (flipZ p z) * IP p n i) *ᵥ x) ((D z * IP p n l) *ᵥ y) := by - let u := (C (flipZ p z)* IP p n i)*ᵥ x - have hu : u∈S z := le_priOut _ _ _ ⟨x,rfl⟩ - let v := D z *ᵥ (IP p n l *ᵥ y) - have hv : v∈V z := (he z).1 ⟨_,rfl⟩ - unfold B - unfold u at hu - rw [← Matrix.mulVec_mulVec] at hu - simp only [← Matrix.mulVec_mulVec] - exact hS z _ hv _ hu - have h1 : eachF p (chanInner p C B)=eachF p (chanInner p C D) := by - funext i e - rw [each_chan_val, each_chan_val] - refine evmat_ext fun x y => ?_ - rw [ev_duom, ev_duom] - exact hE (e,false) i i x y - have h2 : eachF p (chanInner p B C)=eachF p (chanInner p D C) := by - funext i e - rw [each_chan_val,each_chan_val] - refine evmat_ext fun x y => ?_ - rw [ev_duom,ev_duom,dotProduct_comm,dotProduct_comm ((D _ * IP p n i) *ᵥ x)] - exact hE (e,true) i i y x - rw [chanDeriv,chanDeriv,map_add,map_add,h1,h2] - -theorem chanInner_pure {C D : ChanOut p n} {f b : Plan p n} {j : Bool} - (h : C∈deltaSpace p f b j) (h' : D∈deltaSpace p f b j) : - chanInner p C D∈pureSpace p f := by - classical - refine (pureSpace_mem _).mpr (fun e => ?_) - have h1 : ∀ x ∈ f (e,true), C (e,true) *ᵥ x=0 := - (box_kill.mp ((deltaSpace_mem _).mp h _)).2 - have h2 : ∀ x ∈ f (e,false), D (e,false) *ᵥ x=0 := - (box_kill.mp ((deltaSpace_mem _).mp h' _)).2 - rw [box_kill] - constructor - · intro x hx - unfold chanInner - rw [Matrix.transpose_mul,Matrix.transpose_transpose,←mulVec_mulVec,h1 x hx,mulVec_zero] - intro x hx - unfold chanInner; rw [←mulVec_mulVec,h2 x hx,mulVec_zero] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ResponseSolvability + +namespace OAI + +/-! # Derivative Compression -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule +open scoped BigOperators +variable {I J : Type} [Fintype I] [Fintype J] + +theorem mat_mul_fix {A : Mat I I} {B : Mat I J} (h : ∀ x∈colSp B,A *ᵥ x=x) : + A*B=B := by + apply coe_mv_inj + refine LinearMap.ext fun x => ?_ + change _ *ᵥ x=_ *ᵥ _ + rw [← Matrix.mulVec_mulVec]; exact h (B *ᵥ x) ⟨x,rfl⟩ + +/-- Endomorphism taking V into V, preserving dot product against S, +of rank bounded by the observer space S. -/ +private theorem compress_observer (V S : Space (Vec I)) : + ∃ A : Mat I I,(∀ v∈V,A *ᵥ v∈V) ∧ + (∀ v∈V,∀ y∈S, dotProduct y (A *ᵥ v) = dotProduct y v) ∧ + A.rank≤dim S := by + classical + obtain ⟨Q,hQ⟩ := mat_left_inv (pack_inj V) + let P := (pack S)ᵀ * pack V + obtain ⟨B,hB⟩ := proj_exists (colSp Pᵀ) ⊥ disjoint_bot_right + let A := pack V * Bᵀ * Q + have hh (t) : A *ᵥ (pack V *ᵥ t)=pack V *ᵥ (Bᵀ *ᵥ t) := by + simp only [A,← Matrix.mulVec_mulVec] + rw [Matrix.mulVec_mulVec t Q,hQ, Matrix.one_mulVec] + refine ⟨A,fun x hx => ?_,fun x hx y hy => ?_,?_⟩ + · obtain ⟨t,rfl⟩ := (pack_mem_iff x _).mp hx + rw [hh] + exact (pack_mem_iff ..).mpr ⟨_,rfl⟩ + · obtain ⟨t,rfl⟩ := (pack_mem_iff x _).mp hx + obtain ⟨u,rfl⟩ := (pack_mem_iff y _).mp hy + rw [hh] + have he : P * Bᵀ=P := by + have h1 := congrArg Matrix.transpose (mat_mul_fix (A:=B) hB.fixes) + simpa only [transpose_mul,transpose_transpose] using h1 + have hg (t') : dotProduct (pack S *ᵥ u) (pack V *ᵥ t')=dotProduct u (P *ᵥ t') := by + rw [show P=_*_ from rfl,← Matrix.mulVec_mulVec,dotProduct_transpose_mulVec,dotProduct_comm] + rw [hg,hg,Matrix.mulVec_mulVec,he] + · refine ((Matrix.rank_mul_le_left ..).trans (Matrix.rank_mul_le_right ..)).trans ?_ + rw [Matrix.rank_transpose] + exact (rank_maps (colSp Pᵀ) hB.onto).trans (by + rw [colSp_dim,Matrix.rank_transpose] + exact P.rank_le_card_height.trans_eq (Fintype.card_fin _)) + +variable {p : Shape} {n : ℕ} +def priOut (p : Shape) {n} (C : ChanOut p n) (z : Place p) : Space (Vec (Chan p)) := + colSp (C z * IP p n true) ⊔ colSp (C z * IP p n false) +def outSmall (H : ℕ) {p : Shape} {n} (C : ChanOut p n) := + ∀ (z : Place p) i,(C z * IP p n i).rank≤H + +theorem le_priOut (C : ChanOut p n) (z : Place p) (i) : + colSp (C z * IP p n i)≤priOut p C z := by + cases i; exact le_sup_right; exact le_sup_left +theorem dim_priOut {C : ChanOut p n} {H} (h : outSmall H C) (z : Place p) : + dim (priOut p C z) ≤2*H := by + rw [two_mul] + exact (Submodule.finrank_add_le_finrank_add_finrank ..).trans (Nat.add_le_add (h z true) (h z false)) + +theorem outSmall_low {B : Cross p n} {H} (h : lowCross H B) (j : Bool) : + outSmall H (channelOut p B j) := by + intro z i + rw [channelOut, Matrix.transpose_mul,Matrix.mul_assoc] + exact (Matrix.rank_mul_le_right ..).trans (h z i) + +theorem ev_duom {K : Type} [Fintype K] (P : Mat K I) (Q : Mat K J) (v : Vec I) + (w : Vec J) : + evmat (Pᵀ*Q) v w = dotProduct (P *ᵥ v) (Q *ᵥ w) := by + rw [evmat,← Matrix.mulVec_mulVec,dotProduct_transpose_mulVec,dotProduct_comm] + +theorem deriv_compress {C D : ChanOut p n} {f b : Plan p n} {j : Bool} {H} + (h : outSmall H C) (hd : D∈deltaSpace p f b j) : + ∃ B∈deltaSpace p f b j,(∀ z,(B z).rank ≤2*H) ∧ + obsPair p (chanDeriv p C D)=obsPair p (chanDeriv p C B) := by + classical + let S (z) := priOut p C (flipZ p z) + let V (z) := annih (hPin b (flipZ p z) j) + choose A hA hS hT using fun z => compress_observer (V z) (S z) + let B := fun z : Place p => A z * D z + have he z : colSp (D z) ≤ V z ∧ colSp (D z)ᵀ≤ annih (f z) := + (box_mem ..).mp ((deltaSpace_mem _).mp hd z) + refine ⟨B,(deltaSpace_mem _).mpr ?_,fun z => ?_,?_⟩ + · intro z + rw [box_mem] + constructor + · rintro x ⟨y,rfl⟩ + rw [mulVecLin_apply] + unfold B; rw [← mulVec_mulVec] + exact hA z _ ((he z).1 ⟨y,rfl⟩) + · rw [colSp_kill,transpose_transpose] + intro x hx + have h1 : D z *ᵥ x=0 := (box_kill.mp ((deltaSpace_mem _).mp hd z)).2 _ hx + rw [show B z=A z * D z from rfl,←mulVec_mulVec,h1,Matrix.mulVec_zero] + · exact (Matrix.rank_mul_le_left ..).trans ((hT z).trans (dim_priOut h (flipZ p z))) + · rw [obsPair_each,obsPair_each] + have hE (z : Place p) (i l : Bool) (x y : Ray p n) : + dotProduct ((C (flipZ p z) * IP p n i) *ᵥ x) ((B z * IP p n l) *ᵥ y)= + dotProduct ((C (flipZ p z) * IP p n i) *ᵥ x) ((D z * IP p n l) *ᵥ y) := by + let u := (C (flipZ p z)* IP p n i)*ᵥ x + have hu : u∈S z := le_priOut _ _ _ ⟨x,rfl⟩ + let v := D z *ᵥ (IP p n l *ᵥ y) + have hv : v∈V z := (he z).1 ⟨_,rfl⟩ + unfold B + unfold u at hu + rw [← Matrix.mulVec_mulVec] at hu + simp only [← Matrix.mulVec_mulVec] + exact hS z _ hv _ hu + have h1 : eachF p (chanInner p C B)=eachF p (chanInner p C D) := by + funext i e + rw [each_chan_val, each_chan_val] + refine evmat_ext fun x y => ?_ + rw [ev_duom, ev_duom] + exact hE (e,false) i i x y + have h2 : eachF p (chanInner p B C)=eachF p (chanInner p D C) := by + funext i e + rw [each_chan_val,each_chan_val] + refine evmat_ext fun x y => ?_ + rw [ev_duom,ev_duom,dotProduct_comm,dotProduct_comm ((D _ * IP p n i) *ᵥ x)] + exact hE (e,true) i i y x + rw [chanDeriv,chanDeriv,map_add,map_add,h1,h2] + +theorem chanInner_pure {C D : ChanOut p n} {f b : Plan p n} {j : Bool} + (h : C∈deltaSpace p f b j) (h' : D∈deltaSpace p f b j) : + chanInner p C D∈pureSpace p f := by + classical + refine (pureSpace_mem _).mpr (fun e => ?_) + have h1 : ∀ x ∈ f (e,true), C (e,true) *ᵥ x=0 := + (box_kill.mp ((deltaSpace_mem _).mp h _)).2 + have h2 : ∀ x ∈ f (e,false), D (e,false) *ᵥ x=0 := + (box_kill.mp ((deltaSpace_mem _).mp h' _)).2 + rw [box_kill] + constructor + · intro x hx + unfold chanInner + rw [Matrix.transpose_mul,Matrix.transpose_transpose,←mulVec_mulVec,h1 x hx,mulVec_zero] + intro x hx + unfold chanInner; rw [←mulVec_mulVec,h2 x hx,mulVec_zero] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/EmpiricalInformation.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/EmpiricalInformation.lean index 0fe0a946ddfe9cd5abca1c1b8023e872379456c6..e0502d15fc4620e09f2bfa4d3b94d564db6a0223 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/EmpiricalInformation.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/EmpiricalInformation.lean @@ -1,103 +1,103 @@ -import OAI.Combinatorics.HadwigerCounterexample.MutualInformation -import OAI.Combinatorics.HadwigerCounterexample.SumRankBounds - -namespace OAI - -/-! # Empirical Information -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real -open scoped BigOperators -variable {A B C J : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype J] -variable [DecidableEq J] {l : ℕ} - -theorem draw_pick {p : Wgt B} (hp : IsLaw p) (i : J) : - mapW (draws J p) (fun x => x i)=p := by - funext b - let f := fun (_ : Unit) => i - let R := fun (_ : Unit) (j : B) => j=b - have ht := prodW_pr_inj (f.injective_of_subsingleton) (w:=fun _ => p) - (fun _ => hp) R - unfold mapW - simpa [f,R,draws] using ht -omit [Fintype B] [DecidableEq J] in -theorem draw_elem {p : Wgt B} (x : J→B) (i : J) - (h : draws J p x≠0) : p (x i)≠0 := fun hx => h (prod_eq_zero (mem_univ _) hx) - -theorem tension_traj (J : Type) [Fintype J] [DecidableEq J] - (p q : Wgt B) (hp : IsLaw p) (h : lsupp p q) : - tension (draws J p) (draws J q)=num J*tension p q := by - let Q (x : J→B) := - ∑ i:J,(log (p (x i))-log (q (x i))) - have he : tension (draws J p) (draws J q)=avg (draws J p) Q := by - refine avg_congr fun i hi => ?_ - have hp (j) := draw_elem i j hi - change log (∏ j:J,p (i j))-log (∏ j:J,q (i j))=_ - rw [log_prod (fun j _ => hp j),log_prod (fun j _ => h _ (hp j)), ← Finset.sum_sub_distrib] - let r (j : J) := fun x : J→B => log (p (x j))-log (q (x j)) - rw [he, show avg _ Q= ∑ i:J,avg (draws J p) (r i) from avg_sum ..] - have hr (i : J) : - avg (draws J p) (r i)= tension p q := by - unfold r - rw [← mapW_avg (draws J p) (fun x => x i) (fun x => log (p x)-log (q x)), draw_pick hp i] - rfl - simp only [hr,Finset.sum_const, Finset.card_univ,nsmul_eq_mul,num] - -abbrev Track (B : Type) (l : ℕ) := B→ Fin (l+1) -def traceTraj [DecidableEq B] (x : Fin l → B) : - Track B l := - fun i => ⟨(univ.filter (fun j => x j=i)).card, - Nat.lt_succ_of_le ((card_le_card (filter_subset ..)).trans_eq (by simp))⟩ - -theorem draws_trace [DecidableEq B] (p : Wgt B) (x : Fin l → B) : - draws (Fin l) p x=∏ i:B,p i^(traceTraj x i).val := by - classical - have ht (i : B) : p i^(traceTraj x i).val = - ∏ j:Fin l, if x j=i then p i else 1 := by - unfold traceTraj; rw [←Finset.prod_filter]; simp - simp_rw [ht]; rw [Finset.prod_comm] - unfold draws prodW - apply prod_congr rfl - intro i _ - simp - -theorem traj_charge (μ : Wgt A) (p : A→ Wgt B) (w : Wgt B) - (hμ : IsLaw μ) (hp : ∀ i, IsLaw (p i)) - (h : ∀ i,lsupp (p i) w) : - let f := fun i => draws (Fin l) (p i) - let q := draws (Fin l) w - (l:ℝ)*avg μ (fun i => tension (p i) w) ≤ - num B *log ((l:ℝ)+1) + tension (mixW μ f) q := by - classical - intro f q - have he : ↑l*avg μ (fun i => tension (p i) w) = - avg μ (fun i => tension (f i) q) := by - unfold f q - simp_rw [tension_traj _ _ _ (hp _) (h _),avg_mul'] - simp only [num,Fintype.card_fin] - rw [he,tension_mix] - refine add_le_add_left ?_ _ - have h0 : ∀ i,IsLaw (f i) := fun i => draws_law (hp i) - refine (banded_overhead hμ h0 traceTraj (fun i j k ht => ?_)).trans_eq ?_ - · unfold f; rw [draws_trace,draws_trace,ht] - simp only [Track,Fintype.card_fun,Fintype.card_fin,Nat.cast_pow,Real.log_pow,Nat.cast_add, - Nat.cast_one,num] - -/-- If components are coarse with no tiny positive atoms, - their repeat law has a corresponding cap cost for any submeasure. -/ -theorem traj_cap (p : Wgt B) (hp : IsLaw p) (u : ℝ) - (h : ∀ i, p i≠0 → bp (-u)≤p i) : - ∀ x, draws (Fin l) p x≠0 → bp (-u*l) ≤ draws (Fin l) p x := by - intro x hx - have hpos (i : Fin l) : 0 < p (x i) := - lt_of_le_of_ne (hp.nz _) (Ne.symm (draw_elem _ i hx)) - rw [bp_mul_nat] - refine le_trans ?_ (Finset.prod_le_prod₀ (fun i (_: i∈(univ:Finset (Fin l))) => - (bp_pos (-u)).le) fun i _ => h (x i) (hpos i).ne') - simp -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.MutualInformation +import OAI.Combinatorics.HadwigerCounterexample.SumRankBounds + +namespace OAI + +/-! # Empirical Information -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real +open scoped BigOperators +variable {A B C J : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype J] +variable [DecidableEq J] {l : ℕ} + +theorem draw_pick {p : Wgt B} (hp : IsLaw p) (i : J) : + mapW (draws J p) (fun x => x i)=p := by + funext b + let f := fun (_ : Unit) => i + let R := fun (_ : Unit) (j : B) => j=b + have ht := prodW_pr_inj (f.injective_of_subsingleton) (w:=fun _ => p) + (fun _ => hp) R + unfold mapW + simpa [f,R,draws] using ht +omit [Fintype B] [DecidableEq J] in +theorem draw_elem {p : Wgt B} (x : J→B) (i : J) + (h : draws J p x≠0) : p (x i)≠0 := fun hx => h (prod_eq_zero (mem_univ _) hx) + +theorem tension_traj (J : Type) [Fintype J] [DecidableEq J] + (p q : Wgt B) (hp : IsLaw p) (h : lsupp p q) : + tension (draws J p) (draws J q)=num J*tension p q := by + let Q (x : J→B) := + ∑ i:J,(log (p (x i))-log (q (x i))) + have he : tension (draws J p) (draws J q)=avg (draws J p) Q := by + refine avg_congr fun i hi => ?_ + have hp (j) := draw_elem i j hi + change log (∏ j:J,p (i j))-log (∏ j:J,q (i j))=_ + rw [log_prod (fun j _ => hp j),log_prod (fun j _ => h _ (hp j)), ← Finset.sum_sub_distrib] + let r (j : J) := fun x : J→B => log (p (x j))-log (q (x j)) + rw [he, show avg _ Q= ∑ i:J,avg (draws J p) (r i) from avg_sum ..] + have hr (i : J) : + avg (draws J p) (r i)= tension p q := by + unfold r + rw [← mapW_avg (draws J p) (fun x => x i) (fun x => log (p x)-log (q x)), draw_pick hp i] + rfl + simp only [hr,Finset.sum_const, Finset.card_univ,nsmul_eq_mul,num] + +abbrev Track (B : Type) (l : ℕ) := B→ Fin (l+1) +def traceTraj [DecidableEq B] (x : Fin l → B) : + Track B l := + fun i => ⟨(univ.filter (fun j => x j=i)).card, + Nat.lt_succ_of_le ((card_le_card (filter_subset ..)).trans_eq (by simp))⟩ + +theorem draws_trace [DecidableEq B] (p : Wgt B) (x : Fin l → B) : + draws (Fin l) p x=∏ i:B,p i^(traceTraj x i).val := by + classical + have ht (i : B) : p i^(traceTraj x i).val = + ∏ j:Fin l, if x j=i then p i else 1 := by + unfold traceTraj; rw [←Finset.prod_filter]; simp + simp_rw [ht]; rw [Finset.prod_comm] + unfold draws prodW + apply prod_congr rfl + intro i _ + simp + +theorem traj_charge (μ : Wgt A) (p : A→ Wgt B) (w : Wgt B) + (hμ : IsLaw μ) (hp : ∀ i, IsLaw (p i)) + (h : ∀ i,lsupp (p i) w) : + let f := fun i => draws (Fin l) (p i) + let q := draws (Fin l) w + (l:ℝ)*avg μ (fun i => tension (p i) w) ≤ + num B *log ((l:ℝ)+1) + tension (mixW μ f) q := by + classical + intro f q + have he : ↑l*avg μ (fun i => tension (p i) w) = + avg μ (fun i => tension (f i) q) := by + unfold f q + simp_rw [tension_traj _ _ _ (hp _) (h _),avg_mul'] + simp only [num,Fintype.card_fin] + rw [he,tension_mix] + refine add_le_add_left ?_ _ + have h0 : ∀ i,IsLaw (f i) := fun i => draws_law (hp i) + refine (banded_overhead hμ h0 traceTraj (fun i j k ht => ?_)).trans_eq ?_ + · unfold f; rw [draws_trace,draws_trace,ht] + simp only [Track,Fintype.card_fun,Fintype.card_fin,Nat.cast_pow,Real.log_pow,Nat.cast_add, + Nat.cast_one,num] + +/-- If components are coarse with no tiny positive atoms, + their repeat law has a corresponding cap cost for any submeasure. -/ +theorem traj_cap (p : Wgt B) (hp : IsLaw p) (u : ℝ) + (h : ∀ i, p i≠0 → bp (-u)≤p i) : + ∀ x, draws (Fin l) p x≠0 → bp (-u*l) ≤ draws (Fin l) p x := by + intro x hx + have hpos (i : Fin l) : 0 < p (x i) := + lt_of_le_of_ne (hp.nz _) (Ne.symm (draw_elem _ i hx)) + rw [bp_mul_nat] + refine le_trans ?_ (Finset.prod_le_prod₀ (fun i (_: i∈(univ:Finset (Fin l))) => + (bp_pos (-u)).le) fun i _ => h (x i) (hpos i).ne') + simp +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/EndpointEvaluations.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/EndpointEvaluations.lean index f52c17c7550ee0fac8b66d1b0af09ff365411056..9c2019d0790d9efc6f8a2955eec929fd50d1cc10 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/EndpointEvaluations.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/EndpointEvaluations.lean @@ -1,124 +1,124 @@ -import OAI.Combinatorics.HadwigerCounterexample.PairIndexedTests -import OAI.Combinatorics.HadwigerCounterexample.BinaryPrescriptions - -namespace OAI - -/-! # Endpoint Evaluations -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Function LinearMap -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] - -namespace Template -variable (v : Template p I) - -abbrev SameDuet (v : Template p I) := - {i : I×I//v.aim i.1=v.aim i.2 ∧ Fintype.equivFin I i.1 (v.verses i).1 - nextP := fun i => (v.verses i).2 - diff i := by - rcases i with i|i - · intro h; exact i.property.2.ne (congrArg (Fintype.equivFin I) h) - intro h - exact Bool.noConfusion (i.property.1.symm.trans ((congrArg v.aim h).trans i.property.2)) - once i j := by - intro hi hj - have he : v.verses i=v.verses j := Prod.ext hi hj - rcases i with i|i <;> rcases j with j|j - · exact congrArg _ (Subtype.ext (show i.val=j.val from he)) - · have hf : v.aim j.val.1=v.aim j.val.2 := (show i.val=j.val from he) ▸ i.property.1 - simp only [j.property] at hf; cases hf - · have hf : v.aim i.val.1=v.aim i.val.2 := (show j.val=i.val from he.symm) ▸ j.property.1 - simp only [i.property] at hf; cases hf - exact congrArg _ (Subtype.ext (show i.val=j.val from he)) - anti i j h h' := by - rcases i with i|i <;> rcases j with j|j <;> - change i.val.1=j.val.2 at h <;> change i.val.2=j.val.1 at h' - · have hh := i.property.2; rw [h,h'] at hh; exact (not_lt_of_gt hh) j.property.2 - · have hh := i.property.1; rw [h,h',j.property.2,j.property.1] at hh; cases hh - · have hh := j.property.1; rw [←h,←h',i.property.1,i.property.2] at hh; cases hh - have hh := i.property.1; rw [h,j.property.2] at hh; cases hh } - -abbrev Crossing (p : Shape) (i j : Tag p.g) := - {x : Notches p//inc x.1 i ∧ inc x.1 j} -abbrev Harm (p : Shape) := MBits p ⊕ Bool -def Abbey (v : Template p I) : v.Chorus → Type - | .inl _ => Harm p - | .inr x => Crossing p (v.t x.val.1) (v.t x.val.2) -instance (i : v.Chorus) : Fintype (v.Abbey i) := - i.rec (fun _ => inferInstanceAs (Fintype (Harm p))) (fun x => inferInstanceAs (Fintype - (Crossing p (v.t x.val.1) (v.t x.val.2)))) -instance (i : v.Chorus) : DecidableEq (v.Abbey i) := Classical.typeDecidableEq _ - -def monks (v : Template p I) (m : Mixer p n) (x : UnitType p n N) (i : v.Chorus) : - v.Abbey i → Moment p n := - match i with - | .inl _ => Sum.elim (fun l => eitherM l.2 (orderedM m l.1)) - (fun l => eitherM l (selfM p n m.mixM)) - | .inr _ => fun ⟨j,_⟩ => duel p (x.1 j.1) (x.2 j.1) j.2 - -def croon (v : Template p I) (i : I) := spring p (n:=n) (v.t i) (v.s i) (v.f i) - -def chime (m : Mixer p n) (x : UnitType p n N) - (i : v.Chorus) (y z : Knobs p.g n) : Vec (v.Abbey i) := - fun j => evmat (v.monks m x i j) (v.croon (v.choral.first i) y) (v.croon (v.choral.nextP i) z) - -def chorusM (m : Mixer p n) (x : UnitType p n N) - (i : v.Chorus) (y : Vec (v.Abbey i)) := ∑ j:v.Abbey i,y j • monks v m x i j - -omit [DecidableEq I] in -theorem chime_seq (m : Mixer p n) (x : UnitType p n N) (i) - (y : Vec (v.Abbey i)) (u z : Knobs p.g n) : - dotProduct y (v.chime m x i u z)=evmat (v.chorusM m x i y) - (v.croon (v.choral.first i) u) (v.croon (v.choral.nextP i) z) := by - unfold chorusM dotProduct chime - simp_rw [←mpair_outer, mpair_sum,mpair_smul] - -omit [DecidableEq I] in -theorem chorus_same (m : Mixer p n) (x : UnitType p n N) (i : v.SameDuet) - (y : Vec (v.Abbey (.inl i))) : - v.chorusM m x (.inl i) y=indexedSum m (fun j => y (Sum.inl j)) + selfSum m (fun j => y (Sum.inr j)) := by - unfold chorusM - - change ∑ j:Harm p,y j • monks v m x (.inl i) j=_ - rw [Fintype.sum_sum_type]; rfl - -set_option maxHeartbeats 600000 in -omit [DecidableEq I] in -theorem chorus_cross (m : Mixer p n) (x : UnitType p n N) (i : v.OppDuet) - (y : Vec (v.Abbey (.inr i))) (hy : y≠0) : - ∃ w : Vec (Notches p), w≠0 ∧ v.chorusM m x (.inr i) y=issue p w x := by - classical - let T (j : Notches p) := inc j.1 (v.t i.val.1)∧inc j.1 (v.t i.val.2) - let w (j : Notches p) := if h:T j then y (⟨j,h⟩ : Crossing p _ _) else 0 - have he (j : Crossing p (v.t i.val.1) (v.t i.val.2)) : w j.val=y j := dite_eq_left j.property - have hz : w≠0 := fun h => hy (funext (fun j : Crossing p _ _ => by rw [←he,h]; rfl)) - refine ⟨w,hz,?_⟩ - let f (j : Notches p) := w j • duel p (x.1 j.1) (x.2 j.1) j.2 - have h : issue p w x=∑ i : Notches p,f i := by - rw [Fintype.sum_prod_type]; rfl - rw [h] - have ht : ∑ j : {j:Notches p//T j},f j.val = ∑ j : Notches p,f j := by - let s := univ.filter T - rw [← Finset.sum_subtype s (by simp [s]) f] - refine Finset.sum_subset (subset_univ _) (fun i _ hi => ?_) - have hh : ¬T i := fun h => hi (mem_filter.mpr ⟨mem_univ _,h⟩) - unfold f w; rw [dite_eq_right hh,zero_smul] - rw [← ht] - change (∑ j:{j:Notches p//T j},_) = _ - exact Finset.sum_congr rfl fun j _ => by unfold f; rw [he]; rfl -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PairIndexedTests +import OAI.Combinatorics.HadwigerCounterexample.BinaryPrescriptions + +namespace OAI + +/-! # Endpoint Evaluations -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Function LinearMap +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] + +namespace Template +variable (v : Template p I) + +abbrev SameDuet (v : Template p I) := + {i : I×I//v.aim i.1=v.aim i.2 ∧ Fintype.equivFin I i.1 (v.verses i).1 + nextP := fun i => (v.verses i).2 + diff i := by + rcases i with i|i + · intro h; exact i.property.2.ne (congrArg (Fintype.equivFin I) h) + intro h + exact Bool.noConfusion (i.property.1.symm.trans ((congrArg v.aim h).trans i.property.2)) + once i j := by + intro hi hj + have he : v.verses i=v.verses j := Prod.ext hi hj + rcases i with i|i <;> rcases j with j|j + · exact congrArg _ (Subtype.ext (show i.val=j.val from he)) + · have hf : v.aim j.val.1=v.aim j.val.2 := (show i.val=j.val from he) ▸ i.property.1 + simp only [j.property] at hf; cases hf + · have hf : v.aim i.val.1=v.aim i.val.2 := (show j.val=i.val from he.symm) ▸ j.property.1 + simp only [i.property] at hf; cases hf + exact congrArg _ (Subtype.ext (show i.val=j.val from he)) + anti i j h h' := by + rcases i with i|i <;> rcases j with j|j <;> + change i.val.1=j.val.2 at h <;> change i.val.2=j.val.1 at h' + · have hh := i.property.2; rw [h,h'] at hh; exact (not_lt_of_gt hh) j.property.2 + · have hh := i.property.1; rw [h,h',j.property.2,j.property.1] at hh; cases hh + · have hh := j.property.1; rw [←h,←h',i.property.1,i.property.2] at hh; cases hh + have hh := i.property.1; rw [h,j.property.2] at hh; cases hh } + +abbrev Crossing (p : Shape) (i j : Tag p.g) := + {x : Notches p//inc x.1 i ∧ inc x.1 j} +abbrev Harm (p : Shape) := MBits p ⊕ Bool +def Abbey (v : Template p I) : v.Chorus → Type + | .inl _ => Harm p + | .inr x => Crossing p (v.t x.val.1) (v.t x.val.2) +instance (i : v.Chorus) : Fintype (v.Abbey i) := + i.rec (fun _ => inferInstanceAs (Fintype (Harm p))) (fun x => inferInstanceAs (Fintype + (Crossing p (v.t x.val.1) (v.t x.val.2)))) +instance (i : v.Chorus) : DecidableEq (v.Abbey i) := Classical.typeDecidableEq _ + +def monks (v : Template p I) (m : Mixer p n) (x : UnitType p n N) (i : v.Chorus) : + v.Abbey i → Moment p n := + match i with + | .inl _ => Sum.elim (fun l => eitherM l.2 (orderedM m l.1)) + (fun l => eitherM l (selfM p n m.mixM)) + | .inr _ => fun ⟨j,_⟩ => duel p (x.1 j.1) (x.2 j.1) j.2 + +def croon (v : Template p I) (i : I) := spring p (n:=n) (v.t i) (v.s i) (v.f i) + +def chime (m : Mixer p n) (x : UnitType p n N) + (i : v.Chorus) (y z : Knobs p.g n) : Vec (v.Abbey i) := + fun j => evmat (v.monks m x i j) (v.croon (v.choral.first i) y) (v.croon (v.choral.nextP i) z) + +def chorusM (m : Mixer p n) (x : UnitType p n N) + (i : v.Chorus) (y : Vec (v.Abbey i)) := ∑ j:v.Abbey i,y j • monks v m x i j + +omit [DecidableEq I] in +theorem chime_seq (m : Mixer p n) (x : UnitType p n N) (i) + (y : Vec (v.Abbey i)) (u z : Knobs p.g n) : + dotProduct y (v.chime m x i u z)=evmat (v.chorusM m x i y) + (v.croon (v.choral.first i) u) (v.croon (v.choral.nextP i) z) := by + unfold chorusM dotProduct chime + simp_rw [←mpair_outer, mpair_sum,mpair_smul] + +omit [DecidableEq I] in +theorem chorus_same (m : Mixer p n) (x : UnitType p n N) (i : v.SameDuet) + (y : Vec (v.Abbey (.inl i))) : + v.chorusM m x (.inl i) y=indexedSum m (fun j => y (Sum.inl j)) + selfSum m (fun j => y (Sum.inr j)) := by + unfold chorusM + + change ∑ j:Harm p,y j • monks v m x (.inl i) j=_ + rw [Fintype.sum_sum_type]; rfl + +set_option maxHeartbeats 600000 in +omit [DecidableEq I] in +theorem chorus_cross (m : Mixer p n) (x : UnitType p n N) (i : v.OppDuet) + (y : Vec (v.Abbey (.inr i))) (hy : y≠0) : + ∃ w : Vec (Notches p), w≠0 ∧ v.chorusM m x (.inr i) y=issue p w x := by + classical + let T (j : Notches p) := inc j.1 (v.t i.val.1)∧inc j.1 (v.t i.val.2) + let w (j : Notches p) := if h:T j then y (⟨j,h⟩ : Crossing p _ _) else 0 + have he (j : Crossing p (v.t i.val.1) (v.t i.val.2)) : w j.val=y j := dite_eq_left j.property + have hz : w≠0 := fun h => hy (funext (fun j : Crossing p _ _ => by rw [←he,h]; rfl)) + refine ⟨w,hz,?_⟩ + let f (j : Notches p) := w j • duel p (x.1 j.1) (x.2 j.1) j.2 + have h : issue p w x=∑ i : Notches p,f i := by + rw [Fintype.sum_prod_type]; rfl + rw [h] + have ht : ∑ j : {j:Notches p//T j},f j.val = ∑ j : Notches p,f j := by + let s := univ.filter T + rw [← Finset.sum_subtype s (by simp [s]) f] + refine Finset.sum_subset (subset_univ _) (fun i _ hi => ?_) + have hh : ¬T i := fun h => hi (mem_filter.mpr ⟨mem_univ _,h⟩) + unfold f w; rw [dite_eq_right hh,zero_smul] + rw [← ht] + change (∑ j:{j:Notches p//T j},_) = _ + exact Finset.sum_congr rfl fun j _ => by unfold f; rw [he]; rfl +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/EndpointGramRanks.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/EndpointGramRanks.lean index 19ee889c3248b6c2e14949c54a2ecaa89aeaa29d..4bf04551f342768d3ec0d2f23db09cbb164643b7 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/EndpointGramRanks.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/EndpointGramRanks.lean @@ -1,114 +1,114 @@ -import OAI.Combinatorics.HadwigerCounterexample.ReferenceProductTests - -namespace OAI - -/-! # Endpoint Gram Ranks -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module Finset Function -open scoped BigOperators -variable {I J U : Type} [Fintype I] [Fintype J] [Fintype U] -variable [DecidableEq I] [DecidableEq J] [DecidableEq U] -variable {n N : ℕ} - -omit [DecidableEq I] in -theorem pr_gram_target (X : Mat U I) (G : Mat I J) : - pr unif (fun Y : Mat U J => Xᵀ*Y=G) ≤ bp (-(X.rank:ℝ)*num J) := by - classical - let P := pack (colSp X) - obtain ⟨A,h⟩ : ∃ A : Mat I (Fin (dim (colSp X))),X*A=P := by - have h (i:Fin (dim (colSp X))) : P.col i ∈ colSp X := by - have hh : colSp P=colSp X := colSp_pack _ - exact hh.le (colSp_mem _) - choose f hf using fun i : Fin (dim (colSp X)) => - show ∃ y : Vec I,X *ᵥ y=P.col i from h i - refine ⟨Matrix.of (fun i j => f j i),?_⟩ - ext i j; exact congr_fun (hf j) i - have he (Y : Mat U J) (hg : Xᵀ*Y=G) : Pᵀ*Y=Aᵀ*G := by rw [←h,transpose_mul,Matrix.mul_assoc,hg] - refine (pr_mono unif_law.nz he).trans_eq ?_ - rw [pr_gram_fixed (pack_inj _)] - congr 1; rw [show num (Fin (dim (colSp X)))= X.rank from (by rw [num,Fintype.card_fin,colSp_dim])] - -theorem pr_offset_cross (X Y : PlusRack (Fin n) N) (G W : Mat (Fin n) (Fin n)) (r : ℕ) : - pr unif (fun Q : PlusRack (Fin n) N => - Yᵀ*Q=G ∧ (Xᵀ*Q+W).rank ≤ r) ≤ bp ((2*n:ℝ)*r-(fromCols X Y).rank*(n:ℝ)) := by - classical - let g := fromCols X Y - let A := Mat (Fin n) (Fin n) - let T (i : A) := i.rank ≤ r - let f (i : A) (y : PlusRack (Fin n) N) := T i ∧ gᵀ*y=fromRows (i-W) G - have he (y : PlusRack (Fin n) N) (h : Yᵀ*y=G ∧ (Xᵀ*y+W).rank≤r) : ∃ i,f i y := by - refine ⟨Xᵀ*y+W,h.2,?_⟩ - unfold g; rw [transpose_fromCols,fromRows_mul,h.1,add_sub_cancel_right] - let P := bp (-(g.rank:ℝ)*n) - have hi (i) : pr unif (f i) ≤ ind (T i) * P := by - by_cases h : T i - · unfold f; simp only [h,true_and,ind_true,one_mul] - simpa only [num,Fintype.card_fin,P] using pr_gram_target g (fromRows (i-W) G) - simp [f,h,ind] - refine (le_trans (pr_mono unif_law.nz he) (pr_exists_le unif_law.nz f)).trans - ((Finset.sum_le_sum (fun i _ => hi i)).trans ?_) - have ht := nbr_matrix_rank (I:=Fin n) (J:=Fin n) r - rw [← Finset.sum_mul]; unfold P - change nbr T*_ ≤ _ - refine (mul_le_mul_of_nonneg_right ht (bp_pos _).le).trans_eq ?_ - rw [← bp_add]; congr 1; simp only [num,Fintype.card_fin,g]; ring - -def crossSquare (n N : ℕ) (W : Mat (Fin n) (Fin n)) (v : F) - (x : Rack (Fin n) N × Rack (Fin n) N) := - x.1.1ᵀ*x.2.2+(v • (x.1.2ᵀ * x.2.1) + W) - -def rankJump (X Y : PlusRack (Fin n) N) (d : ℕ) := - (fromCols X Y).rank + d≤2*n - -set_option maxHeartbeats 800000 in -theorem shift_square (n N r d : ℕ) (X Y : PlusRack (Fin n) N) - (G H W : Mat (Fin n) (Fin n)) (v : F) - (hp : Injective X.mulVec) (hq : Injective Y.mulVec) : - let p := bp (-(n:ℝ)*n) - pr (pairW unif unif) (fun s : PlusRack (Fin n) N × PlusRack (Fin n) N => - (Xᵀ*s.1=G ∧ Yᵀ*s.2=H) ∧ - (crossSquare n N W v ((X,s.1),(Y,s.2))).rank≤r) ≤ - p^2 * (ind (rankJump X Y d)+bp ((2*n:ℝ)*r - (n-d:ℝ)*n)) := by - intro p - let f (s t : PlusRack (Fin n) N) := - (Xᵀ*s=G ∧ Yᵀ*t=H) ∧ (crossSquare n N W v ((X,s),(Y,t))).rank≤r - have ha : pr unif (fun Q : PlusRack (Fin n) N => Xᵀ*Q=G)=p := by - rw [pr_gram_fixed hp]; simp only [p,num,Fintype.card_fin] - have hb : pr unif (fun Q : PlusRack (Fin n) N => Yᵀ*Q=H)=p := by - rw [pr_gram_fixed hq]; simp only [p,num,Fintype.card_fin] - let c := bp ((2*n:ℝ)*r-(n-d:ℝ)*n) - have hc := bp_pos ((2*n:ℝ)*r-(n-d:ℝ)*n) - change _ ≤ p^2*(ind (rankJump X Y d) + c) - by_cases h : rankJump X Y d - · have he := pairW_pr unif unif (fun Q : PlusRack (Fin n) N => Xᵀ*Q=G) - (fun Q : PlusRack (Fin n) N => Yᵀ*Q=H) - refine (pr_mono (pairW_law unif_law unif_law).nz (fun i h => h.1)).trans ?_ - rw [he,ha,hb,ind_one h] - rw [←pow_two] - exact le_mul_of_one_le_right (sq_nonneg _) (by change 1≤1+c; linarith only [hc]) - have hr : (2*n:ℝ)-d≤(fromCols X Y).rank := by - unfold rankJump at h - have hi : 2*n≤ (fromCols X Y).rank + d := by omega - exact sub_le_iff_le_add.mpr (by exact_mod_cast hi) - have he (s : PlusRack (Fin n) N) : pr unif (fun t => f s t) ≤ ind (Xᵀ*s=G) * (p*c) := by - by_cases hs : Xᵀ*s=G - · simp only [f,hs,true_and,ind_true,one_mul] - have hg := pr_offset_cross X Y H (v • (sᵀ*Y)+W) r - refine le_trans hg ?_ - unfold p c; rw [← bp_add] - apply bp_le - nlinarith only [mul_le_mul_of_nonneg_right hr (Nat.cast_nonneg n : 0≤(n:ℝ))] - simp [f,hs,ind] - rw [pr,pairW_avg] - refine (avg_mono unif_law.nz he).trans ?_ - rw [avg_mul,ind_zero h,zero_add] - change pr unif _ * _ ≤ _ - rw [ha]; exact le_of_eq (by ring) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ReferenceProductTests + +namespace OAI + +/-! # Endpoint Gram Ranks -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module Finset Function +open scoped BigOperators +variable {I J U : Type} [Fintype I] [Fintype J] [Fintype U] +variable [DecidableEq I] [DecidableEq J] [DecidableEq U] +variable {n N : ℕ} + +omit [DecidableEq I] in +theorem pr_gram_target (X : Mat U I) (G : Mat I J) : + pr unif (fun Y : Mat U J => Xᵀ*Y=G) ≤ bp (-(X.rank:ℝ)*num J) := by + classical + let P := pack (colSp X) + obtain ⟨A,h⟩ : ∃ A : Mat I (Fin (dim (colSp X))),X*A=P := by + have h (i:Fin (dim (colSp X))) : P.col i ∈ colSp X := by + have hh : colSp P=colSp X := colSp_pack _ + exact hh.le (colSp_mem _) + choose f hf using fun i : Fin (dim (colSp X)) => + show ∃ y : Vec I,X *ᵥ y=P.col i from h i + refine ⟨Matrix.of (fun i j => f j i),?_⟩ + ext i j; exact congr_fun (hf j) i + have he (Y : Mat U J) (hg : Xᵀ*Y=G) : Pᵀ*Y=Aᵀ*G := by rw [←h,transpose_mul,Matrix.mul_assoc,hg] + refine (pr_mono unif_law.nz he).trans_eq ?_ + rw [pr_gram_fixed (pack_inj _)] + congr 1; rw [show num (Fin (dim (colSp X)))= X.rank from (by rw [num,Fintype.card_fin,colSp_dim])] + +theorem pr_offset_cross (X Y : PlusRack (Fin n) N) (G W : Mat (Fin n) (Fin n)) (r : ℕ) : + pr unif (fun Q : PlusRack (Fin n) N => + Yᵀ*Q=G ∧ (Xᵀ*Q+W).rank ≤ r) ≤ bp ((2*n:ℝ)*r-(fromCols X Y).rank*(n:ℝ)) := by + classical + let g := fromCols X Y + let A := Mat (Fin n) (Fin n) + let T (i : A) := i.rank ≤ r + let f (i : A) (y : PlusRack (Fin n) N) := T i ∧ gᵀ*y=fromRows (i-W) G + have he (y : PlusRack (Fin n) N) (h : Yᵀ*y=G ∧ (Xᵀ*y+W).rank≤r) : ∃ i,f i y := by + refine ⟨Xᵀ*y+W,h.2,?_⟩ + unfold g; rw [transpose_fromCols,fromRows_mul,h.1,add_sub_cancel_right] + let P := bp (-(g.rank:ℝ)*n) + have hi (i) : pr unif (f i) ≤ ind (T i) * P := by + by_cases h : T i + · unfold f; simp only [h,true_and,ind_true,one_mul] + simpa only [num,Fintype.card_fin,P] using pr_gram_target g (fromRows (i-W) G) + simp [f,h,ind] + refine (le_trans (pr_mono unif_law.nz he) (pr_exists_le unif_law.nz f)).trans + ((Finset.sum_le_sum (fun i _ => hi i)).trans ?_) + have ht := nbr_matrix_rank (I:=Fin n) (J:=Fin n) r + rw [← Finset.sum_mul]; unfold P + change nbr T*_ ≤ _ + refine (mul_le_mul_of_nonneg_right ht (bp_pos _).le).trans_eq ?_ + rw [← bp_add]; congr 1; simp only [num,Fintype.card_fin,g]; ring + +def crossSquare (n N : ℕ) (W : Mat (Fin n) (Fin n)) (v : F) + (x : Rack (Fin n) N × Rack (Fin n) N) := + x.1.1ᵀ*x.2.2+(v • (x.1.2ᵀ * x.2.1) + W) + +def rankJump (X Y : PlusRack (Fin n) N) (d : ℕ) := + (fromCols X Y).rank + d≤2*n + +set_option maxHeartbeats 800000 in +theorem shift_square (n N r d : ℕ) (X Y : PlusRack (Fin n) N) + (G H W : Mat (Fin n) (Fin n)) (v : F) + (hp : Injective X.mulVec) (hq : Injective Y.mulVec) : + let p := bp (-(n:ℝ)*n) + pr (pairW unif unif) (fun s : PlusRack (Fin n) N × PlusRack (Fin n) N => + (Xᵀ*s.1=G ∧ Yᵀ*s.2=H) ∧ + (crossSquare n N W v ((X,s.1),(Y,s.2))).rank≤r) ≤ + p^2 * (ind (rankJump X Y d)+bp ((2*n:ℝ)*r - (n-d:ℝ)*n)) := by + intro p + let f (s t : PlusRack (Fin n) N) := + (Xᵀ*s=G ∧ Yᵀ*t=H) ∧ (crossSquare n N W v ((X,s),(Y,t))).rank≤r + have ha : pr unif (fun Q : PlusRack (Fin n) N => Xᵀ*Q=G)=p := by + rw [pr_gram_fixed hp]; simp only [p,num,Fintype.card_fin] + have hb : pr unif (fun Q : PlusRack (Fin n) N => Yᵀ*Q=H)=p := by + rw [pr_gram_fixed hq]; simp only [p,num,Fintype.card_fin] + let c := bp ((2*n:ℝ)*r-(n-d:ℝ)*n) + have hc := bp_pos ((2*n:ℝ)*r-(n-d:ℝ)*n) + change _ ≤ p^2*(ind (rankJump X Y d) + c) + by_cases h : rankJump X Y d + · have he := pairW_pr unif unif (fun Q : PlusRack (Fin n) N => Xᵀ*Q=G) + (fun Q : PlusRack (Fin n) N => Yᵀ*Q=H) + refine (pr_mono (pairW_law unif_law unif_law).nz (fun i h => h.1)).trans ?_ + rw [he,ha,hb,ind_one h] + rw [←pow_two] + exact le_mul_of_one_le_right (sq_nonneg _) (by change 1≤1+c; linarith only [hc]) + have hr : (2*n:ℝ)-d≤(fromCols X Y).rank := by + unfold rankJump at h + have hi : 2*n≤ (fromCols X Y).rank + d := by omega + exact sub_le_iff_le_add.mpr (by exact_mod_cast hi) + have he (s : PlusRack (Fin n) N) : pr unif (fun t => f s t) ≤ ind (Xᵀ*s=G) * (p*c) := by + by_cases hs : Xᵀ*s=G + · simp only [f,hs,true_and,ind_true,one_mul] + have hg := pr_offset_cross X Y H (v • (sᵀ*Y)+W) r + refine le_trans hg ?_ + unfold p c; rw [← bp_add] + apply bp_le + nlinarith only [mul_le_mul_of_nonneg_right hr (Nat.cast_nonneg n : 0≤(n:ℝ))] + simp [f,hs,ind] + rw [pr,pairW_avg] + refine (avg_mono unif_law.nz he).trans ?_ + rw [avg_mul,ind_zero h,zero_add] + change pr unif _ * _ ≤ _ + rw [ha]; exact le_of_eq (by ring) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/EndpointTemplateConcentration.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/EndpointTemplateConcentration.lean index c21d132558dab9df0e5696e3b3b6fe6d6723277f..6b0ad717bc991dec1fa26e66fe4bdac21d9a4b5a 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/EndpointTemplateConcentration.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/EndpointTemplateConcentration.lean @@ -1,88 +1,88 @@ -import OAI.Combinatorics.HadwigerCounterexample.ConcentrationScales - -namespace OAI - -/-! # Endpoint Template Concentration -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Real Finset Matrix Function -open scoped BigOperators -variable {p : Shape} {M n N : ℕ} -variable {I J K G : Type} [Fintype I] [Fintype J] [Fintype K] [Fintype G] -variable [DecidableEq I] [DecidableEq J] [DecidableEq K] [DecidableEq G] - -namespace Template - -variable (v : Template p I) - -def callP (n : ℕ) (g : Route (KeySlots p v.t) G) : Program p n g (Inputs p n I) := - ⟨fun x => queryLaw v x,fun x => queryLaw v x⟩ -def singleP (n : ℕ) := callP v n (ownPort (p:=p) v.t) -def doubleP (n : ℕ) := callP v n (globPort p v.t v.aim) - -omit [Fintype I] [DecidableEq I] in -theorem own_inj (i : Comp p.g) : - Injective (fun i : Port (ownPort (p:=p) v.t) i => i.val.1) := by - rintro ⟨⟨a,c⟩,ha⟩ ⟨⟨b,d⟩,hb⟩ he - change a=b at he; subst b - have h : c=d := Subtype.ext (ha.trans hb.symm) - subst d; rfl - -omit [Fintype I] [DecidableEq I] in -theorem glob_inj (i : Ports p) : - Injective (fun i : Port (globPort p v.t v.aim) i => i.val.1) := by - rintro ⟨⟨a,c⟩,ha⟩ ⟨⟨b,d⟩,hb⟩ he - change a=b at he; subst b - have h : c=d := Subtype.ext (congrArg Prod.snd (ha.trans hb.symm)) - subst d; rfl - -omit [Fintype G] in -theorem free_price (n : ℕ) (w : I→ Wgt (Knobs p.g n)) (hw : ∀ i,IsLaw (w i)) - (hz : ∀ i,mapW (w i) (freePart p)=unif) - (g : Route (KeySlots p v.t) G) - (he : ∀ i : G,Injective (fun j : Port g i => j.val.1)) : - pr (draws K (prodW w)) (fun x => ¬ (v.callP n g).free x)≤ bp (num K * num I-n) := by - refine le_trans ?_ (buds p n _ hz) - exact pr_mono (draws_law (prodW_law hw)).nz fun i h hh => h - ⟨queries_bloom v i g hh he, queries_bloom v i g hh he⟩ - -def callOne (i) (x : Knobs p.g n) (o : Orient p n N) := - keyOne p (v.t i) (v.s i) (lit (v.f i) (v.t i) x) o - -omit [Fintype I] [DecidableEq I] in -theorem single_show (z : Inputs p n I) (x : Orient p n N) : - (v.singleP n).showKey z x=scatter v.t N (fun i => callOne v i (z i) x) := by - apply Prod.ext <;> rfl - -omit [Fintype I] [DecidableEq I] in -theorem double_show (z : Inputs p n I) (x : UnitType p n N) : - (v.doubleP n).showKey z (mergeR p x)=scatter v.t N ((v.draw z).keys v.t x) := - peek_keys v.t (v.draw z) x - -theorem raw_variance (v : Template p I) (M : ℕ) (hM : 1≤M) : - ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n) (w : I→Wgt (Knobs p.g n)), - (∀ i, IsLaw (w i)) → (∀ i,mapW (w i) (freePart p)=unif) → 2*num (Full p n) avg (prodW w) (fun z => T z (fun i => callOne v i (z i) o)) - avg u (fun x => (f x-avg u f)^2) ≤ bp (-(1/4:ℝ)*n) := by - let g := ownPort (p:=p) v.t - filter_upwards [Program.variance_calendar p M g (num Bool*num I) 1 zero_lt_one hM] - with n hn N m w hw hz hN T hT r f - let s := v.singleP n - let t (x : Inputs p n I) (y : Rack (KeySlots p v.t) N) := T x ((scatter v.t N).symm y) - have hf : f = s.oexpect (prodW w) t := by - unfold s f Program.oexpect t - simp_rw [single_show,Equiv.symm_apply_apply] - have h := hn m _ s t (prodW w) (prodW_law hw) (fun x y => hT _ _) hN - (free_price v n w hw hz g (own_inj v)) - rw [one_mul] at h - rw [hf]; exact h - -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ConcentrationScales + +namespace OAI + +/-! # Endpoint Template Concentration -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Real Finset Matrix Function +open scoped BigOperators +variable {p : Shape} {M n N : ℕ} +variable {I J K G : Type} [Fintype I] [Fintype J] [Fintype K] [Fintype G] +variable [DecidableEq I] [DecidableEq J] [DecidableEq K] [DecidableEq G] + +namespace Template + +variable (v : Template p I) + +def callP (n : ℕ) (g : Route (KeySlots p v.t) G) : Program p n g (Inputs p n I) := + ⟨fun x => queryLaw v x,fun x => queryLaw v x⟩ +def singleP (n : ℕ) := callP v n (ownPort (p:=p) v.t) +def doubleP (n : ℕ) := callP v n (globPort p v.t v.aim) + +omit [Fintype I] [DecidableEq I] in +theorem own_inj (i : Comp p.g) : + Injective (fun i : Port (ownPort (p:=p) v.t) i => i.val.1) := by + rintro ⟨⟨a,c⟩,ha⟩ ⟨⟨b,d⟩,hb⟩ he + change a=b at he; subst b + have h : c=d := Subtype.ext (ha.trans hb.symm) + subst d; rfl + +omit [Fintype I] [DecidableEq I] in +theorem glob_inj (i : Ports p) : + Injective (fun i : Port (globPort p v.t v.aim) i => i.val.1) := by + rintro ⟨⟨a,c⟩,ha⟩ ⟨⟨b,d⟩,hb⟩ he + change a=b at he; subst b + have h : c=d := Subtype.ext (congrArg Prod.snd (ha.trans hb.symm)) + subst d; rfl + +omit [Fintype G] in +theorem free_price (n : ℕ) (w : I→ Wgt (Knobs p.g n)) (hw : ∀ i,IsLaw (w i)) + (hz : ∀ i,mapW (w i) (freePart p)=unif) + (g : Route (KeySlots p v.t) G) + (he : ∀ i : G,Injective (fun j : Port g i => j.val.1)) : + pr (draws K (prodW w)) (fun x => ¬ (v.callP n g).free x)≤ bp (num K * num I-n) := by + refine le_trans ?_ (buds p n _ hz) + exact pr_mono (draws_law (prodW_law hw)).nz fun i h hh => h + ⟨queries_bloom v i g hh he, queries_bloom v i g hh he⟩ + +def callOne (i) (x : Knobs p.g n) (o : Orient p n N) := + keyOne p (v.t i) (v.s i) (lit (v.f i) (v.t i) x) o + +omit [Fintype I] [DecidableEq I] in +theorem single_show (z : Inputs p n I) (x : Orient p n N) : + (v.singleP n).showKey z x=scatter v.t N (fun i => callOne v i (z i) x) := by + apply Prod.ext <;> rfl + +omit [Fintype I] [DecidableEq I] in +theorem double_show (z : Inputs p n I) (x : UnitType p n N) : + (v.doubleP n).showKey z (mergeR p x)=scatter v.t N ((v.draw z).keys v.t x) := + peek_keys v.t (v.draw z) x + +theorem raw_variance (v : Template p I) (M : ℕ) (hM : 1≤M) : + ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n) (w : I→Wgt (Knobs p.g n)), + (∀ i, IsLaw (w i)) → (∀ i,mapW (w i) (freePart p)=unif) → 2*num (Full p n) avg (prodW w) (fun z => T z (fun i => callOne v i (z i) o)) + avg u (fun x => (f x-avg u f)^2) ≤ bp (-(1/4:ℝ)*n) := by + let g := ownPort (p:=p) v.t + filter_upwards [Program.variance_calendar p M g (num Bool*num I) 1 zero_lt_one hM] + with n hn N m w hw hz hN T hT r f + let s := v.singleP n + let t (x : Inputs p n I) (y : Rack (KeySlots p v.t) N) := T x ((scatter v.t N).symm y) + have hf : f = s.oexpect (prodW w) t := by + unfold s f Program.oexpect t + simp_rw [single_show,Equiv.symm_apply_apply] + have h := hn m _ s t (prodW w) (prodW_law hw) (fun x y => hT _ _) hN + (free_price v n w hw hz g (own_inj v)) + rw [one_mul] at h + rw [hf]; exact h + +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/EntropyContainers.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/EntropyContainers.lean index f0ec3729a83cdca4a28c14008ac89762ec29a898..cc1d6c27915a21cf1e964ee7c470b399c7f9c2c2 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/EntropyContainers.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/EntropyContainers.lean @@ -1,132 +1,132 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteEntropy -import Mathlib.Data.Finset.Card - -namespace OAI - -/-! # Entropy Containers -/ - -noncomputable section -open scoped BigOperators -open Real Finset -namespace HadwigerCounterexample - -variable {α : Type*} [Fintype α] - -private theorem avg_reached {w f : Wgt α} (hw : IsLaw w) : - ∃ x, 0 < w x ∧ avg w f ≤ f x := by - by_contra! hn - have hp := exists_of_pr_pos (p:=fun _ => True) hw.nz (by rw [pr_true, hw.total]; norm_num) - obtain ⟨x, _, hx⟩ := hp - have h : avg w f < avg w (fun _ => avg w f) := by - unfold avg - apply Finset.sum_lt_sum - · intro y _ - by_cases h : 0 < w y - · exact mul_le_mul_of_nonneg_left (hn y h).le h.le - · rw [le_antisymm (le_of_not_gt h) (hw.nz _), zero_mul, zero_mul] - · exact ⟨x, mem_univ _, mul_lt_mul_of_pos_left (hn x hx) hx⟩ - rw [hw.avg_const] at h - exact lt_irrefl _ h - -omit [Fintype α] in -theorem closed_carried (p : α → Prop) : IsClosed {w : Wgt α | carried w p} := by - have he : {w : Wgt α | carried w p} = ⋂ (x : α) (_ : ¬ p x), {w | w x = 0} := by - ext; simp [carried] - rw [he] - exact isClosed_iInter fun x => isClosed_iInter fun _ => isClosed_eq (continuous_apply x) - continuous_const - -/-- Cover the conflict-independent sets in R by a small family of terminal sets. -/ -theorem containers {ok : Set (Wgt α)} (hcomp : IsCompact ok) (hok : ∀ w ∈ ok, IsLaw w) - (hmid : ∀ w ∈ ok, ∀ v ∈ ok, midLaw w v ∈ ok) (rel : α → α → Prop) - {e : ℝ} (he : 0 < e) (R : Finset α) - (hsat : ∀ w ∈ ok, carried w (· ∈ R) → - e ≤ pr (pairW w w) (fun x => rel x.1 x.2)) - (L : ℕ) (hL : ∀ w ∈ ok, carried w (· ∈ R) → - 0 < negEnt w + L * (e * Real.log 2)) : - ∃ C : Finset (Finset α), - C.card ≤ (R.card + 1)^L ∧ - (∀ r ∈ C, r ⊆ R ∧ ¬∃ w ∈ ok, carried w (· ∈ r)) ∧ - ∀ I : Finset α, I ⊆ R → (∀ v ∈ I, ∀ u ∈ I, ¬rel v u) → - ∃ r ∈ C, I ⊆ r := by - classical - induction R using Finset.strongInductionOn generalizing L with | _ R ih - by_cases h : ∃ w ∈ ok, carried w (· ∈ R) - · let T := ok ∩ {w : Wgt α | carried w (· ∈ R)} - have hn : T.Nonempty := h - obtain ⟨w, hw, hwmin⟩ := (hcomp.inter_right (closed_carried (· ∈ R))).exists_isMinOn hn - negEnt_continuous.continuousOn - have hwL := hok w hw.1 - obtain ⟨v,hv,hv'⟩ := avg_reached (w:=w) (f:=fun x => pr w (rel x)) hwL - have hvR : v ∈ R := Classical.byContradiction (fun h => hv.ne' (hw.2 v h)) - have he' : e ≤ pr w (rel v) := by - have h := hsat w hw.1 hw.2 - unfold pr at * - rw [pairW_avg] at h - exact h.trans hv' - have hwl : 0 < negEnt w + L * (e * Real.log 2) := hL w hw.1 hw.2 - cases L with - | zero => - have hnonpos := negEnt_le_zero hwL.sub - simp [show ¬ (0 < negEnt w) from not_lt.mpr hnonpos] at hwl - | succ L => - let R₁ := R.erase v - let R₂ := R.filter (fun x => ¬rel v x) - have hr₁ : R₁ ⊂ R := Finset.erase_ssubset hvR - have hr₂ : R₂ ⊂ R := by - refine Finset.ssubset_iff_subset_ne.mpr ⟨Finset.filter_subset _ _, ?_⟩ - obtain ⟨x,hx,hx'⟩ := exists_of_pr_pos hwL.nz (lt_of_lt_of_le he he') - intro h - have hxr : x ∈ R := Classical.byContradiction fun h => hx'.ne' (hw.2 _ h) - rw [← h] at hxr - exact (mem_filter.mp hxr).2 hx - have hm {r : Finset α} (hr : r ⊂ R) {w : Wgt α} - (h : carried w (· ∈ r)) : carried w (· ∈ R) := - fun x hx => h x (fun hxr => hx (subset_of_ssubset hr hxr)) - obtain ⟨C, hC, htC, hcovC⟩ := ih R₁ hr₁ (fun w hw h => hsat w hw (hm hr₁ h)) - (L+1) (fun w hw h => hL w hw (hm hr₁ h)) - obtain ⟨D, hD, htD, hcovD⟩ := ih R₂ hr₂ (fun w hw h => hsat w hw (hm hr₂ h)) L (by - intro u hu hRu - have hmidT : midLaw w u ∈ T := by - refine ⟨hmid w hw.1 u hu, fun x hx => ?_⟩ - simp [midLaw, hw.2 x hx, hm hr₂ hRu x hx] - have hle : negEnt w ≤ negEnt (midLaw w u) := hwmin hmidT - have hh := negEnt_gap hwL.nz (hok u hu).nz (rel v) (fun x hx => - hRu x (fun h => (mem_filter.mp h).2 hx)) - have hy : e * Real.log 2 ≤ pr w (rel v) * Real.log 2 := by - gcongr - push_cast at hwl - linarith) - refine ⟨C ∪ D, ?_, ?_, ?_⟩ - · refine (card_union_le _ _).trans ?_ - have h₁ : C.card ≤ R.card^(L+1) := - hC.trans (by gcongr; exact card_lt_card hr₁) - have h₂ : D.card ≤ R.card^L := - hD.trans (by gcongr; exact card_lt_card hr₂) - refine (add_le_add h₁ h₂).trans ?_ - rw [pow_succ, pow_succ] - calc R.card ^ L * R.card + R.card ^ L = R.card ^ L * (R.card + 1) := by ring - _ ≤ _ := by gcongr; omega - · intro r hr - rcases mem_union.mp hr with hr|hr - · exact ⟨(htC r hr).1.trans (subset_of_ssubset hr₁), (htC r hr).2⟩ - · exact ⟨(htD r hr).1.trans (subset_of_ssubset hr₂), (htD r hr).2⟩ - · intro I hIR hI - by_cases h : v ∈ I - · have h' : I ⊆ R₂ := fun x hx => mem_filter.mpr ⟨hIR hx,hI v h x hx⟩ - obtain ⟨r,h1,h2⟩ := hcovD I h' hI - exact ⟨r,mem_union_right _ h1,h2⟩ - · have h' : I ⊆ R₁ := fun x hx => mem_erase.mpr ⟨fun hxv => h (hxv ▸ hx),hIR hx⟩ - obtain ⟨r,h1,h2⟩ := hcovC I h' hI - exact ⟨r,mem_union_left _ h1,h2⟩ - · refine ⟨{R}, ?_, ?_, ?_⟩ - · rw [card_singleton] - exact Nat.one_le_iff_ne_zero.mpr (by positivity) - · simpa using h - · intro I hIR _; exact ⟨R, mem_singleton_self _, hIR⟩ - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteEntropy +import Mathlib.Data.Finset.Card + +namespace OAI + +/-! # Entropy Containers -/ + +noncomputable section +open scoped BigOperators +open Real Finset +namespace HadwigerCounterexample + +variable {α : Type*} [Fintype α] + +private theorem avg_reached {w f : Wgt α} (hw : IsLaw w) : + ∃ x, 0 < w x ∧ avg w f ≤ f x := by + by_contra! hn + have hp := exists_of_pr_pos (p:=fun _ => True) hw.nz (by rw [pr_true, hw.total]; norm_num) + obtain ⟨x, _, hx⟩ := hp + have h : avg w f < avg w (fun _ => avg w f) := by + unfold avg + apply Finset.sum_lt_sum + · intro y _ + by_cases h : 0 < w y + · exact mul_le_mul_of_nonneg_left (hn y h).le h.le + · rw [le_antisymm (le_of_not_gt h) (hw.nz _), zero_mul, zero_mul] + · exact ⟨x, mem_univ _, mul_lt_mul_of_pos_left (hn x hx) hx⟩ + rw [hw.avg_const] at h + exact lt_irrefl _ h + +omit [Fintype α] in +theorem closed_carried (p : α → Prop) : IsClosed {w : Wgt α | carried w p} := by + have he : {w : Wgt α | carried w p} = ⋂ (x : α) (_ : ¬ p x), {w | w x = 0} := by + ext; simp [carried] + rw [he] + exact isClosed_iInter fun x => isClosed_iInter fun _ => isClosed_eq (continuous_apply x) + continuous_const + +/-- Cover the conflict-independent sets in R by a small family of terminal sets. -/ +theorem containers {ok : Set (Wgt α)} (hcomp : IsCompact ok) (hok : ∀ w ∈ ok, IsLaw w) + (hmid : ∀ w ∈ ok, ∀ v ∈ ok, midLaw w v ∈ ok) (rel : α → α → Prop) + {e : ℝ} (he : 0 < e) (R : Finset α) + (hsat : ∀ w ∈ ok, carried w (· ∈ R) → + e ≤ pr (pairW w w) (fun x => rel x.1 x.2)) + (L : ℕ) (hL : ∀ w ∈ ok, carried w (· ∈ R) → + 0 < negEnt w + L * (e * Real.log 2)) : + ∃ C : Finset (Finset α), + C.card ≤ (R.card + 1)^L ∧ + (∀ r ∈ C, r ⊆ R ∧ ¬∃ w ∈ ok, carried w (· ∈ r)) ∧ + ∀ I : Finset α, I ⊆ R → (∀ v ∈ I, ∀ u ∈ I, ¬rel v u) → + ∃ r ∈ C, I ⊆ r := by + classical + induction R using Finset.strongInductionOn generalizing L with | _ R ih + by_cases h : ∃ w ∈ ok, carried w (· ∈ R) + · let T := ok ∩ {w : Wgt α | carried w (· ∈ R)} + have hn : T.Nonempty := h + obtain ⟨w, hw, hwmin⟩ := (hcomp.inter_right (closed_carried (· ∈ R))).exists_isMinOn hn + negEnt_continuous.continuousOn + have hwL := hok w hw.1 + obtain ⟨v,hv,hv'⟩ := avg_reached (w:=w) (f:=fun x => pr w (rel x)) hwL + have hvR : v ∈ R := Classical.byContradiction (fun h => hv.ne' (hw.2 v h)) + have he' : e ≤ pr w (rel v) := by + have h := hsat w hw.1 hw.2 + unfold pr at * + rw [pairW_avg] at h + exact h.trans hv' + have hwl : 0 < negEnt w + L * (e * Real.log 2) := hL w hw.1 hw.2 + cases L with + | zero => + have hnonpos := negEnt_le_zero hwL.sub + simp [show ¬ (0 < negEnt w) from not_lt.mpr hnonpos] at hwl + | succ L => + let R₁ := R.erase v + let R₂ := R.filter (fun x => ¬rel v x) + have hr₁ : R₁ ⊂ R := Finset.erase_ssubset hvR + have hr₂ : R₂ ⊂ R := by + refine Finset.ssubset_iff_subset_ne.mpr ⟨Finset.filter_subset _ _, ?_⟩ + obtain ⟨x,hx,hx'⟩ := exists_of_pr_pos hwL.nz (lt_of_lt_of_le he he') + intro h + have hxr : x ∈ R := Classical.byContradiction fun h => hx'.ne' (hw.2 _ h) + rw [← h] at hxr + exact (mem_filter.mp hxr).2 hx + have hm {r : Finset α} (hr : r ⊂ R) {w : Wgt α} + (h : carried w (· ∈ r)) : carried w (· ∈ R) := + fun x hx => h x (fun hxr => hx (subset_of_ssubset hr hxr)) + obtain ⟨C, hC, htC, hcovC⟩ := ih R₁ hr₁ (fun w hw h => hsat w hw (hm hr₁ h)) + (L+1) (fun w hw h => hL w hw (hm hr₁ h)) + obtain ⟨D, hD, htD, hcovD⟩ := ih R₂ hr₂ (fun w hw h => hsat w hw (hm hr₂ h)) L (by + intro u hu hRu + have hmidT : midLaw w u ∈ T := by + refine ⟨hmid w hw.1 u hu, fun x hx => ?_⟩ + simp [midLaw, hw.2 x hx, hm hr₂ hRu x hx] + have hle : negEnt w ≤ negEnt (midLaw w u) := hwmin hmidT + have hh := negEnt_gap hwL.nz (hok u hu).nz (rel v) (fun x hx => + hRu x (fun h => (mem_filter.mp h).2 hx)) + have hy : e * Real.log 2 ≤ pr w (rel v) * Real.log 2 := by + gcongr + push_cast at hwl + linarith) + refine ⟨C ∪ D, ?_, ?_, ?_⟩ + · refine (card_union_le _ _).trans ?_ + have h₁ : C.card ≤ R.card^(L+1) := + hC.trans (by gcongr; exact card_lt_card hr₁) + have h₂ : D.card ≤ R.card^L := + hD.trans (by gcongr; exact card_lt_card hr₂) + refine (add_le_add h₁ h₂).trans ?_ + rw [pow_succ, pow_succ] + calc R.card ^ L * R.card + R.card ^ L = R.card ^ L * (R.card + 1) := by ring + _ ≤ _ := by gcongr; omega + · intro r hr + rcases mem_union.mp hr with hr|hr + · exact ⟨(htC r hr).1.trans (subset_of_ssubset hr₁), (htC r hr).2⟩ + · exact ⟨(htD r hr).1.trans (subset_of_ssubset hr₂), (htD r hr).2⟩ + · intro I hIR hI + by_cases h : v ∈ I + · have h' : I ⊆ R₂ := fun x hx => mem_filter.mpr ⟨hIR hx,hI v h x hx⟩ + obtain ⟨r,h1,h2⟩ := hcovD I h' hI + exact ⟨r,mem_union_right _ h1,h2⟩ + · have h' : I ⊆ R₁ := fun x hx => mem_erase.mpr ⟨fun hxv => h (hxv ▸ hx),hIR hx⟩ + obtain ⟨r,h1,h2⟩ := hcovC I h' hI + exact ⟨r,mem_union_left _ h1,h2⟩ + · refine ⟨{R}, ?_, ?_, ?_⟩ + · rw [card_singleton] + exact Nat.one_le_iff_ne_zero.mpr (by positivity) + · simpa using h + · intro I hIR _; exact ⟨R, mem_singleton_self _, hIR⟩ + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ExplicitStatusEquations.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ExplicitStatusEquations.lean index 90c0fe3f457db70e4c39e460a0416d05fee9b983..f551ed75e47032ac325d38087636733b3a75b81c 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ExplicitStatusEquations.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ExplicitStatusEquations.lean @@ -1,95 +1,95 @@ -import OAI.Combinatorics.HadwigerCounterexample.StatusCharts - -namespace OAI - -/-! # Explicit Status Equations -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Submodule Finset Function -open scoped BigOperators -namespace StatusAnalysis -variable {d e : Rates} {p : Shape} {n N : ℕ} {q : Format} - -set_option maxHeartbeats 600000 in -theorem speak_val (u : ∀ i,Suite d e i) : - speak d e u = ((fun i=>want _ _ (u i)), - (fun j:Bool=> ∑ i:Bool,couple _ (u (i,j)).2.1), - (fun i:Bool=> ∑ j:Bool,couple _ (u (i,j)).2.2)) := by - unfold speak; rw [LinearMap.sum_apply] - apply Prod.ext - · rw [Prod.fst_sum] - exact Finset.univ_sum_single (fun i=>want _ _ (u i)) - apply Prod.ext - · rw [Prod.snd_sum,Prod.fst_sum] - funext i - rw [Finset.sum_apply] - change (∑ j:Grid,(Pi.single j.2 (couple _ (u j).2.1) : Quota) i)=_ - rw [Fintype.sum_prod_type]; cases i <;> simp [Nodes,Pi.single_apply] - rw [Prod.snd_sum,Prod.snd_sum] - funext i - rw [Finset.sum_apply] - change (∑ j:Grid,(Pi.single j.1 (couple _ (u j).2.2) : Quota) i)=_ - rw [Fintype.sum_prod_type]; cases i <;> simp [Nodes,Pi.single_apply] - -def funds {b : Bool} (x : Amounts p q d b) (i : Grid) : - Whole (d (sendId b i)) := - ∑ k: Fin (q i),(x (⟨i,k⟩ : Messenger q)).2 -def fullq (z : Messenger q → F) (i : Grid) := ∑ k:Fin (q i),z ⟨i,k⟩ - -theorem sendSum_by (u : Messenger q → F) (a : Amounts p q d true) (b : Amounts p q e false) - (i : Grid) : - sendSum u a b i=(fullq u i, (funds a i : Whole (d i.1)), (funds b i : Whole (e i.2))) := by - unfold sendSum - apply Prod.ext - · rw [Prod.fst_sum]; rfl - apply Prod.ext - · rw [Prod.snd_sum,Prod.fst_sum]; rfl - rw [Prod.snd_sum,Prod.snd_sum]; rfl - -def still (b : Bool) (a : Amounts p q d b) (v : Charts p n d) (M : Cross p n) := - (∀ i:Grid,(funds a i).1.2= targetMark p v M (sendId b i) (sendId (!b) i))∧ - ∀ j:Bool,couple _ (funds a (transit b (true,j))) = - couple _ (funds a (transit b (false,j))) - -def rhyme {b : Bool} (a : Amounts p q d b) (x : Amounts p q e (!b)) := - ∀ i:Grid,(funds a i).1.1+(funds x i).1.1=1 - -set_option maxHeartbeats 800000 in -theorem spoken (v : Charts p n d) (w : Charts p n e) (M : Cross p n) (z : Messenger q→ F) - (a : Amounts p q d true) (b : Amounts p q e false) : - speak _ _ (sendSum z a b)=(hailing p v w M,0) ↔ - (∀ i,fullq z i=1)∧rhyme a b∧ still true a v M∧ still false b w (reciprocal p M) := by - classical - let f i:=funds a i; let g i:= funds b i - let h1 i := couple (d (sendId true i)) (f i) - let h2 i := couple (e (sendId false i)) (g i) - rw [speak_val] - simp_rw [sendSum_by] - have h (x y:F) : x+y=0↔ x=y := by rw [← ZModModule.sub_eq_add,sub_eq_zero] - constructor - · intro ht - have hh := congrArg Prod.fst ht - have hx := congrArg Prod.fst (congrArg Prod.snd ht) - have hy := congrArg Prod.snd (congrArg Prod.snd ht) - refine ⟨fun i=>congrArg Prod.fst (congr_fun hh i),fun i=>congrArg (fun x=>x.2.1) - (congr_fun hh i),⟨fun i=>congrArg (fun x=>x.2.2.1) (congr_fun hh i),fun i=>?_⟩, - fun i=>congrArg (fun x=>x.2.2.2) (congr_fun hh i),fun i=>?_⟩ - · have ht:=congr_fun hx i - change ∑ j:Bool,h1 (j,i)=0 at ht; rw [Fintype.sum_bool,h] at ht; exact ht - have ht:=congr_fun hy i; change ∑ j:Bool,h2 (i,j)=0 at ht; rw [Fintype.sum_bool,h] at ht - exact ht - rintro ⟨ht,hv,⟨hF,hA⟩,hG,hB⟩ - apply Prod.ext - · funext i; exact Prod.ext (ht i) (Prod.ext (hv i) (Prod.ext (hF i) (hG i))) - apply Prod.ext - · funext i; change ∑ j:Bool,h1 (j,i)=0 - rw [Fintype.sum_bool,h]; exact hA i - funext i; change ∑ j:Bool,h2 (i,j)=0 - rw [Fintype.sum_bool,h]; exact hB i -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.StatusCharts + +namespace OAI + +/-! # Explicit Status Equations -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Submodule Finset Function +open scoped BigOperators +namespace StatusAnalysis +variable {d e : Rates} {p : Shape} {n N : ℕ} {q : Format} + +set_option maxHeartbeats 600000 in +theorem speak_val (u : ∀ i,Suite d e i) : + speak d e u = ((fun i=>want _ _ (u i)), + (fun j:Bool=> ∑ i:Bool,couple _ (u (i,j)).2.1), + (fun i:Bool=> ∑ j:Bool,couple _ (u (i,j)).2.2)) := by + unfold speak; rw [LinearMap.sum_apply] + apply Prod.ext + · rw [Prod.fst_sum] + exact Finset.univ_sum_single (fun i=>want _ _ (u i)) + apply Prod.ext + · rw [Prod.snd_sum,Prod.fst_sum] + funext i + rw [Finset.sum_apply] + change (∑ j:Grid,(Pi.single j.2 (couple _ (u j).2.1) : Quota) i)=_ + rw [Fintype.sum_prod_type]; cases i <;> simp [Nodes,Pi.single_apply] + rw [Prod.snd_sum,Prod.snd_sum] + funext i + rw [Finset.sum_apply] + change (∑ j:Grid,(Pi.single j.1 (couple _ (u j).2.2) : Quota) i)=_ + rw [Fintype.sum_prod_type]; cases i <;> simp [Nodes,Pi.single_apply] + +def funds {b : Bool} (x : Amounts p q d b) (i : Grid) : + Whole (d (sendId b i)) := + ∑ k: Fin (q i),(x (⟨i,k⟩ : Messenger q)).2 +def fullq (z : Messenger q → F) (i : Grid) := ∑ k:Fin (q i),z ⟨i,k⟩ + +theorem sendSum_by (u : Messenger q → F) (a : Amounts p q d true) (b : Amounts p q e false) + (i : Grid) : + sendSum u a b i=(fullq u i, (funds a i : Whole (d i.1)), (funds b i : Whole (e i.2))) := by + unfold sendSum + apply Prod.ext + · rw [Prod.fst_sum]; rfl + apply Prod.ext + · rw [Prod.snd_sum,Prod.fst_sum]; rfl + rw [Prod.snd_sum,Prod.snd_sum]; rfl + +def still (b : Bool) (a : Amounts p q d b) (v : Charts p n d) (M : Cross p n) := + (∀ i:Grid,(funds a i).1.2= targetMark p v M (sendId b i) (sendId (!b) i))∧ + ∀ j:Bool,couple _ (funds a (transit b (true,j))) = + couple _ (funds a (transit b (false,j))) + +def rhyme {b : Bool} (a : Amounts p q d b) (x : Amounts p q e (!b)) := + ∀ i:Grid,(funds a i).1.1+(funds x i).1.1=1 + +set_option maxHeartbeats 800000 in +theorem spoken (v : Charts p n d) (w : Charts p n e) (M : Cross p n) (z : Messenger q→ F) + (a : Amounts p q d true) (b : Amounts p q e false) : + speak _ _ (sendSum z a b)=(hailing p v w M,0) ↔ + (∀ i,fullq z i=1)∧rhyme a b∧ still true a v M∧ still false b w (reciprocal p M) := by + classical + let f i:=funds a i; let g i:= funds b i + let h1 i := couple (d (sendId true i)) (f i) + let h2 i := couple (e (sendId false i)) (g i) + rw [speak_val] + simp_rw [sendSum_by] + have h (x y:F) : x+y=0↔ x=y := by rw [← ZModModule.sub_eq_add,sub_eq_zero] + constructor + · intro ht + have hh := congrArg Prod.fst ht + have hx := congrArg Prod.fst (congrArg Prod.snd ht) + have hy := congrArg Prod.snd (congrArg Prod.snd ht) + refine ⟨fun i=>congrArg Prod.fst (congr_fun hh i),fun i=>congrArg (fun x=>x.2.1) + (congr_fun hh i),⟨fun i=>congrArg (fun x=>x.2.2.1) (congr_fun hh i),fun i=>?_⟩, + fun i=>congrArg (fun x=>x.2.2.2) (congr_fun hh i),fun i=>?_⟩ + · have ht:=congr_fun hx i + change ∑ j:Bool,h1 (j,i)=0 at ht; rw [Fintype.sum_bool,h] at ht; exact ht + have ht:=congr_fun hy i; change ∑ j:Bool,h2 (i,j)=0 at ht; rw [Fintype.sum_bool,h] at ht + exact ht + rintro ⟨ht,hv,⟨hF,hA⟩,hG,hB⟩ + apply Prod.ext + · funext i; exact Prod.ext (ht i) (Prod.ext (hv i) (Prod.ext (hF i) (hG i))) + apply Prod.ext + · funext i; change ∑ j:Bool,h1 (j,i)=0 + rw [Fintype.sum_bool,h]; exact hA i + funext i; change ∑ j:Bool,h2 (i,j)=0 + rw [Fintype.sum_bool,h]; exact hB i +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ExponentialGraphTransfer.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ExponentialGraphTransfer.lean index 583d79076b260c6905d9ccaa2dc432019ff05657..8e731ab49cee89a6fe6a8455af69dddd8eb26d57 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ExponentialGraphTransfer.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ExponentialGraphTransfer.lean @@ -1,131 +1,131 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteGraphTransfer -import OAI.Combinatorics.HadwigerCounterexample.ExponentialRates - -namespace OAI - -/-! # Exponential Graph Transfer -/ - -noncomputable section -namespace HadwigerCounterexample -open HadwigerMatching Real Filter - -def ord (g N : ℕ) := (2:ℕ)^(1000*g*N) -theorem cast_ord (g N : ℕ) : ((ord g N : ℕ):ℝ) = bp (1000*g*N) := by - unfold ord - have h := bp_nat (1000*g*N) - push_cast at * - exact h.symm - -theorem tendsto_ord {g : ℕ} (hg : 0 < g) : Tendsto (ord g) atTop atTop := by - have hl : Tendsto (fun n : ℕ => bp (1000*g*n)) atTop atTop := - (bp_tendsto (show (0:ℝ)<1000*g by positivity)).comp tendsto_natCast_atTop_atTop - rw [tendsto_atTop] - intro b - filter_upwards [hl.eventually (eventually_ge_atTop (b:ℝ))] with i hi - change _ ≤ bp _ at hi - rw [← cast_ord] at hi - exact_mod_cast hi - -/-- Raw supersaturation ⇒ existence for the sampled order. Takes any fixed -polynomial bit-count bound of degree two for the raw unit space. In particular -the eventual N-bound is independent of every law and graph. -/ -theorem transfer_scales {g : ℕ} (hg : 0 < g) {B : ℝ} (hB : 0 ≤ B) : - ∀ᶠ N : ℕ in atTop, ∀ (A : Type) [Fintype A] [Nonempty A] - (H : Holes A) (μ : Wgt A), IsLaw μ → - (Fintype.card (A × A) : ℝ) ≤ bp (B * (N:ℝ)^2) → - (∀ w : Wgt (A × A), IsLaw w → pairCaps μ (bp 1000) (bp (4000*g*N)) w → - carried w H.unit → bp (-100*g*N) ≤ pr (pairW w w) (fun x => H.conflict x.1 x.2)) → - ∃ x : Fin (ord g N) → A, - (H.graph x).indepNum ≤ 2 ∧ - (connectedMatchingNumber (H.graph x) : ℚ) < (ord g N : ℚ)/100 := by - have hg' : (1:ℝ) ≤ g := by exact_mod_cast hg - have hh := bp_poly_dom_nat (a:=100*g) (by positivity) (B+1) 2 - filter_upwards [hh, eventually_ge_atTop 1, - (tendsto_ord hg).eventually (eventually_ge_atTop 2)] with N hN hN' hord - intro A _ _ H μ hμ hA hs - let y : ℝ := g * (N:ℝ) - have hNr : (1:ℝ) ≤ N := by exact_mod_cast hN' - have hy : 1 ≤ y := by unfold y; nlinarith - let m := ord g N - let L : ℕ := 2^(200*g*N) - have hm : (m:ℝ) = bp (1000*y) := by rw [cast_ord]; unfold y; ring_nf - have hl : (L:ℝ) = bp (200*y) := by - have h := (bp_nat (200*g*N)).symm - push_cast at h - dsimp only [L] - push_cast - unfold y - rwa [← mul_assoc] - let z : ℝ := B*(N:ℝ)^2 - have hz : 0 ≤ z := by unfold z; positivity - have hb : z + 1 < bp (100*y) := by - have hh : (B+1)*(N:ℝ)^2 < bp (100*y) := by simpa only [y, mul_assoc] using hN - unfold z - nlinarith only [hh,hNr] - let k := (m+199)/200 - refine transfer H hμ (bp_pos _) (bp_pos _) (bp_pos _) hs (L:=L) (k:=k) ?_ ?_ ?_ - · have hi : log (Fintype.card (A × A) : ℝ) ≤ z * Real.log 2 := by - rw [← log_bp] - exact Real.log_le_log (by exact_mod_cast Fintype.card_pos) hA - apply lt_of_le_of_lt hi - calc z * log 2 < bp (100*y)*log 2 := - mul_lt_mul_of_pos_right (by linarith only [hb]) (Real.log_pos (by norm_num)) - _ = _ := by - rw [hl,← mul_assoc (bp (200 * y)),← bp_add] - unfold y; ring_nf - · change 200*((m+199)/200) < m+200 - omega - · have hk : (m:ℝ) ≤ 200*k := by - have hk : m ≤ 200*k := by unfold k; omega - exact_mod_cast hk - have hm' : (2:ℝ) ≤ m := by exact_mod_cast hord - let a := (Fintype.card (A × A):ℝ)+1 - have ha : a ≤ bp (z+1) := by - rw [bp_add,bp_one] - have hx : 1 ≤ bp z := by simpa only [bp_zero] using bp_le hz - change _ ≤ bp z at hA - dsimp only [a] - linarith only [hx,hA] - have hal : a^L ≤ bp (m:ℝ) := calc - a^L ≤ bp (z+1)^L := by - have hp : 0 ≤ a := by dsimp [a]; positivity - gcongr - _ = bp ((z+1)*L) := (bp_mul_nat _ _).symm - _ ≤ bp (m:ℝ) := bp_le (by - rw [hm,hl] - calc (z+1)*bp (200*y) ≤ bp (100*y)*bp (200*y) := - mul_le_mul_of_nonneg_right hb.le (bp_pos _).le - _ ≤ bp (1000*y) := by rw [← bp_add]; apply bp_le; linarith only [hy]) - let d := bp (4000*(g:ℝ)*(N:ℝ)) - have ha1 : bp (m:ℝ) * ((2:ℝ)^m * (2/bp 1000)^k) ≤ bp (-(m:ℝ)) := by - rw [← bp_nat, show 2/bp 1000 = bp (1-1000) by simp only [bp_sub,bp_one], - ← bp_mul_nat, ← bp_add, ← bp_add] - apply bp_le - linarith - have ha2 : bp (m:ℝ) * ((m:ℝ)^(k+k) * (d⁻¹)^k) ≤ bp (-(m:ℝ)) := by - - have he : (m:ℝ)^(k+k) = bp ((1000*y)*(k+k:ℕ)) := by - rw [hm,bp_mul_nat] - rw [he, show d⁻¹ = bp (-(4000*y)) by simp only [bp_neg,d,y,mul_assoc], - ← bp_mul_nat, ← bp_add, ← bp_add] - apply bp_le - push_cast - have hx : (k:ℝ) ≤ y*k := by - have : 0 ≤ (k:ℝ) := Nat.cast_nonneg _ - nlinarith - linarith - have hx : bp (-(m:ℝ)) < 1/2 := by - rw [show (1:ℝ)/2 = bp (-1) by simp only [one_div,bp_neg,bp_one]] - exact bp_lt (by linarith only [hm']) - change a^L * (2^m * (2/bp 1000)^k + (m:ℝ)^(k+k) * d⁻¹^k) < 1 - refine lt_of_le_of_lt (mul_le_mul_of_nonneg_right hal (by - have h := bp_pos 1000 - have h' : 0 < d := bp_pos _ - positivity)) ?_ - linarith only [ha1,ha2,hx] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteGraphTransfer +import OAI.Combinatorics.HadwigerCounterexample.ExponentialRates + +namespace OAI + +/-! # Exponential Graph Transfer -/ + +noncomputable section +namespace HadwigerCounterexample +open HadwigerMatching Real Filter + +def ord (g N : ℕ) := (2:ℕ)^(1000*g*N) +theorem cast_ord (g N : ℕ) : ((ord g N : ℕ):ℝ) = bp (1000*g*N) := by + unfold ord + have h := bp_nat (1000*g*N) + push_cast at * + exact h.symm + +theorem tendsto_ord {g : ℕ} (hg : 0 < g) : Tendsto (ord g) atTop atTop := by + have hl : Tendsto (fun n : ℕ => bp (1000*g*n)) atTop atTop := + (bp_tendsto (show (0:ℝ)<1000*g by positivity)).comp tendsto_natCast_atTop_atTop + rw [tendsto_atTop] + intro b + filter_upwards [hl.eventually (eventually_ge_atTop (b:ℝ))] with i hi + change _ ≤ bp _ at hi + rw [← cast_ord] at hi + exact_mod_cast hi + +/-- Raw supersaturation ⇒ existence for the sampled order. Takes any fixed +polynomial bit-count bound of degree two for the raw unit space. In particular +the eventual N-bound is independent of every law and graph. -/ +theorem transfer_scales {g : ℕ} (hg : 0 < g) {B : ℝ} (hB : 0 ≤ B) : + ∀ᶠ N : ℕ in atTop, ∀ (A : Type) [Fintype A] [Nonempty A] + (H : Holes A) (μ : Wgt A), IsLaw μ → + (Fintype.card (A × A) : ℝ) ≤ bp (B * (N:ℝ)^2) → + (∀ w : Wgt (A × A), IsLaw w → pairCaps μ (bp 1000) (bp (4000*g*N)) w → + carried w H.unit → bp (-100*g*N) ≤ pr (pairW w w) (fun x => H.conflict x.1 x.2)) → + ∃ x : Fin (ord g N) → A, + (H.graph x).indepNum ≤ 2 ∧ + (connectedMatchingNumber (H.graph x) : ℚ) < (ord g N : ℚ)/100 := by + have hg' : (1:ℝ) ≤ g := by exact_mod_cast hg + have hh := bp_poly_dom_nat (a:=100*g) (by positivity) (B+1) 2 + filter_upwards [hh, eventually_ge_atTop 1, + (tendsto_ord hg).eventually (eventually_ge_atTop 2)] with N hN hN' hord + intro A _ _ H μ hμ hA hs + let y : ℝ := g * (N:ℝ) + have hNr : (1:ℝ) ≤ N := by exact_mod_cast hN' + have hy : 1 ≤ y := by unfold y; nlinarith + let m := ord g N + let L : ℕ := 2^(200*g*N) + have hm : (m:ℝ) = bp (1000*y) := by rw [cast_ord]; unfold y; ring_nf + have hl : (L:ℝ) = bp (200*y) := by + have h := (bp_nat (200*g*N)).symm + push_cast at h + dsimp only [L] + push_cast + unfold y + rwa [← mul_assoc] + let z : ℝ := B*(N:ℝ)^2 + have hz : 0 ≤ z := by unfold z; positivity + have hb : z + 1 < bp (100*y) := by + have hh : (B+1)*(N:ℝ)^2 < bp (100*y) := by simpa only [y, mul_assoc] using hN + unfold z + nlinarith only [hh,hNr] + let k := (m+199)/200 + refine transfer H hμ (bp_pos _) (bp_pos _) (bp_pos _) hs (L:=L) (k:=k) ?_ ?_ ?_ + · have hi : log (Fintype.card (A × A) : ℝ) ≤ z * Real.log 2 := by + rw [← log_bp] + exact Real.log_le_log (by exact_mod_cast Fintype.card_pos) hA + apply lt_of_le_of_lt hi + calc z * log 2 < bp (100*y)*log 2 := + mul_lt_mul_of_pos_right (by linarith only [hb]) (Real.log_pos (by norm_num)) + _ = _ := by + rw [hl,← mul_assoc (bp (200 * y)),← bp_add] + unfold y; ring_nf + · change 200*((m+199)/200) < m+200 + omega + · have hk : (m:ℝ) ≤ 200*k := by + have hk : m ≤ 200*k := by unfold k; omega + exact_mod_cast hk + have hm' : (2:ℝ) ≤ m := by exact_mod_cast hord + let a := (Fintype.card (A × A):ℝ)+1 + have ha : a ≤ bp (z+1) := by + rw [bp_add,bp_one] + have hx : 1 ≤ bp z := by simpa only [bp_zero] using bp_le hz + change _ ≤ bp z at hA + dsimp only [a] + linarith only [hx,hA] + have hal : a^L ≤ bp (m:ℝ) := calc + a^L ≤ bp (z+1)^L := by + have hp : 0 ≤ a := by dsimp [a]; positivity + gcongr + _ = bp ((z+1)*L) := (bp_mul_nat _ _).symm + _ ≤ bp (m:ℝ) := bp_le (by + rw [hm,hl] + calc (z+1)*bp (200*y) ≤ bp (100*y)*bp (200*y) := + mul_le_mul_of_nonneg_right hb.le (bp_pos _).le + _ ≤ bp (1000*y) := by rw [← bp_add]; apply bp_le; linarith only [hy]) + let d := bp (4000*(g:ℝ)*(N:ℝ)) + have ha1 : bp (m:ℝ) * ((2:ℝ)^m * (2/bp 1000)^k) ≤ bp (-(m:ℝ)) := by + rw [← bp_nat, show 2/bp 1000 = bp (1-1000) by simp only [bp_sub,bp_one], + ← bp_mul_nat, ← bp_add, ← bp_add] + apply bp_le + linarith + have ha2 : bp (m:ℝ) * ((m:ℝ)^(k+k) * (d⁻¹)^k) ≤ bp (-(m:ℝ)) := by + + have he : (m:ℝ)^(k+k) = bp ((1000*y)*(k+k:ℕ)) := by + rw [hm,bp_mul_nat] + rw [he, show d⁻¹ = bp (-(4000*y)) by simp only [bp_neg,d,y,mul_assoc], + ← bp_mul_nat, ← bp_add, ← bp_add] + apply bp_le + push_cast + have hx : (k:ℝ) ≤ y*k := by + have : 0 ≤ (k:ℝ) := Nat.cast_nonneg _ + nlinarith + linarith + have hx : bp (-(m:ℝ)) < 1/2 := by + rw [show (1:ℝ)/2 = bp (-1) by simp only [one_div,bp_neg,bp_one]] + exact bp_lt (by linarith only [hm']) + change a^L * (2^m * (2/bp 1000)^k + (m:ℝ)^(k+k) * d⁻¹^k) < 1 + refine lt_of_le_of_lt (mul_le_mul_of_nonneg_right hal (by + have h := bp_pos 1000 + have h' : 0 < d := bp_pos _ + positivity)) ?_ + linarith only [ha1,ha2,hx] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ExponentialRates.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ExponentialRates.lean index 65da1bf544aa1156610eab56ea457c2c3a98ee54..062801a1c7977c8042857a13979e79393298689e 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ExponentialRates.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ExponentialRates.lean @@ -1,122 +1,122 @@ -import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics -import Mathlib.Tactic.Linarith -import Mathlib.Tactic.Ring -import Mathlib.Tactic.Positivity - -namespace OAI - -/-! # Exponential Rates -/ - -noncomputable section -namespace HadwigerCounterexample - -open Filter Real -open scoped Topology - -def bp (x : ℝ) := (2:ℝ)^x -@[simp] theorem bp_zero : bp 0 = 1 := by simp [bp] -@[simp] theorem bp_one : bp 1 = 2 := by simp [bp] -theorem bp_pos (x : ℝ) : 0 < bp x := by unfold bp; positivity -theorem bp_nat (x : ℕ) : bp x = (2:ℝ)^x := by simp [bp] -theorem bp_add (x y : ℝ) : bp (x+y) = bp x * bp y := - Real.rpow_add (by norm_num) _ _ -theorem bp_sub (x y : ℝ) : bp (x-y) = bp x / bp y := - Real.rpow_sub (by norm_num) _ _ -theorem bp_neg (x : ℝ) : bp (-x) = (bp x)⁻¹ := by simpa using bp_sub 0 x -theorem bp_mul_nat (x : ℝ) (n : ℕ) : bp (x*n) = bp x ^ n := by - unfold bp; rw [Real.rpow_mul (by norm_num)]; simp -@[gcongr] theorem bp_le {x y : ℝ} (h : x ≤ y) : bp x ≤ bp y := - Real.rpow_le_rpow_of_exponent_le (by norm_num) h -@[gcongr] theorem bp_lt {x y : ℝ} (h : x < y) : bp x < bp y := - Real.rpow_lt_rpow_of_exponent_lt (by norm_num) h -theorem log_bp (x : ℝ) : log (bp x) = x * log 2 := Real.log_rpow (by norm_num) _ - -theorem bp_poly_dom {a : ℝ} (ha : 0 < a) (c d : ℝ) : - ∀ᶠ x : ℝ in atTop, c*x^d < bp (a*x) := by - have hla : 0 < Real.log 2 * a := mul_pos (Real.log_pos (by norm_num)) ha - have h := tendsto_exp_mul_div_rpow_atTop d _ hla - filter_upwards [h.eventually (eventually_gt_atTop c), eventually_gt_atTop (0:ℝ)] with x hx hx' - change c < Real.exp ((Real.log 2*a)*x)/x^d at hx - rw [lt_div_iff₀ (by positivity)] at hx - rwa [bp, Real.rpow_def_of_pos (by norm_num : (0:ℝ)<2), ← mul_assoc] - -theorem bp_poly_dom_nat {a : ℝ} (ha : 0 < a) (c : ℝ) (d : ℕ) : - ∀ᶠ n : ℕ in atTop, c*(n:ℝ)^d < bp (a*n) := by - have h := (tendsto_natCast_atTop_atTop (R:=ℝ)).eventually (bp_poly_dom ha c d) - simpa using h - -theorem bp_tendsto {a : ℝ} (ha : 0 < a) : - Tendsto (fun x : ℝ => bp (a*x)) atTop atTop := - (tendsto_rpow_atTop_of_base_gt_one 2 (by norm_num)).comp - ((tendsto_const_mul_atTop_of_pos ha).mpr tendsto_id) - -theorem bp_tendsto_zero {a : ℝ} (ha : 0 < a) : - Tendsto (fun x : ℝ => bp (-a*x)) atTop (𝓝 0) := by - simp_rw [neg_mul,bp_neg] - exact (bp_tendsto ha).inv_tendsto_atTop - -variable {ι : Type*} {l : Filter ι} {n f g : ι → ℝ} - -/-- Exponentially small at scale n. -/ -def ExpSmall (l : Filter ι) (n f : ι → ℝ) := - ∃ c : ℝ, 0 < c ∧ ∀ᶠ i in l, |f i| ≤ bp (-c * n i) - -/-- Subexponential upper bound at scale n. -/ -def ExpO (l : Filter ι) (n f : ι → ℝ) := - ∀ c : ℝ, 0 < c → ∀ᶠ i in l, |f i| ≤ bp (c * n i) - -namespace ExpSmall -theorem mono (hf : ExpSmall l n f) (h : ∀ᶠ i in l, |g i| ≤ |f i|) : ExpSmall l n g := by - rcases hf with ⟨c,hc,hf⟩ - exact ⟨c,hc, h.and hf |>.mono fun _ ⟨h,g⟩ => h.trans g⟩ - -theorem zero (l : Filter ι) (n : ι → ℝ) : ExpSmall l n (fun _ => 0) := by - refine ⟨1, by norm_num, .of_forall fun _ => ?_⟩ - rw [abs_zero]; exact (bp_pos _).le - -theorem mul (hf : ExpSmall l n f) (hg : ExpO l n g) : - ExpSmall l n (fun i => f i*g i) := by - obtain ⟨c,hc,h⟩ := hf - refine ⟨c/2,by linarith,?_⟩ - filter_upwards [h,hg (c/2) (by linarith)] with i hi hj - rw [abs_mul, show -(c/2)*n i = -c*n i + c/2*n i by ring, bp_add] - exact mul_le_mul hi hj (abs_nonneg _) (bp_pos _).le - -theorem add (hn : Tendsto n l atTop) (hf : ExpSmall l n f) (hg : ExpSmall l n g) : - ExpSmall l n (fun i => f i+g i) := by - obtain ⟨c,hc,h⟩ := hf; obtain ⟨d,hd,h'⟩ := hg - let a := min c d - have ha : 0 < a := lt_min hc hd - refine ⟨a/2,by linarith, ?_⟩ - filter_upwards [h,h',hn.eventually (eventually_ge_atTop 0), - ((bp_tendsto (show 0 < a/2 by linarith)).comp hn).eventually - (eventually_ge_atTop 2)] with i hi hj hx hb - change 2 ≤ bp (a/2*n i) at hb - have h₁ : -c*n i ≤ -a*n i := by gcongr; exact min_le_left _ _ - have h₂ : -d*n i ≤ -a*n i := by gcongr; exact min_le_right _ _ - refine le_trans (abs_add_le _ _) ?_ - rw [show -(a/2)*n i = a/2*n i + -a*n i by ring,bp_add] - calc |f i| + |g i| ≤ bp (-a*n i)+bp (-a*n i) := - add_le_add (hi.trans (bp_le h₁)) (hj.trans (bp_le h₂)) - _ = 2*bp (-a*n i) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_right hb (bp_pos _).le - -theorem lim (hn : Tendsto n l atTop) (hf : ExpSmall l n f) : - Tendsto f l (𝓝 0) := by - obtain ⟨c,hc,h⟩ := hf - have hl := (bp_tendsto_zero hc).comp hn - refine tendsto_of_tendsto_of_tendsto_of_le_of_le' ?_ hl - (h.mono fun i hi => (abs_le.mp hi).1) - (h.mono fun i hi => (abs_le.mp hi).2) - simpa using hl.neg -end ExpSmall - -theorem expO_const (hn : Tendsto n l atTop) (b : ℝ) : - ExpO l n (fun _ => b) := fun _ hc => - ((bp_tendsto hc).comp hn).eventually (eventually_ge_atTop _) - -end HadwigerCounterexample - -end - -end OAI +import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics +import Mathlib.Tactic.Linarith +import Mathlib.Tactic.Ring +import Mathlib.Tactic.Positivity + +namespace OAI + +/-! # Exponential Rates -/ + +noncomputable section +namespace HadwigerCounterexample + +open Filter Real +open scoped Topology + +def bp (x : ℝ) := (2:ℝ)^x +@[simp] theorem bp_zero : bp 0 = 1 := by simp [bp] +@[simp] theorem bp_one : bp 1 = 2 := by simp [bp] +theorem bp_pos (x : ℝ) : 0 < bp x := by unfold bp; positivity +theorem bp_nat (x : ℕ) : bp x = (2:ℝ)^x := by simp [bp] +theorem bp_add (x y : ℝ) : bp (x+y) = bp x * bp y := + Real.rpow_add (by norm_num) _ _ +theorem bp_sub (x y : ℝ) : bp (x-y) = bp x / bp y := + Real.rpow_sub (by norm_num) _ _ +theorem bp_neg (x : ℝ) : bp (-x) = (bp x)⁻¹ := by simpa using bp_sub 0 x +theorem bp_mul_nat (x : ℝ) (n : ℕ) : bp (x*n) = bp x ^ n := by + unfold bp; rw [Real.rpow_mul (by norm_num)]; simp +@[gcongr] theorem bp_le {x y : ℝ} (h : x ≤ y) : bp x ≤ bp y := + Real.rpow_le_rpow_of_exponent_le (by norm_num) h +@[gcongr] theorem bp_lt {x y : ℝ} (h : x < y) : bp x < bp y := + Real.rpow_lt_rpow_of_exponent_lt (by norm_num) h +theorem log_bp (x : ℝ) : log (bp x) = x * log 2 := Real.log_rpow (by norm_num) _ + +theorem bp_poly_dom {a : ℝ} (ha : 0 < a) (c d : ℝ) : + ∀ᶠ x : ℝ in atTop, c*x^d < bp (a*x) := by + have hla : 0 < Real.log 2 * a := mul_pos (Real.log_pos (by norm_num)) ha + have h := tendsto_exp_mul_div_rpow_atTop d _ hla + filter_upwards [h.eventually (eventually_gt_atTop c), eventually_gt_atTop (0:ℝ)] with x hx hx' + change c < Real.exp ((Real.log 2*a)*x)/x^d at hx + rw [lt_div_iff₀ (by positivity)] at hx + rwa [bp, Real.rpow_def_of_pos (by norm_num : (0:ℝ)<2), ← mul_assoc] + +theorem bp_poly_dom_nat {a : ℝ} (ha : 0 < a) (c : ℝ) (d : ℕ) : + ∀ᶠ n : ℕ in atTop, c*(n:ℝ)^d < bp (a*n) := by + have h := (tendsto_natCast_atTop_atTop (R:=ℝ)).eventually (bp_poly_dom ha c d) + simpa using h + +theorem bp_tendsto {a : ℝ} (ha : 0 < a) : + Tendsto (fun x : ℝ => bp (a*x)) atTop atTop := + (tendsto_rpow_atTop_of_base_gt_one 2 (by norm_num)).comp + ((tendsto_const_mul_atTop_of_pos ha).mpr tendsto_id) + +theorem bp_tendsto_zero {a : ℝ} (ha : 0 < a) : + Tendsto (fun x : ℝ => bp (-a*x)) atTop (𝓝 0) := by + simp_rw [neg_mul,bp_neg] + exact (bp_tendsto ha).inv_tendsto_atTop + +variable {ι : Type*} {l : Filter ι} {n f g : ι → ℝ} + +/-- Exponentially small at scale n. -/ +def ExpSmall (l : Filter ι) (n f : ι → ℝ) := + ∃ c : ℝ, 0 < c ∧ ∀ᶠ i in l, |f i| ≤ bp (-c * n i) + +/-- Subexponential upper bound at scale n. -/ +def ExpO (l : Filter ι) (n f : ι → ℝ) := + ∀ c : ℝ, 0 < c → ∀ᶠ i in l, |f i| ≤ bp (c * n i) + +namespace ExpSmall +theorem mono (hf : ExpSmall l n f) (h : ∀ᶠ i in l, |g i| ≤ |f i|) : ExpSmall l n g := by + rcases hf with ⟨c,hc,hf⟩ + exact ⟨c,hc, h.and hf |>.mono fun _ ⟨h,g⟩ => h.trans g⟩ + +theorem zero (l : Filter ι) (n : ι → ℝ) : ExpSmall l n (fun _ => 0) := by + refine ⟨1, by norm_num, .of_forall fun _ => ?_⟩ + rw [abs_zero]; exact (bp_pos _).le + +theorem mul (hf : ExpSmall l n f) (hg : ExpO l n g) : + ExpSmall l n (fun i => f i*g i) := by + obtain ⟨c,hc,h⟩ := hf + refine ⟨c/2,by linarith,?_⟩ + filter_upwards [h,hg (c/2) (by linarith)] with i hi hj + rw [abs_mul, show -(c/2)*n i = -c*n i + c/2*n i by ring, bp_add] + exact mul_le_mul hi hj (abs_nonneg _) (bp_pos _).le + +theorem add (hn : Tendsto n l atTop) (hf : ExpSmall l n f) (hg : ExpSmall l n g) : + ExpSmall l n (fun i => f i+g i) := by + obtain ⟨c,hc,h⟩ := hf; obtain ⟨d,hd,h'⟩ := hg + let a := min c d + have ha : 0 < a := lt_min hc hd + refine ⟨a/2,by linarith, ?_⟩ + filter_upwards [h,h',hn.eventually (eventually_ge_atTop 0), + ((bp_tendsto (show 0 < a/2 by linarith)).comp hn).eventually + (eventually_ge_atTop 2)] with i hi hj hx hb + change 2 ≤ bp (a/2*n i) at hb + have h₁ : -c*n i ≤ -a*n i := by gcongr; exact min_le_left _ _ + have h₂ : -d*n i ≤ -a*n i := by gcongr; exact min_le_right _ _ + refine le_trans (abs_add_le _ _) ?_ + rw [show -(a/2)*n i = a/2*n i + -a*n i by ring,bp_add] + calc |f i| + |g i| ≤ bp (-a*n i)+bp (-a*n i) := + add_le_add (hi.trans (bp_le h₁)) (hj.trans (bp_le h₂)) + _ = 2*bp (-a*n i) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_right hb (bp_pos _).le + +theorem lim (hn : Tendsto n l atTop) (hf : ExpSmall l n f) : + Tendsto f l (𝓝 0) := by + obtain ⟨c,hc,h⟩ := hf + have hl := (bp_tendsto_zero hc).comp hn + refine tendsto_of_tendsto_of_tendsto_of_le_of_le' ?_ hl + (h.mono fun i hi => (abs_le.mp hi).1) + (h.mono fun i hi => (abs_le.mp hi).2) + simpa using hl.neg +end ExpSmall + +theorem expO_const (hn : Tendsto n l atTop) (b : ℝ) : + ExpO l n (fun _ => b) := fun _ hc => + ((bp_tendsto hc).comp hn).eventually (eventually_ge_atTop _) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FinalContradiction.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FinalContradiction.lean index ba14a92d3b46bd4b53b78a8dac770dcad5e38c3f..5bd78b7137d6faf253328690a05e5dbe254c1a64 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FinalContradiction.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FinalContradiction.lean @@ -1,121 +1,121 @@ -import OAI.Combinatorics.HadwigerCounterexample.CompatiblePairTests - -namespace OAI - -/-! # Final Contradiction -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Matrix Finset Module LinearMap Function -open scoped BigOperators Topology -open Template -namespace StatusAnalysis -open PreparationParameters Station PredictionClass Club Guild DualAnalysis -variable {p:Shape} {n N M r s0:ℕ} {w:rhythms p M} - {m:cycleM p} {u:tale p M} {b:PreparationParameters} {l:Filter ℕ} - -private theorem focused (x:Sketch p M): - ∃ (L:ℕ) (Y:∀ n,Silhouette p (M*n) L),∀ (n r:ℕ) (X:Silhouette p (M*n) r), - refines X (Y n) → ∀ τ:ℝ, recital x.c p (fun i=>x.g i n) x.α τ → - ∃ f:Bool→ Pulsar p r,hue x.c X f (fun i=>x.g i n) x.α τ := by - classical - let L:=Fintype.card (Bool→ F); let E:=Fintype.equivFin (Bool→F) - let Y (n:ℕ):Silhouette p (M*n) L := fun i q y=> E (fun j=> x.g j n i q y) - refine ⟨L,Y,fun n r X h τ ht=>?_⟩ - choose f hf using h - by_cases he : x.c=dusk - · exact ⟨0,ht.1,fun hh=>(hh he).elim,fun _ _=>rfl,ht⟩ - let g j i q k:= (E.symm (f i q k)) j - have hv j: fromPulse X (g j)=x.g j n:= by - unfold fromPulse g; funext i q y; rw [← hf] - exact congr_fun (Equiv.symm_apply_apply E _) j - exact ⟨g, ht.1,fun _=>hv,fun h=>(he h).elim,ht⟩ - -private theorem haveLeads (h:veil p M b s0 l m w u) : - ∀ᶠ n in l,Lead (u n) (w n) (m n) b:= by - filter_upwards [h.durableS.shape,h.moment,h.durableS.mass.positive] with n hn ht hh - exact ⟨hn.1,hh,ht.1.law,hn.2⟩ - -set_option maxHeartbeats 1400000 in -theorem goldEnd (v:Stations p M b.pins w) (h:veil p M b s0 l m w u) (ht:∀ᶠ n in l,(v n).bank) - (hs:l.NeBot) (x:Sketch p M) - (hb:b.bright l p M m w x) (hf:glowOutcome l p M u w x) : False := by - classical - obtain ⟨A,hA,hF⟩:=hf - obtain ⟨τ,hτ,hT⟩:=hb.forecasts.classes - let B:=min τ (1/4); have hB:0x.g i n) x.α B := ⟨hf.1,fun i j s t r hi hg=>hf.2 i j s t r - hi (fun i j=>(hg i j).trans (min_le_left ..))⟩ - obtain ⟨f,hf⟩:= hY _ _ X hX B hh - let W:=KAspect (w n); let V:=cirque (w n) (u n) - let H (i:W):=¬gauze p d d X (m n) K i.2 - let P (i:W×W):= eligiblePair (v n) (m n) i.1 i.2 X a - let S := fun i:UnitType p n (M*n)×_=>matchProg x n i∧secureAt p (w n).rooting i - let T:= fun i:W×W=> S (i.1.2,i.2.2) - have hD i (hi: V i≠0)(hq:T i): ((H i.1∨H i.2) ∨ P i):=by - by_cases hc:H i.1∨ H i.2 - · exact Or.inl hc - refine Or.inr (foretold w m x _ h _ hn heE heq ht'.age X f hf he hC hp hx_ - (show 10*ε≤B from by linarith only [hM]) - (show 2*B<1 by have h: B≤1/4:=min_le_right ..; linarith only [h]) - hP i hi (not_not.mp (mt Or.inl hc)) (not_not.mp (mt Or.inr hc)) hq.1 hq.2) - have hQ0 := (troupe_bill hn).1; have hV:IsLaw V:=pairW_law hQ0 hQ0 - have hV' : pr V T ≥ A := by - unfold gilded at hξ; rw [←cirque_unit _ hn,mapW_pr] at hξ; exact hξ - have h1 := (sickBound (u n) (v n) X hn _ _ _ _ hP).2 - have h2 : pr V T ≤ (A/4+A/4)+A/4:= ((pr_on_mono hV.nz hD).trans - (pr_or_le hV.nz)).trans (add_le_add h1 hP.zone) - linarith only [h1,h2,hV',hA] - exact hX.exists.elim (fun _ h=>h) - -set_option maxHeartbeats 1200000 in -theorem quietEnd (v:Stations p M b.pins w) (h:veil p M b s0 l m w u) - (ht:∀ᶠ n in l,(v n).bank) (hs:l.NeBot) - (hq:b.silenceOutcome l p M m u w) : False := by - classical - obtain ⟨τ,hτ,hQ⟩:=hq - let K:=b.pins - obtain ⟨ε,η,he,hM,hC⟩:= cheapFest p K (τ/20) (by positivity) - obtain ⟨a,hp⟩:= engagedBudget p K hC.pos - obtain ⟨r,d,hr⟩:=lightmap v h a ε (1/16) hp.1 he (by norm_num) 1 - (fun _ _ _ _=>0) - have hF:∀ᶠ n in l, False := by - filter_upwards [hr,hQ,ht,h.upright,haveLeads h] with n hn hq ht hi hx - obtain ⟨X,_,hE⟩:=hn - exact no_out (w n) b (m n) X (u n) _ _ _ _ _ τ hx ht h.easel hi.age hC he hp hE - (by linarith only [hM]) hq.1 hq.2 - exact hF.exists.elim (fun _ hi=>hi) - -instance stationInhabited (p : Shape) (n N K : ℕ) (w:LeafMixture p n N) : - Inhabited (Station p n N K w) := ⟨⟨fun _ _ _=>0,fun _ _ _=>0⟩⟩ - -theorem refuteVeil (h:veil p M b s0 l m w u) (hs:l.NeBot) - (hT: b.silenceOutcome l p M m u w ∨ b.predOutcome l p M m u w) : - False := by - classical - have he : - ∀ᶠ n in l, ∃ s:Station p n (M*n) b.pins (w n),s.bank := by - filter_upwards [h.durableS.shape] with n hn - exact Station.create (fun x=>(hn.1.leaf _ x.property).bound) - obtain ⟨s,hq⟩:= taking he - rcases hT with hP|⟨b,hf,hR|hR⟩ - · exact quietEnd s h hq hs hP - · exact goldEnd s h hq hs b hf hR - exact dim_end h s hq hs b hf hR -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CompatiblePairTests + +namespace OAI + +/-! # Final Contradiction -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Matrix Finset Module LinearMap Function +open scoped BigOperators Topology +open Template +namespace StatusAnalysis +open PreparationParameters Station PredictionClass Club Guild DualAnalysis +variable {p:Shape} {n N M r s0:ℕ} {w:rhythms p M} + {m:cycleM p} {u:tale p M} {b:PreparationParameters} {l:Filter ℕ} + +private theorem focused (x:Sketch p M): + ∃ (L:ℕ) (Y:∀ n,Silhouette p (M*n) L),∀ (n r:ℕ) (X:Silhouette p (M*n) r), + refines X (Y n) → ∀ τ:ℝ, recital x.c p (fun i=>x.g i n) x.α τ → + ∃ f:Bool→ Pulsar p r,hue x.c X f (fun i=>x.g i n) x.α τ := by + classical + let L:=Fintype.card (Bool→ F); let E:=Fintype.equivFin (Bool→F) + let Y (n:ℕ):Silhouette p (M*n) L := fun i q y=> E (fun j=> x.g j n i q y) + refine ⟨L,Y,fun n r X h τ ht=>?_⟩ + choose f hf using h + by_cases he : x.c=dusk + · exact ⟨0,ht.1,fun hh=>(hh he).elim,fun _ _=>rfl,ht⟩ + let g j i q k:= (E.symm (f i q k)) j + have hv j: fromPulse X (g j)=x.g j n:= by + unfold fromPulse g; funext i q y; rw [← hf] + exact congr_fun (Equiv.symm_apply_apply E _) j + exact ⟨g, ht.1,fun _=>hv,fun h=>(he h).elim,ht⟩ + +private theorem haveLeads (h:veil p M b s0 l m w u) : + ∀ᶠ n in l,Lead (u n) (w n) (m n) b:= by + filter_upwards [h.durableS.shape,h.moment,h.durableS.mass.positive] with n hn ht hh + exact ⟨hn.1,hh,ht.1.law,hn.2⟩ + +set_option maxHeartbeats 1400000 in +theorem goldEnd (v:Stations p M b.pins w) (h:veil p M b s0 l m w u) (ht:∀ᶠ n in l,(v n).bank) + (hs:l.NeBot) (x:Sketch p M) + (hb:b.bright l p M m w x) (hf:glowOutcome l p M u w x) : False := by + classical + obtain ⟨A,hA,hF⟩:=hf + obtain ⟨τ,hτ,hT⟩:=hb.forecasts.classes + let B:=min τ (1/4); have hB:0x.g i n) x.α B := ⟨hf.1,fun i j s t r hi hg=>hf.2 i j s t r + hi (fun i j=>(hg i j).trans (min_le_left ..))⟩ + obtain ⟨f,hf⟩:= hY _ _ X hX B hh + let W:=KAspect (w n); let V:=cirque (w n) (u n) + let H (i:W):=¬gauze p d d X (m n) K i.2 + let P (i:W×W):= eligiblePair (v n) (m n) i.1 i.2 X a + let S := fun i:UnitType p n (M*n)×_=>matchProg x n i∧secureAt p (w n).rooting i + let T:= fun i:W×W=> S (i.1.2,i.2.2) + have hD i (hi: V i≠0)(hq:T i): ((H i.1∨H i.2) ∨ P i):=by + by_cases hc:H i.1∨ H i.2 + · exact Or.inl hc + refine Or.inr (foretold w m x _ h _ hn heE heq ht'.age X f hf he hC hp hx_ + (show 10*ε≤B from by linarith only [hM]) + (show 2*B<1 by have h: B≤1/4:=min_le_right ..; linarith only [h]) + hP i hi (not_not.mp (mt Or.inl hc)) (not_not.mp (mt Or.inr hc)) hq.1 hq.2) + have hQ0 := (troupe_bill hn).1; have hV:IsLaw V:=pairW_law hQ0 hQ0 + have hV' : pr V T ≥ A := by + unfold gilded at hξ; rw [←cirque_unit _ hn,mapW_pr] at hξ; exact hξ + have h1 := (sickBound (u n) (v n) X hn _ _ _ _ hP).2 + have h2 : pr V T ≤ (A/4+A/4)+A/4:= ((pr_on_mono hV.nz hD).trans + (pr_or_le hV.nz)).trans (add_le_add h1 hP.zone) + linarith only [h1,h2,hV',hA] + exact hX.exists.elim (fun _ h=>h) + +set_option maxHeartbeats 1200000 in +theorem quietEnd (v:Stations p M b.pins w) (h:veil p M b s0 l m w u) + (ht:∀ᶠ n in l,(v n).bank) (hs:l.NeBot) + (hq:b.silenceOutcome l p M m u w) : False := by + classical + obtain ⟨τ,hτ,hQ⟩:=hq + let K:=b.pins + obtain ⟨ε,η,he,hM,hC⟩:= cheapFest p K (τ/20) (by positivity) + obtain ⟨a,hp⟩:= engagedBudget p K hC.pos + obtain ⟨r,d,hr⟩:=lightmap v h a ε (1/16) hp.1 he (by norm_num) 1 + (fun _ _ _ _=>0) + have hF:∀ᶠ n in l, False := by + filter_upwards [hr,hQ,ht,h.upright,haveLeads h] with n hn hq ht hi hx + obtain ⟨X,_,hE⟩:=hn + exact no_out (w n) b (m n) X (u n) _ _ _ _ _ τ hx ht h.easel hi.age hC he hp hE + (by linarith only [hM]) hq.1 hq.2 + exact hF.exists.elim (fun _ hi=>hi) + +instance stationInhabited (p : Shape) (n N K : ℕ) (w:LeafMixture p n N) : + Inhabited (Station p n N K w) := ⟨⟨fun _ _ _=>0,fun _ _ _=>0⟩⟩ + +theorem refuteVeil (h:veil p M b s0 l m w u) (hs:l.NeBot) + (hT: b.silenceOutcome l p M m u w ∨ b.predOutcome l p M m u w) : + False := by + classical + have he : + ∀ᶠ n in l, ∃ s:Station p n (M*n) b.pins (w n),s.bank := by + filter_upwards [h.durableS.shape] with n hn + exact Station.create (fun x=>(hn.1.leaf _ x.property).bound) + obtain ⟨s,hq⟩:= taking he + rcases hT with hP|⟨b,hf,hR|hR⟩ + · exact quietEnd s h hq hs hP + · exact goldEnd s h hq hs b hf hR + exact dim_end h s hq hs b hf hR +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteAffineLaws.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteAffineLaws.lean index 79bce217e1a1fcf06cb590f33beb61d2de07f18a..f4cc46269baf500560c8fcae42550623db318494 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteAffineLaws.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteAffineLaws.lean @@ -1,97 +1,97 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteConditioning -import OAI.Combinatorics.HadwigerCounterexample.MatrixRanks -import OAI.Combinatorics.HadwigerCounterexample.ExponentialRates - -namespace OAI - -/-! # Finite Affine Laws -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap -open scoped BigOperators - -section General -variable (V W : Type) -variable [AddCommGroup V] [Module F V] [AddCommGroup W] [Module F W] - -theorem card_space [Fintype V] : (Fintype.card V : ℝ) = bp (dim V) := by - rw [Module.card_eq_pow_finrank (K:=F)] - rw [show Fintype.card F = 2 from ZMod.card 2, bp_nat] - push_cast; rfl - -variable {V W} - -theorem add_polar (t : V) : ∀ x : V, x+t+t=x := by - intro x; rw [add_assoc,char_two,add_zero] - -/-- Equally likely images along every direction of an indexed family. The -translation hypothesis is before testing the specified targets. -/ -theorem translate_cap [Fintype V] [Fintype W] {T : Type*} [Fintype T] [Nonempty T] - {w : Wgt V} (hw : SubLaw w) - (f : V →ₗ[F] W) (g : T ↪ W) (h : ∀ t, ∃ v, f v = g t ∧ ∀ x, w (x+v) = w x) (y : W) : - pr w (fun x => f x=y) ≤ (Fintype.card T : ℝ)⁻¹ := by - classical - let u := mapW w f - have h1 (t : T) : u (y+g t) = u y := by - obtain ⟨v,hv,he⟩ := h t - change avg w _ = avg w _ - let E : V ≃ V := ⟨(·+v),(·+v),add_polar v,add_polar v⟩ - rw [← avg_bij E w (fun x => ind (f x = y+g t))] - change (avg (fun x => w (x+v)) (fun x => ind (f (x+v)=y+g t))) = _ - simp_rw [he,map_add,hv] - simp - have hu' : ∀ x, 0 ≤ u x := fun _ => pr_nonneg hw.nz - have hut : tot u ≤ 1 := by - have h : tot u = tot w := by simpa [u] using mapW_pr w f (fun _ => True) - exact h.le.trans hw.total - let k : T ↪ W := ⟨fun t => y+g t, fun i j h => g.injective (add_left_cancel h)⟩ - have h2 : (Fintype.card T:ℝ)*u y ≤ tot u := calc - _ = ∑ t : T, u (y+g t) := by simp [h1] - _ = ∑ x ∈ Finset.univ.map k, u x := by rw [Finset.sum_map]; rfl - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - (fun i _ _ => hu' i) - change u y ≤ _ - rw [←one_div,le_div_iff₀ (by exact_mod_cast Fintype.card_pos)] - rw [mul_comm] - exact h2.trans hut - -theorem unif_lin [Fintype V] [Fintype W] (f : V →ₗ[F] W) : - mapW unif f = unifOn (fun y => y ∈ range f) := by - rw [← unifOn_true] - refine uniform_orbit _ ⟨0,trivial⟩ (fun x _ => ⟨x,rfl⟩) ?_ - rintro _ _ ⟨y,rfl⟩ ⟨z,rfl⟩ - let d := z-y - let E : V ≃ V := ⟨(·+d),(·+d),add_polar d,add_polar d⟩ - refine ⟨E,fun _ => Iff.rfl, fun x => ?_⟩ - change f x = f y ↔ f (x+(z-y))=f z - rw [map_add,map_sub] - constructor - · intro h; rw [h,add_sub_cancel] - · intro h - apply add_right_cancel (b := f z-f y) - rw [h,add_sub_cancel] - -theorem pr_unif_lin [Fintype V] [Fintype W] (f : V →ₗ[F] W) (y : W) : - pr unif (fun x => f x=y) = ind (y ∈ range f) * bp (-(rk f:ℝ)) := by - classical - change mapW unif f y = _ - rw [unif_lin,unifOn_val,nbr_eq_card] - rw [card_space,bp_neg,div_eq_mul_inv] - -theorem map_unif_surjective [Fintype V] [Fintype W] (f : V →ₗ[F] W) - (h : Function.Surjective f) : mapW unif f = unif := by - rw [unif_lin,range_eq_top.mpr h] - simp only [Submodule.mem_top,unifOn_true] - -end General - -theorem dim_mat (I J : Type) [Fintype I] [Fintype J] : - dim (Mat I J) = Fintype.card I * Fintype.card J := by - simp only [dim,Mat,finrank_matrix,finrank_self,mul_one] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteConditioning +import OAI.Combinatorics.HadwigerCounterexample.MatrixRanks +import OAI.Combinatorics.HadwigerCounterexample.ExponentialRates + +namespace OAI + +/-! # Finite Affine Laws -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap +open scoped BigOperators + +section General +variable (V W : Type) +variable [AddCommGroup V] [Module F V] [AddCommGroup W] [Module F W] + +theorem card_space [Fintype V] : (Fintype.card V : ℝ) = bp (dim V) := by + rw [Module.card_eq_pow_finrank (K:=F)] + rw [show Fintype.card F = 2 from ZMod.card 2, bp_nat] + push_cast; rfl + +variable {V W} + +theorem add_polar (t : V) : ∀ x : V, x+t+t=x := by + intro x; rw [add_assoc,char_two,add_zero] + +/-- Equally likely images along every direction of an indexed family. The +translation hypothesis is before testing the specified targets. -/ +theorem translate_cap [Fintype V] [Fintype W] {T : Type*} [Fintype T] [Nonempty T] + {w : Wgt V} (hw : SubLaw w) + (f : V →ₗ[F] W) (g : T ↪ W) (h : ∀ t, ∃ v, f v = g t ∧ ∀ x, w (x+v) = w x) (y : W) : + pr w (fun x => f x=y) ≤ (Fintype.card T : ℝ)⁻¹ := by + classical + let u := mapW w f + have h1 (t : T) : u (y+g t) = u y := by + obtain ⟨v,hv,he⟩ := h t + change avg w _ = avg w _ + let E : V ≃ V := ⟨(·+v),(·+v),add_polar v,add_polar v⟩ + rw [← avg_bij E w (fun x => ind (f x = y+g t))] + change (avg (fun x => w (x+v)) (fun x => ind (f (x+v)=y+g t))) = _ + simp_rw [he,map_add,hv] + simp + have hu' : ∀ x, 0 ≤ u x := fun _ => pr_nonneg hw.nz + have hut : tot u ≤ 1 := by + have h : tot u = tot w := by simpa [u] using mapW_pr w f (fun _ => True) + exact h.le.trans hw.total + let k : T ↪ W := ⟨fun t => y+g t, fun i j h => g.injective (add_left_cancel h)⟩ + have h2 : (Fintype.card T:ℝ)*u y ≤ tot u := calc + _ = ∑ t : T, u (y+g t) := by simp [h1] + _ = ∑ x ∈ Finset.univ.map k, u x := by rw [Finset.sum_map]; rfl + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun i _ _ => hu' i) + change u y ≤ _ + rw [←one_div,le_div_iff₀ (by exact_mod_cast Fintype.card_pos)] + rw [mul_comm] + exact h2.trans hut + +theorem unif_lin [Fintype V] [Fintype W] (f : V →ₗ[F] W) : + mapW unif f = unifOn (fun y => y ∈ range f) := by + rw [← unifOn_true] + refine uniform_orbit _ ⟨0,trivial⟩ (fun x _ => ⟨x,rfl⟩) ?_ + rintro _ _ ⟨y,rfl⟩ ⟨z,rfl⟩ + let d := z-y + let E : V ≃ V := ⟨(·+d),(·+d),add_polar d,add_polar d⟩ + refine ⟨E,fun _ => Iff.rfl, fun x => ?_⟩ + change f x = f y ↔ f (x+(z-y))=f z + rw [map_add,map_sub] + constructor + · intro h; rw [h,add_sub_cancel] + · intro h + apply add_right_cancel (b := f z-f y) + rw [h,add_sub_cancel] + +theorem pr_unif_lin [Fintype V] [Fintype W] (f : V →ₗ[F] W) (y : W) : + pr unif (fun x => f x=y) = ind (y ∈ range f) * bp (-(rk f:ℝ)) := by + classical + change mapW unif f y = _ + rw [unif_lin,unifOn_val,nbr_eq_card] + rw [card_space,bp_neg,div_eq_mul_inv] + +theorem map_unif_surjective [Fintype V] [Fintype W] (f : V →ₗ[F] W) + (h : Function.Surjective f) : mapW unif f = unif := by + rw [unif_lin,range_eq_top.mpr h] + simp only [Submodule.mem_top,unifOn_true] + +end General + +theorem dim_mat (I J : Type) [Fintype I] [Fintype J] : + dim (Mat I J) = Fintype.card I * Fintype.card J := by + simp only [dim,Mat,finrank_matrix,finrank_self,mul_one] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteComparisonBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteComparisonBounds.lean index 6a16b4e544453f59596701e5d2744d04ca221fd5..7e466015f356b60658738995dffad474607f8d0e 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteComparisonBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteComparisonBounds.lean @@ -1,111 +1,111 @@ -import OAI.Combinatorics.HadwigerCounterexample.AggregateCostBounds - -namespace OAI - -/-! # Finite Comparison Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Function Finset Module LinearMap Filter -open scoped BigOperators Topology -open Template -variable {p:Shape} {n N K M r s0:ℕ} -namespace StatusAnalysis -open PreparationParameters Station PredictionClass DualAnalysis Club Guild - -def trimBeta (p : Shape) (K:ℕ):=basebeta p K/2 -theorem trimBeta_pos (p:Shape) (K:ℕ): 0 P x.1∨P x.2) ≤ τ+τ := by - classical - intro P - let μ:=troupe w U; have hi:= (troupe_bill h) - have hh :pr μ P ≤ τ := ((mapW_pr μ Prod.snd (fun i=>¬gauze p δ δ Y m b.pins i)).symm).trans_le - (hi.2.symm ▸ hp.rare) - refine ⟨hh,?_⟩ - apply (pr_or_le (pairW_law hi.1 hi.1).nz).trans - refine add_le_add ?_ ?_ - · refine le_trans ?_ hh - have h:= pairW_pr μ μ P (fun _=>True) - have hl : IsLaw μ:=hi.1 - exact le_of_eq (by simpa [hl.total] using h) - refine le_trans ?_ hh - have h:=pairW_pr μ μ (fun _=> True) P - have hl:IsLaw μ:=hi.1 - exact le_of_eq (by simpa [hl.total] using h) - -structure Loupe (p : Shape) (n N K : ℕ) (s:LeafMixture p n N) where - r : s.T → Stakes K - H : s.T → Stalls p - -structure Shipped (w:LeafMixture p n N) (K:ℕ) (u:Station p n N K w) (t:Loupe p n N K w) : Prop where - charts i: charted (u.cAxes i (toRates (t.r i))) (w.pin i.val).sp - baseline i: booths p K (w.pin i.val).sp (t.H i) - -theorem ready_loupe (w:LeafMixture p n N) (u:Station p n N b.pins w) (hu:u.bank) - (h:AnalyticParameters p M b s0) (he:∀ i:w.T,planRank (w.pin i.val).sp ≤ b.pins) : - ∃ t,Shipped w b.pins u t := by - classical - choose d hd using fun i:w.T=>sizedCharts _ _ _ hu i (he i) - choose S hS using fun i:w.T=> buildBooths _ _ (he i) h.penRoom - exact ⟨⟨d,S⟩,hd,hS⟩ -variable (w:LeafMixture p n N) (L:Loupe p n N b.pins w) (t:Station p n N b.pins w) -def routeC {K} (w:LeafMixture p n N) (L:Loupe p n N K w) (t:Station p n N K w) - (x:Aspect p n N w) := - t.cAxes x.1 (toRates (L.r x.1)) -abbrev KAspect {p:Shape} {n N:ℕ} (w:LeafMixture p n N):=Aspect p n N w - -set_option maxHeartbeats 800000 in -theorem routeLive (h:Shipped w b.pins t L) (m:Mixer p n) - (H: AnalyticParameters p M b s0) (hn:2*p.r≤n) - (x:Aspect p n N w) (Y: Silhouette p N r) - (δ:ℝ)(he:0<δ) (hk:planRank (w.pin x.1.val).sp ≤b.pins) - (hp:gauze p δ δ Y m b.pins x.2) : - reports p r (wisp p Y) (wake p Y m x.2 (routeC w L t x)) (trimBeta p b.pins) δ := by - apply plume_reports p b.pins m Y (w.pin x.1.val).sp _ _ (h.charts x.1) - _ hk H.enter.first.hG H.enter.first.hR hn δ he hp - intro i; exact Nat.lt_succ_iff.mp (L.r x.1 i).isLt -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.AggregateCostBounds + +namespace OAI + +/-! # Finite Comparison Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Function Finset Module LinearMap Filter +open scoped BigOperators Topology +open Template +variable {p:Shape} {n N K M r s0:ℕ} +namespace StatusAnalysis +open PreparationParameters Station PredictionClass DualAnalysis Club Guild + +def trimBeta (p : Shape) (K:ℕ):=basebeta p K/2 +theorem trimBeta_pos (p:Shape) (K:ℕ): 0 P x.1∨P x.2) ≤ τ+τ := by + classical + intro P + let μ:=troupe w U; have hi:= (troupe_bill h) + have hh :pr μ P ≤ τ := ((mapW_pr μ Prod.snd (fun i=>¬gauze p δ δ Y m b.pins i)).symm).trans_le + (hi.2.symm ▸ hp.rare) + refine ⟨hh,?_⟩ + apply (pr_or_le (pairW_law hi.1 hi.1).nz).trans + refine add_le_add ?_ ?_ + · refine le_trans ?_ hh + have h:= pairW_pr μ μ P (fun _=>True) + have hl : IsLaw μ:=hi.1 + exact le_of_eq (by simpa [hl.total] using h) + refine le_trans ?_ hh + have h:=pairW_pr μ μ (fun _=> True) P + have hl:IsLaw μ:=hi.1 + exact le_of_eq (by simpa [hl.total] using h) + +structure Loupe (p : Shape) (n N K : ℕ) (s:LeafMixture p n N) where + r : s.T → Stakes K + H : s.T → Stalls p + +structure Shipped (w:LeafMixture p n N) (K:ℕ) (u:Station p n N K w) (t:Loupe p n N K w) : Prop where + charts i: charted (u.cAxes i (toRates (t.r i))) (w.pin i.val).sp + baseline i: booths p K (w.pin i.val).sp (t.H i) + +theorem ready_loupe (w:LeafMixture p n N) (u:Station p n N b.pins w) (hu:u.bank) + (h:AnalyticParameters p M b s0) (he:∀ i:w.T,planRank (w.pin i.val).sp ≤ b.pins) : + ∃ t,Shipped w b.pins u t := by + classical + choose d hd using fun i:w.T=>sizedCharts _ _ _ hu i (he i) + choose S hS using fun i:w.T=> buildBooths _ _ (he i) h.penRoom + exact ⟨⟨d,S⟩,hd,hS⟩ +variable (w:LeafMixture p n N) (L:Loupe p n N b.pins w) (t:Station p n N b.pins w) +def routeC {K} (w:LeafMixture p n N) (L:Loupe p n N K w) (t:Station p n N K w) + (x:Aspect p n N w) := + t.cAxes x.1 (toRates (L.r x.1)) +abbrev KAspect {p:Shape} {n N:ℕ} (w:LeafMixture p n N):=Aspect p n N w + +set_option maxHeartbeats 800000 in +theorem routeLive (h:Shipped w b.pins t L) (m:Mixer p n) + (H: AnalyticParameters p M b s0) (hn:2*p.r≤n) + (x:Aspect p n N w) (Y: Silhouette p N r) + (δ:ℝ)(he:0<δ) (hk:planRank (w.pin x.1.val).sp ≤b.pins) + (hp:gauze p δ δ Y m b.pins x.2) : + reports p r (wisp p Y) (wake p Y m x.2 (routeC w L t x)) (trimBeta p b.pins) δ := by + apply plume_reports p b.pins m Y (w.pin x.1.val).sp _ _ (h.charts x.1) + _ hk H.enter.first.hG H.enter.first.hR hn δ he hp + intro i; exact Nat.lt_succ_iff.mp (L.r x.1 i).isLt +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteConditioning.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteConditioning.lean index 24254ae67a0e24a7e8086e7784592d6234c7f97d..2321b9e5c170964122fdaa78cc87491e26597fe5 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteConditioning.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteConditioning.lean @@ -1,155 +1,155 @@ -import OAI.Combinatorics.HadwigerCounterexample.ProductLaws -import Mathlib.Tactic.FieldSimp - -namespace OAI - - -/-! # Finite Conditioning -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators - -variable {A B : Type*} [Fintype A] - -/-- Number of solutions as a real. -/ -def nbr (p : A → Prop) := tot (fun x => ind (p x)) - -def onW (w : Wgt A) (p : A → Prop) := normW (subW w p) - -theorem nbr_eq_card (p : A → Prop) [Fintype {x // p x}] : - nbr p = (Fintype.card {x // p x}:ℝ) := by - classical - rw [Fintype.card_subtype] - simp [nbr,tot,ind] - -theorem pr_unif (p : A → Prop) : - pr unif p = nbr p / Fintype.card A := by - simp only [pr, avg, nbr, tot, unif_apply, div_eq_mul_inv] - rw [Finset.sum_mul] - exact Finset.sum_congr rfl fun _ _ => mul_comm _ _ - -theorem unifOn_val (p : A → Prop) (x) : - unifOn p x = ind (p x) / nbr p := rfl - -theorem unifOn_sub (p : A → Prop) : SubLaw (unifOn p) := - normW_subLaw fun x => ind_nonneg (p x) - -theorem unifOn_carried (p : A → Prop) : carried (unifOn p) p := - fun x h => by rw [unifOn_val,ind_zero h,zero_div] - -theorem on_unif [Nonempty A] (p : A → Prop) : onW unif p = unifOn p := by - have h : (0:ℝ) True) = unif := by - simp [unifOn, unif] - -theorem pr_on (w : Wgt A) (p q : A → Prop) : - pr (onW w p) q = pr w (fun x => p x ∧ q x) / pr w p := by - unfold onW - change avg _ _ = _ - rw [avg_norm,subW_tot] - exact congrArg (fun b => b / pr w p) (pr_sub w p q) - -theorem pr_of_on {w : Wgt A} (hw : ∀ x, 0 ≤ w x) (p q : A → Prop) : - pr w (fun x => p x ∧ q x) = pr w p * pr (onW w p) q := by - rw [pr_on] - by_cases h : pr w p = 0 - · rw [h,zero_mul] - apply le_antisymm _ (pr_nonneg hw) - rw [← h] - exact pr_mono hw fun _ => And.left - · field_simp - -theorem onW_val (w : Wgt A) (p : A → Prop) (x) : - onW w p x = w x * ind (p x) / pr w p := rfl - -theorem on_mon {w : Wgt A} (hw : ∀ x, 0 ≤ w x) {p : A → Prop} {a : ℝ} - (ha : 0 < a) (h : a ≤ pr w p) (x) : onW w p x ≤ a⁻¹ * w x := - calc onW w p x = (subW w p x) / pr w p := rfl - _ ≤ w x / a := div_le_div₀ (hw x) (subW_le hw p x) ha h - _ = _ := by rw [div_eq_mul_inv,mul_comm] - -/-- Being a probability with support p and all point masses there equal -uniquely characterizes unifOn. -/ -theorem uniform_support {w : Wgt A} {p : A → Prop} (hw : IsLaw w) - (hp : carried w p) (he : ∀ x y, p x → p y → w x = w y) : - w = unifOn p := by - have h := (carried_iff_pr hw.nz).mp hp - rw [hw.total] at h - obtain ⟨x,hx,_⟩ := exists_of_pr_pos hw.nz (h.trans_gt zero_lt_one) - have e : ∀ y, w y = w x * ind (p y) := by - intro y; by_cases h : p y - · rw [ind_one h, mul_one, he _ _ h hx] - · rw [hp y h,ind_zero h,mul_zero] - have hsum : w x * nbr p = 1 := by - calc w x * nbr p = tot w := by - unfold nbr tot; rw [Finset.mul_sum]; exact Finset.sum_congr rfl fun y _ => (e y).symm - _ = 1 := hw.total - have hn : nbr p ≠ 0 := right_ne_zero_of_mul (hsum.trans_ne one_ne_zero) - funext y; rw [e,unifOn_val,eq_div_iff hn,mul_right_comm,hsum,one_mul] - -theorem avg_bij (e : A ≃ A) (w f : Wgt A) : - avg (fun x => w (e x)) (fun x => f (e x)) = avg w f := by - unfold avg - exact Equiv.sum_comp e (fun x => w x * f x) - -variable [Fintype B] - -omit [Fintype B] in -theorem mapW_carried {w : Wgt A} {p : A → Prop} {q : B → Prop} {f : A → B} - (hw : carried w p) (h : ∀ x, p x → q (f x)) : carried (mapW w f) q := by - intro y hy - change ∑ x, w x * ind (f x=y) = 0 - refine Finset.sum_eq_zero fun x _ => ?_ - by_cases e : f x=y - · rw [hw x (fun hp => hy (e ▸ h x hp)),zero_mul] - · rw [ind_zero e,mul_zero] - -/-- Pointwise transitivity transfer of a uniform law under observation. -/ -theorem uniform_orbit {p : A → Prop} {q : B → Prop} (f : A → B) (hp : ∃ x, p x) - (hq : ∀ x, p x → q (f x)) - (h : ∀ y z, q y → q z → ∃ e : A ≃ A, (∀ x, p x ↔ p (e x)) - ∧ ∀ x, f x = y ↔ f (e x)=z) : - mapW (unifOn p) f = unifOn q := by - refine uniform_support (mapW_law (unifOn_law hp) _) (mapW_carried (unifOn_carried p) hq) - (fun y z hy hz => ?_) - obtain ⟨e,he,hE⟩ := h y z hy hz - unfold mapW pr - rw [← avg_bij e (unifOn p) (fun x => ind (f x = z))] - simp_rw [unifOn_val,← he,← hE] - rfl - -/-- A pointwise fiber disintegration. -/ -theorem disintegrate {w : Wgt A} (hw : ∀ x, 0 ≤ w x) (f : A → B) : - w = mixW (mapW w f) (fun y => onW w (fun x => f x = y)) := by - funext x - unfold mixW avg - rw [Finset.sum_eq_single (f x)] - · simp only [mapW,onW_val,ind_true,mul_one] - by_cases h : pr w (fun z => f z = f x) = 0 - · rw [h,zero_mul] - apply le_antisymm _ (hw x) - rw [← h]; exact weight_le_pr hw rfl - · field_simp - · intro i _ hi; simp [onW_val, ind, Ne.symm hi] - · simp - -omit [Fintype B] in -/-- Mapping changes a density bound functorially. -/ -theorem mapW_cap {w v : Wgt A} {c : ℝ} (h : ∀ x, w x ≤ c * v x) (f : A → B) (y) : - mapW w f y ≤ c * mapW v f y := by - unfold mapW - refine (pr_mono_left (v:=fun x => c * v x) h _).trans_eq ?_ - simp only [pr,avg,Finset.mul_sum,mul_assoc] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ProductLaws +import Mathlib.Tactic.FieldSimp + +namespace OAI + + +/-! # Finite Conditioning -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators + +variable {A B : Type*} [Fintype A] + +/-- Number of solutions as a real. -/ +def nbr (p : A → Prop) := tot (fun x => ind (p x)) + +def onW (w : Wgt A) (p : A → Prop) := normW (subW w p) + +theorem nbr_eq_card (p : A → Prop) [Fintype {x // p x}] : + nbr p = (Fintype.card {x // p x}:ℝ) := by + classical + rw [Fintype.card_subtype] + simp [nbr,tot,ind] + +theorem pr_unif (p : A → Prop) : + pr unif p = nbr p / Fintype.card A := by + simp only [pr, avg, nbr, tot, unif_apply, div_eq_mul_inv] + rw [Finset.sum_mul] + exact Finset.sum_congr rfl fun _ _ => mul_comm _ _ + +theorem unifOn_val (p : A → Prop) (x) : + unifOn p x = ind (p x) / nbr p := rfl + +theorem unifOn_sub (p : A → Prop) : SubLaw (unifOn p) := + normW_subLaw fun x => ind_nonneg (p x) + +theorem unifOn_carried (p : A → Prop) : carried (unifOn p) p := + fun x h => by rw [unifOn_val,ind_zero h,zero_div] + +theorem on_unif [Nonempty A] (p : A → Prop) : onW unif p = unifOn p := by + have h : (0:ℝ) True) = unif := by + simp [unifOn, unif] + +theorem pr_on (w : Wgt A) (p q : A → Prop) : + pr (onW w p) q = pr w (fun x => p x ∧ q x) / pr w p := by + unfold onW + change avg _ _ = _ + rw [avg_norm,subW_tot] + exact congrArg (fun b => b / pr w p) (pr_sub w p q) + +theorem pr_of_on {w : Wgt A} (hw : ∀ x, 0 ≤ w x) (p q : A → Prop) : + pr w (fun x => p x ∧ q x) = pr w p * pr (onW w p) q := by + rw [pr_on] + by_cases h : pr w p = 0 + · rw [h,zero_mul] + apply le_antisymm _ (pr_nonneg hw) + rw [← h] + exact pr_mono hw fun _ => And.left + · field_simp + +theorem onW_val (w : Wgt A) (p : A → Prop) (x) : + onW w p x = w x * ind (p x) / pr w p := rfl + +theorem on_mon {w : Wgt A} (hw : ∀ x, 0 ≤ w x) {p : A → Prop} {a : ℝ} + (ha : 0 < a) (h : a ≤ pr w p) (x) : onW w p x ≤ a⁻¹ * w x := + calc onW w p x = (subW w p x) / pr w p := rfl + _ ≤ w x / a := div_le_div₀ (hw x) (subW_le hw p x) ha h + _ = _ := by rw [div_eq_mul_inv,mul_comm] + +/-- Being a probability with support p and all point masses there equal +uniquely characterizes unifOn. -/ +theorem uniform_support {w : Wgt A} {p : A → Prop} (hw : IsLaw w) + (hp : carried w p) (he : ∀ x y, p x → p y → w x = w y) : + w = unifOn p := by + have h := (carried_iff_pr hw.nz).mp hp + rw [hw.total] at h + obtain ⟨x,hx,_⟩ := exists_of_pr_pos hw.nz (h.trans_gt zero_lt_one) + have e : ∀ y, w y = w x * ind (p y) := by + intro y; by_cases h : p y + · rw [ind_one h, mul_one, he _ _ h hx] + · rw [hp y h,ind_zero h,mul_zero] + have hsum : w x * nbr p = 1 := by + calc w x * nbr p = tot w := by + unfold nbr tot; rw [Finset.mul_sum]; exact Finset.sum_congr rfl fun y _ => (e y).symm + _ = 1 := hw.total + have hn : nbr p ≠ 0 := right_ne_zero_of_mul (hsum.trans_ne one_ne_zero) + funext y; rw [e,unifOn_val,eq_div_iff hn,mul_right_comm,hsum,one_mul] + +theorem avg_bij (e : A ≃ A) (w f : Wgt A) : + avg (fun x => w (e x)) (fun x => f (e x)) = avg w f := by + unfold avg + exact Equiv.sum_comp e (fun x => w x * f x) + +variable [Fintype B] + +omit [Fintype B] in +theorem mapW_carried {w : Wgt A} {p : A → Prop} {q : B → Prop} {f : A → B} + (hw : carried w p) (h : ∀ x, p x → q (f x)) : carried (mapW w f) q := by + intro y hy + change ∑ x, w x * ind (f x=y) = 0 + refine Finset.sum_eq_zero fun x _ => ?_ + by_cases e : f x=y + · rw [hw x (fun hp => hy (e ▸ h x hp)),zero_mul] + · rw [ind_zero e,mul_zero] + +/-- Pointwise transitivity transfer of a uniform law under observation. -/ +theorem uniform_orbit {p : A → Prop} {q : B → Prop} (f : A → B) (hp : ∃ x, p x) + (hq : ∀ x, p x → q (f x)) + (h : ∀ y z, q y → q z → ∃ e : A ≃ A, (∀ x, p x ↔ p (e x)) + ∧ ∀ x, f x = y ↔ f (e x)=z) : + mapW (unifOn p) f = unifOn q := by + refine uniform_support (mapW_law (unifOn_law hp) _) (mapW_carried (unifOn_carried p) hq) + (fun y z hy hz => ?_) + obtain ⟨e,he,hE⟩ := h y z hy hz + unfold mapW pr + rw [← avg_bij e (unifOn p) (fun x => ind (f x = z))] + simp_rw [unifOn_val,← he,← hE] + rfl + +/-- A pointwise fiber disintegration. -/ +theorem disintegrate {w : Wgt A} (hw : ∀ x, 0 ≤ w x) (f : A → B) : + w = mixW (mapW w f) (fun y => onW w (fun x => f x = y)) := by + funext x + unfold mixW avg + rw [Finset.sum_eq_single (f x)] + · simp only [mapW,onW_val,ind_true,mul_one] + by_cases h : pr w (fun z => f z = f x) = 0 + · rw [h,zero_mul] + apply le_antisymm _ (hw x) + rw [← h]; exact weight_le_pr hw rfl + · field_simp + · intro i _ hi; simp [onW_val, ind, Ne.symm hi] + · simp + +omit [Fintype B] in +/-- Mapping changes a density bound functorially. -/ +theorem mapW_cap {w v : Wgt A} {c : ℝ} (h : ∀ x, w x ≤ c * v x) (f : A → B) (y) : + mapW w f y ≤ c * mapW v f y := by + unfold mapW + refine (pr_mono_left (v:=fun x => c * v x) h _).trans_eq ?_ + simp only [pr,avg,Finset.mul_sum,mul_assoc] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteDualSystems.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteDualSystems.lean index adcf7fa49f084879ddc2b2d4d8ec30005cdb2c22..4ae0d1be2cb239e1a744fc825aa3910ff2bebc47 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteDualSystems.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteDualSystems.lean @@ -1,170 +1,170 @@ -import OAI.Combinatorics.HadwigerCounterexample.IncompatibleMassBounds - -namespace OAI - -/-! # Finite Dual Systems -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Matrix Finset Function LinearMap Module -open scoped BigOperators Topology -open Template -variable {p : Shape} {N n r K : ℕ} -namespace StatusAnalysis - -/-- envelope information to certify a generator, shared l and q. -/ -structure Zodiac (p : Shape) where - l : Tag p.g - q : F - s : Bool → Label p.b - f : Bool→Flavor p.g - -namespace Zodiac -def aspect (w : Zodiac p) (b : Bool) : Appearance p := - ⟨w.l,w.s b,w.f b,w.q⟩ -def common (w : Zodiac p) := ∀ b,(w.aspect b).apt -end Zodiac -instance zodiac_dec (p:Shape): DecidableEq (Zodiac p) := Classical.typeDecidableEq _ - -abbrev Terrain (p:Shape) (r:ℕ):= Tag p.g → F → Wgt (Fin r) -abbrev Gazette (p:Shape) (r:ℕ) (d : Rates) := - (i:Nodes)→Appearance p → Fin r→ Wgt (Magazine p (d i)) - -variable {d e : Rates} -namespace DualAnalysis - -def wisp (p : Shape) (Y : Silhouette p N r) : Terrain p r := - fun i z => mapW (lawOmega p N i z) (Y i z) -def wake (p : Shape) (Y : Silhouette p N r) (m:Mixer p n) (o:UnitType p n N) - (s : Charts p n d) : Gazette p r d := - fun i x a=> x.reflected Y i o m (s i) a -def parcelOrg (A:Stalls p) (i:Nodes) (a:Appearance p) := a.s∉ A i - -def origami (p:Shape) (r:ℕ) (u:Terrain p r) (δ:ℝ) := - (∀ i q,IsLaw (u i q)) ∧ ∀ i q,1/2 ≤ pr (u i q) (fun x=>δ ≤ u i q x) -structure reports (p:Shape) (r:ℕ) (u:Terrain p r) (s:Gazette p r d) - (β δ:ℝ) : Prop where - law : ∀ i (x:Appearance p),x.apt → ∀ k:Fin r,IsLaw (s i x k) - supp : ∀ i (x:Appearance p),x.apt →∀ k,carried (s i x k) x.fitsink - generous : ∀ i (x:Appearance p), x.f=Flavor.full → x.apt → - ∀ k:Fin r,δ ≤ u x.l x.q k → ∀ v: Par (d i), - β ≤ pr (s i x k) (fun w=>w.2.1=v) - -def playbook (p : Shape) (K : ℕ) := num (Magazine p (K^2) × Magazine p (K^2)) - -theorem playbook_pos (p : Shape) (K : ℕ) : 0 < playbook p K := by unfold playbook num; positivity -theorem booklet_cap (p:Shape) (K d e:ℕ) (hd:d≤K^2) (he:e≤K^2) : - num (Magazine p d × Magazine p e) ≤ playbook p K := by - have ht (d e) (h:d≤e) : - Fintype.card (Magazine p d) ≤ Fintype.card (Magazine p e) := by - simp only [Magazine,Whole,Par,Fintype.card_prod,Cell,Vec,Fintype.card_fun,Fintype.card_fin] - have hF:0le_trans (effective_rank (i:=i) (s:=s) (by rw [←(hs i).1]; exact mem_range_self _ _)) h) - exact hf.trans (pr_mono (x.reflectedLaw Y (Appearance.witLaw he hp hn) i o m (t i) k).nz - (fun j hj=>hj.2.trans (Prod.ext hc rfl))) - -abbrev Scriptum (p:Shape) (d e: Rates) (i : Grid) := - Zodiac p × Magazine p (d i.1) × Magazine p (e i.2) -abbrev Touch (p:Shape) (d e : Rates) (i : Grid) := Magazine p (d i.1) × Magazine p (e i.2) -variable (u:Terrain p r) (s:Gazette p r d) (t:Gazette p r e) - (η:ℝ) -def couplePage (x:Zodiac p) (i:Grid) := - fun j:Fin r=> pairW (s i.1 (x.aspect true) j) (t i.2 (x.aspect false) j) -def circlet (x:Zodiac p) (i:Grid) : Wgt (Touch p d e i) := - mixW (u x.l x.q) (couplePage s t x i) -def eligible (x:Zodiac p) (i:Grid) (a : Touch p d e i) := - x.common ∧ (x.aspect true).fitsink a.1 ∧ (x.aspect false).fitsink a.2 ∧ - η ≤ circlet u s t x i a -def stellar (A B : Stalls p) : Congress (Scriptum p d e) d e (Label p.b) := - fun i=> { - valid x:= x.1.s true∉ A i.1 ∧ x.1.s false∉ B i.2 ∧ eligible u s t η x.1 i x.2 - writes x:= (x.1.q,x.2.1.2,x.2.2.2) - addr x:= x.1.s - } - -variable {β δ:ℝ} -theorem circlet_state (hu:origami p r u δ) (hs:reports p r u s β δ) - (ht:reports p r u t β δ) - (x: Zodiac p) (hx:x.common) (i:Grid): - IsLaw (circlet u s t x i) ∧ carried (circlet u s t x i) - (fun y=>(x.aspect true).fitsink y.1 ∧ (x.aspect false).fitsink y.2) := by - have hh := hu.1 x.l x.q - refine ⟨mixW_law hh (fun _=>pairW_law (hs.law _ _ (hx _) _) (ht.law _ _ (hx _) _)),?_⟩ - intro y hy - have hi j : couplePage s t x i j y=0 := by - by_cases h :(x.aspect true).fitsink y.1 - · unfold couplePage pairW - rw [ht.supp _ _ (hx _) j _ (fun hh=>hy ⟨h,hh⟩),mul_zero] - unfold couplePage pairW; rw [hs.supp _ _ (hx _) j y.1 h,zero_mul] - unfold circlet mixW - simp_rw [hi,avg_const,mul_zero] - -set_option maxHeartbeats 1000000 in -theorem sturdy_contact (hu:origami p r u δ) (hs:reports p r u s β δ) - (ht:reports p r u t β δ) (hβ:0<β) - (x: Zodiac p) (hx:x.common) (h:∀ i, x.f i=Flavor.full) - (i: Grid) (L: Par (d i.1)) (R: Par (e i.2)) - {η:ℝ} (he:0<η) (hη:num (Touch p d e i)*η < 1/2*β^2): - ∃ j : Touch p d e i, eligible u s t η x i j ∧ j.1.2.1=L∧ j.2.2.1=R := by - classical - obtain ⟨hF,hG⟩:= circlet_state u s t hu hs ht x hx i - let μ:=u x.l x.q - let Q j:=δ≤μ j - let Z (j:Touch p d e i):=j.1.2.1=L∧ j.2.2.1=R - let W:=circlet u s t x i - have hh:1/2*β^2 ≤ pr W Z := by - let g:= couplePage s t x i - have hh : pr W Z=avg μ (fun j=>pr (g j) Z):= mixW_avg .. - have heq j (hj : Q j) : - β^2≤ pr (g j) Z := by - rw [pow_two] - let P0 (x:Magazine p (d i.1)):= x.2.1=L - let Q0 (x:Magazine p (e i.2)):= x.2.1=R - have he := pairW_pr (s i.1 (x.aspect true) j) (t i.2 (x.aspect false) j) P0 Q0 - have hh:=hs.generous i.1 (x.aspect true) (h _) (hx _) j hj L - exact (mul_le_mul hh (ht.generous i.2 (x.aspect false) (h _) (hx _) j hj R) hβ.le - (hβ.le.trans hh)).trans_eq he.symm - refine (mul_le_mul_of_nonneg_right (hu.2 x.l x.q) (sq_nonneg _)).trans ?_ - rw [hh]; unfold pr; rw [←avg_mul]; refine avg_mono (hu.1 _ _).nz (fun j=> ?_) - change ind (Q j) * β^2 ≤ pr (g j) Z - by_cases hj:Q j - · rw [ind_one hj,one_mul]; exact heq _ hj - rw [ind_zero hj,zero_mul] - exact pr_nonneg (pairW_law (hs.law _ _ (hx _) j) (ht.law _ _ (hx _) j)).nz - by_contra! hv - have hg j : W j * ind (Z j) ≤ η := by - by_cases h:Z j - · rw [ind_one h,mul_one] - by_contra! he' - have hc : W j≠0:=(he.trans he').ne' - have h1 : (x.aspect true).fitsink j.1∧(x.aspect false).fitsink j.2 := - not_not.mp fun h=> hc (hG _ h) - exact hv _ ⟨hx,h1.1,h1.2,he'.le⟩ h.1 h.2 - rw [ind_zero h,mul_zero]; exact he.le - apply hη.not_ge; exact hh.trans ((Finset.sum_le_sum fun i _=>hg i).trans_eq (by simp [num])) - -end DualAnalysis -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.IncompatibleMassBounds + +namespace OAI + +/-! # Finite Dual Systems -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Matrix Finset Function LinearMap Module +open scoped BigOperators Topology +open Template +variable {p : Shape} {N n r K : ℕ} +namespace StatusAnalysis + +/-- envelope information to certify a generator, shared l and q. -/ +structure Zodiac (p : Shape) where + l : Tag p.g + q : F + s : Bool → Label p.b + f : Bool→Flavor p.g + +namespace Zodiac +def aspect (w : Zodiac p) (b : Bool) : Appearance p := + ⟨w.l,w.s b,w.f b,w.q⟩ +def common (w : Zodiac p) := ∀ b,(w.aspect b).apt +end Zodiac +instance zodiac_dec (p:Shape): DecidableEq (Zodiac p) := Classical.typeDecidableEq _ + +abbrev Terrain (p:Shape) (r:ℕ):= Tag p.g → F → Wgt (Fin r) +abbrev Gazette (p:Shape) (r:ℕ) (d : Rates) := + (i:Nodes)→Appearance p → Fin r→ Wgt (Magazine p (d i)) + +variable {d e : Rates} +namespace DualAnalysis + +def wisp (p : Shape) (Y : Silhouette p N r) : Terrain p r := + fun i z => mapW (lawOmega p N i z) (Y i z) +def wake (p : Shape) (Y : Silhouette p N r) (m:Mixer p n) (o:UnitType p n N) + (s : Charts p n d) : Gazette p r d := + fun i x a=> x.reflected Y i o m (s i) a +def parcelOrg (A:Stalls p) (i:Nodes) (a:Appearance p) := a.s∉ A i + +def origami (p:Shape) (r:ℕ) (u:Terrain p r) (δ:ℝ) := + (∀ i q,IsLaw (u i q)) ∧ ∀ i q,1/2 ≤ pr (u i q) (fun x=>δ ≤ u i q x) +structure reports (p:Shape) (r:ℕ) (u:Terrain p r) (s:Gazette p r d) + (β δ:ℝ) : Prop where + law : ∀ i (x:Appearance p),x.apt → ∀ k:Fin r,IsLaw (s i x k) + supp : ∀ i (x:Appearance p),x.apt →∀ k,carried (s i x k) x.fitsink + generous : ∀ i (x:Appearance p), x.f=Flavor.full → x.apt → + ∀ k:Fin r,δ ≤ u x.l x.q k → ∀ v: Par (d i), + β ≤ pr (s i x k) (fun w=>w.2.1=v) + +def playbook (p : Shape) (K : ℕ) := num (Magazine p (K^2) × Magazine p (K^2)) + +theorem playbook_pos (p : Shape) (K : ℕ) : 0 < playbook p K := by unfold playbook num; positivity +theorem booklet_cap (p:Shape) (K d e:ℕ) (hd:d≤K^2) (he:e≤K^2) : + num (Magazine p d × Magazine p e) ≤ playbook p K := by + have ht (d e) (h:d≤e) : + Fintype.card (Magazine p d) ≤ Fintype.card (Magazine p e) := by + simp only [Magazine,Whole,Par,Fintype.card_prod,Cell,Vec,Fintype.card_fun,Fintype.card_fin] + have hF:0le_trans (effective_rank (i:=i) (s:=s) (by rw [←(hs i).1]; exact mem_range_self _ _)) h) + exact hf.trans (pr_mono (x.reflectedLaw Y (Appearance.witLaw he hp hn) i o m (t i) k).nz + (fun j hj=>hj.2.trans (Prod.ext hc rfl))) + +abbrev Scriptum (p:Shape) (d e: Rates) (i : Grid) := + Zodiac p × Magazine p (d i.1) × Magazine p (e i.2) +abbrev Touch (p:Shape) (d e : Rates) (i : Grid) := Magazine p (d i.1) × Magazine p (e i.2) +variable (u:Terrain p r) (s:Gazette p r d) (t:Gazette p r e) + (η:ℝ) +def couplePage (x:Zodiac p) (i:Grid) := + fun j:Fin r=> pairW (s i.1 (x.aspect true) j) (t i.2 (x.aspect false) j) +def circlet (x:Zodiac p) (i:Grid) : Wgt (Touch p d e i) := + mixW (u x.l x.q) (couplePage s t x i) +def eligible (x:Zodiac p) (i:Grid) (a : Touch p d e i) := + x.common ∧ (x.aspect true).fitsink a.1 ∧ (x.aspect false).fitsink a.2 ∧ + η ≤ circlet u s t x i a +def stellar (A B : Stalls p) : Congress (Scriptum p d e) d e (Label p.b) := + fun i=> { + valid x:= x.1.s true∉ A i.1 ∧ x.1.s false∉ B i.2 ∧ eligible u s t η x.1 i x.2 + writes x:= (x.1.q,x.2.1.2,x.2.2.2) + addr x:= x.1.s + } + +variable {β δ:ℝ} +theorem circlet_state (hu:origami p r u δ) (hs:reports p r u s β δ) + (ht:reports p r u t β δ) + (x: Zodiac p) (hx:x.common) (i:Grid): + IsLaw (circlet u s t x i) ∧ carried (circlet u s t x i) + (fun y=>(x.aspect true).fitsink y.1 ∧ (x.aspect false).fitsink y.2) := by + have hh := hu.1 x.l x.q + refine ⟨mixW_law hh (fun _=>pairW_law (hs.law _ _ (hx _) _) (ht.law _ _ (hx _) _)),?_⟩ + intro y hy + have hi j : couplePage s t x i j y=0 := by + by_cases h :(x.aspect true).fitsink y.1 + · unfold couplePage pairW + rw [ht.supp _ _ (hx _) j _ (fun hh=>hy ⟨h,hh⟩),mul_zero] + unfold couplePage pairW; rw [hs.supp _ _ (hx _) j y.1 h,zero_mul] + unfold circlet mixW + simp_rw [hi,avg_const,mul_zero] + +set_option maxHeartbeats 1000000 in +theorem sturdy_contact (hu:origami p r u δ) (hs:reports p r u s β δ) + (ht:reports p r u t β δ) (hβ:0<β) + (x: Zodiac p) (hx:x.common) (h:∀ i, x.f i=Flavor.full) + (i: Grid) (L: Par (d i.1)) (R: Par (e i.2)) + {η:ℝ} (he:0<η) (hη:num (Touch p d e i)*η < 1/2*β^2): + ∃ j : Touch p d e i, eligible u s t η x i j ∧ j.1.2.1=L∧ j.2.2.1=R := by + classical + obtain ⟨hF,hG⟩:= circlet_state u s t hu hs ht x hx i + let μ:=u x.l x.q + let Q j:=δ≤μ j + let Z (j:Touch p d e i):=j.1.2.1=L∧ j.2.2.1=R + let W:=circlet u s t x i + have hh:1/2*β^2 ≤ pr W Z := by + let g:= couplePage s t x i + have hh : pr W Z=avg μ (fun j=>pr (g j) Z):= mixW_avg .. + have heq j (hj : Q j) : + β^2≤ pr (g j) Z := by + rw [pow_two] + let P0 (x:Magazine p (d i.1)):= x.2.1=L + let Q0 (x:Magazine p (e i.2)):= x.2.1=R + have he := pairW_pr (s i.1 (x.aspect true) j) (t i.2 (x.aspect false) j) P0 Q0 + have hh:=hs.generous i.1 (x.aspect true) (h _) (hx _) j hj L + exact (mul_le_mul hh (ht.generous i.2 (x.aspect false) (h _) (hx _) j hj R) hβ.le + (hβ.le.trans hh)).trans_eq he.symm + refine (mul_le_mul_of_nonneg_right (hu.2 x.l x.q) (sq_nonneg _)).trans ?_ + rw [hh]; unfold pr; rw [←avg_mul]; refine avg_mono (hu.1 _ _).nz (fun j=> ?_) + change ind (Q j) * β^2 ≤ pr (g j) Z + by_cases hj:Q j + · rw [ind_one hj,one_mul]; exact heq _ hj + rw [ind_zero hj,zero_mul] + exact pr_nonneg (pairW_law (hs.law _ _ (hx _) j) (ht.law _ _ (hx _) j)).nz + by_contra! hv + have hg j : W j * ind (Z j) ≤ η := by + by_cases h:Z j + · rw [ind_one h,mul_one] + by_contra! he' + have hc : W j≠0:=(he.trans he').ne' + have h1 : (x.aspect true).fitsink j.1∧(x.aspect false).fitsink j.2 := + not_not.mp fun h=> hc (hG _ h) + exact hv _ ⟨hx,h1.1,h1.2,he'.le⟩ h.1 h.2 + rw [ind_zero h,mul_zero]; exact he.le + apply hη.not_ge; exact hh.trans ((Finset.sum_le_sum fun i _=>hg i).trans_eq (by simp [num])) + +end DualAnalysis +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteEntropy.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteEntropy.lean index db7a4355f805cea290fdf4d435bed2c331529c89..a5596205f18a87373c645cafd49d189584aff04a 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteEntropy.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteEntropy.lean @@ -1,129 +1,129 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteLaws -import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog -import Mathlib.Tactic.FieldSimp - -namespace OAI - -/-! # Finite Entropy -/ - -noncomputable section -namespace HadwigerCounterexample - -open scoped BigOperators -open Real - -variable {α : Type*} [Fintype α] - -def negEnt (w : Wgt α) : ℝ := ∑ x, w x * Real.log (w x) -def midLaw (w v : Wgt α) : Wgt α := fun x => (w x + v x) * 2⁻¹ - -@[fun_prop] theorem tot_continuous : Continuous (tot : Wgt α → ℝ) := by - unfold tot; fun_prop -@[fun_prop] theorem pr_continuous (p : α → Prop) : Continuous (pr (α := α) · p) := by - unfold pr avg; fun_prop -@[fun_prop] theorem negEnt_continuous : Continuous (negEnt : Wgt α → ℝ) := by - unfold negEnt - exact continuous_finsetSum _ fun x _ => Real.continuous_mul_log.comp (continuous_apply x) - -theorem closed_isLaw : IsClosed {w : Wgt α | IsLaw w} := by - have he : - {w : Wgt α | IsLaw w} = - (⋂ x : α, {w | 0 ≤ w x}) ∩ {w : Wgt α | tot w = 1} := by - ext w; simp - constructor - · intro hw - exact ⟨hw.nz, hw.total⟩ - · rintro ⟨h,g⟩ - exact ⟨h,g⟩ - rw [he] - refine (isClosed_iInter (fun x => ?_)).inter (isClosed_eq tot_continuous continuous_const) - exact isClosed_le continuous_const (continuous_apply x) - -theorem compact_isLaw : IsCompact {w : Wgt α | IsLaw w} := by - refine IsCompact.of_isClosed_subset (s := Set.Icc (0 : Wgt α) 1) isCompact_Icc - closed_isLaw ?_ - intro w hw - exact ⟨hw.nz, hw.weight_le_one⟩ - -theorem negEnt_le_zero {w : Wgt α} (hw : SubLaw w) : negEnt w ≤ 0 := by - refine Finset.sum_nonpos fun x _ => mul_nonpos_of_nonneg_of_nonpos (hw.nz x) ?_ - exact Real.log_nonpos (hw.nz x) (hw.weight_le_one x) - -private theorem log_bound {m x : ℝ} (hm : 0 < m) (hx : 0 ≤ x) : - x * (1 - Real.log m) - m⁻¹ ≤ x * Real.log x := by - rcases lt_or_eq_of_le hx with h | h - · have hp := Real.self_sub_one_le_mul_log (show 0 ≤ m*x from mul_nonneg hm.le hx) - rw [Real.log_mul hm.ne' h.ne'] at hp - apply (mul_le_mul_iff_right₀ hm).mp - - have hi := mul_inv_cancel₀ hm.ne' - nlinarith only [hp, hi] - · rw [← h] - have := inv_pos.mpr hm - linarith - -theorem log_card_le_negEnt [Nonempty α] {w : Wgt α} (hw : IsLaw w) : - -Real.log (Fintype.card α) ≤ negEnt w := by - let m := (Fintype.card α : ℝ) - have hm : 0 < m := by simp [m, Fintype.card_pos] - have h1 : - ∑ x, (w x * (1 - Real.log m) - m⁻¹) ≤ negEnt w := - Finset.sum_le_sum fun x _ => log_bound hm (hw.nz x) - have hs : ∑ x, w x = 1 := hw.total - rw [Finset.sum_sub_distrib, ← Finset.sum_mul, hs, one_mul, Finset.sum_const] at h1 - simp only [Finset.card_univ, nsmul_eq_mul] at h1 - change 1 - Real.log m - m * m⁻¹ ≤ _ at h1 - rw [mul_inv_cancel₀ hm.ne'] at h1 - change -Real.log m ≤ _ - linarith - -private theorem negEnt_gap_elem {x y : ℝ} (h : 0 ≤ x) (g : 0 ≤ y) : - 0 ≤ x * Real.log x + y * Real.log y - - 2 * (((x + y)*2⁻¹) * Real.log ((x + y)*2⁻¹)) := by - have hh := Real.convexOn_mul_log.2 (Set.mem_Ici.mpr h) (Set.mem_Ici.mpr g) - (by norm_num : 0 ≤ (2:ℝ)⁻¹) (by norm_num : 0 ≤ (2:ℝ)⁻¹) (by norm_num) - simp only [smul_eq_mul] at hh - rw [show 2⁻¹*x+2⁻¹*y = (x+y)*2⁻¹ by ring] at hh - linarith - -private theorem negEnt_gap_on_zero {x : ℝ} (hx : 0 ≤ x) : - x * Real.log x - 2 * ((x * 2⁻¹) * Real.log (x * 2⁻¹)) = x * Real.log 2 := by - rcases lt_or_eq_of_le hx with h | h - · rw [Real.log_mul h.ne' (by norm_num), Real.log_inv]; ring - · rw [← h]; ring - -/-- Mixing two laws incurs a quantified entropy gap if one gives mass to a set -missed by the other. This midpoint bound suffices without a support lemma. -/ -theorem negEnt_gap {w v : Wgt α} (hw : ∀ x, 0 ≤ w x) (hv : ∀ x, 0 ≤ v x) - (p : α → Prop) (hp : ∀ x, p x → v x = 0) : - pr w p * Real.log 2 ≤ negEnt w + negEnt v - 2 * negEnt (midLaw w v) := by - unfold pr avg negEnt - rw [Finset.sum_mul, ← Finset.sum_add_distrib, Finset.mul_sum, - ← Finset.sum_sub_distrib] - refine Finset.sum_le_sum fun x _ => ?_ - by_cases hx : p x - · simp only [hp x hx, ind_one hx, mul_one, midLaw, add_zero, zero_mul] - rw [negEnt_gap_on_zero (hw x)] - · simp only [ind_zero hx, mul_zero, zero_mul] - exact negEnt_gap_elem (hw _) (hv _) - -theorem mid_tot (w v : Wgt α) : tot (midLaw w v) = (tot w + tot v) * 2⁻¹ := by - rw [tot, tot, tot, ← Finset.sum_add_distrib, Finset.sum_mul] - rfl - -theorem midLaw_pr (w v : Wgt α) (p : α → Prop) : - pr (midLaw w v) p = (pr w p + pr v p) * 2⁻¹ := by - unfold pr - rw [avg_comm, avg_comm w, avg_comm v] - change avg _ (fun x => (w x + v x) * 2⁻¹) = _ - rw [avg_mul, avg_add] - -theorem mid_isLaw {w v : Wgt α} (hw : IsLaw w) (hv : IsLaw v) : IsLaw (midLaw w v) := by - refine ⟨fun x => mul_nonneg (add_nonneg (hw.nz x) (hv.nz x)) (by norm_num), ?_⟩ - rw [mid_tot, hw.total, hv.total]; norm_num - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteLaws +import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog +import Mathlib.Tactic.FieldSimp + +namespace OAI + +/-! # Finite Entropy -/ + +noncomputable section +namespace HadwigerCounterexample + +open scoped BigOperators +open Real + +variable {α : Type*} [Fintype α] + +def negEnt (w : Wgt α) : ℝ := ∑ x, w x * Real.log (w x) +def midLaw (w v : Wgt α) : Wgt α := fun x => (w x + v x) * 2⁻¹ + +@[fun_prop] theorem tot_continuous : Continuous (tot : Wgt α → ℝ) := by + unfold tot; fun_prop +@[fun_prop] theorem pr_continuous (p : α → Prop) : Continuous (pr (α := α) · p) := by + unfold pr avg; fun_prop +@[fun_prop] theorem negEnt_continuous : Continuous (negEnt : Wgt α → ℝ) := by + unfold negEnt + exact continuous_finsetSum _ fun x _ => Real.continuous_mul_log.comp (continuous_apply x) + +theorem closed_isLaw : IsClosed {w : Wgt α | IsLaw w} := by + have he : + {w : Wgt α | IsLaw w} = + (⋂ x : α, {w | 0 ≤ w x}) ∩ {w : Wgt α | tot w = 1} := by + ext w; simp + constructor + · intro hw + exact ⟨hw.nz, hw.total⟩ + · rintro ⟨h,g⟩ + exact ⟨h,g⟩ + rw [he] + refine (isClosed_iInter (fun x => ?_)).inter (isClosed_eq tot_continuous continuous_const) + exact isClosed_le continuous_const (continuous_apply x) + +theorem compact_isLaw : IsCompact {w : Wgt α | IsLaw w} := by + refine IsCompact.of_isClosed_subset (s := Set.Icc (0 : Wgt α) 1) isCompact_Icc + closed_isLaw ?_ + intro w hw + exact ⟨hw.nz, hw.weight_le_one⟩ + +theorem negEnt_le_zero {w : Wgt α} (hw : SubLaw w) : negEnt w ≤ 0 := by + refine Finset.sum_nonpos fun x _ => mul_nonpos_of_nonneg_of_nonpos (hw.nz x) ?_ + exact Real.log_nonpos (hw.nz x) (hw.weight_le_one x) + +private theorem log_bound {m x : ℝ} (hm : 0 < m) (hx : 0 ≤ x) : + x * (1 - Real.log m) - m⁻¹ ≤ x * Real.log x := by + rcases lt_or_eq_of_le hx with h | h + · have hp := Real.self_sub_one_le_mul_log (show 0 ≤ m*x from mul_nonneg hm.le hx) + rw [Real.log_mul hm.ne' h.ne'] at hp + apply (mul_le_mul_iff_right₀ hm).mp + + have hi := mul_inv_cancel₀ hm.ne' + nlinarith only [hp, hi] + · rw [← h] + have := inv_pos.mpr hm + linarith + +theorem log_card_le_negEnt [Nonempty α] {w : Wgt α} (hw : IsLaw w) : + -Real.log (Fintype.card α) ≤ negEnt w := by + let m := (Fintype.card α : ℝ) + have hm : 0 < m := by simp [m, Fintype.card_pos] + have h1 : + ∑ x, (w x * (1 - Real.log m) - m⁻¹) ≤ negEnt w := + Finset.sum_le_sum fun x _ => log_bound hm (hw.nz x) + have hs : ∑ x, w x = 1 := hw.total + rw [Finset.sum_sub_distrib, ← Finset.sum_mul, hs, one_mul, Finset.sum_const] at h1 + simp only [Finset.card_univ, nsmul_eq_mul] at h1 + change 1 - Real.log m - m * m⁻¹ ≤ _ at h1 + rw [mul_inv_cancel₀ hm.ne'] at h1 + change -Real.log m ≤ _ + linarith + +private theorem negEnt_gap_elem {x y : ℝ} (h : 0 ≤ x) (g : 0 ≤ y) : + 0 ≤ x * Real.log x + y * Real.log y + - 2 * (((x + y)*2⁻¹) * Real.log ((x + y)*2⁻¹)) := by + have hh := Real.convexOn_mul_log.2 (Set.mem_Ici.mpr h) (Set.mem_Ici.mpr g) + (by norm_num : 0 ≤ (2:ℝ)⁻¹) (by norm_num : 0 ≤ (2:ℝ)⁻¹) (by norm_num) + simp only [smul_eq_mul] at hh + rw [show 2⁻¹*x+2⁻¹*y = (x+y)*2⁻¹ by ring] at hh + linarith + +private theorem negEnt_gap_on_zero {x : ℝ} (hx : 0 ≤ x) : + x * Real.log x - 2 * ((x * 2⁻¹) * Real.log (x * 2⁻¹)) = x * Real.log 2 := by + rcases lt_or_eq_of_le hx with h | h + · rw [Real.log_mul h.ne' (by norm_num), Real.log_inv]; ring + · rw [← h]; ring + +/-- Mixing two laws incurs a quantified entropy gap if one gives mass to a set +missed by the other. This midpoint bound suffices without a support lemma. -/ +theorem negEnt_gap {w v : Wgt α} (hw : ∀ x, 0 ≤ w x) (hv : ∀ x, 0 ≤ v x) + (p : α → Prop) (hp : ∀ x, p x → v x = 0) : + pr w p * Real.log 2 ≤ negEnt w + negEnt v - 2 * negEnt (midLaw w v) := by + unfold pr avg negEnt + rw [Finset.sum_mul, ← Finset.sum_add_distrib, Finset.mul_sum, + ← Finset.sum_sub_distrib] + refine Finset.sum_le_sum fun x _ => ?_ + by_cases hx : p x + · simp only [hp x hx, ind_one hx, mul_one, midLaw, add_zero, zero_mul] + rw [negEnt_gap_on_zero (hw x)] + · simp only [ind_zero hx, mul_zero, zero_mul] + exact negEnt_gap_elem (hw _) (hv _) + +theorem mid_tot (w v : Wgt α) : tot (midLaw w v) = (tot w + tot v) * 2⁻¹ := by + rw [tot, tot, tot, ← Finset.sum_add_distrib, Finset.sum_mul] + rfl + +theorem midLaw_pr (w v : Wgt α) (p : α → Prop) : + pr (midLaw w v) p = (pr w p + pr v p) * 2⁻¹ := by + unfold pr + rw [avg_comm, avg_comm w, avg_comm v] + change avg _ (fun x => (w x + v x) * 2⁻¹) = _ + rw [avg_mul, avg_add] + +theorem mid_isLaw {w v : Wgt α} (hw : IsLaw w) (hv : IsLaw v) : IsLaw (midLaw w v) := by + refine ⟨fun x => mul_nonneg (add_nonneg (hw.nz x) (hv.nz x)) (by norm_num), ?_⟩ + rw [mid_tot, hw.total, hv.total]; norm_num + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteGraphTransfer.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteGraphTransfer.lean index 87229c2f5650dd4addf437866b94492916546965..3ac9379a549f7e7c21cbd10b78608162b04e8211 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteGraphTransfer.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteGraphTransfer.lean @@ -1,206 +1,206 @@ -import OAI.Combinatorics.HadwigerCounterexample.TerminalCut -import OAI.Combinatorics.HadwigerCounterexample.ProductLaws -import OAI.Combinatorics.HadwigerCounterexample.SampledGraphs -import Mathlib.Data.Fintype.Powerset - -namespace OAI - -/-! # Finite Graph Transfer -/ - -noncomputable section - -namespace HadwigerCounterexample -open Finset Real HadwigerMatching -open scoped BigOperators -variable {A V : Type*} - -/-- k distinct samples in S (unordered). -/ -private def badS (S : A → Prop) (k : ℕ) (x : V → A) := - ∃ T : Finset V, T.card = k ∧ ∀ v ∈ T, S (x v) - -private theorem badS_pr [Fintype A] {μ : Wgt A} (hμ : IsLaw μ) - (S : A → Prop) (k m : ℕ) : - pr (prodW (fun _ : Fin m => μ)) (badS S k) ≤ - 2 ^ m * (pr μ S)^k := by - classical - let q := prodW (fun _ : Fin m => μ) - have hp (T : Finset (Fin m)) : - pr q (fun x => T.card = k ∧ ∀ v ∈ T, S (x v)) ≤ (pr μ S)^k := by - by_cases h : T.card = k - · have e (x : Fin m → A) : (∀ v ∈ T, S (x v)) ↔ ∀ v : T, S (x v.val) := by simp - have h' := prodW_pr_inj (e:=fun v : T => v.val) Subtype.val_injective - (w:=fun _ => μ) (fun _ => hμ) (fun _ : T => S) - simp_rw [h, true_and, e] - simp only [prod_const, Finset.card_univ, Fintype.card_coe,h] at h' - exact h'.le - · have hn : 0 ≤ pr μ S := pr_nonneg hμ.nz - simp only [h, false_and, pr_false] - positivity - have he := pr_exists_le (prodW_nonneg (w:=fun _ : Fin m => μ) (fun _ => hμ.nz)) - (fun T : Finset (Fin m) => (fun x => T.card = k ∧ ∀ v ∈ T, S (x v))) - refine he.trans ((sum_le_sum (fun i _ => hp i)).trans_eq ?_) - simp - -/-- k pair exceptions using disjoint sample positions (ordered pairs). -/ -private def badE (E : A × A → Prop) (k : ℕ) (x : V → A) := - ∃ e : Fin k ⊕ Fin k → V, Function.Injective e ∧ - ∀ i, E (x (e (.inl i)), x (e (.inr i))) - -private theorem badE_pr [Fintype A] {μ : Wgt A} (hμ : IsLaw μ) - (E : A × A → Prop) (k m : ℕ) : - pr (prodW (fun _ : Fin m => μ)) (badE E k) ≤ - (m : ℝ)^(k+k) * (pr (pairW μ μ) E)^k := by - classical - let Q := prodW (fun _ : Fin m => μ) - let P (e : Fin k ⊕ Fin k → Fin m) (x : Fin m → A) := - Function.Injective e ∧ ∀ i, E (x (e (.inl i)), x (e (.inr i))) - have hp (e : Fin k ⊕ Fin k → Fin m) : - pr Q (P e) ≤ (pr (pairW μ μ) E)^k := by - by_cases h : Function.Injective e - · have h' := prodW_map_pairs e h hμ - let f (x : Fin m → A) (i : Fin k) := (x (e (.inl i)), x (e (.inr i))) - have hp : P e = (fun x => ∀ i, E (f x i)) := by simp [P,h,f] - rw [hp, ← mapW_pr Q f (fun x => ∀ i, E (x i))] - change mapW Q f = _ at h' - rw [h'] - have hb := prodW_pr (w:=fun _ : Fin k => pairW μ μ) (p:=fun _ => E) - simpa using hb.le - · have hn : 0 ≤ pr (pairW μ μ) E := pr_nonneg (pairW_law hμ hμ).nz - simp only [P,h,false_and,pr_false]; positivity - have he := pr_exists_le (prodW_nonneg (w:=fun _ : Fin m => μ) (fun _ => hμ.nz)) P - refine he.trans ((sum_le_sum (fun i _ => hp i)).trans_eq ?_) - simp - -private theorem many_bad {x : V → A} (S : A → Prop) (E : A × A → Prop) - {k t : ℕ} (ht : k + k ≤ t + 1) - {e : Fin t ⊕ Fin t → V} (he : Function.Injective e) - (hp : ∀ i, S (x (e (.inl i))) ∨ S (x (e (.inr i))) ∨ - E (x (e (.inl i)), x (e (.inr i)))) : - badS S k x ∨ badE E k x := by - classical - let p (i : Fin t) := S (x (e (.inl i))) ∨ S (x (e (.inr i))) - let I := univ.filter p - let J := univ.filter (fun i => ¬ p i) - by_cases hI : k ≤ I.card - · left - obtain ⟨r⟩ := Function.Embedding.nonempty_of_card_le - (show Fintype.card (Fin k) ≤ Fintype.card I by simpa using hI) - let f : Fin k → Fin t := fun i => r i - have hf : Function.Injective f := fun i j g => r.injective (Subtype.ext g) - let y : Fin k → Fin t ⊕ Fin t := - fun i => if S (x (e (.inl (f i)))) then .inl (f i) else .inr (f i) - have hy (i : Fin k) : S (x (e (y i))) := by - have h : p (f i) := (mem_filter.mp (r i).property).2 - unfold p at h - unfold y - split - · assumption - · rename_i hn; exact h.resolve_left hn - have hid i : Sum.elim id id (y i) = f i := by unfold y; split <;> rfl - have hy' : Function.Injective y := fun i j g => - hf (by rw [←hid,←hid,g]) - refine ⟨univ.image (e ∘ y), by rw [card_image_of_injective _ (he.comp hy')]; simp,?_⟩ - intro v hv - obtain ⟨i,_,rfl⟩ := mem_image.mp hv - exact hy i - · right - have hJ : k ≤ J.card := by - have hsum : I.card + J.card = t := by - simpa using Finset.card_filter_add_card_filter_not (s:=univ) p - omega - obtain ⟨r⟩ := Function.Embedding.nonempty_of_card_le - (show Fintype.card (Fin k) ≤ Fintype.card J by simpa using hJ) - let f : Fin k → Fin t := fun i => r i - have hf : Function.Injective f := fun i j g => r.injective (Subtype.ext g) - refine ⟨e ∘ Sum.map f f, he.comp (Sum.map_injective.mpr ⟨hf,hf⟩),?_⟩ - intro i - have h : ¬p (f i) := (mem_filter.mp (r i).property).2 - exact ((hp _).resolve_left (fun g => h (Or.inl g))).resolve_left - (fun g => h (Or.inr g)) - -/-- Finite transfer with an explicit error term. If T denotes the terminal count -bound, it suffices that -T*(2^m*(2/M)^k + m^(2*k)*(1/D)^k) < 1. -The rate version just instantiates these inequalities. -/ -theorem transfer [Fintype A] [Nonempty A] (H : Holes A) {μ : Wgt A} (hμ : IsLaw μ) - {M D ε : ℝ} (hM : 0 < M) (hD : 0 < D) (hε : 0 < ε) - (hsat : ∀ w : Wgt (A × A), IsLaw w → pairCaps μ M D w → carried w H.unit → - ε ≤ pr (pairW w w) (fun x => H.conflict x.1 x.2)) - {L m k : ℕ} (hL : Real.log (Fintype.card (A × A)) < L * (ε * Real.log 2)) - (hk : 200*k < m+200) - (herr : - ((Fintype.card (A × A) : ℝ) + 1)^L * - (2^m * (2/M)^k + (m:ℝ)^(k+k) * D⁻¹^k) < 1) : - ∃ x : Fin m → A, - (H.graph x).indepNum ≤ 2 ∧ - (connectedMatchingNumber (H.graph x) : ℚ) < (m : ℚ)/100 := by - classical - let R := univ.filter H.unit - let O := {w : Wgt (A × A) | IsLaw w} ∩ {w | pairCaps μ M D w} - obtain ⟨C,hC,hTC,hCC⟩ := containers (ok:=O) - (compact_isLaw.inter_right (closed_pairCaps _ _ _)) (fun _ h => h.1) - (fun _ h _ g => ⟨mid_isLaw h.1 g.1, mid_pairCaps h.2 g.2⟩) - H.conflict hε R (fun w hw g => hsat w hw.1 hw.2 (by simpa [carried,R] using g)) - L (fun w hw _ => by - have h := log_card_le_negEnt hw.1 - linarith) - have hx (r : C) : - ∃ (S : A → Prop) (E : A × A → Prop), M* pr μ S < 2 ∧ - D * pr (pairW μ μ) E < 1 ∧ ∀ x : A × A, x ∈ r.val → S x.1 ∨ S x.2 ∨ E x := - terminal hμ.nz hM hD _ (fun ⟨w,h,g,k⟩ => (hTC _ r.property).2 ⟨w,⟨h,g⟩,k⟩) - choose S E hs hq hcover using hx - let P (r : C) (x : Fin m → A) := badS (S r) k x ∨ badE (E r) k x - let W := prodW (fun _ : Fin m => μ) - have hw : IsLaw W := prodW_law fun _ => hμ - let b := (2:ℝ)^m * (2/M)^k + (m:ℝ)^(k+k) * D⁻¹^k - have hp (r : C) : pr W (P r) ≤ b := by - have h₁ := badS_pr hμ (S r) k m - have h₂ := badE_pr hμ (E r) k m - refine (pr_or_le hw.nz).trans ((add_le_add h₁ h₂).trans ?_) - have hi : 0 ≤ pr μ (S r) := pr_nonneg hμ.nz - have hj : 0 ≤ pr (pairW μ μ) (E r) := pr_nonneg (pairW_law hμ hμ).nz - have hk : pr μ (S r) ≤ 2/M := (le_div_iff₀ hM).mpr (by linarith only [hs r]) - have hn : pr (pairW μ μ) (E r) ≤ D⁻¹ := by - rw [← one_div] - apply (le_div_iff₀ hD).mpr - linarith only [hq r] - unfold b; gcongr - have hf : pr W (fun x => ∃ r, P r x) < 1 := by - have h : pr W (fun x => ∃ r, P r x) ≤ (C.card : ℝ) * b := by - refine (pr_exists_le hw.nz P).trans ((sum_le_sum (fun i _ => hp i)).trans_eq ?_) - simp - apply lt_of_le_of_lt h - apply lt_of_le_of_lt _ herr - have hg : C.card ≤ (Fintype.card (A × A) + 1)^L := - hC.trans (by gcongr; exact card_le_univ _) - have hb : 0 ≤ b := by unfold b; positivity - exact mul_le_mul_of_nonneg_right (by exact_mod_cast hg) hb - have hg : 0 < pr W (fun x => ¬∃ r, P r x) := by rw [pr_not, hw.total]; linarith only [hf] - obtain ⟨x,hx,_⟩ := exists_of_pr_pos hw.nz hg - refine ⟨x, H.indepNum_graph_le _,?_⟩ - let t := connectedMatchingNumber (H.graph x) - by_contra! hn - obtain ⟨e,he,he₁,he₂⟩ := H.matching_pairs x - let f (i : Fin t) : A × A := (x (e (.inl i)), x (e (.inr i))) - let I := univ.image f - have hIR : I ⊆ R := by - intro y hy; obtain ⟨i,_,rfl⟩ := mem_image.mp hy - exact mem_filter.mpr ⟨mem_univ _, he₁ i⟩ - have hI (v) (hv : v ∈ I) (w) (hw : w ∈ I) : ¬ H.conflict v w := by - obtain ⟨i,_,rfl⟩ := mem_image.mp hv - obtain ⟨j,_,rfl⟩ := mem_image.mp hw - exact he₂ i j - obtain ⟨r,hr,g⟩ := hCC I hIR hI - have ht : m ≤ t * 100 := by - change (m:ℚ)/100 ≤ (t:ℚ) at hn - have h : (m:ℚ) ≤ (t:ℚ)*100 := by linarith - exact_mod_cast h - apply hx - let r' : C := ⟨r,hr⟩ - refine ⟨r', many_bad (S r') (E r') (by omega) he fun i => - hcover r' (f i) (g (mem_image_of_mem f (mem_univ i)))⟩ -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.TerminalCut +import OAI.Combinatorics.HadwigerCounterexample.ProductLaws +import OAI.Combinatorics.HadwigerCounterexample.SampledGraphs +import Mathlib.Data.Fintype.Powerset + +namespace OAI + +/-! # Finite Graph Transfer -/ + +noncomputable section + +namespace HadwigerCounterexample +open Finset Real HadwigerMatching +open scoped BigOperators +variable {A V : Type*} + +/-- k distinct samples in S (unordered). -/ +private def badS (S : A → Prop) (k : ℕ) (x : V → A) := + ∃ T : Finset V, T.card = k ∧ ∀ v ∈ T, S (x v) + +private theorem badS_pr [Fintype A] {μ : Wgt A} (hμ : IsLaw μ) + (S : A → Prop) (k m : ℕ) : + pr (prodW (fun _ : Fin m => μ)) (badS S k) ≤ + 2 ^ m * (pr μ S)^k := by + classical + let q := prodW (fun _ : Fin m => μ) + have hp (T : Finset (Fin m)) : + pr q (fun x => T.card = k ∧ ∀ v ∈ T, S (x v)) ≤ (pr μ S)^k := by + by_cases h : T.card = k + · have e (x : Fin m → A) : (∀ v ∈ T, S (x v)) ↔ ∀ v : T, S (x v.val) := by simp + have h' := prodW_pr_inj (e:=fun v : T => v.val) Subtype.val_injective + (w:=fun _ => μ) (fun _ => hμ) (fun _ : T => S) + simp_rw [h, true_and, e] + simp only [prod_const, Finset.card_univ, Fintype.card_coe,h] at h' + exact h'.le + · have hn : 0 ≤ pr μ S := pr_nonneg hμ.nz + simp only [h, false_and, pr_false] + positivity + have he := pr_exists_le (prodW_nonneg (w:=fun _ : Fin m => μ) (fun _ => hμ.nz)) + (fun T : Finset (Fin m) => (fun x => T.card = k ∧ ∀ v ∈ T, S (x v))) + refine he.trans ((sum_le_sum (fun i _ => hp i)).trans_eq ?_) + simp + +/-- k pair exceptions using disjoint sample positions (ordered pairs). -/ +private def badE (E : A × A → Prop) (k : ℕ) (x : V → A) := + ∃ e : Fin k ⊕ Fin k → V, Function.Injective e ∧ + ∀ i, E (x (e (.inl i)), x (e (.inr i))) + +private theorem badE_pr [Fintype A] {μ : Wgt A} (hμ : IsLaw μ) + (E : A × A → Prop) (k m : ℕ) : + pr (prodW (fun _ : Fin m => μ)) (badE E k) ≤ + (m : ℝ)^(k+k) * (pr (pairW μ μ) E)^k := by + classical + let Q := prodW (fun _ : Fin m => μ) + let P (e : Fin k ⊕ Fin k → Fin m) (x : Fin m → A) := + Function.Injective e ∧ ∀ i, E (x (e (.inl i)), x (e (.inr i))) + have hp (e : Fin k ⊕ Fin k → Fin m) : + pr Q (P e) ≤ (pr (pairW μ μ) E)^k := by + by_cases h : Function.Injective e + · have h' := prodW_map_pairs e h hμ + let f (x : Fin m → A) (i : Fin k) := (x (e (.inl i)), x (e (.inr i))) + have hp : P e = (fun x => ∀ i, E (f x i)) := by simp [P,h,f] + rw [hp, ← mapW_pr Q f (fun x => ∀ i, E (x i))] + change mapW Q f = _ at h' + rw [h'] + have hb := prodW_pr (w:=fun _ : Fin k => pairW μ μ) (p:=fun _ => E) + simpa using hb.le + · have hn : 0 ≤ pr (pairW μ μ) E := pr_nonneg (pairW_law hμ hμ).nz + simp only [P,h,false_and,pr_false]; positivity + have he := pr_exists_le (prodW_nonneg (w:=fun _ : Fin m => μ) (fun _ => hμ.nz)) P + refine he.trans ((sum_le_sum (fun i _ => hp i)).trans_eq ?_) + simp + +private theorem many_bad {x : V → A} (S : A → Prop) (E : A × A → Prop) + {k t : ℕ} (ht : k + k ≤ t + 1) + {e : Fin t ⊕ Fin t → V} (he : Function.Injective e) + (hp : ∀ i, S (x (e (.inl i))) ∨ S (x (e (.inr i))) ∨ + E (x (e (.inl i)), x (e (.inr i)))) : + badS S k x ∨ badE E k x := by + classical + let p (i : Fin t) := S (x (e (.inl i))) ∨ S (x (e (.inr i))) + let I := univ.filter p + let J := univ.filter (fun i => ¬ p i) + by_cases hI : k ≤ I.card + · left + obtain ⟨r⟩ := Function.Embedding.nonempty_of_card_le + (show Fintype.card (Fin k) ≤ Fintype.card I by simpa using hI) + let f : Fin k → Fin t := fun i => r i + have hf : Function.Injective f := fun i j g => r.injective (Subtype.ext g) + let y : Fin k → Fin t ⊕ Fin t := + fun i => if S (x (e (.inl (f i)))) then .inl (f i) else .inr (f i) + have hy (i : Fin k) : S (x (e (y i))) := by + have h : p (f i) := (mem_filter.mp (r i).property).2 + unfold p at h + unfold y + split + · assumption + · rename_i hn; exact h.resolve_left hn + have hid i : Sum.elim id id (y i) = f i := by unfold y; split <;> rfl + have hy' : Function.Injective y := fun i j g => + hf (by rw [←hid,←hid,g]) + refine ⟨univ.image (e ∘ y), by rw [card_image_of_injective _ (he.comp hy')]; simp,?_⟩ + intro v hv + obtain ⟨i,_,rfl⟩ := mem_image.mp hv + exact hy i + · right + have hJ : k ≤ J.card := by + have hsum : I.card + J.card = t := by + simpa using Finset.card_filter_add_card_filter_not (s:=univ) p + omega + obtain ⟨r⟩ := Function.Embedding.nonempty_of_card_le + (show Fintype.card (Fin k) ≤ Fintype.card J by simpa using hJ) + let f : Fin k → Fin t := fun i => r i + have hf : Function.Injective f := fun i j g => r.injective (Subtype.ext g) + refine ⟨e ∘ Sum.map f f, he.comp (Sum.map_injective.mpr ⟨hf,hf⟩),?_⟩ + intro i + have h : ¬p (f i) := (mem_filter.mp (r i).property).2 + exact ((hp _).resolve_left (fun g => h (Or.inl g))).resolve_left + (fun g => h (Or.inr g)) + +/-- Finite transfer with an explicit error term. If T denotes the terminal count +bound, it suffices that +T*(2^m*(2/M)^k + m^(2*k)*(1/D)^k) < 1. +The rate version just instantiates these inequalities. -/ +theorem transfer [Fintype A] [Nonempty A] (H : Holes A) {μ : Wgt A} (hμ : IsLaw μ) + {M D ε : ℝ} (hM : 0 < M) (hD : 0 < D) (hε : 0 < ε) + (hsat : ∀ w : Wgt (A × A), IsLaw w → pairCaps μ M D w → carried w H.unit → + ε ≤ pr (pairW w w) (fun x => H.conflict x.1 x.2)) + {L m k : ℕ} (hL : Real.log (Fintype.card (A × A)) < L * (ε * Real.log 2)) + (hk : 200*k < m+200) + (herr : + ((Fintype.card (A × A) : ℝ) + 1)^L * + (2^m * (2/M)^k + (m:ℝ)^(k+k) * D⁻¹^k) < 1) : + ∃ x : Fin m → A, + (H.graph x).indepNum ≤ 2 ∧ + (connectedMatchingNumber (H.graph x) : ℚ) < (m : ℚ)/100 := by + classical + let R := univ.filter H.unit + let O := {w : Wgt (A × A) | IsLaw w} ∩ {w | pairCaps μ M D w} + obtain ⟨C,hC,hTC,hCC⟩ := containers (ok:=O) + (compact_isLaw.inter_right (closed_pairCaps _ _ _)) (fun _ h => h.1) + (fun _ h _ g => ⟨mid_isLaw h.1 g.1, mid_pairCaps h.2 g.2⟩) + H.conflict hε R (fun w hw g => hsat w hw.1 hw.2 (by simpa [carried,R] using g)) + L (fun w hw _ => by + have h := log_card_le_negEnt hw.1 + linarith) + have hx (r : C) : + ∃ (S : A → Prop) (E : A × A → Prop), M* pr μ S < 2 ∧ + D * pr (pairW μ μ) E < 1 ∧ ∀ x : A × A, x ∈ r.val → S x.1 ∨ S x.2 ∨ E x := + terminal hμ.nz hM hD _ (fun ⟨w,h,g,k⟩ => (hTC _ r.property).2 ⟨w,⟨h,g⟩,k⟩) + choose S E hs hq hcover using hx + let P (r : C) (x : Fin m → A) := badS (S r) k x ∨ badE (E r) k x + let W := prodW (fun _ : Fin m => μ) + have hw : IsLaw W := prodW_law fun _ => hμ + let b := (2:ℝ)^m * (2/M)^k + (m:ℝ)^(k+k) * D⁻¹^k + have hp (r : C) : pr W (P r) ≤ b := by + have h₁ := badS_pr hμ (S r) k m + have h₂ := badE_pr hμ (E r) k m + refine (pr_or_le hw.nz).trans ((add_le_add h₁ h₂).trans ?_) + have hi : 0 ≤ pr μ (S r) := pr_nonneg hμ.nz + have hj : 0 ≤ pr (pairW μ μ) (E r) := pr_nonneg (pairW_law hμ hμ).nz + have hk : pr μ (S r) ≤ 2/M := (le_div_iff₀ hM).mpr (by linarith only [hs r]) + have hn : pr (pairW μ μ) (E r) ≤ D⁻¹ := by + rw [← one_div] + apply (le_div_iff₀ hD).mpr + linarith only [hq r] + unfold b; gcongr + have hf : pr W (fun x => ∃ r, P r x) < 1 := by + have h : pr W (fun x => ∃ r, P r x) ≤ (C.card : ℝ) * b := by + refine (pr_exists_le hw.nz P).trans ((sum_le_sum (fun i _ => hp i)).trans_eq ?_) + simp + apply lt_of_le_of_lt h + apply lt_of_le_of_lt _ herr + have hg : C.card ≤ (Fintype.card (A × A) + 1)^L := + hC.trans (by gcongr; exact card_le_univ _) + have hb : 0 ≤ b := by unfold b; positivity + exact mul_le_mul_of_nonneg_right (by exact_mod_cast hg) hb + have hg : 0 < pr W (fun x => ¬∃ r, P r x) := by rw [pr_not, hw.total]; linarith only [hf] + obtain ⟨x,hx,_⟩ := exists_of_pr_pos hw.nz hg + refine ⟨x, H.indepNum_graph_le _,?_⟩ + let t := connectedMatchingNumber (H.graph x) + by_contra! hn + obtain ⟨e,he,he₁,he₂⟩ := H.matching_pairs x + let f (i : Fin t) : A × A := (x (e (.inl i)), x (e (.inr i))) + let I := univ.image f + have hIR : I ⊆ R := by + intro y hy; obtain ⟨i,_,rfl⟩ := mem_image.mp hy + exact mem_filter.mpr ⟨mem_univ _, he₁ i⟩ + have hI (v) (hv : v ∈ I) (w) (hw : w ∈ I) : ¬ H.conflict v w := by + obtain ⟨i,_,rfl⟩ := mem_image.mp hv + obtain ⟨j,_,rfl⟩ := mem_image.mp hw + exact he₂ i j + obtain ⟨r,hr,g⟩ := hCC I hIR hI + have ht : m ≤ t * 100 := by + change (m:ℚ)/100 ≤ (t:ℚ) at hn + have h : (m:ℚ) ≤ (t:ℚ)*100 := by linarith + exact_mod_cast h + apply hx + let r' : C := ⟨r,hr⟩ + refine ⟨r', many_bad (S r') (E r') (by omega) he fun i => + hcover r' (f i) (g (mem_image_of_mem f (mem_univ i)))⟩ +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteLaws.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteLaws.lean index 24b4fd221997cb91f438c768965f7e2d2b1f28bb..a30450dff38f50a6542e6760fcbdd4f46349afc4 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteLaws.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteLaws.lean @@ -1,401 +1,401 @@ -import Mathlib.Basic.Real.Basic -import Mathlib.Data.Fintype.BigOperators -import Mathlib.Algebra.BigOperators.Ring.Finset -import Mathlib.Algebra.Order.BigOperators.Group.Finset -import Mathlib.Algebra.Order.BigOperators.Ring.Finset -import Mathlib.Tactic.Linarith -import Mathlib.Tactic.GCongr -import Mathlib.Tactic.Positivity -import Mathlib.Tactic.Ring -import Mathlib.Tactic.NormNum - -namespace OAI - -/-! # Finite Laws -/ - -noncomputable section -open scoped BigOperators - -namespace HadwigerCounterexample - -abbrev Wgt (α : Type*) := α → ℝ - -variable {α β : Type*} - -/-- Real indicator. -/ -def ind (p : Prop) : ℝ := @ite ℝ p (Classical.propDecidable _) 1 0 - -theorem ind_eq (p : Prop) [Decidable p] : ind p = if p then 1 else 0 := by - unfold ind - congr - -theorem ind_one {p : Prop} (h : p) : ind p = 1 := by classical simp [ind, h] -theorem ind_zero {p : Prop} (h : ¬p) : ind p = 0 := by classical simp [ind, h] -@[simp] theorem ind_true : ind True = 1 := ind_one trivial -@[simp] theorem ind_false : ind False = 0 := ind_zero (not_false) - -theorem ind_nonneg (p : Prop) : 0 ≤ ind p := by - by_cases h : p - · exact le_of_lt (by rw [ind_one h]; norm_num) - · rw [ind_zero h] - -theorem ind_le_one (p : Prop) : ind p ≤ 1 := by - by_cases h : p - · rw [ind_one h] - · rw [ind_zero h] - norm_num - -theorem ind_mono {p q : Prop} (hp : p → q) : ind p ≤ ind q := by - by_cases h : p - · rw [ind_one h, ind_one (hp h)] - · rw [ind_zero h] - exact ind_nonneg _ - -theorem ind_not (p : Prop) : ind (¬p) = 1 - ind p := by - by_cases h : p <;> simp [ind, h] - -theorem ind_and (p q : Prop) : ind (p ∧ q) = ind p * ind q := by - by_cases h : p <;> by_cases h2 : q <;> simp [ind, h, h2] - -theorem ind_or_le (p q : Prop) : ind (p ∨ q) ≤ ind p + ind q := by - by_cases h : p - · simp only [h, true_or, ind_true] - have := ind_nonneg q - linarith - · simp [h] - -/-- Total weight. -/ -def tot [Fintype α] (w : Wgt α) : ℝ := ∑ x, w x -/-- Weighted average (not normalized if the weights are not a probability law). -/ -def avg [Fintype α] (w f : Wgt α) : ℝ := ∑ x, w x * f x -/-- Weight of an event. -/ -def pr [Fintype α] (w : Wgt α) (p : α → Prop) := avg w (fun x => ind (p x)) - -structure SubLaw [Fintype α] (w : Wgt α) : Prop where - nz (x : α) : 0 ≤ w x - total : tot w ≤ 1 -structure IsLaw [Fintype α] (w : Wgt α) : Prop where - nz (x : α) : 0 ≤ w x - total : tot w = 1 - -theorem IsLaw.sub [Fintype α] {w : Wgt α} (hw : IsLaw w) : SubLaw w where - nz := hw.nz - total := hw.total.le - -/-- All positive mass is supported on `p`. We use the equivalent contrapositive with -zero mass (and supply nonnegativity wherever we speak of a law). -/ -def carried (w : Wgt α) (p : α → Prop) := ∀ x : α, ¬ p x → w x = 0 - -section Basic -variable [Fintype α] {w v f g : Wgt α} {p q : α → Prop} - -theorem tot_nonneg (hw : ∀ x, 0 ≤ w x) : 0 ≤ tot w := Finset.sum_nonneg fun x _ => hw x - -theorem tot_mono (h : ∀ x, w x ≤ v x) : tot w ≤ tot v := - Finset.sum_le_sum fun x _ => h x - -theorem weight_le_tot (hw : ∀ x, 0 ≤ w x) (x) : w x ≤ tot w := - Finset.single_le_sum (fun y _ => hw y) (Finset.mem_univ x) - -theorem SubLaw.weight_le_one (hw : SubLaw w) (x) : w x ≤ 1 := - (weight_le_tot hw.nz x).trans hw.total - -theorem IsLaw.weight_le_one (hw : IsLaw w) (x) : w x ≤ 1 := hw.sub.weight_le_one x - -theorem avg_comm (w f : Wgt α) : avg w f = avg f w := by simp only [avg, mul_comm] - -theorem avg_mono (hw : ∀ x, 0 ≤ w x) (h : ∀ x, f x ≤ g x) : avg w f ≤ avg w g := - Finset.sum_le_sum fun x _ => mul_le_mul_of_nonneg_left (h x) (hw x) - -theorem avg_mono_left (hf : ∀ x, 0 ≤ f x) (h : ∀ x, w x ≤ v x) : avg w f ≤ avg v f := by - rw [avg_comm w, avg_comm v] - exact avg_mono hf h - -theorem avg_nonneg (hw : ∀ x, 0 ≤ w x) (hf : ∀ x, 0 ≤ f x) : 0 ≤ avg w f := - Finset.sum_nonneg fun x _ => mul_nonneg (hw x) (hf x) - -@[simp] theorem avg_zero (w : Wgt α) : avg w (fun _ => 0) = 0 := by simp [avg] - -theorem avg_const (w : Wgt α) (a : ℝ) : avg w (fun _ => a) = tot w * a := by - rw [avg, tot, Finset.sum_mul] - -theorem IsLaw.avg_const (hw : IsLaw w) (a : ℝ) : avg w (fun _ => a) = a := by - rw [HadwigerCounterexample.avg_const, hw.total, one_mul] - -theorem SubLaw.avg_le (hw : SubLaw w) {b : ℝ} (hb : 0 ≤ b) (h : ∀ x, f x ≤ b) : - avg w f ≤ b := by - refine (avg_mono hw.nz h).trans ?_ - rw [avg_const] - exact (mul_le_mul_of_nonneg_right hw.total hb).trans_eq (one_mul b) - -theorem IsLaw.avg_le (hw : IsLaw w) {b : ℝ} (h : ∀ x, f x ≤ b) : avg w f ≤ b := - (avg_mono hw.nz h).trans (hw.avg_const _).le - -theorem IsLaw.le_avg (hw : IsLaw w) {b : ℝ} (h : ∀ x, b ≤ f x) : b ≤ avg w f := - (hw.avg_const _).ge.trans (avg_mono hw.nz h) - -theorem abs_avg_le (hw : ∀ x, 0 ≤ w x) : |avg w f| ≤ avg w (fun x => |f x|) := by - rw [avg, avg] - refine (Finset.abs_sum_le_sum_abs _ _).trans_eq ?_ - simp_rw [abs_mul, abs_of_nonneg (hw _)] - -theorem avg_add (w f g : Wgt α) : avg w (fun x => f x + g x) = avg w f + avg w g := by - simp only [avg, mul_add, Finset.sum_add_distrib] - -theorem avg_sub (w f g : Wgt α) : avg w (fun x => f x - g x) = avg w f - avg w g := by - simp only [avg, mul_sub, Finset.sum_sub_distrib] - -theorem avg_mul (w f : Wgt α) (b : ℝ) : avg w (fun x => f x * b) = avg w f * b := by - simp only [avg, Finset.sum_mul, mul_assoc] - -theorem avg_mul' (w f : Wgt α) (b : ℝ) : avg w (fun x => b * f x) = b * avg w f := by - simpa only [mul_comm b] using avg_mul w f b - -theorem avg_div (w f : Wgt α) (b : ℝ) : avg w (fun x => f x / b) = avg w f / b := by - simp_rw [div_eq_mul_inv] - exact avg_mul _ _ _ - -theorem avg_congr (h : ∀ x, w x ≠ 0 → f x = g x) : avg w f = avg w g := by - unfold avg - refine Finset.sum_congr rfl fun x _ => ?_ - by_cases hx : w x = 0 - · rw [hx, zero_mul, zero_mul] - · rw [h x hx] - -theorem avg_sum {ι : Type*} (w : Wgt α) (s : Finset ι) (f : ι → Wgt α) : - avg w (fun x => ∑ i ∈ s, f i x) = ∑ i ∈ s, avg w (f i) := by - simp only [avg, Finset.mul_sum] - rw [Finset.sum_comm] - -theorem avg_avg [Fintype β] (w : Wgt α) (v : Wgt β) (f : α → β → ℝ) : - avg w (fun x => avg v (f x)) = avg v (fun y => avg w (fun x => f x y)) := by - simp only [avg, Finset.mul_sum] - rw [Finset.sum_comm] - simp only [mul_left_comm] - -theorem pr_nonneg (hw : ∀ x, 0 ≤ w x) : 0 ≤ pr w p := - avg_nonneg hw fun _ => ind_nonneg _ - -theorem pr_le_tot (hw : ∀ x, 0 ≤ w x) : pr w p ≤ tot w := by - unfold pr - refine (avg_mono hw fun x => ind_le_one (p x)).trans_eq ?_ - rw [avg_const, mul_one] - -theorem pr_mono (hw : ∀ x, 0 ≤ w x) (h : ∀ x, p x → q x) : pr w p ≤ pr w q := - avg_mono hw fun x => ind_mono (h x) - -theorem pr_mono_left (h : ∀ x, w x ≤ v x) (p : α → Prop) : pr w p ≤ pr v p := - avg_mono_left (fun x => ind_nonneg (p x)) h - -theorem pr_not (w : Wgt α) (p : α → Prop) : pr w (fun x => ¬p x) = tot w - pr w p := by - simp_rw [pr, ind_not, avg_sub, avg_const, mul_one] - -@[simp] theorem pr_point (w : Wgt α) (x : α) : pr w (fun y => x = y) = w x := by - classical simp [pr, avg, ind] - -@[simp] theorem pr_point' (w : Wgt α) (x : α) : pr w (fun y => y = x) = w x := by - classical simp [pr, avg, ind] - -@[simp] theorem pr_true (w : Wgt α) : pr w (fun _ => True) = tot w := by simp [pr, avg, tot] -@[simp] theorem pr_false (w : Wgt α) : pr w (fun _ => False) = 0 := by simp [pr] - -theorem pr_or_le (hw : ∀ x, 0 ≤ w x) : - pr w (fun x => p x ∨ q x) ≤ pr w p + pr w q := - (avg_mono hw fun x => ind_or_le (p x) (q x)).trans_eq (avg_add _ _ _) - -theorem pr_union_le (hw : ∀ x, 0 ≤ w x) {ι : Type*} (s : Finset ι) (p : ι → α → Prop) : - pr w (fun x => ∃ i ∈ s, p i x) ≤ ∑ i ∈ s, pr w (p i) := by - let F : ι → Wgt α := fun i x => ind (p i x) - change _ ≤ ∑ i ∈ s, avg w (F i) - rw [← avg_sum] - refine avg_mono hw fun x => ?_ - change ind (∃ i ∈ s, p i x) ≤ _ - by_cases h : ∃ i ∈ s, p i x - · rw [ind_one h] - obtain ⟨i, hi, hp⟩ := h - have : F i x ≤ ∑ i ∈ s, F i x := - Finset.single_le_sum (fun (j : ι) _ => ind_nonneg (p j x)) hi - simpa only [F, ind_one hp] using this - · rw [ind_zero h] - exact Finset.sum_nonneg fun i _ => ind_nonneg (p i x) - -theorem pr_exists_le (hw : ∀ x, 0 ≤ w x) {ι : Type*} [Fintype ι] (p : ι → α → Prop) : - pr w (fun x => ∃ i, p i x) ≤ ∑ i, pr w (p i) := by - simpa using pr_union_le hw Finset.univ p - -theorem weight_le_pr (hw : ∀ x, 0 ≤ w x) {x} (hx : p x) : w x ≤ pr w p := by - have h := pr_mono (p:=fun y => x = y) (q:=p) hw (fun y e => e ▸ hx) - simpa only [pr_point] using h - -theorem exists_of_pr_pos (hw : ∀ x, 0 ≤ w x) (hp : 0 < pr w p) : - ∃ x, p x ∧ 0 < w x := by - by_contra! hn - have h : pr w p = 0 := by - unfold pr avg - refine Finset.sum_eq_zero fun x _ => ?_ - by_cases hx : p x - · rw [le_antisymm (hn x hx) (hw x), zero_mul] - · simp only [ind_zero hx, mul_zero] - exact hp.ne' h - -theorem carried_iff_pr (hw : ∀ x, 0 ≤ w x) : carried w p ↔ pr w p = tot w := by - constructor - · intro h - unfold pr - have e : avg w (fun x => ind (p x)) = avg w (fun _ => 1) := by - refine avg_congr fun x hx => ind_one (Classical.byContradiction fun hn => hx (h x hn)) - rw [e, avg_const, mul_one] - · intro he x hx - have h := weight_le_pr (p:=fun x => ¬p x) hw hx - rw [pr_not, he, sub_self] at h - exact le_antisymm h (hw x) - -theorem le_avg_markov (hw : ∀ x, 0 ≤ w x) (hf : ∀ x, 0 ≤ f x) (b : ℝ) : - b * pr w (fun x => b ≤ f x) ≤ avg w f := by - unfold pr - rw [← avg_mul'] - refine avg_mono hw fun x => ?_ - by_cases h : b ≤ f x - · simpa [ind_one h] using h - · simpa [ind_zero h] using hf x - -end Basic - -/-- Restrict weights; *not* renormalized. -/ -def subW (w : Wgt α) (p : α → Prop) := fun x => w x * ind (p x) - -/-- Divide a finite weight function by its total, giving zero if total is zero. -/ -def normW [Fintype α] (w : Wgt α) := fun x => w x / tot w - -def unif [Fintype α] : Wgt α := normW fun _ => 1 -def unifOn [Fintype α] (p : α → Prop) : Wgt α := normW (fun x => ind (p x)) - -section Restrict -variable [Fintype α] {w : Wgt α} {p : α → Prop} - -omit [Fintype α] in -theorem subW_nonneg (hw : ∀ x, 0 ≤ w x) (p : α → Prop) : ∀ x, 0 ≤ subW w p x := - fun x => mul_nonneg (hw x) (ind_nonneg _) - -@[simp] theorem subW_tot (w : Wgt α) (p : α → Prop) : tot (subW w p) = pr w p := rfl - -omit [Fintype α] in -theorem subW_le (hw : ∀ x, 0 ≤ w x) (p : α → Prop) (x : α) : subW w p x ≤ w x := - (mul_le_mul_of_nonneg_left (ind_le_one _) (hw x)).trans_eq (mul_one _) - -omit [Fintype α] in -theorem subW_carried (w : Wgt α) (p : α → Prop) : carried (subW w p) p := - fun x h => by rw [subW, ind_zero h, mul_zero] - -theorem subLaw_sub (hw : SubLaw w) (p : α → Prop) : SubLaw (subW w p) := - ⟨subW_nonneg hw.nz p, (pr_le_tot hw.nz).trans hw.total⟩ - -theorem pr_sub (w : Wgt α) (p q : α → Prop) : - pr (subW w p) q = pr w (fun x => p x ∧ q x) := by - simp only [pr, avg, ind_and, subW, mul_assoc] - -theorem normW_nonneg (hw : ∀ x, 0 ≤ w x) : ∀ x, 0 ≤ normW w x := - fun x => div_nonneg (hw x) (tot_nonneg hw) - -theorem avg_norm (w f : Wgt α) : avg (normW w) f = avg w f / tot w := by - rw [avg_comm, avg_comm w f] - exact avg_div _ _ _ - -theorem tot_norm (w : Wgt α) : tot (normW w) = tot w / tot w := by - simp only [tot, normW, div_eq_mul_inv, Finset.sum_mul] - -theorem normW_law (hw : ∀ x, 0 ≤ w x) (hpos : 0 < tot w) : IsLaw (normW w) := - ⟨normW_nonneg hw, by rw [tot_norm, div_self hpos.ne']⟩ - -theorem normW_subLaw (hw : ∀ x, 0 ≤ w x) : SubLaw (normW w) := by - refine ⟨normW_nonneg hw, ?_⟩ - rw [tot_norm] - by_cases h : tot w = 0 <;> simp [h] - -theorem normW_carried (hp : carried w p) : carried (normW w) p := - fun x h => by rw [normW, hp x h, zero_div] - -theorem unif_apply (x : α) : unif x = (Fintype.card α : ℝ)⁻¹ := by - simp [unif, normW, tot] - -theorem unif_subLaw : SubLaw (unif : Wgt α) := - normW_subLaw (fun _ => zero_le_one) - -theorem unif_law [Nonempty α] : IsLaw (unif : Wgt α) := by - refine normW_law (fun _ => zero_le_one) ?_ - simp [tot, Fintype.card_pos] - -theorem unifOn_law (h : ∃ x, p x) : IsLaw (unifOn p) := by - refine normW_law (fun _ => ind_nonneg _) ?_ - obtain ⟨x, hx⟩ := h - have := weight_le_tot (fun x => ind_nonneg (p x)) x - change 0 < tot _ - rw [ind_one hx] at this - exact lt_of_lt_of_le zero_lt_one this - -end Restrict - -def pairW (w : Wgt α) (v : Wgt β) : Wgt (α × β) := fun p => w p.1 * v p.2 -def mixW [Fintype α] (w : Wgt α) (F : α → Wgt β) : Wgt β := fun y => avg w (fun x => F x y) -def mapW [Fintype α] (w : Wgt α) (f : α → β) : Wgt β := fun y => pr w (fun x => f x = y) - -section Prod -variable [Fintype α] [Fintype β] {w : Wgt α} {v : Wgt β} - -theorem pairW_avg (w : Wgt α) (v : Wgt β) (f : α × β → ℝ) : - avg (pairW w v) f = avg w (fun x => avg v (fun y => f (x,y))) := by - simp only [avg, Finset.mul_sum, Fintype.sum_prod_type, pairW, mul_assoc] - -theorem pairW_separate (w f : Wgt α) (v g : Wgt β) : - avg (pairW w v) (fun p => f p.1 * g p.2) = avg w f * avg v g := by - simp only [pairW_avg, avg_mul', avg_mul] - -theorem pairW_pr (w : Wgt α) (v : Wgt β) (p : α → Prop) (q : β → Prop) : - pr (pairW w v) (fun x => p x.1 ∧ q x.2) = pr w p * pr v q := by - simp_rw [pr, ind_and] - exact pairW_separate w (fun x => ind (p x)) v (fun y => ind (q y)) - -theorem pairW_tot (w : Wgt α) (v : Wgt β) : tot (pairW w v) = tot w * tot v := by - simpa using pairW_pr w v (fun _ => True) (fun _ => True) - -theorem pairW_law (hw : IsLaw w) (hv : IsLaw v) : IsLaw (pairW w v) := - ⟨fun x => mul_nonneg (hw.nz _) (hv.nz _), by rw [pairW_tot, hw.total, hv.total, mul_one]⟩ - -theorem mixW_avg (w : Wgt α) (F : α → Wgt β) (g : Wgt β) : - avg (mixW w F) g = avg w (fun x => avg (F x) g) := by - simp only [avg, mixW, Finset.mul_sum, Finset.sum_mul] - rw [Finset.sum_comm] - simp only [mul_assoc] - -theorem mixW_tot (w : Wgt α) (F : α → Wgt β) : - tot (mixW w F) = avg w (fun x => tot (F x)) := by - simpa only [avg_const, mul_one] using mixW_avg w F (fun _ => 1) - -theorem mixW_law (hw : IsLaw w) {F : α → Wgt β} (hF : ∀ x, IsLaw (F x)) : - IsLaw (mixW w F) := by - refine ⟨fun x => avg_nonneg hw.nz (fun y => (hF y).nz _), ?_⟩ - rw [mixW_tot] - simp_rw [(hF _).total] - exact hw.avg_const _ - -theorem mapW_avg (w : Wgt α) (f : α → β) (g : Wgt β) : - avg (mapW w f) g = avg w (fun x => g (f x)) := by - classical - change avg (mixW w (fun x y => ind (f x = y))) g = _ - rw [mixW_avg] - simp [avg, ind] - -theorem mapW_law (hw : IsLaw w) (f : α → β) : IsLaw (mapW w f) := by - refine ⟨fun _ => pr_nonneg hw.nz, ?_⟩ - simpa only [avg_const, mul_one, hw.total] using mapW_avg w f (fun _ => 1) - -theorem mapW_pr (w : Wgt α) (f : α → β) (q : β → Prop) : - pr (mapW w f) q = pr w (fun x => q (f x)) := mapW_avg _ _ _ - -end Prod - -end HadwigerCounterexample - -end - -end OAI +import Mathlib.Basic.Real.Basic +import Mathlib.Data.Fintype.BigOperators +import Mathlib.Algebra.BigOperators.Ring.Finset +import Mathlib.Algebra.Order.BigOperators.Group.Finset +import Mathlib.Algebra.Order.BigOperators.Ring.Finset +import Mathlib.Tactic.Linarith +import Mathlib.Tactic.GCongr +import Mathlib.Tactic.Positivity +import Mathlib.Tactic.Ring +import Mathlib.Tactic.NormNum + +namespace OAI + +/-! # Finite Laws -/ + +noncomputable section +open scoped BigOperators + +namespace HadwigerCounterexample + +abbrev Wgt (α : Type*) := α → ℝ + +variable {α β : Type*} + +/-- Real indicator. -/ +def ind (p : Prop) : ℝ := @ite ℝ p (Classical.propDecidable _) 1 0 + +theorem ind_eq (p : Prop) [Decidable p] : ind p = if p then 1 else 0 := by + unfold ind + congr + +theorem ind_one {p : Prop} (h : p) : ind p = 1 := by classical simp [ind, h] +theorem ind_zero {p : Prop} (h : ¬p) : ind p = 0 := by classical simp [ind, h] +@[simp] theorem ind_true : ind True = 1 := ind_one trivial +@[simp] theorem ind_false : ind False = 0 := ind_zero (not_false) + +theorem ind_nonneg (p : Prop) : 0 ≤ ind p := by + by_cases h : p + · exact le_of_lt (by rw [ind_one h]; norm_num) + · rw [ind_zero h] + +theorem ind_le_one (p : Prop) : ind p ≤ 1 := by + by_cases h : p + · rw [ind_one h] + · rw [ind_zero h] + norm_num + +theorem ind_mono {p q : Prop} (hp : p → q) : ind p ≤ ind q := by + by_cases h : p + · rw [ind_one h, ind_one (hp h)] + · rw [ind_zero h] + exact ind_nonneg _ + +theorem ind_not (p : Prop) : ind (¬p) = 1 - ind p := by + by_cases h : p <;> simp [ind, h] + +theorem ind_and (p q : Prop) : ind (p ∧ q) = ind p * ind q := by + by_cases h : p <;> by_cases h2 : q <;> simp [ind, h, h2] + +theorem ind_or_le (p q : Prop) : ind (p ∨ q) ≤ ind p + ind q := by + by_cases h : p + · simp only [h, true_or, ind_true] + have := ind_nonneg q + linarith + · simp [h] + +/-- Total weight. -/ +def tot [Fintype α] (w : Wgt α) : ℝ := ∑ x, w x +/-- Weighted average (not normalized if the weights are not a probability law). -/ +def avg [Fintype α] (w f : Wgt α) : ℝ := ∑ x, w x * f x +/-- Weight of an event. -/ +def pr [Fintype α] (w : Wgt α) (p : α → Prop) := avg w (fun x => ind (p x)) + +structure SubLaw [Fintype α] (w : Wgt α) : Prop where + nz (x : α) : 0 ≤ w x + total : tot w ≤ 1 +structure IsLaw [Fintype α] (w : Wgt α) : Prop where + nz (x : α) : 0 ≤ w x + total : tot w = 1 + +theorem IsLaw.sub [Fintype α] {w : Wgt α} (hw : IsLaw w) : SubLaw w where + nz := hw.nz + total := hw.total.le + +/-- All positive mass is supported on `p`. We use the equivalent contrapositive with +zero mass (and supply nonnegativity wherever we speak of a law). -/ +def carried (w : Wgt α) (p : α → Prop) := ∀ x : α, ¬ p x → w x = 0 + +section Basic +variable [Fintype α] {w v f g : Wgt α} {p q : α → Prop} + +theorem tot_nonneg (hw : ∀ x, 0 ≤ w x) : 0 ≤ tot w := Finset.sum_nonneg fun x _ => hw x + +theorem tot_mono (h : ∀ x, w x ≤ v x) : tot w ≤ tot v := + Finset.sum_le_sum fun x _ => h x + +theorem weight_le_tot (hw : ∀ x, 0 ≤ w x) (x) : w x ≤ tot w := + Finset.single_le_sum (fun y _ => hw y) (Finset.mem_univ x) + +theorem SubLaw.weight_le_one (hw : SubLaw w) (x) : w x ≤ 1 := + (weight_le_tot hw.nz x).trans hw.total + +theorem IsLaw.weight_le_one (hw : IsLaw w) (x) : w x ≤ 1 := hw.sub.weight_le_one x + +theorem avg_comm (w f : Wgt α) : avg w f = avg f w := by simp only [avg, mul_comm] + +theorem avg_mono (hw : ∀ x, 0 ≤ w x) (h : ∀ x, f x ≤ g x) : avg w f ≤ avg w g := + Finset.sum_le_sum fun x _ => mul_le_mul_of_nonneg_left (h x) (hw x) + +theorem avg_mono_left (hf : ∀ x, 0 ≤ f x) (h : ∀ x, w x ≤ v x) : avg w f ≤ avg v f := by + rw [avg_comm w, avg_comm v] + exact avg_mono hf h + +theorem avg_nonneg (hw : ∀ x, 0 ≤ w x) (hf : ∀ x, 0 ≤ f x) : 0 ≤ avg w f := + Finset.sum_nonneg fun x _ => mul_nonneg (hw x) (hf x) + +@[simp] theorem avg_zero (w : Wgt α) : avg w (fun _ => 0) = 0 := by simp [avg] + +theorem avg_const (w : Wgt α) (a : ℝ) : avg w (fun _ => a) = tot w * a := by + rw [avg, tot, Finset.sum_mul] + +theorem IsLaw.avg_const (hw : IsLaw w) (a : ℝ) : avg w (fun _ => a) = a := by + rw [HadwigerCounterexample.avg_const, hw.total, one_mul] + +theorem SubLaw.avg_le (hw : SubLaw w) {b : ℝ} (hb : 0 ≤ b) (h : ∀ x, f x ≤ b) : + avg w f ≤ b := by + refine (avg_mono hw.nz h).trans ?_ + rw [avg_const] + exact (mul_le_mul_of_nonneg_right hw.total hb).trans_eq (one_mul b) + +theorem IsLaw.avg_le (hw : IsLaw w) {b : ℝ} (h : ∀ x, f x ≤ b) : avg w f ≤ b := + (avg_mono hw.nz h).trans (hw.avg_const _).le + +theorem IsLaw.le_avg (hw : IsLaw w) {b : ℝ} (h : ∀ x, b ≤ f x) : b ≤ avg w f := + (hw.avg_const _).ge.trans (avg_mono hw.nz h) + +theorem abs_avg_le (hw : ∀ x, 0 ≤ w x) : |avg w f| ≤ avg w (fun x => |f x|) := by + rw [avg, avg] + refine (Finset.abs_sum_le_sum_abs _ _).trans_eq ?_ + simp_rw [abs_mul, abs_of_nonneg (hw _)] + +theorem avg_add (w f g : Wgt α) : avg w (fun x => f x + g x) = avg w f + avg w g := by + simp only [avg, mul_add, Finset.sum_add_distrib] + +theorem avg_sub (w f g : Wgt α) : avg w (fun x => f x - g x) = avg w f - avg w g := by + simp only [avg, mul_sub, Finset.sum_sub_distrib] + +theorem avg_mul (w f : Wgt α) (b : ℝ) : avg w (fun x => f x * b) = avg w f * b := by + simp only [avg, Finset.sum_mul, mul_assoc] + +theorem avg_mul' (w f : Wgt α) (b : ℝ) : avg w (fun x => b * f x) = b * avg w f := by + simpa only [mul_comm b] using avg_mul w f b + +theorem avg_div (w f : Wgt α) (b : ℝ) : avg w (fun x => f x / b) = avg w f / b := by + simp_rw [div_eq_mul_inv] + exact avg_mul _ _ _ + +theorem avg_congr (h : ∀ x, w x ≠ 0 → f x = g x) : avg w f = avg w g := by + unfold avg + refine Finset.sum_congr rfl fun x _ => ?_ + by_cases hx : w x = 0 + · rw [hx, zero_mul, zero_mul] + · rw [h x hx] + +theorem avg_sum {ι : Type*} (w : Wgt α) (s : Finset ι) (f : ι → Wgt α) : + avg w (fun x => ∑ i ∈ s, f i x) = ∑ i ∈ s, avg w (f i) := by + simp only [avg, Finset.mul_sum] + rw [Finset.sum_comm] + +theorem avg_avg [Fintype β] (w : Wgt α) (v : Wgt β) (f : α → β → ℝ) : + avg w (fun x => avg v (f x)) = avg v (fun y => avg w (fun x => f x y)) := by + simp only [avg, Finset.mul_sum] + rw [Finset.sum_comm] + simp only [mul_left_comm] + +theorem pr_nonneg (hw : ∀ x, 0 ≤ w x) : 0 ≤ pr w p := + avg_nonneg hw fun _ => ind_nonneg _ + +theorem pr_le_tot (hw : ∀ x, 0 ≤ w x) : pr w p ≤ tot w := by + unfold pr + refine (avg_mono hw fun x => ind_le_one (p x)).trans_eq ?_ + rw [avg_const, mul_one] + +theorem pr_mono (hw : ∀ x, 0 ≤ w x) (h : ∀ x, p x → q x) : pr w p ≤ pr w q := + avg_mono hw fun x => ind_mono (h x) + +theorem pr_mono_left (h : ∀ x, w x ≤ v x) (p : α → Prop) : pr w p ≤ pr v p := + avg_mono_left (fun x => ind_nonneg (p x)) h + +theorem pr_not (w : Wgt α) (p : α → Prop) : pr w (fun x => ¬p x) = tot w - pr w p := by + simp_rw [pr, ind_not, avg_sub, avg_const, mul_one] + +@[simp] theorem pr_point (w : Wgt α) (x : α) : pr w (fun y => x = y) = w x := by + classical simp [pr, avg, ind] + +@[simp] theorem pr_point' (w : Wgt α) (x : α) : pr w (fun y => y = x) = w x := by + classical simp [pr, avg, ind] + +@[simp] theorem pr_true (w : Wgt α) : pr w (fun _ => True) = tot w := by simp [pr, avg, tot] +@[simp] theorem pr_false (w : Wgt α) : pr w (fun _ => False) = 0 := by simp [pr] + +theorem pr_or_le (hw : ∀ x, 0 ≤ w x) : + pr w (fun x => p x ∨ q x) ≤ pr w p + pr w q := + (avg_mono hw fun x => ind_or_le (p x) (q x)).trans_eq (avg_add _ _ _) + +theorem pr_union_le (hw : ∀ x, 0 ≤ w x) {ι : Type*} (s : Finset ι) (p : ι → α → Prop) : + pr w (fun x => ∃ i ∈ s, p i x) ≤ ∑ i ∈ s, pr w (p i) := by + let F : ι → Wgt α := fun i x => ind (p i x) + change _ ≤ ∑ i ∈ s, avg w (F i) + rw [← avg_sum] + refine avg_mono hw fun x => ?_ + change ind (∃ i ∈ s, p i x) ≤ _ + by_cases h : ∃ i ∈ s, p i x + · rw [ind_one h] + obtain ⟨i, hi, hp⟩ := h + have : F i x ≤ ∑ i ∈ s, F i x := + Finset.single_le_sum (fun (j : ι) _ => ind_nonneg (p j x)) hi + simpa only [F, ind_one hp] using this + · rw [ind_zero h] + exact Finset.sum_nonneg fun i _ => ind_nonneg (p i x) + +theorem pr_exists_le (hw : ∀ x, 0 ≤ w x) {ι : Type*} [Fintype ι] (p : ι → α → Prop) : + pr w (fun x => ∃ i, p i x) ≤ ∑ i, pr w (p i) := by + simpa using pr_union_le hw Finset.univ p + +theorem weight_le_pr (hw : ∀ x, 0 ≤ w x) {x} (hx : p x) : w x ≤ pr w p := by + have h := pr_mono (p:=fun y => x = y) (q:=p) hw (fun y e => e ▸ hx) + simpa only [pr_point] using h + +theorem exists_of_pr_pos (hw : ∀ x, 0 ≤ w x) (hp : 0 < pr w p) : + ∃ x, p x ∧ 0 < w x := by + by_contra! hn + have h : pr w p = 0 := by + unfold pr avg + refine Finset.sum_eq_zero fun x _ => ?_ + by_cases hx : p x + · rw [le_antisymm (hn x hx) (hw x), zero_mul] + · simp only [ind_zero hx, mul_zero] + exact hp.ne' h + +theorem carried_iff_pr (hw : ∀ x, 0 ≤ w x) : carried w p ↔ pr w p = tot w := by + constructor + · intro h + unfold pr + have e : avg w (fun x => ind (p x)) = avg w (fun _ => 1) := by + refine avg_congr fun x hx => ind_one (Classical.byContradiction fun hn => hx (h x hn)) + rw [e, avg_const, mul_one] + · intro he x hx + have h := weight_le_pr (p:=fun x => ¬p x) hw hx + rw [pr_not, he, sub_self] at h + exact le_antisymm h (hw x) + +theorem le_avg_markov (hw : ∀ x, 0 ≤ w x) (hf : ∀ x, 0 ≤ f x) (b : ℝ) : + b * pr w (fun x => b ≤ f x) ≤ avg w f := by + unfold pr + rw [← avg_mul'] + refine avg_mono hw fun x => ?_ + by_cases h : b ≤ f x + · simpa [ind_one h] using h + · simpa [ind_zero h] using hf x + +end Basic + +/-- Restrict weights; *not* renormalized. -/ +def subW (w : Wgt α) (p : α → Prop) := fun x => w x * ind (p x) + +/-- Divide a finite weight function by its total, giving zero if total is zero. -/ +def normW [Fintype α] (w : Wgt α) := fun x => w x / tot w + +def unif [Fintype α] : Wgt α := normW fun _ => 1 +def unifOn [Fintype α] (p : α → Prop) : Wgt α := normW (fun x => ind (p x)) + +section Restrict +variable [Fintype α] {w : Wgt α} {p : α → Prop} + +omit [Fintype α] in +theorem subW_nonneg (hw : ∀ x, 0 ≤ w x) (p : α → Prop) : ∀ x, 0 ≤ subW w p x := + fun x => mul_nonneg (hw x) (ind_nonneg _) + +@[simp] theorem subW_tot (w : Wgt α) (p : α → Prop) : tot (subW w p) = pr w p := rfl + +omit [Fintype α] in +theorem subW_le (hw : ∀ x, 0 ≤ w x) (p : α → Prop) (x : α) : subW w p x ≤ w x := + (mul_le_mul_of_nonneg_left (ind_le_one _) (hw x)).trans_eq (mul_one _) + +omit [Fintype α] in +theorem subW_carried (w : Wgt α) (p : α → Prop) : carried (subW w p) p := + fun x h => by rw [subW, ind_zero h, mul_zero] + +theorem subLaw_sub (hw : SubLaw w) (p : α → Prop) : SubLaw (subW w p) := + ⟨subW_nonneg hw.nz p, (pr_le_tot hw.nz).trans hw.total⟩ + +theorem pr_sub (w : Wgt α) (p q : α → Prop) : + pr (subW w p) q = pr w (fun x => p x ∧ q x) := by + simp only [pr, avg, ind_and, subW, mul_assoc] + +theorem normW_nonneg (hw : ∀ x, 0 ≤ w x) : ∀ x, 0 ≤ normW w x := + fun x => div_nonneg (hw x) (tot_nonneg hw) + +theorem avg_norm (w f : Wgt α) : avg (normW w) f = avg w f / tot w := by + rw [avg_comm, avg_comm w f] + exact avg_div _ _ _ + +theorem tot_norm (w : Wgt α) : tot (normW w) = tot w / tot w := by + simp only [tot, normW, div_eq_mul_inv, Finset.sum_mul] + +theorem normW_law (hw : ∀ x, 0 ≤ w x) (hpos : 0 < tot w) : IsLaw (normW w) := + ⟨normW_nonneg hw, by rw [tot_norm, div_self hpos.ne']⟩ + +theorem normW_subLaw (hw : ∀ x, 0 ≤ w x) : SubLaw (normW w) := by + refine ⟨normW_nonneg hw, ?_⟩ + rw [tot_norm] + by_cases h : tot w = 0 <;> simp [h] + +theorem normW_carried (hp : carried w p) : carried (normW w) p := + fun x h => by rw [normW, hp x h, zero_div] + +theorem unif_apply (x : α) : unif x = (Fintype.card α : ℝ)⁻¹ := by + simp [unif, normW, tot] + +theorem unif_subLaw : SubLaw (unif : Wgt α) := + normW_subLaw (fun _ => zero_le_one) + +theorem unif_law [Nonempty α] : IsLaw (unif : Wgt α) := by + refine normW_law (fun _ => zero_le_one) ?_ + simp [tot, Fintype.card_pos] + +theorem unifOn_law (h : ∃ x, p x) : IsLaw (unifOn p) := by + refine normW_law (fun _ => ind_nonneg _) ?_ + obtain ⟨x, hx⟩ := h + have := weight_le_tot (fun x => ind_nonneg (p x)) x + change 0 < tot _ + rw [ind_one hx] at this + exact lt_of_lt_of_le zero_lt_one this + +end Restrict + +def pairW (w : Wgt α) (v : Wgt β) : Wgt (α × β) := fun p => w p.1 * v p.2 +def mixW [Fintype α] (w : Wgt α) (F : α → Wgt β) : Wgt β := fun y => avg w (fun x => F x y) +def mapW [Fintype α] (w : Wgt α) (f : α → β) : Wgt β := fun y => pr w (fun x => f x = y) + +section Prod +variable [Fintype α] [Fintype β] {w : Wgt α} {v : Wgt β} + +theorem pairW_avg (w : Wgt α) (v : Wgt β) (f : α × β → ℝ) : + avg (pairW w v) f = avg w (fun x => avg v (fun y => f (x,y))) := by + simp only [avg, Finset.mul_sum, Fintype.sum_prod_type, pairW, mul_assoc] + +theorem pairW_separate (w f : Wgt α) (v g : Wgt β) : + avg (pairW w v) (fun p => f p.1 * g p.2) = avg w f * avg v g := by + simp only [pairW_avg, avg_mul', avg_mul] + +theorem pairW_pr (w : Wgt α) (v : Wgt β) (p : α → Prop) (q : β → Prop) : + pr (pairW w v) (fun x => p x.1 ∧ q x.2) = pr w p * pr v q := by + simp_rw [pr, ind_and] + exact pairW_separate w (fun x => ind (p x)) v (fun y => ind (q y)) + +theorem pairW_tot (w : Wgt α) (v : Wgt β) : tot (pairW w v) = tot w * tot v := by + simpa using pairW_pr w v (fun _ => True) (fun _ => True) + +theorem pairW_law (hw : IsLaw w) (hv : IsLaw v) : IsLaw (pairW w v) := + ⟨fun x => mul_nonneg (hw.nz _) (hv.nz _), by rw [pairW_tot, hw.total, hv.total, mul_one]⟩ + +theorem mixW_avg (w : Wgt α) (F : α → Wgt β) (g : Wgt β) : + avg (mixW w F) g = avg w (fun x => avg (F x) g) := by + simp only [avg, mixW, Finset.mul_sum, Finset.sum_mul] + rw [Finset.sum_comm] + simp only [mul_assoc] + +theorem mixW_tot (w : Wgt α) (F : α → Wgt β) : + tot (mixW w F) = avg w (fun x => tot (F x)) := by + simpa only [avg_const, mul_one] using mixW_avg w F (fun _ => 1) + +theorem mixW_law (hw : IsLaw w) {F : α → Wgt β} (hF : ∀ x, IsLaw (F x)) : + IsLaw (mixW w F) := by + refine ⟨fun x => avg_nonneg hw.nz (fun y => (hF y).nz _), ?_⟩ + rw [mixW_tot] + simp_rw [(hF _).total] + exact hw.avg_const _ + +theorem mapW_avg (w : Wgt α) (f : α → β) (g : Wgt β) : + avg (mapW w f) g = avg w (fun x => g (f x)) := by + classical + change avg (mixW w (fun x y => ind (f x = y))) g = _ + rw [mixW_avg] + simp [avg, ind] + +theorem mapW_law (hw : IsLaw w) (f : α → β) : IsLaw (mapW w f) := by + refine ⟨fun _ => pr_nonneg hw.nz, ?_⟩ + simpa only [avg_const, mul_one, hw.total] using mapW_avg w f (fun _ => 1) + +theorem mapW_pr (w : Wgt α) (f : α → β) (q : β → Prop) : + pr (mapW w f) q = pr w (fun x => q (f x)) := mapW_avg _ _ _ + +end Prod + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteOptionLabels.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteOptionLabels.lean index fa5b1d2fc2ec6b96d5155fa8813bcf0df5248554..2e67821b7f4b65c03d00717d86b5194b47e5c561 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteOptionLabels.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteOptionLabels.lean @@ -1,127 +1,127 @@ -import OAI.Combinatorics.HadwigerCounterexample.RelationMismatchBounds - -namespace OAI - -/-! # Finite Option Labels -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Matrix Finset Function Submodule LinearMap -open scoped BigOperators Topology -open Template -variable {p:Shape} {N n r K : ℕ} -namespace StatusAnalysis -namespace DualAnalysis -open Club Guild -variable {d e: Rates} - {u:Terrain p r} {s:Gazette p r d} {t:Gazette p r e} - {β η δ:ℝ} - -abbrev Engagement (p:Shape) (q : Format) (d e:Rates) := - (i : Messenger q) → Scriptum p d e i.1 - -set_option maxHeartbeats 800000 in -theorem invite (p: Shape) (u:Terrain p r) (s:Gazette p r d) (t:Gazette p r e) - (A B:Stalls p) (η:ℝ) - (v: ∀ i,Suite d e i) (H:Straps (Label p.b)) (f:Bags (Scriptum p d e)) - (hf : Parade (stellar u s t η A B) H v f Finset.univ) : - let C:=stellar u s t η A B - ∃ (q : Volumes) (g:Engagement p (toFormat q) d e), - (∀ i,1 ≤ toFormat q i ∧ toFormat q i ≤7) ∧ - (∀ i:Messenger (toFormat q),(C i.1).valid (g i)) ∧ - (∀ b:Bool,Injective (fun i:Messenger (toFormat q)=>(g i).1.s b)) ∧ - ∀ i,∑ j:Fin (toFormat q i),(C i).writes (g ⟨i,j⟩)=v i := by - classical - intro C - have he i:= hf.batch i (mem_univ _) - let q (i:Grid):Fin 8:= ⟨(f i).card,Nat.lt_succ_of_le (he i).2.2.2⟩ - let Q:=toFormat q - let E (i:Grid): Fin (Q i)≃(↑(f i) : Type) := (Fintype.equivFinOfCardEq (Fintype.card_coe _)).symm - let g:Engagement p Q d e:=fun i=>(E _ i.2).val - have hG (i) : g i∈ f i.1:=(E i.1 i.2).property - refine ⟨q,g,fun i=>(he i).2.2,fun i=>((he _).1.1 _ (hG i)).1,fun b i j h=>?_, - fun i=>?_⟩ - · rcases i with ⟨i,x⟩;rcases j with ⟨j,y⟩ - by_cases hi:i=j - · subst j - have ht : g ⟨i,x⟩=g ⟨i,y⟩:= - (he i).1.2 b (hG ⟨i,x⟩) (hG ⟨i,y⟩) h - rw [show x=y from (E i).injective (Subtype.ext ht)] - exact (hf.mixed i j (mem_univ _) (mem_univ _) hi _ (hG ⟨i,x⟩) _ (hG ⟨j,y⟩) b h).elim - calc _ = ∑ x:↑(f i), (C i).writes x.val := Equiv.sum_comp (E i) (fun x=>(C i).writes x.val) - _ = _ := (Finset.sum_coe_sort (f i) _).trans (he i).2.1 - -variable (p:Shape) -namespace Engagement - -def tags {q:Format} (f:Engagement p q d e) := - fun i:Messenger q=> (f i).1.l -def bits {q:Format} (f:Engagement p q d e) := - fun i:Messenger q=> (f i).1.q -def genre0 {q:Format} (f:Engagement p q d e): Fabric p q d true := - {sel i:= (f i).1.s true - flav i:= (f i).1.f true - amp i:= (f i).2.1} -def genre1 {q:Format} (f:Engagement p q d e): Fabric p q e false := - {sel i:= (f i).1.s false - flav i:= (f i).1.f false - amp i:= (f i).2.2} -def binding {q:Format} (f:Engagement p q d e) (a b:Script p (Messenger q)) : - Typus p q d e := - ⟨tags p f,bits p f,(genre0 p f).hang a,(genre1 p f).hang b⟩ - -set_option maxHeartbeats 900000 in -theorem solicit {q:Format} (g:Engagement p q d e) (a b:Script p (Messenger q)) - (Y : Silhouette p N r) (X:Charts p n d) (Z:Charts p n e) (m:Mixer p n) - (o o':UnitType p n N) (i:Messenger q) : - (g.binding p a b).chimera o o' X Z m Y i= - let H:= g i - circlet (wisp p Y) (wake p Y m o X) (wake p Y m o' Z) H.1 i.1 H.2 := by - classical - let H:=g i - let μ:= lawOmega p N H.1.l H.1.q - let u:= Y H.1.l H.1.q - let F:=couplePage (wake p Y m o X) (wake p Y m o' Z) H.1 i.1 - change _=avg (mapW μ u) (fun i =>F i H.2) - rw [mapW_avg] - rfl -end Engagement - -set_option maxHeartbeats 1200000 in -theorem processions (K:ℕ) {u:Terrain p r} {s:Gazette p r d} {t:Gazette p r e} (A:Stalls p) (B:Stalls p) (a b:Pin p n N) - (X:Charts p n d) (W:Charts p n e) (T:Cross p n) - (hA:charted X a.sp) (hB:charted W b.sp) (ha:tableInj a.sp b.sp T) (hb:tableInj b.sp a.sp - (reciprocal p T)) - (x y:Stalls p) (hX:booths p K a.sp x) (hY:booths p K b.sp y) (hx: x ≤ A) (hy: y ≤ B) - (hg:2≤p.g) (hp:1≤p.J) - (H:Straps (Label p.b)) - (ht : ∀ i:Grid,(stellar u s t η A B i).travels H 100 (view _ _) - (chapter (stellar u s t η A B) H i)) - (hv:scorecard (chapter (stellar u s t η A B) H) (hailing p X W T)) : - ∃ (q:Volumes) (g:Engagement p (toFormat q) d e) (s0 t0:Script p (Messenger (toFormat q))), - (g.binding p s0 t0).chances X W a b T K ∧ ∀ i:Messenger (toFormat q), - η≤circlet u s t (g i).1 i.1 (g i).2 := by - classical - obtain ⟨v,hv,hp0⟩:=hv - let C:=stellar u s t η A B - obtain ⟨g,hg'⟩:= full_parade C H ht hv - obtain ⟨q,g,hI,hG,hS,hQ⟩:=invite p u s t A B η v H g hg' - let z:=g.tags p; let w:=g.bits p; let F0:=g.genre0 p; let F1:=g.genre1 p - have hM : F0.up z w ∧ F1.up z w := by - constructor - · exact ⟨hS true,fun i=> (hG i).2.2.2.1.2.1,fun i=> (hG i).2.2.2.1.1⟩ - exact ⟨hS false,fun i=> (hG i).2.2.2.2.1.2.1,fun i=>(hG i).2.2.2.2.1.1⟩ - obtain ⟨P,Q,hP⟩:= optionVia (toFormat q) d e a b T K ha hb z X W hA hB F0 F1 x y hX hY - (fun i h=> (hG i).1 (hx _ h)) (fun i h=> (hG i).2.1 (hy _ h)) w hM.1 hM.2 hp hg hI - (by - have he : sendSum w F0.amp F1.amp = v := funext (fun i=>hQ i) - rw [he]; exact hp0) - exact ⟨q,g,P,Q,hP,fun i=>(hG i).2.2.2.2.2⟩ - -end DualAnalysis -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RelationMismatchBounds + +namespace OAI + +/-! # Finite Option Labels -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Matrix Finset Function Submodule LinearMap +open scoped BigOperators Topology +open Template +variable {p:Shape} {N n r K : ℕ} +namespace StatusAnalysis +namespace DualAnalysis +open Club Guild +variable {d e: Rates} + {u:Terrain p r} {s:Gazette p r d} {t:Gazette p r e} + {β η δ:ℝ} + +abbrev Engagement (p:Shape) (q : Format) (d e:Rates) := + (i : Messenger q) → Scriptum p d e i.1 + +set_option maxHeartbeats 800000 in +theorem invite (p: Shape) (u:Terrain p r) (s:Gazette p r d) (t:Gazette p r e) + (A B:Stalls p) (η:ℝ) + (v: ∀ i,Suite d e i) (H:Straps (Label p.b)) (f:Bags (Scriptum p d e)) + (hf : Parade (stellar u s t η A B) H v f Finset.univ) : + let C:=stellar u s t η A B + ∃ (q : Volumes) (g:Engagement p (toFormat q) d e), + (∀ i,1 ≤ toFormat q i ∧ toFormat q i ≤7) ∧ + (∀ i:Messenger (toFormat q),(C i.1).valid (g i)) ∧ + (∀ b:Bool,Injective (fun i:Messenger (toFormat q)=>(g i).1.s b)) ∧ + ∀ i,∑ j:Fin (toFormat q i),(C i).writes (g ⟨i,j⟩)=v i := by + classical + intro C + have he i:= hf.batch i (mem_univ _) + let q (i:Grid):Fin 8:= ⟨(f i).card,Nat.lt_succ_of_le (he i).2.2.2⟩ + let Q:=toFormat q + let E (i:Grid): Fin (Q i)≃(↑(f i) : Type) := (Fintype.equivFinOfCardEq (Fintype.card_coe _)).symm + let g:Engagement p Q d e:=fun i=>(E _ i.2).val + have hG (i) : g i∈ f i.1:=(E i.1 i.2).property + refine ⟨q,g,fun i=>(he i).2.2,fun i=>((he _).1.1 _ (hG i)).1,fun b i j h=>?_, + fun i=>?_⟩ + · rcases i with ⟨i,x⟩;rcases j with ⟨j,y⟩ + by_cases hi:i=j + · subst j + have ht : g ⟨i,x⟩=g ⟨i,y⟩:= + (he i).1.2 b (hG ⟨i,x⟩) (hG ⟨i,y⟩) h + rw [show x=y from (E i).injective (Subtype.ext ht)] + exact (hf.mixed i j (mem_univ _) (mem_univ _) hi _ (hG ⟨i,x⟩) _ (hG ⟨j,y⟩) b h).elim + calc _ = ∑ x:↑(f i), (C i).writes x.val := Equiv.sum_comp (E i) (fun x=>(C i).writes x.val) + _ = _ := (Finset.sum_coe_sort (f i) _).trans (he i).2.1 + +variable (p:Shape) +namespace Engagement + +def tags {q:Format} (f:Engagement p q d e) := + fun i:Messenger q=> (f i).1.l +def bits {q:Format} (f:Engagement p q d e) := + fun i:Messenger q=> (f i).1.q +def genre0 {q:Format} (f:Engagement p q d e): Fabric p q d true := + {sel i:= (f i).1.s true + flav i:= (f i).1.f true + amp i:= (f i).2.1} +def genre1 {q:Format} (f:Engagement p q d e): Fabric p q e false := + {sel i:= (f i).1.s false + flav i:= (f i).1.f false + amp i:= (f i).2.2} +def binding {q:Format} (f:Engagement p q d e) (a b:Script p (Messenger q)) : + Typus p q d e := + ⟨tags p f,bits p f,(genre0 p f).hang a,(genre1 p f).hang b⟩ + +set_option maxHeartbeats 900000 in +theorem solicit {q:Format} (g:Engagement p q d e) (a b:Script p (Messenger q)) + (Y : Silhouette p N r) (X:Charts p n d) (Z:Charts p n e) (m:Mixer p n) + (o o':UnitType p n N) (i:Messenger q) : + (g.binding p a b).chimera o o' X Z m Y i= + let H:= g i + circlet (wisp p Y) (wake p Y m o X) (wake p Y m o' Z) H.1 i.1 H.2 := by + classical + let H:=g i + let μ:= lawOmega p N H.1.l H.1.q + let u:= Y H.1.l H.1.q + let F:=couplePage (wake p Y m o X) (wake p Y m o' Z) H.1 i.1 + change _=avg (mapW μ u) (fun i =>F i H.2) + rw [mapW_avg] + rfl +end Engagement + +set_option maxHeartbeats 1200000 in +theorem processions (K:ℕ) {u:Terrain p r} {s:Gazette p r d} {t:Gazette p r e} (A:Stalls p) (B:Stalls p) (a b:Pin p n N) + (X:Charts p n d) (W:Charts p n e) (T:Cross p n) + (hA:charted X a.sp) (hB:charted W b.sp) (ha:tableInj a.sp b.sp T) (hb:tableInj b.sp a.sp + (reciprocal p T)) + (x y:Stalls p) (hX:booths p K a.sp x) (hY:booths p K b.sp y) (hx: x ≤ A) (hy: y ≤ B) + (hg:2≤p.g) (hp:1≤p.J) + (H:Straps (Label p.b)) + (ht : ∀ i:Grid,(stellar u s t η A B i).travels H 100 (view _ _) + (chapter (stellar u s t η A B) H i)) + (hv:scorecard (chapter (stellar u s t η A B) H) (hailing p X W T)) : + ∃ (q:Volumes) (g:Engagement p (toFormat q) d e) (s0 t0:Script p (Messenger (toFormat q))), + (g.binding p s0 t0).chances X W a b T K ∧ ∀ i:Messenger (toFormat q), + η≤circlet u s t (g i).1 i.1 (g i).2 := by + classical + obtain ⟨v,hv,hp0⟩:=hv + let C:=stellar u s t η A B + obtain ⟨g,hg'⟩:= full_parade C H ht hv + obtain ⟨q,g,hI,hG,hS,hQ⟩:=invite p u s t A B η v H g hg' + let z:=g.tags p; let w:=g.bits p; let F0:=g.genre0 p; let F1:=g.genre1 p + have hM : F0.up z w ∧ F1.up z w := by + constructor + · exact ⟨hS true,fun i=> (hG i).2.2.2.1.2.1,fun i=> (hG i).2.2.2.1.1⟩ + exact ⟨hS false,fun i=> (hG i).2.2.2.2.1.2.1,fun i=>(hG i).2.2.2.2.1.1⟩ + obtain ⟨P,Q,hP⟩:= optionVia (toFormat q) d e a b T K ha hb z X W hA hB F0 F1 x y hX hY + (fun i h=> (hG i).1 (hx _ h)) (fun i h=> (hG i).2.1 (hy _ h)) w hM.1 hM.2 hp hg hI + (by + have he : sendSum w F0.amp F1.amp = v := funext (fun i=>hQ i) + rw [he]; exact hp0) + exact ⟨q,g,P,Q,hP,fun i=>(hG i).2.2.2.2.2⟩ + +end DualAnalysis +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FinitePhaseAlternative.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FinitePhaseAlternative.lean index 21a5879fc25d8555298afc2df02b8012cd5b8aef..90a81d64bede95f38478c6fae0e2b9ed466c290e 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FinitePhaseAlternative.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FinitePhaseAlternative.lean @@ -1,157 +1,157 @@ -import OAI.Combinatorics.HadwigerCounterexample.PhaseAlternativeSupport - -namespace OAI - -/-! # Finite Phase Alternative -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Function Finset -open scoped BigOperators -variable {p : Shape} {n N r : ℕ} - -def maxSpan (m b r : ℕ) := r*(2^m*(2*b)) - -structure PhaseReady (p : Shape) (n N m b r k d : ℕ) (mix : Mixer p n) - (c l ψ ε L H : ℝ) : Prop where - hb : 1≤b - hm : 16*r ¬voidFrame p x T) ≤ scaleBill p n N r H := by - classical - let P := fun i : Place p × Bool => fun x => ¬ Disjoint (imageP p (x : UnitType p n N) i.2 i.1) - (T i.1) - have h x : ¬voidFrame p (n:=n) x T → ∃ i,P i x := by - intro h - unfold voidFrame at h; push Not at h - obtain ⟨i,z,h⟩ := h - exact ⟨(z,i),fun he => h he.symm⟩ - let Y := H*2 * bp (num (Row p n)+r-N) - have hr i : pr w (P i) ≤ Y := by - rcases i with ⟨⟨z,b⟩,i⟩ - have hh' : dim (T (z,b)) ≤ r := - (Finset.single_le_sum (fun j _ => Nat.zero_le (dim (T (j,b)))) (Finset.mem_univ z)).trans - (hT b) - exact (any_frame_hit m hl hh i _ hN _).trans (mul_le_mul_of_nonneg_left (bp_le (by - have hf : (dim (T (z,b)):ℝ) ≤ r := by exact_mod_cast hh' - linarith only [hf])) (by positivity)) - refine ((pr_mono hw.nz h).trans (pr_exists_le hw.nz P)).trans ?_ - refine (Finset.sum_le_sum fun i _ => hr i).trans_eq ?_ - simp only [Y,scaleBill,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,num,Fintype.card_prod, - Fintype.card_bool,Nat.cast_mul,Nat.cast_ofNat] - -private theorem mark_bazaar (m : BMark p n N) {v : Wgt (UnitType p n N)} - {T : Cov p N} (h : ∀ x,v x≠0 → covered p T (delta m x) ∧ voidFrame p x T ∧ - delta m x≠0 ∧ epoch p (mrAmbient m x true)≤r) : - ∃ s : Bazaar p n r T,s.opened (delta m) v := by - classical - have he x : ∃ s : Atlas p r T, - v x≠0 → - standard s ∧ ∀ i,∃ A,compFor s A (imageP p x i) (delta m x) := by - by_cases he : v x≠0 - · obtain ⟨hC,hV,hD,hR⟩ := h x he - obtain ⟨X,hX,hY⟩ := delta_offset m x hC hD hV hR - exact ⟨X,fun _ => ⟨hX,hY⟩⟩ - exact ⟨default,fun hs => (he hs).elim⟩ - choose f hf using he - choose A hA using - show ∀ (M : Atlas p r T) (i : Bool) (x), ∃ A, - M=f x → v x≠0 → compFor M A (imageP p x i) (delta m x) from by - intro M i x - by_cases hs : v x=0 - · exact ⟨0,fun _ hh => (hh hs).elim⟩ - by_cases he : M=f x - · subst M - obtain ⟨A,hA⟩ := (hf x hs).2 i - exact ⟨A,fun _ _ => hA⟩ - exact ⟨0,fun H => (he H).elim⟩ - exact ⟨⟨f,A⟩,fun x h => ⟨(hf x h).1,fun i => hA _ i x rfl h⟩⟩ - -set_option maxHeartbeats 800000 in -theorem phase_alternative {w : Wgt (UnitType p n N)} - (mark : BMark p n N) - {c l ψ ε L H : ℝ} {m b k d : ℕ} - (mix : Mixer p n) (hr : PhaseReady p n N m b r k d mix c l ψ ε L H) - (hw : IsLaw w) - (hk : bySide p w mix L) - (hv : ∀ x,w x≤H * pairW (raw mix N) (raw mix N) x) - (hh : ∀ x,w x≠0 → delta mark x≠0 ∧ epoch p (mrAmbient mark x true) ≤ r) - (hK : ∀ x,epoch p (delta mark x) ≤r) : - ∃ P : UnitType p n N→Prop,(c/2)*(l/2)≤pr w P ∧ - (tonalMix p (delta mark) (onW w P) ∨ tonalTiny p (delta mark) (onW w P) d) := by - classical - have hc := hr.hc - have hl := hr.hl - by_cases he : ∀ T : Cov p N, (∀ i,cdSign p T i≤maxSpan m b r) → - pr w (fun i => covered p T (delta mark i)) ≤ c - · refine ⟨fun _ => True,?_,Or.inl ?_⟩ - · rw [pr_true,hw.total] - nlinarith [hr.hc',hr.hl'] - rw [onW_true w hw] - apply tonal_left _ _ - intro S R hS - exact (pitch_no_cover p _ hw S R hS _ _ _ hK hr.hm hr.hb c ψ H hc.le he - hr.hψ hr.hH mix hr.hN hv).trans_lt hr.noBranch - push Not at he - obtain ⟨T,hT,hW⟩ := he - let P := fun x : UnitType p n N => covered p T (delta mark x) ∧ voidFrame p x T - let v := onW w P - have hp : c/2≤pr w P := by - have he := framesCost hw.sub mix hr.hL hk hr.hN T (maxSpan m b r) hT - have hs := pr_shield hw.nz (fun x => covered p T (delta mark x)) (fun x => voidFrame p x T) - change _ ≤ pr w P at hs - linarith only [hr.frames,hW,he,hs] - have hpp : 0 by - obtain ⟨⟨ha,hb⟩,ht⟩ := onW_ne h; exact ⟨ha,hb,hh x ht⟩) - have hH := hr.hH; have hL := hr.hL - have hm : IsLaw (raw mix N) := raw_law mix (by linarith only [hr.hN]) - have he x : v x≤rhUp H c * pairW (raw mix N) (raw mix N) x := by - apply (on_mon hw.nz (half_pos hc) hp x).trans - unfold rhUp; rw [mul_assoc] - exact mul_le_mul_of_nonneg_left (hv x) (by positivity) - obtain ⟨Q,hQ,hV⟩ := s.cover_options _ v mix hf h hm hr.cap - (by unfold rhUp; positivity) hl hr.hl' (bySide_on mix hw.nz hk P hc hp) - (by unfold rhUp; positivity) he hr.hN (hr.atlas T hT) hr.price hr.price' - k d hr.hk hr.localQ hr.testFailure hr.testFailure' hr.beatSlack - refine ⟨fun x => P x ∧ Q x,?_,?_⟩ - · rw [pr_of_on hw.nz] - exact mul_le_mul hp hQ (by positivity) hpp.le - rw [← on_both w P Q hw.nz hpp (lt_of_lt_of_le (half_pos hl) hQ)] - exact hV - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PhaseAlternativeSupport + +namespace OAI + +/-! # Finite Phase Alternative -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Function Finset +open scoped BigOperators +variable {p : Shape} {n N r : ℕ} + +def maxSpan (m b r : ℕ) := r*(2^m*(2*b)) + +structure PhaseReady (p : Shape) (n N m b r k d : ℕ) (mix : Mixer p n) + (c l ψ ε L H : ℝ) : Prop where + hb : 1≤b + hm : 16*r ¬voidFrame p x T) ≤ scaleBill p n N r H := by + classical + let P := fun i : Place p × Bool => fun x => ¬ Disjoint (imageP p (x : UnitType p n N) i.2 i.1) + (T i.1) + have h x : ¬voidFrame p (n:=n) x T → ∃ i,P i x := by + intro h + unfold voidFrame at h; push Not at h + obtain ⟨i,z,h⟩ := h + exact ⟨(z,i),fun he => h he.symm⟩ + let Y := H*2 * bp (num (Row p n)+r-N) + have hr i : pr w (P i) ≤ Y := by + rcases i with ⟨⟨z,b⟩,i⟩ + have hh' : dim (T (z,b)) ≤ r := + (Finset.single_le_sum (fun j _ => Nat.zero_le (dim (T (j,b)))) (Finset.mem_univ z)).trans + (hT b) + exact (any_frame_hit m hl hh i _ hN _).trans (mul_le_mul_of_nonneg_left (bp_le (by + have hf : (dim (T (z,b)):ℝ) ≤ r := by exact_mod_cast hh' + linarith only [hf])) (by positivity)) + refine ((pr_mono hw.nz h).trans (pr_exists_le hw.nz P)).trans ?_ + refine (Finset.sum_le_sum fun i _ => hr i).trans_eq ?_ + simp only [Y,scaleBill,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,num,Fintype.card_prod, + Fintype.card_bool,Nat.cast_mul,Nat.cast_ofNat] + +private theorem mark_bazaar (m : BMark p n N) {v : Wgt (UnitType p n N)} + {T : Cov p N} (h : ∀ x,v x≠0 → covered p T (delta m x) ∧ voidFrame p x T ∧ + delta m x≠0 ∧ epoch p (mrAmbient m x true)≤r) : + ∃ s : Bazaar p n r T,s.opened (delta m) v := by + classical + have he x : ∃ s : Atlas p r T, + v x≠0 → + standard s ∧ ∀ i,∃ A,compFor s A (imageP p x i) (delta m x) := by + by_cases he : v x≠0 + · obtain ⟨hC,hV,hD,hR⟩ := h x he + obtain ⟨X,hX,hY⟩ := delta_offset m x hC hD hV hR + exact ⟨X,fun _ => ⟨hX,hY⟩⟩ + exact ⟨default,fun hs => (he hs).elim⟩ + choose f hf using he + choose A hA using + show ∀ (M : Atlas p r T) (i : Bool) (x), ∃ A, + M=f x → v x≠0 → compFor M A (imageP p x i) (delta m x) from by + intro M i x + by_cases hs : v x=0 + · exact ⟨0,fun _ hh => (hh hs).elim⟩ + by_cases he : M=f x + · subst M + obtain ⟨A,hA⟩ := (hf x hs).2 i + exact ⟨A,fun _ _ => hA⟩ + exact ⟨0,fun H => (he H).elim⟩ + exact ⟨⟨f,A⟩,fun x h => ⟨(hf x h).1,fun i => hA _ i x rfl h⟩⟩ + +set_option maxHeartbeats 800000 in +theorem phase_alternative {w : Wgt (UnitType p n N)} + (mark : BMark p n N) + {c l ψ ε L H : ℝ} {m b k d : ℕ} + (mix : Mixer p n) (hr : PhaseReady p n N m b r k d mix c l ψ ε L H) + (hw : IsLaw w) + (hk : bySide p w mix L) + (hv : ∀ x,w x≤H * pairW (raw mix N) (raw mix N) x) + (hh : ∀ x,w x≠0 → delta mark x≠0 ∧ epoch p (mrAmbient mark x true) ≤ r) + (hK : ∀ x,epoch p (delta mark x) ≤r) : + ∃ P : UnitType p n N→Prop,(c/2)*(l/2)≤pr w P ∧ + (tonalMix p (delta mark) (onW w P) ∨ tonalTiny p (delta mark) (onW w P) d) := by + classical + have hc := hr.hc + have hl := hr.hl + by_cases he : ∀ T : Cov p N, (∀ i,cdSign p T i≤maxSpan m b r) → + pr w (fun i => covered p T (delta mark i)) ≤ c + · refine ⟨fun _ => True,?_,Or.inl ?_⟩ + · rw [pr_true,hw.total] + nlinarith [hr.hc',hr.hl'] + rw [onW_true w hw] + apply tonal_left _ _ + intro S R hS + exact (pitch_no_cover p _ hw S R hS _ _ _ hK hr.hm hr.hb c ψ H hc.le he + hr.hψ hr.hH mix hr.hN hv).trans_lt hr.noBranch + push Not at he + obtain ⟨T,hT,hW⟩ := he + let P := fun x : UnitType p n N => covered p T (delta mark x) ∧ voidFrame p x T + let v := onW w P + have hp : c/2≤pr w P := by + have he := framesCost hw.sub mix hr.hL hk hr.hN T (maxSpan m b r) hT + have hs := pr_shield hw.nz (fun x => covered p T (delta mark x)) (fun x => voidFrame p x T) + change _ ≤ pr w P at hs + linarith only [hr.frames,hW,he,hs] + have hpp : 0 by + obtain ⟨⟨ha,hb⟩,ht⟩ := onW_ne h; exact ⟨ha,hb,hh x ht⟩) + have hH := hr.hH; have hL := hr.hL + have hm : IsLaw (raw mix N) := raw_law mix (by linarith only [hr.hN]) + have he x : v x≤rhUp H c * pairW (raw mix N) (raw mix N) x := by + apply (on_mon hw.nz (half_pos hc) hp x).trans + unfold rhUp; rw [mul_assoc] + exact mul_le_mul_of_nonneg_left (hv x) (by positivity) + obtain ⟨Q,hQ,hV⟩ := s.cover_options _ v mix hf h hm hr.cap + (by unfold rhUp; positivity) hl hr.hl' (bySide_on mix hw.nz hk P hc hp) + (by unfold rhUp; positivity) he hr.hN (hr.atlas T hT) hr.price hr.price' + k d hr.hk hr.localQ hr.testFailure hr.testFailure' hr.beatSlack + refine ⟨fun x => P x ∧ Q x,?_,?_⟩ + · rw [pr_of_on hw.nz] + exact mul_le_mul hp hQ (by positivity) hpp.le + rw [← on_both w P Q hw.nz hpp (lt_of_lt_of_le (half_pos hl) hQ)] + exact hV + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FinitePredictions.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FinitePredictions.lean index 1f36f19ecdadd16f3f48b82ce8aac0c0178ab14d..637e58705d473dfd2f944a0dee769933c6ae19f4 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FinitePredictions.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FinitePredictions.lean @@ -1,126 +1,126 @@ -import OAI.Combinatorics.HadwigerCounterexample.UniqueStatusCoefficients - -namespace OAI - -/-! # Finite Predictions -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Filter Finset LinearMap Module Function -open scoped BigOperators Topology -open Template -namespace StatusAnalysis -namespace DualAnalysis -variable {p:Shape} {r n N K:ℕ} {d:Rates} - -def fromPulse (Y: Silhouette p N r) (f:Pulsar p r) : Augur p N := - fun l q x=> f l q (Y l q x) - -def yokeSet {n:ℕ} (w:Cell n) (α:F) : RhymeSet n := - ⟨1,w,1+α,0⟩ -def compass (i : Bool) (o:UnitType p n N) (s:Charts p n d) - (m:Mixer p n) (w:Cell (d i)) (α:F) := - yoke p m o i (s i w) α - -theorem lyrically (i:Bool) (o:UnitType p n N) - (m:Mixer p n) (s:Charts p n d) (w:Cell (d i)) (α:F) (x: Appearance p) (z:Knobs p.g n) : - (yokeSet w α).soot x (x.profile i o m (s i) z)= - compass i o s m w α (useAtom p x.l x.s x.f z) := by - classical - let A:=useAtom p x.l x.s x.f z - change 1*(innerP p o i) A+dotProduct w (roll (s i) (Tsym m A)) + - (1+(1+α))*role p n A+0*x.q=(innerP p o i) A+(Tsym m (s i w) A+α*role p n A) - rw [one_mul,←add_assoc (1:F),char_two,zero_add,zero_mul,add_zero,dotProduct_comm,← roll_project, - T_swap,add_assoc] - -theorem notary (s:Charts p n d) (Y:Silhouette p N r) (i:Bool) (o:UnitType p n N) - (m:Mixer p n) (w:Cell (d i)) (α:F) (x:Appearance p) (f:Pulsar p r) - {δ:ℝ} (h:x.close Y (onSide o i) δ) (hx:IsLaw (x.wit n)) : - let g:= mismatch p (fromPulse Y f) (compass i o s m w α) x.l x.s x.f (onSide o i) - |shot (wisp p Y) (wake p Y m o s) i x (yokeSet w α) f - pr (x.wit n) g|≤δ := by - classical - intro g - let P k (y:Magazine p (d i)):= ((yokeSet w α).soot x y≠ f x.l x.q k) - let W k y:=ind (P k y) - have hh (k y):|W k y|≤1 := by unfold W; rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ - have he := x.close_expect Y i o m (s i) hx W hh h - let f' := x.profile i o m (s i) - let V z:= W (x.showTag Y (onSide o i) z) (f' z) - have hf : avg (x.wit n) V=pr (x.wit n) g := by - refine avg_congr fun z hz =>?_ - have hx : dialed p x.l x.f z=x.q := (onW_ne hz).1 - have hq : g z ↔ P (x.showTag Y (onSide o i) z) (f' z) := by - unfold g mismatch fromPulse P f' - rw [hx, lyrically] - rfl - exact congrArg ind (propext hq.symm) - change |_ - avg (x.wit n) V|≤_ at he; rw [hf] at he; exact he - -set_option maxHeartbeats 800000 in -theorem praise_predict (s:Charts p n d) (Y:Silhouette p N r) (i:Bool) - (o:UnitType p n N) (m:Mixer p n) (w:Cell (d i)) (α:F) (f:Pulsar p r) {ε δ:ℝ} - (A:Finset (Label p.b)) - (he:0≤ε) (hδ:0≤δ) - (hp : 1≤ p.r) (hn:2*p.r≤n) - (hh:∀ x:Appearance p,x.apt→x.close Y (onSide o i) δ) - (hw:praise (wisp p Y) (wake p Y m o s) i A (yokeSet w α) f ε) : - postulates p (onSide o i) (fromPulse Y f) (compass i o s m w α) A ((ε+δ)*2) := by - classical - intro b hb t g - let μ:=spins p n; let v:=onSide o i; let X (y:F) : Appearance p:= - ⟨t,b,g,y⟩ - let Z:=mismatch p (fromPulse Y f) (compass i o s m w α) t b g v - let Q y (x:Knobs p.g n):=dialed p t g x=y - have hμ := spins_law p n - have hz (y:F) : pr μ (fun x=>Z x∧Q y x)≤ ε+δ := by - let x:=X y - by_cases hg : x.apt - · have hk:= hw x hb hg; have hx:= Appearance.witLaw hg hp hn - have hi:= notary s Y i o m w α x f (hh x hg) hx - change |_ - pr (x.wit n) Z|≤δ at hi - have he : pr (x.wit n) Z ≤ ε+δ := by linarith only [hk, (abs_le.mp hi).1] - rw [show (fun x=> Z x ∧ Q y x)=(fun x=>Q y x ∧ Z x) from funext fun x=>propext and_comm, - pr_of_on hμ.nz] - exact ((mul_le_mul_of_nonneg_right ((pr_le_tot hμ.nz).trans hμ.total.le) - (pr_nonneg hx.nz)).trans_eq (one_mul _)).trans he - have hm z : ¬ Q y z := by - intro h - refine hg ⟨scan p t g z,fun j hj=>?_,h⟩ - unfold scan; rw [ite_eq_right hj] - simp_rw [show ∀ z,(Z z∧Q y z)=False from (fun z=>eq_false (fun h=>hm z h.2)), - pr_false]; exact add_nonneg he hδ - refine (sum_pr_tag μ Z (dialed p t g)).symm.le.trans - ((Finset.sum_le_sum fun i _=>hz i).trans_eq ?_) - simp only [sum_const,card_univ,nsmul_eq_mul,F,ZMod.card]; ring - -set_option maxHeartbeats 800000 in -theorem predict_praise (s:Charts p n d) (Y:Silhouette p N r) (i:Bool) - (o:UnitType p n N) (m:Mixer p n) (w:Cell (d i)) (α:F) (f:Pulsar p r) {ε δ:ℝ} - (A:Finset (Label p.b)) - (he:0≤ε) - (hp:1≤p.r) (hn:2*p.r≤n) - (hh:∀ x:Appearance p,x.apt → x.close Y (onSide o i) δ) - (hw:postulates p (onSide o i) (fromPulse Y f) (compass i o s m w α) A (scanPrice p *ε)) : - praise (wisp p Y) (wake p Y m o s) i A (yokeSet w α) f (ε+δ) := by - intro x hx h - let Z:= mismatch p (fromPulse Y f) (compass i o s m w α) x.l x.s x.f (onSide o i) - have hwit := Appearance.witLaw h hp hn - have hz:= notary s Y i o m w α x f (hh x h) hwit - have hv : pr (x.wit n) Z ≤ε := by - unfold Appearance.wit scopedBit - let w:=spins p n - let Q (i:Knobs p.g n):=dialed p x.l x.f i=x.q - have hf := show scanPrice p ≤ pr w Q from dial_fraction p n _ _ _ hp hn h - rw [pr_on,div_le_iff₀ ((scanPrice_pos _).trans_le hf)] - exact (((pr_mono (spins_law p n).nz fun _=> And.right).trans (hw _ hx _ _)).trans - (((mul_comm (scanPrice p) ε).le).trans (mul_le_mul_of_nonneg_left hf he))) - change |_-pr _ Z| ≤_ at hz - linarith only [(abs_le.mp hz).2,hv] - -end DualAnalysis -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.UniqueStatusCoefficients + +namespace OAI + +/-! # Finite Predictions -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Filter Finset LinearMap Module Function +open scoped BigOperators Topology +open Template +namespace StatusAnalysis +namespace DualAnalysis +variable {p:Shape} {r n N K:ℕ} {d:Rates} + +def fromPulse (Y: Silhouette p N r) (f:Pulsar p r) : Augur p N := + fun l q x=> f l q (Y l q x) + +def yokeSet {n:ℕ} (w:Cell n) (α:F) : RhymeSet n := + ⟨1,w,1+α,0⟩ +def compass (i : Bool) (o:UnitType p n N) (s:Charts p n d) + (m:Mixer p n) (w:Cell (d i)) (α:F) := + yoke p m o i (s i w) α + +theorem lyrically (i:Bool) (o:UnitType p n N) + (m:Mixer p n) (s:Charts p n d) (w:Cell (d i)) (α:F) (x: Appearance p) (z:Knobs p.g n) : + (yokeSet w α).soot x (x.profile i o m (s i) z)= + compass i o s m w α (useAtom p x.l x.s x.f z) := by + classical + let A:=useAtom p x.l x.s x.f z + change 1*(innerP p o i) A+dotProduct w (roll (s i) (Tsym m A)) + + (1+(1+α))*role p n A+0*x.q=(innerP p o i) A+(Tsym m (s i w) A+α*role p n A) + rw [one_mul,←add_assoc (1:F),char_two,zero_add,zero_mul,add_zero,dotProduct_comm,← roll_project, + T_swap,add_assoc] + +theorem notary (s:Charts p n d) (Y:Silhouette p N r) (i:Bool) (o:UnitType p n N) + (m:Mixer p n) (w:Cell (d i)) (α:F) (x:Appearance p) (f:Pulsar p r) + {δ:ℝ} (h:x.close Y (onSide o i) δ) (hx:IsLaw (x.wit n)) : + let g:= mismatch p (fromPulse Y f) (compass i o s m w α) x.l x.s x.f (onSide o i) + |shot (wisp p Y) (wake p Y m o s) i x (yokeSet w α) f - pr (x.wit n) g|≤δ := by + classical + intro g + let P k (y:Magazine p (d i)):= ((yokeSet w α).soot x y≠ f x.l x.q k) + let W k y:=ind (P k y) + have hh (k y):|W k y|≤1 := by unfold W; rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ + have he := x.close_expect Y i o m (s i) hx W hh h + let f' := x.profile i o m (s i) + let V z:= W (x.showTag Y (onSide o i) z) (f' z) + have hf : avg (x.wit n) V=pr (x.wit n) g := by + refine avg_congr fun z hz =>?_ + have hx : dialed p x.l x.f z=x.q := (onW_ne hz).1 + have hq : g z ↔ P (x.showTag Y (onSide o i) z) (f' z) := by + unfold g mismatch fromPulse P f' + rw [hx, lyrically] + rfl + exact congrArg ind (propext hq.symm) + change |_ - avg (x.wit n) V|≤_ at he; rw [hf] at he; exact he + +set_option maxHeartbeats 800000 in +theorem praise_predict (s:Charts p n d) (Y:Silhouette p N r) (i:Bool) + (o:UnitType p n N) (m:Mixer p n) (w:Cell (d i)) (α:F) (f:Pulsar p r) {ε δ:ℝ} + (A:Finset (Label p.b)) + (he:0≤ε) (hδ:0≤δ) + (hp : 1≤ p.r) (hn:2*p.r≤n) + (hh:∀ x:Appearance p,x.apt→x.close Y (onSide o i) δ) + (hw:praise (wisp p Y) (wake p Y m o s) i A (yokeSet w α) f ε) : + postulates p (onSide o i) (fromPulse Y f) (compass i o s m w α) A ((ε+δ)*2) := by + classical + intro b hb t g + let μ:=spins p n; let v:=onSide o i; let X (y:F) : Appearance p:= + ⟨t,b,g,y⟩ + let Z:=mismatch p (fromPulse Y f) (compass i o s m w α) t b g v + let Q y (x:Knobs p.g n):=dialed p t g x=y + have hμ := spins_law p n + have hz (y:F) : pr μ (fun x=>Z x∧Q y x)≤ ε+δ := by + let x:=X y + by_cases hg : x.apt + · have hk:= hw x hb hg; have hx:= Appearance.witLaw hg hp hn + have hi:= notary s Y i o m w α x f (hh x hg) hx + change |_ - pr (x.wit n) Z|≤δ at hi + have he : pr (x.wit n) Z ≤ ε+δ := by linarith only [hk, (abs_le.mp hi).1] + rw [show (fun x=> Z x ∧ Q y x)=(fun x=>Q y x ∧ Z x) from funext fun x=>propext and_comm, + pr_of_on hμ.nz] + exact ((mul_le_mul_of_nonneg_right ((pr_le_tot hμ.nz).trans hμ.total.le) + (pr_nonneg hx.nz)).trans_eq (one_mul _)).trans he + have hm z : ¬ Q y z := by + intro h + refine hg ⟨scan p t g z,fun j hj=>?_,h⟩ + unfold scan; rw [ite_eq_right hj] + simp_rw [show ∀ z,(Z z∧Q y z)=False from (fun z=>eq_false (fun h=>hm z h.2)), + pr_false]; exact add_nonneg he hδ + refine (sum_pr_tag μ Z (dialed p t g)).symm.le.trans + ((Finset.sum_le_sum fun i _=>hz i).trans_eq ?_) + simp only [sum_const,card_univ,nsmul_eq_mul,F,ZMod.card]; ring + +set_option maxHeartbeats 800000 in +theorem predict_praise (s:Charts p n d) (Y:Silhouette p N r) (i:Bool) + (o:UnitType p n N) (m:Mixer p n) (w:Cell (d i)) (α:F) (f:Pulsar p r) {ε δ:ℝ} + (A:Finset (Label p.b)) + (he:0≤ε) + (hp:1≤p.r) (hn:2*p.r≤n) + (hh:∀ x:Appearance p,x.apt → x.close Y (onSide o i) δ) + (hw:postulates p (onSide o i) (fromPulse Y f) (compass i o s m w α) A (scanPrice p *ε)) : + praise (wisp p Y) (wake p Y m o s) i A (yokeSet w α) f (ε+δ) := by + intro x hx h + let Z:= mismatch p (fromPulse Y f) (compass i o s m w α) x.l x.s x.f (onSide o i) + have hwit := Appearance.witLaw h hp hn + have hz:= notary s Y i o m w α x f (hh x h) hwit + have hv : pr (x.wit n) Z ≤ε := by + unfold Appearance.wit scopedBit + let w:=spins p n + let Q (i:Knobs p.g n):=dialed p x.l x.f i=x.q + have hf := show scanPrice p ≤ pr w Q from dial_fraction p n _ _ _ hp hn h + rw [pr_on,div_le_iff₀ ((scanPrice_pos _).trans_le hf)] + exact (((pr_mono (spins_law p n).nz fun _=> And.right).trans (hw _ hx _ _)).trans + (((mul_comm (scanPrice p) ε).le).trans (mul_le_mul_of_nonneg_left hf he))) + change |_-pr _ Z| ≤_ at hz + linarith only [(abs_le.mp hz).2,hv] + +end DualAnalysis +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteProjectionCenters.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteProjectionCenters.lean index 870262a86fa5bb5ead371bf689b4048703401a60..2acd52afe56e67e17ce6820506b143d75c4e2830 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteProjectionCenters.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteProjectionCenters.lean @@ -1,94 +1,94 @@ -import OAI.Combinatorics.HadwigerCounterexample.ProjectionNets - -namespace OAI - -/-! # Finite Projection Centers -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Filter Matrix Real Function -open scoped BigOperators -variable {A B C D : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype D] - -theorem var_pour (q : Wgt B) (f : B → C) (hq : IsLaw q) (w v : Wgt C) : - varOne (pour q f w) (pour q f v)≤varOne w v := by - classical - let Q := mapW q f - have hQ := mapW_law hq f - let g i := |w i-v i| / Q i - have he : varOne (pour q f w) (pour q f v)=avg Q g := by - unfold Q - rw [mapW_avg] - unfold varOne avg; refine sum_congr rfl fun i _ => ?_ - simp only [pour,←mul_sub,←sub_div,abs_mul,abs_div, - abs_of_nonneg (hq.nz i),abs_of_nonneg (hQ.nz _)] - rfl - rw [he] - unfold varOne avg; refine sum_le_sum fun i _ => ?_ - by_cases hi : Q i=0 - · rw [hi,zero_mul]; exact abs_nonneg _ - exact le_of_eq (by unfold g; field_simp) - -def roster (P : Wgt A→ Prop) (r : ℕ) (ε : ℝ) := - ∃ (t : ℕ), t ≤ r ∧ ∃ w : Fin t→ Wgt A, ∀ p,P p→ ∃ i,varOne p (w i)≤ ε - -theorem roster_mono (P Q : Wgt A → Prop) (h : ∀ i,P i→Q i) (r ε) - (hw : roster Q r ε) : roster P r ε := by - obtain ⟨t,ht,w,hw⟩ := hw; exact ⟨t,ht,w,fun i hi => hw i (h i hi)⟩ - -private theorem grid_form (k : ℕ) (hk : 0 (i.val:ℝ)/(k:ℝ) - ∀ a : ℝ,0≤a→a≤1→∃ i,|a-G i|≤(k:ℝ)⁻¹ := by - intro G a ha h1 - let i := ⌊a*(k:ℝ)⌋₊ - have hk : 0<(k:ℝ) := by exact_mod_cast hk - have hx : ↑i≤a*k := Nat.floor_le (by positivity) - have hy : i≤k := by - exact_mod_cast (show (i:ℝ)≤k from hx.trans (by nlinarith)) - have hi : a*(k:ℝ)< (i:ℝ) +1 := Nat.lt_floor_add_one _ - refine ⟨⟨i,Nat.lt_succ_of_le hy⟩,?_⟩ - change |a-(i:ℝ)/k|≤_ - rw [abs_of_nonneg (sub_nonneg.mpr ((div_le_iff₀ hk).mpr hx))] - refine sub_le_iff_le_add.mpr ?_ - rw [← one_div,←add_div] - exact (le_div_iff₀ hk).mpr (by linarith only [hi]) - -variable {μ : Wgt A} {p : A→ Wgt B} - -theorem roster_price (r : ℕ) (ε : ℝ) (hε : 0<ε) : - ∃ s : ℕ,∀ (A B : Type) [Fintype A] [Fintype B] [Nonempty B] - (μ : Wgt A) (p : A→ Wgt B), Ultra μ p → - ample μ p r (ε/2) → roster (catalog μ p) s ε := by - classical - obtain ⟨k,hk⟩ := exists_nat_gt (max 0 ((r:ℝ)/(ε/2))) - have h0 := (max_lt_iff.mp hk).1 - have h1 : 0<ε/2 := by positivity - have hk' := (div_lt_iff₀ h1).mp ((max_lt_iff.mp hk).2) - have hv := grid_form k (by exact_mod_cast h0) - refine ⟨(k+1)^r,fun A B _ _ _ μ p hw ⟨t,ht,f,h⟩ => ?_⟩ - let e := Fintype.equivFin (Fin t → Fin (k+1)) - let G (i : Fin (k+1)) := (i.val:ℝ)/(k:ℝ) - let g (i : Fin (Fintype.card (Fin t →Fin (k+1)))) := G∘(e.symm i) - refine ⟨Fintype.card (Fin t → Fin (k+1)),(by simp; exact Nat.pow_le_pow_right (by omega) ht), - fun i => pour unif f (g i),fun w hw' => ?_⟩ - let Q := mapW w f - have he := hw.cat_sub w hw' - choose j hj using fun i : Fin t => - hv (Q i) (map_nz he.nz f i) ((pr_le_tot he.nz).trans he.total) - have he : varOne Q (g (e j)) ≤ ε/2 := by - refine le_trans (Finset.sum_le_sum (g:=fun i : Fin t => (k:ℝ)⁻¹) ?_) ?_ - · intro i _ - simp only [g,Function.comp_apply,Equiv.symm_apply_apply] - exact hj i - simp only [Finset.sum_const, Finset.card_univ,nsmul_eq_mul, Fintype.card_fin, - ←div_eq_mul_inv] - rw [mul_comm (k:ℝ)] at hk' - exact (div_le_iff₀ h0).mpr ((by exact_mod_cast ht : (t:ℝ)≤r).trans hk'.le) - exact ⟨e j,(var_tri _ _ _).trans ((add_le_add (h w hw') ((var_pour _ f unif_law Q - (g (e j))).trans he)).trans_eq (by ring))⟩ - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ProjectionNets + +namespace OAI + +/-! # Finite Projection Centers -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Filter Matrix Real Function +open scoped BigOperators +variable {A B C D : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype D] + +theorem var_pour (q : Wgt B) (f : B → C) (hq : IsLaw q) (w v : Wgt C) : + varOne (pour q f w) (pour q f v)≤varOne w v := by + classical + let Q := mapW q f + have hQ := mapW_law hq f + let g i := |w i-v i| / Q i + have he : varOne (pour q f w) (pour q f v)=avg Q g := by + unfold Q + rw [mapW_avg] + unfold varOne avg; refine sum_congr rfl fun i _ => ?_ + simp only [pour,←mul_sub,←sub_div,abs_mul,abs_div, + abs_of_nonneg (hq.nz i),abs_of_nonneg (hQ.nz _)] + rfl + rw [he] + unfold varOne avg; refine sum_le_sum fun i _ => ?_ + by_cases hi : Q i=0 + · rw [hi,zero_mul]; exact abs_nonneg _ + exact le_of_eq (by unfold g; field_simp) + +def roster (P : Wgt A→ Prop) (r : ℕ) (ε : ℝ) := + ∃ (t : ℕ), t ≤ r ∧ ∃ w : Fin t→ Wgt A, ∀ p,P p→ ∃ i,varOne p (w i)≤ ε + +theorem roster_mono (P Q : Wgt A → Prop) (h : ∀ i,P i→Q i) (r ε) + (hw : roster Q r ε) : roster P r ε := by + obtain ⟨t,ht,w,hw⟩ := hw; exact ⟨t,ht,w,fun i hi => hw i (h i hi)⟩ + +private theorem grid_form (k : ℕ) (hk : 0 (i.val:ℝ)/(k:ℝ) + ∀ a : ℝ,0≤a→a≤1→∃ i,|a-G i|≤(k:ℝ)⁻¹ := by + intro G a ha h1 + let i := ⌊a*(k:ℝ)⌋₊ + have hk : 0<(k:ℝ) := by exact_mod_cast hk + have hx : ↑i≤a*k := Nat.floor_le (by positivity) + have hy : i≤k := by + exact_mod_cast (show (i:ℝ)≤k from hx.trans (by nlinarith)) + have hi : a*(k:ℝ)< (i:ℝ) +1 := Nat.lt_floor_add_one _ + refine ⟨⟨i,Nat.lt_succ_of_le hy⟩,?_⟩ + change |a-(i:ℝ)/k|≤_ + rw [abs_of_nonneg (sub_nonneg.mpr ((div_le_iff₀ hk).mpr hx))] + refine sub_le_iff_le_add.mpr ?_ + rw [← one_div,←add_div] + exact (le_div_iff₀ hk).mpr (by linarith only [hi]) + +variable {μ : Wgt A} {p : A→ Wgt B} + +theorem roster_price (r : ℕ) (ε : ℝ) (hε : 0<ε) : + ∃ s : ℕ,∀ (A B : Type) [Fintype A] [Fintype B] [Nonempty B] + (μ : Wgt A) (p : A→ Wgt B), Ultra μ p → + ample μ p r (ε/2) → roster (catalog μ p) s ε := by + classical + obtain ⟨k,hk⟩ := exists_nat_gt (max 0 ((r:ℝ)/(ε/2))) + have h0 := (max_lt_iff.mp hk).1 + have h1 : 0<ε/2 := by positivity + have hk' := (div_lt_iff₀ h1).mp ((max_lt_iff.mp hk).2) + have hv := grid_form k (by exact_mod_cast h0) + refine ⟨(k+1)^r,fun A B _ _ _ μ p hw ⟨t,ht,f,h⟩ => ?_⟩ + let e := Fintype.equivFin (Fin t → Fin (k+1)) + let G (i : Fin (k+1)) := (i.val:ℝ)/(k:ℝ) + let g (i : Fin (Fintype.card (Fin t →Fin (k+1)))) := G∘(e.symm i) + refine ⟨Fintype.card (Fin t → Fin (k+1)),(by simp; exact Nat.pow_le_pow_right (by omega) ht), + fun i => pour unif f (g i),fun w hw' => ?_⟩ + let Q := mapW w f + have he := hw.cat_sub w hw' + choose j hj using fun i : Fin t => + hv (Q i) (map_nz he.nz f i) ((pr_le_tot he.nz).trans he.total) + have he : varOne Q (g (e j)) ≤ ε/2 := by + refine le_trans (Finset.sum_le_sum (g:=fun i : Fin t => (k:ℝ)⁻¹) ?_) ?_ + · intro i _ + simp only [g,Function.comp_apply,Equiv.symm_apply_apply] + exact hj i + simp only [Finset.sum_const, Finset.card_univ,nsmul_eq_mul, Fintype.card_fin, + ←div_eq_mul_inv] + rw [mul_comm (k:ℝ)] at hk' + exact (div_le_iff₀ h0).mpr ((by exact_mod_cast ht : (t:ℝ)≤r).trans hk'.le) + exact ⟨e j,(var_tri _ _ _).trans ((add_le_add (h w hw') ((var_pour _ f unif_law Q + (g (e j))).trans he)).trans_eq (by ring))⟩ + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteTableEnumeration.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteTableEnumeration.lean index 35cd0ec34281cbb833f123c61d4f7d788925c8fc..4fe32e709e391d52eb501471ba94d93f87833966 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteTableEnumeration.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FiniteTableEnumeration.lean @@ -1,85 +1,85 @@ -import OAI.Combinatorics.HadwigerCounterexample.NumericalGradientTests - -namespace OAI - -/-! # Finite Table Enumeration -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Finset LinearMap Submodule Module Function -open scoped BigOperators -variable {p : Shape} {n N : ℕ} -namespace StatusAnalysis -abbrev CouponDeck (p : Shape) {n} (a b : Plan p n) := - ∀ i : Place p,Mat (Fin (dim (tabSpace a i))) (Fin (dim (tabSpace b (flipZ p i)))) -def nomen (p : Shape) {n} (a b : Plan p n) (v : Cross p n) : CouponDeck p a b := - fun i=>pullM (pack (tabSpace a i)) (pack (tabSpace b (flipZ p i))) (v i) - -theorem nomen_fits (p : Shape) (n : ℕ) (a b : Plan p n) (x y : Cross p n) - (h : nomen p a b x=nomen p a b y) : - fitsTable a b x y := by - intro i j hj k hk - obtain ⟨u,rfl⟩: ∃ v, pack (tabSpace a i)*ᵥv=j := by - exact (pack_mem_iff ..).mp hj - obtain ⟨v,rfl⟩: ∃ v, pack (tabSpace b (flipZ p i))*ᵥv=k := (pack_mem_iff ..).mp hk - simp_rw [← evmat_pull]; exact congrArg (fun t=>evmat t u v) (congr_fun h i) - -instance deckFin (p : Shape) (n : ℕ) (a b : Plan p n) : Fintype (CouponDeck p a b) := by - classical - infer_instance - -def deckMax (p : Shape) (K : ℕ) := - Fintype.card (Place p)*(2*(K+p.h))^2 - -theorem deck_cap (p : Shape) (n : ℕ) (K : ℕ) - (a b : Plan p n) (h : planRank a ≤ K) (hg :planRank b ≤ K) : - Fintype.card (CouponDeck p a b) ≤ 2^ deckMax p K := by - classical - have ht : - dim (CouponDeck p a b)=∑ i:Place p,dim (tabSpace a i)*dim (tabSpace b (flipZ p i)) := by - unfold CouponDeck dim; rw [Module.finrank_pi_fintype] - refine Finset.sum_congr rfl fun i _=>?_ - rw [show Module.finrank F _ = _ from dim_mat (Fin (dim (tabSpace a i))) - (Fin (dim (tabSpace b (flipZ p i)))),Fintype.card_fin,Fintype.card_fin] - have he (i) : dim (tabSpace a i)*dim (tabSpace b (flipZ p i)) ≤ (2*(K+p.h))^2 := by - rw [pow_two]; exact Nat.mul_le_mul ((table_dim ..).trans (by omega)) ((table_dim ..).trans - (by omega)) - have hi : dim (CouponDeck p a b) ≤ deckMax p K := ht ▸ - (Finset.sum_le_sum (fun i _=>he i)).trans_eq (by rw [Finset.sum_const]; exact - (by simp [deckMax])) - have hh := card_space (CouponDeck p a b) - have hx : (↑(Fintype.card (CouponDeck p a b)) : ℝ)≤2^deckMax p K := hh.le.trans - ((bp_le (by exact_mod_cast hi : (dim (CouponDeck p a b):ℝ) ≤ deckMax p K)).trans_eq (bp_nat _)) - exact_mod_cast hx - -theorem deck_cast (p : Shape) (n : ℕ) (K : ℕ) - (a b : Plan p n) (h : planRank a ≤ K) (hg :planRank b ≤ K) : - ∃ M : Fin (2^deckMax p K)→Cross p n,∀ v,∃ i,fitsTable a b (M i) v := by - classical - let A := CouponDeck p a b - let f := nomen p a b - choose w he using fun x : A => - show ∃ y:Cross p n,∀ z,f z=x → f y=x from (by - by_cases h : ∃ z,f z=x - · obtain ⟨z,hz⟩:=h; exact ⟨z,fun _ _=>hz⟩ - exact ⟨0,fun i hi=>(h ⟨i,hi⟩).elim⟩) - let t := Fintype.card A - let e := Fintype.equivFin A - let g (x : Fin (2^deckMax p K)) := if h : x.val?_⟩ - let i:=e (f v); let z:Fin (2^deckMax p K):= Fin.castLE hk i - refine ⟨z,nomen_fits p n _ _ _ _ ?_⟩ - change f (g z)=f v - unfold g; rw [dite_eq_left (show z.val (hf i j hj k (pin_le_table b.sp _ hk)).trans (h i j hj k hk) -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.NumericalGradientTests + +namespace OAI + +/-! # Finite Table Enumeration -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Finset LinearMap Submodule Module Function +open scoped BigOperators +variable {p : Shape} {n N : ℕ} +namespace StatusAnalysis +abbrev CouponDeck (p : Shape) {n} (a b : Plan p n) := + ∀ i : Place p,Mat (Fin (dim (tabSpace a i))) (Fin (dim (tabSpace b (flipZ p i)))) +def nomen (p : Shape) {n} (a b : Plan p n) (v : Cross p n) : CouponDeck p a b := + fun i=>pullM (pack (tabSpace a i)) (pack (tabSpace b (flipZ p i))) (v i) + +theorem nomen_fits (p : Shape) (n : ℕ) (a b : Plan p n) (x y : Cross p n) + (h : nomen p a b x=nomen p a b y) : + fitsTable a b x y := by + intro i j hj k hk + obtain ⟨u,rfl⟩: ∃ v, pack (tabSpace a i)*ᵥv=j := by + exact (pack_mem_iff ..).mp hj + obtain ⟨v,rfl⟩: ∃ v, pack (tabSpace b (flipZ p i))*ᵥv=k := (pack_mem_iff ..).mp hk + simp_rw [← evmat_pull]; exact congrArg (fun t=>evmat t u v) (congr_fun h i) + +instance deckFin (p : Shape) (n : ℕ) (a b : Plan p n) : Fintype (CouponDeck p a b) := by + classical + infer_instance + +def deckMax (p : Shape) (K : ℕ) := + Fintype.card (Place p)*(2*(K+p.h))^2 + +theorem deck_cap (p : Shape) (n : ℕ) (K : ℕ) + (a b : Plan p n) (h : planRank a ≤ K) (hg :planRank b ≤ K) : + Fintype.card (CouponDeck p a b) ≤ 2^ deckMax p K := by + classical + have ht : + dim (CouponDeck p a b)=∑ i:Place p,dim (tabSpace a i)*dim (tabSpace b (flipZ p i)) := by + unfold CouponDeck dim; rw [Module.finrank_pi_fintype] + refine Finset.sum_congr rfl fun i _=>?_ + rw [show Module.finrank F _ = _ from dim_mat (Fin (dim (tabSpace a i))) + (Fin (dim (tabSpace b (flipZ p i)))),Fintype.card_fin,Fintype.card_fin] + have he (i) : dim (tabSpace a i)*dim (tabSpace b (flipZ p i)) ≤ (2*(K+p.h))^2 := by + rw [pow_two]; exact Nat.mul_le_mul ((table_dim ..).trans (by omega)) ((table_dim ..).trans + (by omega)) + have hi : dim (CouponDeck p a b) ≤ deckMax p K := ht ▸ + (Finset.sum_le_sum (fun i _=>he i)).trans_eq (by rw [Finset.sum_const]; exact + (by simp [deckMax])) + have hh := card_space (CouponDeck p a b) + have hx : (↑(Fintype.card (CouponDeck p a b)) : ℝ)≤2^deckMax p K := hh.le.trans + ((bp_le (by exact_mod_cast hi : (dim (CouponDeck p a b):ℝ) ≤ deckMax p K)).trans_eq (bp_nat _)) + exact_mod_cast hx + +theorem deck_cast (p : Shape) (n : ℕ) (K : ℕ) + (a b : Plan p n) (h : planRank a ≤ K) (hg :planRank b ≤ K) : + ∃ M : Fin (2^deckMax p K)→Cross p n,∀ v,∃ i,fitsTable a b (M i) v := by + classical + let A := CouponDeck p a b + let f := nomen p a b + choose w he using fun x : A => + show ∃ y:Cross p n,∀ z,f z=x → f y=x from (by + by_cases h : ∃ z,f z=x + · obtain ⟨z,hz⟩:=h; exact ⟨z,fun _ _=>hz⟩ + exact ⟨0,fun i hi=>(h ⟨i,hi⟩).elim⟩) + let t := Fintype.card A + let e := Fintype.equivFin A + let g (x : Fin (2^deckMax p K)) := if h : x.val?_⟩ + let i:=e (f v); let z:Fin (2^deckMax p K):= Fin.castLE hk i + refine ⟨z,nomen_fits p n _ _ _ _ ?_⟩ + change f (g z)=f v + unfold g; rw [dite_eq_left (show z.val (hf i j hj k (pin_le_table b.sp _ hk)).trans (h i j hj k hk) +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FixedPositionTests.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FixedPositionTests.lean index 83056514d545051130499799a84df966cefe640f..fff64cc25be3ddf0c96f337a6018f301cd779ce3 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FixedPositionTests.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FixedPositionTests.lean @@ -1,105 +1,105 @@ -import OAI.Combinatorics.HadwigerCounterexample.UnaryCellComparisons -import OAI.Combinatorics.HadwigerCounterexample.KeyTestCorrespondence - -namespace OAI - -/-! # Fixed Position Tests -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Function LinearMap -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] - -namespace Template -variable (v : Template p I) - -def bolts (v : Template p I) {i j : I} - (x : AtomKey (p:=p) (v.t i) N) (y : AtomKey (p:=p) (v.t j) N) := - ∀ e (h : inc e (v.t i)) (h' : inc e (v.t j)), - dotProduct (x ⟨e,h⟩ true) (y ⟨e,h'⟩ false)=0 ∧ - dotProduct (y ⟨e,h'⟩ true) (x ⟨e,h⟩ false)=0 -def boundTail (_ : Template p I) (j : I) - (q : I→F) := fun i : Aside j => q i.val -def scriptTail (s : Script p I) (j : I) : Script p (Aside j) := - fun i k=> s i.val k.val - -omit [Fintype I] in -theorem bolts_split (v : Template p I) (j : I) (q : I→F) - (x : Keys (p:=p) v.t N) : - ownPart (p:=p) v.t q x ↔ - ownOne p (v.t j) (q j) (x j) ∧ (∀ i:Aside j,v.bolts (x j) (x i.val)) ∧ - ownPart (p:=p) (v.beyond j).t (v.boundTail j q) ((v.chairK j N x).2) := by - classical - rw [ownPart_def,ownPart_def] - let f (i k : I) := ∀ (e : Comp p.g) (h : inc e (v.t i)) (h' : inc e (v.t k)), - i≠k→dotProduct (x i ⟨e,h⟩ true) (x k ⟨e,h'⟩ false)=0 - let r := v.beyond j - constructor - · rintro ⟨h1,h2⟩ - refine ⟨h1 j,fun k e a b=> ⟨h2 j k.val e a b (Ne.symm k.property), - h2 k.val j e b a k.property⟩,fun i=> h1 i.val,?_⟩ - intro i k e a b hh; exact h2 _ _ e a b (fun ht=>hh (Subtype.ext ht)) - rintro ⟨h1,h2,h,h'⟩ - constructor - · intro i - by_cases hh:i=j - · subst i; exact h1 - exact h ⟨i,hh⟩ - intro i k e a b hi - by_cases he : i=j - · subst i; exact (h2 ⟨k,Ne.symm hi⟩ e a b).1 - by_cases hh : k=j - · subst k; exact (h2 ⟨i,hi⟩ e b a).2 - exact h' (⟨i,he⟩) (⟨k,hh⟩) e a b (fun h=>hi (congrArg Subtype.val h)) - -def huts (v : Template p I) (m : Mixer p n) (s : Script p I) (i k:I) - (x y : Knobs p.g n) := - v.aim i=v.aim k → ∀ j:MOne p, - s i k j=evmat (orderedM m j) (v.croon i x) (v.croon k y) ∧ - s k i j=evmat (orderedM m j) (v.croon k y) (v.croon i x) - -omit [Fintype I] in -theorem read_split (v : Template p I) (j:I) (m : Mixer p n) (s : Script p I) - (z : Inputs p n I) : - (v.draw z).reads s m ↔ - (∀ i:Aside j,v.huts m s j i.val (z j) (z i.val)) ∧ - ((v.beyond j).draw (fun i => z i.val)).reads (scriptTail s j) m := by - constructor - · intro h - constructor - · exact fun i hA v=> ⟨h j i.val (Ne.symm i.property) hA v,h i.val j i.property - (Eq.symm hA) v⟩ - intro x y he ha i; exact h x.val y.val (fun ht=>he (Subtype.ext ht)) ha i - rintro ⟨h1,h2⟩ i k he ha d - by_cases hh:i=j - · subst i; exact (h1 ⟨k,Ne.symm he⟩ ha d).1 - by_cases hz:k=j - · subst k; exact (h1 ⟨i,hh⟩ (Eq.symm ha) d).2 - exact h2 (⟨i,hh⟩) (⟨k,hz⟩) (fun h=>he (congrArg Subtype.val h)) ha d - -def nib (v : Template p I) (o : UnitType p n N) (i : I) (z : Knobs p.g n) := - v.callOne i z (onSide o (v.aim i)) - -def lintel (v : Template p I) (j : I) (m : Mixer p n) (s : Script p I) - (o : UnitType p n N) (x : Knobs p.g n) (i : Aside j) (z : Knobs p.g n) := - v.bolts (nib v o j x) (nib v o i.val z) ∧ v.huts m s j i.val x z - -omit [Fintype I] in -theorem earns_split (v : Template p I) (j : I) (q : I→F) (m : Mixer p n) (s : Script p I) - (o : UnitType p n N) (z : Inputs p n I) : - earns v s m q o z↔ ownOne p (v.t j) (q j) (nib v o j (z j)) ∧ - (∀ i:Aside j,v.lintel j m s o (z j) i (z i.val)) ∧ - earns (v.beyond j) (scriptTail s j) m (v.boundTail j q) o - (fun i:Aside j => z i.val) := by - unfold earns lintel - rw [read_split v j,bolts_split v j, key_split] - have he (i : I) : resultKey v o z i=nib v o i (z i) := rfl - simp_rw [he,forall_and] - tauto -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.UnaryCellComparisons +import OAI.Combinatorics.HadwigerCounterexample.KeyTestCorrespondence + +namespace OAI + +/-! # Fixed Position Tests -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Function LinearMap +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] + +namespace Template +variable (v : Template p I) + +def bolts (v : Template p I) {i j : I} + (x : AtomKey (p:=p) (v.t i) N) (y : AtomKey (p:=p) (v.t j) N) := + ∀ e (h : inc e (v.t i)) (h' : inc e (v.t j)), + dotProduct (x ⟨e,h⟩ true) (y ⟨e,h'⟩ false)=0 ∧ + dotProduct (y ⟨e,h'⟩ true) (x ⟨e,h⟩ false)=0 +def boundTail (_ : Template p I) (j : I) + (q : I→F) := fun i : Aside j => q i.val +def scriptTail (s : Script p I) (j : I) : Script p (Aside j) := + fun i k=> s i.val k.val + +omit [Fintype I] in +theorem bolts_split (v : Template p I) (j : I) (q : I→F) + (x : Keys (p:=p) v.t N) : + ownPart (p:=p) v.t q x ↔ + ownOne p (v.t j) (q j) (x j) ∧ (∀ i:Aside j,v.bolts (x j) (x i.val)) ∧ + ownPart (p:=p) (v.beyond j).t (v.boundTail j q) ((v.chairK j N x).2) := by + classical + rw [ownPart_def,ownPart_def] + let f (i k : I) := ∀ (e : Comp p.g) (h : inc e (v.t i)) (h' : inc e (v.t k)), + i≠k→dotProduct (x i ⟨e,h⟩ true) (x k ⟨e,h'⟩ false)=0 + let r := v.beyond j + constructor + · rintro ⟨h1,h2⟩ + refine ⟨h1 j,fun k e a b=> ⟨h2 j k.val e a b (Ne.symm k.property), + h2 k.val j e b a k.property⟩,fun i=> h1 i.val,?_⟩ + intro i k e a b hh; exact h2 _ _ e a b (fun ht=>hh (Subtype.ext ht)) + rintro ⟨h1,h2,h,h'⟩ + constructor + · intro i + by_cases hh:i=j + · subst i; exact h1 + exact h ⟨i,hh⟩ + intro i k e a b hi + by_cases he : i=j + · subst i; exact (h2 ⟨k,Ne.symm hi⟩ e a b).1 + by_cases hh : k=j + · subst k; exact (h2 ⟨i,hi⟩ e b a).2 + exact h' (⟨i,he⟩) (⟨k,hh⟩) e a b (fun h=>hi (congrArg Subtype.val h)) + +def huts (v : Template p I) (m : Mixer p n) (s : Script p I) (i k:I) + (x y : Knobs p.g n) := + v.aim i=v.aim k → ∀ j:MOne p, + s i k j=evmat (orderedM m j) (v.croon i x) (v.croon k y) ∧ + s k i j=evmat (orderedM m j) (v.croon k y) (v.croon i x) + +omit [Fintype I] in +theorem read_split (v : Template p I) (j:I) (m : Mixer p n) (s : Script p I) + (z : Inputs p n I) : + (v.draw z).reads s m ↔ + (∀ i:Aside j,v.huts m s j i.val (z j) (z i.val)) ∧ + ((v.beyond j).draw (fun i => z i.val)).reads (scriptTail s j) m := by + constructor + · intro h + constructor + · exact fun i hA v=> ⟨h j i.val (Ne.symm i.property) hA v,h i.val j i.property + (Eq.symm hA) v⟩ + intro x y he ha i; exact h x.val y.val (fun ht=>he (Subtype.ext ht)) ha i + rintro ⟨h1,h2⟩ i k he ha d + by_cases hh:i=j + · subst i; exact (h1 ⟨k,Ne.symm he⟩ ha d).1 + by_cases hz:k=j + · subst k; exact (h1 ⟨i,hh⟩ (Eq.symm ha) d).2 + exact h2 (⟨i,hh⟩) (⟨k,hz⟩) (fun h=>he (congrArg Subtype.val h)) ha d + +def nib (v : Template p I) (o : UnitType p n N) (i : I) (z : Knobs p.g n) := + v.callOne i z (onSide o (v.aim i)) + +def lintel (v : Template p I) (j : I) (m : Mixer p n) (s : Script p I) + (o : UnitType p n N) (x : Knobs p.g n) (i : Aside j) (z : Knobs p.g n) := + v.bolts (nib v o j x) (nib v o i.val z) ∧ v.huts m s j i.val x z + +omit [Fintype I] in +theorem earns_split (v : Template p I) (j : I) (q : I→F) (m : Mixer p n) (s : Script p I) + (o : UnitType p n N) (z : Inputs p n I) : + earns v s m q o z↔ ownOne p (v.t j) (q j) (nib v o j (z j)) ∧ + (∀ i:Aside j,v.lintel j m s o (z j) i (z i.val)) ∧ + earns (v.beyond j) (scriptTail s j) m (v.boundTail j q) o + (fun i:Aside j => z i.val) := by + unfold earns lintel + rw [read_split v j,bolts_split v j, key_split] + have he (i : I) : resultKey v o z i=nib v o i (z i) := rfl + simp_rw [he,forall_and] + tauto +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FlatLevelShifts.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FlatLevelShifts.lean index 0e83eb49703f8be349ae92decc1b91616a8fc94c..1cf1571b34ec57a75fb21a981793a4984c09218b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FlatLevelShifts.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FlatLevelShifts.lean @@ -1,88 +1,88 @@ -import OAI.Combinatorics.HadwigerCounterexample.MatrixFactorization - -namespace OAI - -/-! # Flat Level Shifts -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix - -variable {I J Q : Type} [Fintype I] [Fintype J] [Fintype Q] - -/-- Shift a P row to an X t row. If the Gram comparisons obey Boolean -monomial identities, there are coordinate factors of H for which both the -left and the right row arrays diagonalize all these shifts. -/ -theorem shift_factors [DecidableEq J] (P : Mat I J) (H : Mat J J) - (hP : Function.Injective P.mulVec) (hH : Function.Injective H.mulVec) - (X : Q → Mat I J) - (h1 : ∀ a, X a * H * Pᵀ = P * H * (X a)ᵀ) - (h2 : ∀ a b, X a * H * (X b)ᵀ = X b * H * (X a)ᵀ) - (h3 : ∀ a, X a * H * (X a)ᵀ = X a * H * Pᵀ) : - ∃ (K C : Mat J J) (f : Q → J → F), H = K * Cᵀ ∧ - ∀ a, X a * C = P * C * diagonal (f a) ∧ X a * K = P * K * diagonal (f a) := by - classical - obtain ⟨R,hR⟩ := mat_left_inv hP - obtain ⟨L,hL⟩ := mat_left_inv hH - have hh : H*L=1 := mul_eq_one_comm.mp hL - have hr : Pᵀ*Rᵀ=1 := by rw [← Matrix.transpose_mul,hR,Matrix.transpose_one] - have hp_cancel {A B : Mat J J} (h : P*A*Pᵀ=P*B*Pᵀ) : A=B := by - have hx := matrix_cancel_left hP (A*Pᵀ) (B*Pᵀ) - (by simpa only [Matrix.mul_assoc] using h) - have hx := congrArg (fun A => A*Rᵀ) hx - simpa only [Matrix.mul_assoc,hr,Matrix.mul_one] using hx - have hr_cancel {W : Type} [Fintype W] (A B : Mat W J) - (h : A*H=B*H) : A=B := by - have he := congrArg (fun t : Mat W J => t*L) h - simpa only [Matrix.mul_assoc,hh,Matrix.mul_one] using he - let M := fun a => R*X a - have he (a : Q) : X a = P*M a := by - apply hr_cancel - calc X a * H = X a * H * (Pᵀ*Rᵀ) := by rw [hr,Matrix.mul_one] - _ = P * (H * ((X a)ᵀ * Rᵀ)) := by - rw [← Matrix.mul_assoc, h1] - simp only [Matrix.mul_assoc] - _ = P * (R * (P * H * (X a)ᵀ) * Rᵀ) := by - simp only [← Matrix.mul_assoc,hR,Matrix.mul_one] - _ = P * M a * H := by - rw [← h1] - simp only [M,Matrix.mul_assoc,hr,Matrix.mul_one] - have es a : M a*H=H*(M a)ᵀ := by - apply hp_cancel - have hh := h1 a - rw [he] at hh - simpa only [transpose_mul,Matrix.mul_assoc] using hh - have ei (a b) : - P*(M a*(M b*H))*Pᵀ=X a*H*(X b)ᵀ := by - simp only [he,es b,transpose_mul,Matrix.mul_assoc] - have hc (a b) : M a * M b=M b*M a := by - apply hr_cancel - apply hp_cancel - rw [Matrix.mul_assoc (M a), ei, h2, Matrix.mul_assoc (M b),ei] - have hi a : M a * M a=M a := by - apply hr_cancel - apply hp_cancel - rw [Matrix.mul_assoc (M a), ei, h3, he] - simp only [Matrix.mul_assoc] - obtain ⟨C,D,hD,hc1,hc2,hc3⟩ := diagonalize M hc hi - let K := H * Dᵀ - refine ⟨K,C,hD,?_,fun a => ?_⟩ - · unfold K - rw [Matrix.mul_assoc,←transpose_mul,hc2,transpose_one,Matrix.mul_one] - have hv : D*M a=diagonal (hD a)*D := by - calc D*M a = D*(M a*C)*D := by simp only [Matrix.mul_assoc,hc2,Matrix.mul_one] - _ = diagonal (hD a)*D := by rw [hc3,←Matrix.mul_assoc,hc1,Matrix.one_mul] - have hk : M a*K=K*diagonal (hD a) := by - unfold K - rw [←Matrix.mul_assoc,es a, Matrix.mul_assoc, ← transpose_mul,hv,transpose_mul, - diagonal_transpose,Matrix.mul_assoc] - rw [he] - constructor - · simp only [Matrix.mul_assoc,hc3] - · simp only [Matrix.mul_assoc,hk] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.MatrixFactorization + +namespace OAI + +/-! # Flat Level Shifts -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix + +variable {I J Q : Type} [Fintype I] [Fintype J] [Fintype Q] + +/-- Shift a P row to an X t row. If the Gram comparisons obey Boolean +monomial identities, there are coordinate factors of H for which both the +left and the right row arrays diagonalize all these shifts. -/ +theorem shift_factors [DecidableEq J] (P : Mat I J) (H : Mat J J) + (hP : Function.Injective P.mulVec) (hH : Function.Injective H.mulVec) + (X : Q → Mat I J) + (h1 : ∀ a, X a * H * Pᵀ = P * H * (X a)ᵀ) + (h2 : ∀ a b, X a * H * (X b)ᵀ = X b * H * (X a)ᵀ) + (h3 : ∀ a, X a * H * (X a)ᵀ = X a * H * Pᵀ) : + ∃ (K C : Mat J J) (f : Q → J → F), H = K * Cᵀ ∧ + ∀ a, X a * C = P * C * diagonal (f a) ∧ X a * K = P * K * diagonal (f a) := by + classical + obtain ⟨R,hR⟩ := mat_left_inv hP + obtain ⟨L,hL⟩ := mat_left_inv hH + have hh : H*L=1 := mul_eq_one_comm.mp hL + have hr : Pᵀ*Rᵀ=1 := by rw [← Matrix.transpose_mul,hR,Matrix.transpose_one] + have hp_cancel {A B : Mat J J} (h : P*A*Pᵀ=P*B*Pᵀ) : A=B := by + have hx := matrix_cancel_left hP (A*Pᵀ) (B*Pᵀ) + (by simpa only [Matrix.mul_assoc] using h) + have hx := congrArg (fun A => A*Rᵀ) hx + simpa only [Matrix.mul_assoc,hr,Matrix.mul_one] using hx + have hr_cancel {W : Type} [Fintype W] (A B : Mat W J) + (h : A*H=B*H) : A=B := by + have he := congrArg (fun t : Mat W J => t*L) h + simpa only [Matrix.mul_assoc,hh,Matrix.mul_one] using he + let M := fun a => R*X a + have he (a : Q) : X a = P*M a := by + apply hr_cancel + calc X a * H = X a * H * (Pᵀ*Rᵀ) := by rw [hr,Matrix.mul_one] + _ = P * (H * ((X a)ᵀ * Rᵀ)) := by + rw [← Matrix.mul_assoc, h1] + simp only [Matrix.mul_assoc] + _ = P * (R * (P * H * (X a)ᵀ) * Rᵀ) := by + simp only [← Matrix.mul_assoc,hR,Matrix.mul_one] + _ = P * M a * H := by + rw [← h1] + simp only [M,Matrix.mul_assoc,hr,Matrix.mul_one] + have es a : M a*H=H*(M a)ᵀ := by + apply hp_cancel + have hh := h1 a + rw [he] at hh + simpa only [transpose_mul,Matrix.mul_assoc] using hh + have ei (a b) : + P*(M a*(M b*H))*Pᵀ=X a*H*(X b)ᵀ := by + simp only [he,es b,transpose_mul,Matrix.mul_assoc] + have hc (a b) : M a * M b=M b*M a := by + apply hr_cancel + apply hp_cancel + rw [Matrix.mul_assoc (M a), ei, h2, Matrix.mul_assoc (M b),ei] + have hi a : M a * M a=M a := by + apply hr_cancel + apply hp_cancel + rw [Matrix.mul_assoc (M a), ei, h3, he] + simp only [Matrix.mul_assoc] + obtain ⟨C,D,hD,hc1,hc2,hc3⟩ := diagonalize M hc hi + let K := H * Dᵀ + refine ⟨K,C,hD,?_,fun a => ?_⟩ + · unfold K + rw [Matrix.mul_assoc,←transpose_mul,hc2,transpose_one,Matrix.mul_one] + have hv : D*M a=diagonal (hD a)*D := by + calc D*M a = D*(M a*C)*D := by simp only [Matrix.mul_assoc,hc2,Matrix.mul_one] + _ = diagonal (hD a)*D := by rw [hc3,←Matrix.mul_assoc,hc1,Matrix.one_mul] + have hk : M a*K=K*diagonal (hD a) := by + unfold K + rw [←Matrix.mul_assoc,es a, Matrix.mul_assoc, ← transpose_mul,hv,transpose_mul, + diagonal_transpose,Matrix.mul_assoc] + rw [he] + constructor + · simp only [Matrix.mul_assoc,hc3] + · simp only [Matrix.mul_assoc,hk] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FlatRankLevels.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FlatRankLevels.lean index 74cf36298a22f4288e28b2a6d6d3e6004df9549a..6a706bebbdf36584a984fd05bc4e7bce6fb97f34 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FlatRankLevels.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FlatRankLevels.lean @@ -1,144 +1,144 @@ -import OAI.Combinatorics.HadwigerCounterexample.BooleanLabels -import OAI.Combinatorics.HadwigerCounterexample.FlatLevelShifts - -namespace OAI - -/-! # Flat Rank Levels -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix -open scoped BigOperators -variable {p : Shape} {n k : ℕ} - -abbrev Layer (p : Shape) (n k : ℕ) := SelIdx p.b k × AIdx p.g n - -def rise (p : Shape) {n k m} (h : k≤m) (i : Layer p n k) : Layer p n m := - (⟨i.1.val,i.1.property.trans h⟩,i.2) - -def bump (p : Shape) {n k} (a : Fin p.b) (i : Layer p n k) : Layer p n (k+1) := - (⟨insert a i.1.val,(Finset.card_insert_le ..).trans (Nat.add_le_add_right i.1.property 1)⟩,i.2) - -def atLayer (M : Moment p n) {k : ℕ} (h : k≤p.j) := M.submatrix (rise p h) (rise p h) - -theorem rank_atLayer_le (M : Moment p n) {k : ℕ} (h : k≤p.j) : - (atLayer M h).rank ≤ M.rank := M.rank_submatrix_le _ _ - -private theorem atLayer_mono (M : Moment p n) {k l} (h : k≤l) (hh : l≤p.j) : - (atLayer M (h.trans hh)).rank ≤ (atLayer M hh).rank := by - let f := (rise p (n:=n) h) - have he := (atLayer M hh).rank_submatrix_le f f - exact he - -theorem flat_atLayer (M : Moment p n) {R : ℕ} (hR : M.rank ≤ R) - (hj : 6*R+4 ≤ p.j) : - ∃ (k : ℕ) (h : k+1≤p.j), 4*R+2≤k ∧ - (atLayer M ((Nat.le_succ k).trans h)).rank = (atLayer M h).rank := by - classical - by_contra hn - let a := 4*R+2 - have hi (i : ℕ) (h : a+i ≤ p.j) : - i ≤ (atLayer M h).rank := by - induction i with - | zero => exact Nat.zero_le _ - | succ i ih => - have he : a+i ≤ p.j := (Nat.le_succ _).trans h - have hh : (atLayer M he).rank < (atLayer M h).rank := by - refine lt_of_le_of_ne (atLayer_mono M (Nat.le_succ _) h) (fun hx => hn ?_) - exact ⟨a+i,h,by unfold a; omega,hx⟩ - exact (Nat.succ_le_succ (ih he)).trans hh - have he : a+(R+1)≤p.j := by unfold a; omega - have hx := ((hi (R+1) he).trans (rank_atLayer_le M he)).trans hR - omega - -theorem flat_entries {M : Moment p n} (hs : Mᵀ=M) (hh : hankel M) - (hk : k+1≤p.j) (hr : - (atLayer M ((Nat.le_succ _).trans hk)).rank = (atLayer M hk).rank) : - let t := (atLayer M hk).rank - ∃ (s : Fin t → Label p.b) (u v : Fin t → Vec (AIdx p.g n)), - ∀ i j : Layer p n k, - atLayer M ((Nat.le_succ _).trans hk) i j = ∑ x : Fin t, - monoBit (s x) i.1.val * monoBit (s x) j.1.val * (u x i.2 * v x j.2) := by - classical - intro t - let h := (Nat.le_succ k).trans hk - let A := atLayer M hk - let r := rise p (n:=n) (Nat.le_succ k) - obtain ⟨Q,H,hQ,_,hH,hA⟩ := rank_symmetric A (show Aᵀ=A by - ext i j - exact congr_fun (congr_fun hs _) _) - let P := Q.submatrix r id - let X := fun i => Q.submatrix (bump p (k:=k) i) id - have eqn (a b : Layer p n k → Layer p n (k+1)) : - Q.submatrix a id * H * (Q.submatrix b id)ᵀ = A.submatrix a b := by - - have he : - Q.submatrix a id * H * (Q.submatrix b id)ᵀ = - (Q*H*Qᵀ).submatrix a b := by ext; rfl - exact he.trans (congrArg (fun m => m.submatrix a b) hA) - have hL : P*H*Pᵀ=atLayer M h := eqn _ _ - have hP : Function.Injective P.mulVec := by - rw [mrk_inj,Fintype.card_fin] - apply le_antisymm (by simpa using P.rank_le_card_width) ?_ - have hh := (Matrix.rank_mul_le_left (P*H) Pᵀ).trans (Matrix.rank_mul_le_left P H) - rw [hL] at hh - rwa [hr] at hh - have hentry (x y a b : Layer p n (k+1)) - (h1 : x.2 = a.2) (h2 : y.2=b.2) - (h3 : x.1.val∪y.1.val=a.1.val∪b.1.val) : A x y=A a b := by - change M (⟨_,_⟩,x.2) (⟨_,_⟩,y.2) = M (⟨_,_⟩,a.2) (⟨_,_⟩,b.2) - rw [h1,h2]; exact hh _ _ _ _ _ _ h3 - obtain ⟨K,C,f,hf,hd⟩ := shift_factors P H hP hH X - (fun a => by - unfold X P; rw [eqn,eqn]; ext i j - apply hentry <;> simp [bump,r,rise]) - (fun a b => by - unfold X; rw [eqn,eqn]; ext i j - apply hentry <;> try rfl - simp only [bump] - ext; simp; tauto) - (fun a => by - unfold X P; rw [eqn,eqn]; ext i j - apply hentry <;> try rfl - simp only [bump,r,rise] - ext; simp) - let s (x : Fin t) : Label p.b := fun a => f a x - have hi (F : Mat (Fin t) (Fin t)) (hF : ∀ a, X a * F=P*F*diagonal (f a)) - (x : Fin t) (i : Layer p n k) : - (P*F) i x = monoBit (s x) i.1.val * (P*F) (emptySel,i.2) x := by - rcases i with ⟨⟨l,hl⟩,i⟩ - induction l using Finset.induction with - | empty => - simp only [monoBit,Finset.prod_empty,one_mul] - rfl - | insert a l ha ih => - have hg := Finset.card_insert_of_notMem ha - have he : l.card≤k := by omega - let u : Layer p n k := (⟨l,he⟩,i) - have hh := congr_fun (congr_fun (hF a) u) x - rw [Matrix.mul_diagonal] at hh - change (P*F) (⟨insert a l,hl⟩,i) x = _ - change (P*F) (⟨insert a l,hl⟩,i) x = (P*F) u x * _ at hh - rw [hh] - change (P*F) (⟨l,he⟩,i) x * s x a = monoBit (s x) (insert a l) * _ - rw [ih he,mono_insert] - ring - let u := P*K - let v := P*C - refine ⟨s,fun x i => u (emptySel,i) x, fun x i => v (emptySel,i) x,fun i j => ?_⟩ - have he : u*vᵀ=atLayer M h := by rw [← hL,hf]; simp only [u,v,Matrix.transpose_mul, - Matrix.mul_assoc] - rw [← he] - simp only [Matrix.mul_apply,Matrix.transpose_apply] - refine Finset.sum_congr rfl fun x _ => ?_ - have hu := hi K (fun a => (hd a).2) x i - have hv := hi C (fun a => (hd a).1) x j - dsimp only [u,v] at * - rw [hu,hv] - ring - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BooleanLabels +import OAI.Combinatorics.HadwigerCounterexample.FlatLevelShifts + +namespace OAI + +/-! # Flat Rank Levels -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix +open scoped BigOperators +variable {p : Shape} {n k : ℕ} + +abbrev Layer (p : Shape) (n k : ℕ) := SelIdx p.b k × AIdx p.g n + +def rise (p : Shape) {n k m} (h : k≤m) (i : Layer p n k) : Layer p n m := + (⟨i.1.val,i.1.property.trans h⟩,i.2) + +def bump (p : Shape) {n k} (a : Fin p.b) (i : Layer p n k) : Layer p n (k+1) := + (⟨insert a i.1.val,(Finset.card_insert_le ..).trans (Nat.add_le_add_right i.1.property 1)⟩,i.2) + +def atLayer (M : Moment p n) {k : ℕ} (h : k≤p.j) := M.submatrix (rise p h) (rise p h) + +theorem rank_atLayer_le (M : Moment p n) {k : ℕ} (h : k≤p.j) : + (atLayer M h).rank ≤ M.rank := M.rank_submatrix_le _ _ + +private theorem atLayer_mono (M : Moment p n) {k l} (h : k≤l) (hh : l≤p.j) : + (atLayer M (h.trans hh)).rank ≤ (atLayer M hh).rank := by + let f := (rise p (n:=n) h) + have he := (atLayer M hh).rank_submatrix_le f f + exact he + +theorem flat_atLayer (M : Moment p n) {R : ℕ} (hR : M.rank ≤ R) + (hj : 6*R+4 ≤ p.j) : + ∃ (k : ℕ) (h : k+1≤p.j), 4*R+2≤k ∧ + (atLayer M ((Nat.le_succ k).trans h)).rank = (atLayer M h).rank := by + classical + by_contra hn + let a := 4*R+2 + have hi (i : ℕ) (h : a+i ≤ p.j) : + i ≤ (atLayer M h).rank := by + induction i with + | zero => exact Nat.zero_le _ + | succ i ih => + have he : a+i ≤ p.j := (Nat.le_succ _).trans h + have hh : (atLayer M he).rank < (atLayer M h).rank := by + refine lt_of_le_of_ne (atLayer_mono M (Nat.le_succ _) h) (fun hx => hn ?_) + exact ⟨a+i,h,by unfold a; omega,hx⟩ + exact (Nat.succ_le_succ (ih he)).trans hh + have he : a+(R+1)≤p.j := by unfold a; omega + have hx := ((hi (R+1) he).trans (rank_atLayer_le M he)).trans hR + omega + +theorem flat_entries {M : Moment p n} (hs : Mᵀ=M) (hh : hankel M) + (hk : k+1≤p.j) (hr : + (atLayer M ((Nat.le_succ _).trans hk)).rank = (atLayer M hk).rank) : + let t := (atLayer M hk).rank + ∃ (s : Fin t → Label p.b) (u v : Fin t → Vec (AIdx p.g n)), + ∀ i j : Layer p n k, + atLayer M ((Nat.le_succ _).trans hk) i j = ∑ x : Fin t, + monoBit (s x) i.1.val * monoBit (s x) j.1.val * (u x i.2 * v x j.2) := by + classical + intro t + let h := (Nat.le_succ k).trans hk + let A := atLayer M hk + let r := rise p (n:=n) (Nat.le_succ k) + obtain ⟨Q,H,hQ,_,hH,hA⟩ := rank_symmetric A (show Aᵀ=A by + ext i j + exact congr_fun (congr_fun hs _) _) + let P := Q.submatrix r id + let X := fun i => Q.submatrix (bump p (k:=k) i) id + have eqn (a b : Layer p n k → Layer p n (k+1)) : + Q.submatrix a id * H * (Q.submatrix b id)ᵀ = A.submatrix a b := by + + have he : + Q.submatrix a id * H * (Q.submatrix b id)ᵀ = + (Q*H*Qᵀ).submatrix a b := by ext; rfl + exact he.trans (congrArg (fun m => m.submatrix a b) hA) + have hL : P*H*Pᵀ=atLayer M h := eqn _ _ + have hP : Function.Injective P.mulVec := by + rw [mrk_inj,Fintype.card_fin] + apply le_antisymm (by simpa using P.rank_le_card_width) ?_ + have hh := (Matrix.rank_mul_le_left (P*H) Pᵀ).trans (Matrix.rank_mul_le_left P H) + rw [hL] at hh + rwa [hr] at hh + have hentry (x y a b : Layer p n (k+1)) + (h1 : x.2 = a.2) (h2 : y.2=b.2) + (h3 : x.1.val∪y.1.val=a.1.val∪b.1.val) : A x y=A a b := by + change M (⟨_,_⟩,x.2) (⟨_,_⟩,y.2) = M (⟨_,_⟩,a.2) (⟨_,_⟩,b.2) + rw [h1,h2]; exact hh _ _ _ _ _ _ h3 + obtain ⟨K,C,f,hf,hd⟩ := shift_factors P H hP hH X + (fun a => by + unfold X P; rw [eqn,eqn]; ext i j + apply hentry <;> simp [bump,r,rise]) + (fun a b => by + unfold X; rw [eqn,eqn]; ext i j + apply hentry <;> try rfl + simp only [bump] + ext; simp; tauto) + (fun a => by + unfold X P; rw [eqn,eqn]; ext i j + apply hentry <;> try rfl + simp only [bump,r,rise] + ext; simp) + let s (x : Fin t) : Label p.b := fun a => f a x + have hi (F : Mat (Fin t) (Fin t)) (hF : ∀ a, X a * F=P*F*diagonal (f a)) + (x : Fin t) (i : Layer p n k) : + (P*F) i x = monoBit (s x) i.1.val * (P*F) (emptySel,i.2) x := by + rcases i with ⟨⟨l,hl⟩,i⟩ + induction l using Finset.induction with + | empty => + simp only [monoBit,Finset.prod_empty,one_mul] + rfl + | insert a l ha ih => + have hg := Finset.card_insert_of_notMem ha + have he : l.card≤k := by omega + let u : Layer p n k := (⟨l,he⟩,i) + have hh := congr_fun (congr_fun (hF a) u) x + rw [Matrix.mul_diagonal] at hh + change (P*F) (⟨insert a l,hl⟩,i) x = _ + change (P*F) (⟨insert a l,hl⟩,i) x = (P*F) u x * _ at hh + rw [hh] + change (P*F) (⟨l,he⟩,i) x * s x a = monoBit (s x) (insert a l) * _ + rw [ih he,mono_insert] + ring + let u := P*K + let v := P*C + refine ⟨s,fun x i => u (emptySel,i) x, fun x i => v (emptySel,i) x,fun i j => ?_⟩ + have he : u*vᵀ=atLayer M h := by rw [← hL,hf]; simp only [u,v,Matrix.transpose_mul, + Matrix.mul_assoc] + rw [← he] + simp only [Matrix.mul_apply,Matrix.transpose_apply] + refine Finset.sum_congr rfl fun x _ => ?_ + have hu := hi K (fun a => (hd a).2) x i + have hv := hi C (fun a => (hd a).1) x j + dsimp only [u,v] at * + rw [hu,hv] + ring + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ForbiddenPredictions.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ForbiddenPredictions.lean index 46000f56113d0b14ac1aeaf1cfb7d7e89de7d014..c67a88346a4f7fcf1f9eebacae700e13a5245d09 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ForbiddenPredictions.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ForbiddenPredictions.lean @@ -1,153 +1,153 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteComparisonBounds - -namespace OAI - -/-! # Forbidden Predictions -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Matrix Module LinearMap Finset Function -open scoped BigOperators Topology -open Template -namespace StatusAnalysis -open PreparationParameters Station PredictionClass Club Guild DualAnalysis -variable {p : Shape} {n N M r s0 K : ℕ} {w:LeafMixture p n N} {b:PreparationParameters} - -def witnessed (w:LeafMixture p n N) (v:Station p n N K w) (L:Loupe p n N K w) - (m:Mixer p n) (Y:Silhouette p N r) - (δ ε:ℝ) (B:ℕ) (d:Dict p r) (x: Aspect p n N w) := - gauze p δ δ Y m K x.2 ∧ announced (wisp p Y) (wake p Y m x.2 (routeC w L v x)) d B ε - -set_option maxHeartbeats 1200000 in -theorem witnessed_cost (w:LeafMixture p n N) (v:Station p n N b.pins w) (L:Loupe p n N b.pins w) - (h:Shipped w b.pins v L) - (m:Mixer p n) (Y:Silhouette p N r) - (δ ε a:ℝ) (U:Wgt (UnitType p n N)) (d:Dict p r) - (hp:Lead U w m b) (hq:AnalyticParameters p M b s0) (hn:2*p.r≤n) - (hδ:0≤δ) (he:0≤ε) (ht:(ε+δ)*2≤a) - (hy:¬b.predicts p N m w U a) : - pr (troupe w U) (witnessed w v L m Y δ ε b.B d) ≤ 0.001 := by - classical - let t:=troupe w U - let F (i:Memo) := fun j=>fromPulse Y (Memo.words d i j) - let P (i : Memo) (x : UnitType p n N):=∃ l B α,b.seems p m w x (F i) l B α a - have hT:=troupe_bill hp - have hi : - pr t (fun i=>∃ j,P j i.2) ≤0.001 := by - refine ((pr_exists_le hT.1.nz _).trans - ((Finset.sum_le_sum (g:=fun _=>0.000001) fun i _ => ?_).trans ?_)) - · have hh : pr t (fun x=>P i x.2)=pr (w.sap U) (P i) := by - rw [←hT.2,mapW_pr] - rw [hh]; exact le_of_not_ge (fun he=> hy ⟨F i,he⟩) - rw [Finset.sum_const,card_univ,memo_card] - norm_num - refine (pr_on_mono hT.1.nz ?_).trans hi - rintro x hx ⟨hβ,i,q,r,S,hγ⟩ - let Q:=routeC w L v x - have hm k:= praise_predict Q Y k x.2 m (q k) (r k) (Memo.words d i k) - (S k) he hδ hq.enter.first.hR hn - (fun z hz=> (hβ k z).1 hz) ((hγ k).2) - have hh:=troupe_home hp x hx - refine ⟨i,(fun i=>Q i (q i)), S,r,fun j=>⟨(hγ j).1,?_⟩, - fun j i hi x v => (hm j i hi x v).trans ht⟩ - rw [hh.2.1,←(h.charts x.1 j).1]; exact mem_range_self _ _ - -set_option maxHeartbeats 2000000 in -theorem no_out (w:LeafMixture p n N) (b:PreparationParameters) - (m:Mixer p n) (Y:Silhouette p N r) (U:Wgt (UnitType p n N)) - (v:Station p n N b.pins w) (ε η a δ τ:ℝ) - (h:Lead U w m b) (ht:v.bank) (he:AnalyticParameters p M b s0) (hn:2*p.r≤n) - (hp:Jubilee p b.pins ε η) (hε:0<ε) - (hB:supportBudget p b.pins η a) - (hv:Beams b m Y w U v a ε δ (1/16)) - (hτ:(9*ε+ε)*2≤τ) (hh:¬b.predicts p N m w U τ) - (hu:0.99 < pr (pairW (w.sap U) (w.sap U)) (secureAt p w.rooting)) : - False := by - classical - let W:=Aspect p n N w; let K:=b.pins; let L:=troupe w U; let V:=cirque w U - let u:=wisp p Y - let β:=trimBeta p K - let S (x:W):=gauze p δ δ Y m K x.2 - have hK i: planRank (w.pin (Subtype.val (show w.T from i))).sp ≤ K := - (h.strength.leaf _ i.property).bound - obtain ⟨g,hg⟩:= ready_loupe w v ht he hK - let f (x:W):=routeC w g v x - let Q (x:W):=wake p Y m x.2 (f x) - have ht' := he.enter.first - have hd (x:W) (hx:S x) : reports p r u (Q x) β δ := - routeLive w g v hg m he hn x Y δ hv.haze.1 (hK x.1) hx - have hL:2*b.Bht'⟩ - exact ⟨0,fun h=>(hx h).elim⟩ - let X (x:W×W):= secureAt p w.rooting (x.1.2,x.2.2) - let Y1 (x:W×W):= witnessed w v g m Y δ (9*ε) b.B (d x.2) x.1 - let Y2 (x:W×W):= witnessed w v g m Y δ (9*ε) b.B (d x.1) x.2 - let Z (x:W×W):=¬ S x.1∨¬ S x.2 - let P (x:W×W):=eligiblePair v m x.1 x.2 Y a - have hF:∀ i,V i ≠0 → X i→ ((Z i∨P i)∨ (Y1 i∨Y2 i)) := by - intro i hi hk - by_cases hQ:Z i∨P i - · exact Or.inl hQ - have ha1:S i.1:=not_not.mp (mt (fun x=>Or.inl (Or.inl x)) hQ) - have ha2:S i.2:=not_not.mp (mt (fun x=>Or.inl (Or.inr x)) hQ) - let A:=g.H i.1.1; let B:=g.H i.2.1 - let C:= stellar u (Q i.1) (Q i.2) η A B - have hk0 (i t) := Nat.lt_succ_iff.mp (g.r i t).isLt - have hz i:seeking p (g.H i):=by - have h:= boothseek b _ (g.H i) ⊥ (hg.baseline i) he (fun _=>Nat.zero_le b.B) - rwa [sup_bot_eq] at h - have hC : rich C := plenitude hv.soft (hd _ ha1) (hd _ ha2) ht'.hG A B (hz _) (hz _) - hβ hp.pos hp.sturdyR (hk0 _) (hk0 _) - obtain ⟨E,hE,hI⟩:=stable C hC - have hm0:= troupe_home h i.1 (left_ne_zero_of_mul hi) - have hm1:= troupe_home h i.2 (right_ne_zero_of_mul hi) - obtain ⟨k,hk⟩:= issueTicket _ _ w v i.1.1 i.2.1 h.strength.part hm0.1 hm1.1 ht hk - let T:= v.mails i.1.1 i.2.1 k - let R:= hailing p (f i.1) (f i.2) T - by_cases hV:scorecard (chapter C E) R - · exact (hQ (Or.inr (inform w v m Y i.1 i.2 hm0.2.2.1 hm1.2.2.1 - hm0.2.2.2 hm1.2.2.2 (g.r _) (g.r _) (hg.charts _) (hg.charts _) hB A B (hg.baseline _) - (hg.baseline _) A B le_rfl le_rfl ht'.hG he.jump hp.pos k hk E hI hV))).elim - obtain ⟨z,hz1,hz2,hz3⟩ := jargon_score _ _ hV (rich_covers C hC E (fun x=>(hE x).trans (by norm_num))) - have hStory: countStory p K η δ ε β u:=⟨hv.soft,hβ.le,hε.le,hp.pos.le,hp.book,hp.low⟩ - let G0:=outstraps A E true; let G1:=outstraps B E false - have hE0 (j):= outcard p A E (hz _) hE true j - have hE1 (j):= outcard p B E (hz _) hE false j - have hT:= tells z hStory (hd _ ha1) (hd _ ha2) A B E hz2 (hk0 _) (hk0 _) hE0 hE1 ht'.hG - have hu i (j k:Bool): (outstraps (g.H i) E j k).card≤ b.B:= by - refine (card_union_le ..).trans ?_ - have hi:=(hg.baseline i).1 k; have hh:= hE j; have hx:= he.forbid; omega - right - have hh:=quotes (d i.1) (d i.2) (hd _ ha1) (hd _ ha2) hv.soft z hz1 G0 G1 hT b.B - (hD _ ha1) (hD _ ha2) (hu _ _) (hu _ _) - rw [show 3*(3*ε)=9*ε from by ring] at hh - exact hh.elim (fun h=>Or.inl ⟨ha1,h⟩) (fun h=>Or.inr ⟨ha2,h⟩) - have hL:IsLaw L:= (troupe_bill h).1 - have hz0 (i:W): pr L (witnessed w v g m Y δ (9*ε) b.B (d i)) ≤ 0.001 := - witnessed_cost w v g hg m Y δ (9*ε) τ U (d i) h he hn hv.haze.1.le (by linarith) - (by linarith only [hτ,hv.haze.2]) hh - have hZ1: pr V Y1 ≤ 0.001 := by - unfold pr V cirque; rw [pairW_avg,avg_avg]; exact hL.avg_le hz0 - have hZ2: pr V Y2 ≤0.001 := by unfold pr V cirque; rw [pairW_avg]; exact hL.avg_le hz0 - have hO:IsLaw V:=pairW_law hL hL - have hX :0.99 < pr V X := by rw [←cirque_unit _ h,mapW_pr] at hu; exact hu - have hP:= show pr V P≤1/16 from hv.zone - have hZ:= show pr V Z ≤ 1/16+1/16 from (sickBound U v Y h _ _ _ _ hv).2 - have hx: pr V X≤(1/16+1/16+1/16)+(0.001+0.001):= - ((pr_on_mono hO.nz hF).trans (pr_or_le hO.nz)).trans - (add_le_add ((pr_or_le hO.nz).trans (add_le_add hZ hP)) ((pr_or_le hO.nz).trans - (add_le_add hZ1 hZ2))) - linarith only [hX,hx] -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteComparisonBounds + +namespace OAI + +/-! # Forbidden Predictions -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Matrix Module LinearMap Finset Function +open scoped BigOperators Topology +open Template +namespace StatusAnalysis +open PreparationParameters Station PredictionClass Club Guild DualAnalysis +variable {p : Shape} {n N M r s0 K : ℕ} {w:LeafMixture p n N} {b:PreparationParameters} + +def witnessed (w:LeafMixture p n N) (v:Station p n N K w) (L:Loupe p n N K w) + (m:Mixer p n) (Y:Silhouette p N r) + (δ ε:ℝ) (B:ℕ) (d:Dict p r) (x: Aspect p n N w) := + gauze p δ δ Y m K x.2 ∧ announced (wisp p Y) (wake p Y m x.2 (routeC w L v x)) d B ε + +set_option maxHeartbeats 1200000 in +theorem witnessed_cost (w:LeafMixture p n N) (v:Station p n N b.pins w) (L:Loupe p n N b.pins w) + (h:Shipped w b.pins v L) + (m:Mixer p n) (Y:Silhouette p N r) + (δ ε a:ℝ) (U:Wgt (UnitType p n N)) (d:Dict p r) + (hp:Lead U w m b) (hq:AnalyticParameters p M b s0) (hn:2*p.r≤n) + (hδ:0≤δ) (he:0≤ε) (ht:(ε+δ)*2≤a) + (hy:¬b.predicts p N m w U a) : + pr (troupe w U) (witnessed w v L m Y δ ε b.B d) ≤ 0.001 := by + classical + let t:=troupe w U + let F (i:Memo) := fun j=>fromPulse Y (Memo.words d i j) + let P (i : Memo) (x : UnitType p n N):=∃ l B α,b.seems p m w x (F i) l B α a + have hT:=troupe_bill hp + have hi : + pr t (fun i=>∃ j,P j i.2) ≤0.001 := by + refine ((pr_exists_le hT.1.nz _).trans + ((Finset.sum_le_sum (g:=fun _=>0.000001) fun i _ => ?_).trans ?_)) + · have hh : pr t (fun x=>P i x.2)=pr (w.sap U) (P i) := by + rw [←hT.2,mapW_pr] + rw [hh]; exact le_of_not_ge (fun he=> hy ⟨F i,he⟩) + rw [Finset.sum_const,card_univ,memo_card] + norm_num + refine (pr_on_mono hT.1.nz ?_).trans hi + rintro x hx ⟨hβ,i,q,r,S,hγ⟩ + let Q:=routeC w L v x + have hm k:= praise_predict Q Y k x.2 m (q k) (r k) (Memo.words d i k) + (S k) he hδ hq.enter.first.hR hn + (fun z hz=> (hβ k z).1 hz) ((hγ k).2) + have hh:=troupe_home hp x hx + refine ⟨i,(fun i=>Q i (q i)), S,r,fun j=>⟨(hγ j).1,?_⟩, + fun j i hi x v => (hm j i hi x v).trans ht⟩ + rw [hh.2.1,←(h.charts x.1 j).1]; exact mem_range_self _ _ + +set_option maxHeartbeats 2000000 in +theorem no_out (w:LeafMixture p n N) (b:PreparationParameters) + (m:Mixer p n) (Y:Silhouette p N r) (U:Wgt (UnitType p n N)) + (v:Station p n N b.pins w) (ε η a δ τ:ℝ) + (h:Lead U w m b) (ht:v.bank) (he:AnalyticParameters p M b s0) (hn:2*p.r≤n) + (hp:Jubilee p b.pins ε η) (hε:0<ε) + (hB:supportBudget p b.pins η a) + (hv:Beams b m Y w U v a ε δ (1/16)) + (hτ:(9*ε+ε)*2≤τ) (hh:¬b.predicts p N m w U τ) + (hu:0.99 < pr (pairW (w.sap U) (w.sap U)) (secureAt p w.rooting)) : + False := by + classical + let W:=Aspect p n N w; let K:=b.pins; let L:=troupe w U; let V:=cirque w U + let u:=wisp p Y + let β:=trimBeta p K + let S (x:W):=gauze p δ δ Y m K x.2 + have hK i: planRank (w.pin (Subtype.val (show w.T from i))).sp ≤ K := + (h.strength.leaf _ i.property).bound + obtain ⟨g,hg⟩:= ready_loupe w v ht he hK + let f (x:W):=routeC w g v x + let Q (x:W):=wake p Y m x.2 (f x) + have ht' := he.enter.first + have hd (x:W) (hx:S x) : reports p r u (Q x) β δ := + routeLive w g v hg m he hn x Y δ hv.haze.1 (hK x.1) hx + have hL:2*b.Bht'⟩ + exact ⟨0,fun h=>(hx h).elim⟩ + let X (x:W×W):= secureAt p w.rooting (x.1.2,x.2.2) + let Y1 (x:W×W):= witnessed w v g m Y δ (9*ε) b.B (d x.2) x.1 + let Y2 (x:W×W):= witnessed w v g m Y δ (9*ε) b.B (d x.1) x.2 + let Z (x:W×W):=¬ S x.1∨¬ S x.2 + let P (x:W×W):=eligiblePair v m x.1 x.2 Y a + have hF:∀ i,V i ≠0 → X i→ ((Z i∨P i)∨ (Y1 i∨Y2 i)) := by + intro i hi hk + by_cases hQ:Z i∨P i + · exact Or.inl hQ + have ha1:S i.1:=not_not.mp (mt (fun x=>Or.inl (Or.inl x)) hQ) + have ha2:S i.2:=not_not.mp (mt (fun x=>Or.inl (Or.inr x)) hQ) + let A:=g.H i.1.1; let B:=g.H i.2.1 + let C:= stellar u (Q i.1) (Q i.2) η A B + have hk0 (i t) := Nat.lt_succ_iff.mp (g.r i t).isLt + have hz i:seeking p (g.H i):=by + have h:= boothseek b _ (g.H i) ⊥ (hg.baseline i) he (fun _=>Nat.zero_le b.B) + rwa [sup_bot_eq] at h + have hC : rich C := plenitude hv.soft (hd _ ha1) (hd _ ha2) ht'.hG A B (hz _) (hz _) + hβ hp.pos hp.sturdyR (hk0 _) (hk0 _) + obtain ⟨E,hE,hI⟩:=stable C hC + have hm0:= troupe_home h i.1 (left_ne_zero_of_mul hi) + have hm1:= troupe_home h i.2 (right_ne_zero_of_mul hi) + obtain ⟨k,hk⟩:= issueTicket _ _ w v i.1.1 i.2.1 h.strength.part hm0.1 hm1.1 ht hk + let T:= v.mails i.1.1 i.2.1 k + let R:= hailing p (f i.1) (f i.2) T + by_cases hV:scorecard (chapter C E) R + · exact (hQ (Or.inr (inform w v m Y i.1 i.2 hm0.2.2.1 hm1.2.2.1 + hm0.2.2.2 hm1.2.2.2 (g.r _) (g.r _) (hg.charts _) (hg.charts _) hB A B (hg.baseline _) + (hg.baseline _) A B le_rfl le_rfl ht'.hG he.jump hp.pos k hk E hI hV))).elim + obtain ⟨z,hz1,hz2,hz3⟩ := jargon_score _ _ hV (rich_covers C hC E (fun x=>(hE x).trans (by norm_num))) + have hStory: countStory p K η δ ε β u:=⟨hv.soft,hβ.le,hε.le,hp.pos.le,hp.book,hp.low⟩ + let G0:=outstraps A E true; let G1:=outstraps B E false + have hE0 (j):= outcard p A E (hz _) hE true j + have hE1 (j):= outcard p B E (hz _) hE false j + have hT:= tells z hStory (hd _ ha1) (hd _ ha2) A B E hz2 (hk0 _) (hk0 _) hE0 hE1 ht'.hG + have hu i (j k:Bool): (outstraps (g.H i) E j k).card≤ b.B:= by + refine (card_union_le ..).trans ?_ + have hi:=(hg.baseline i).1 k; have hh:= hE j; have hx:= he.forbid; omega + right + have hh:=quotes (d i.1) (d i.2) (hd _ ha1) (hd _ ha2) hv.soft z hz1 G0 G1 hT b.B + (hD _ ha1) (hD _ ha2) (hu _ _) (hu _ _) + rw [show 3*(3*ε)=9*ε from by ring] at hh + exact hh.elim (fun h=>Or.inl ⟨ha1,h⟩) (fun h=>Or.inr ⟨ha2,h⟩) + have hL:IsLaw L:= (troupe_bill h).1 + have hz0 (i:W): pr L (witnessed w v g m Y δ (9*ε) b.B (d i)) ≤ 0.001 := + witnessed_cost w v g hg m Y δ (9*ε) τ U (d i) h he hn hv.haze.1.le (by linarith) + (by linarith only [hτ,hv.haze.2]) hh + have hZ1: pr V Y1 ≤ 0.001 := by + unfold pr V cirque; rw [pairW_avg,avg_avg]; exact hL.avg_le hz0 + have hZ2: pr V Y2 ≤0.001 := by unfold pr V cirque; rw [pairW_avg]; exact hL.avg_le hz0 + have hO:IsLaw V:=pairW_law hL hL + have hX :0.99 < pr V X := by rw [←cirque_unit _ h,mapW_pr] at hu; exact hu + have hP:= show pr V P≤1/16 from hv.zone + have hZ:= show pr V Z ≤ 1/16+1/16 from (sickBound U v Y h _ _ _ _ hv).2 + have hx: pr V X≤(1/16+1/16+1/16)+(0.001+0.001):= + ((pr_on_mono hO.nz hF).trans (pr_or_le hO.nz)).trans + (add_le_add ((pr_or_le hO.nz).trans (add_le_add hZ hP)) ((pr_or_le hO.nz).trans + (add_le_add hZ1 hZ2))) + linarith only [hX,hx] +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FourCornerMasks.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FourCornerMasks.lean index 33737fed9d7738f101252fff08ec750e7175632f..8631aa090f0cae5a01564ea41d6912a88b2241c8 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FourCornerMasks.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FourCornerMasks.lean @@ -1,120 +1,120 @@ -import OAI.Combinatorics.HadwigerCounterexample.SinglePositionExpansion - -namespace OAI - -/-! # Four Corner Masks -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Filter Function -open scoped BigOperators -variable {p : Shape} {I : Type} [Fintype I] [DecidableEq I] {n N : ℕ} - -def wingpair (I : Type) : (Bool→ I)≃ I × I where - toFun x := (x true,x false) - invFun x := onSide x - left_inv i := by funext j; cases j <;> rfl - right_inv _ := rfl - -namespace Template -variable (v : Template p I) -abbrev PackSlot (v : Template p I) := Bool × KeySlots p v.t - -abbrev PackStack (v : Template p I) (N : ℕ) := Rack v.PackSlot N - -def untwin (v : Template p I) (N) : - v.PackStack N ≃ Keys (p:=p) v.t N × Keys (p:=p) v.t N := - let E:=scatter v.t N - ((relay Bool (KeySlots p v.t) N).trans (wingpair _)).trans (E.symm.prodCongr E.symm) - -def yieldK (v : Template p I) (j : I) (c : Corn) (x : v.PackStack N) := - criss (v.chairK j N) (v.untwin N x) c -def seam (v : Template p I) : Route v.PackSlot (Ports p) := tied (globPort p v.t v.aim) Bool - -def sees (v : Template p I) (j : I) (c : Corn) (w : v.PackSlot) := - arm j w.2.1 c=w.1 -instance (v : Template p I) (j c w) : Decidable (sees v j c w) := Classical.propDecidable _ - -def cantRail (v : Template p I) (j : I) := open Classical in - (crowded v.seam).filter (fun x => ¬∃ c,sees v j c x.1 ∧ sees v j c x.2) - -theorem cant_mem (v : Template p I) (j) (x) : - x∈cantRail v j ↔ x∈crowded v.seam ∧ ¬∃ c,sees v j c x.1 ∧ sees v j c x.2 := mem_filter - -def cantVec (v : Template p I) (j : I) (Z : GeoM v.seam) : Vec (cantRail v j) := - fun x => directions _ Z ⟨x.val,((cant_mem ..).mp x.property).1⟩ - -theorem yield_view (v : Template p I) (j) (c : Corn) (x : v.PackStack N) - (i : v.PackSlot) (he : sees v j c i) (b : Bool) (z : Fin N) : - yieldK v j c x i.2.1 i.2.2 b z= if b then x.1 z i else x.2 z i := by - classical - have hh : yieldK v j c x i.2.1=onSide (v.untwin N x) i.1 i.2.1 := by - have hg := chair_arm (X:=fun i=>AtomKey (p:=p) (v.t i) N) (v.untwin N x) j i.2.1 c - rw [show arm j i.2.1 c=i.1 from he] at hg - exact hg - rw [hh] - cases i with | mk r y => cases r <;> cases b <;> rfl - -theorem scores_together (v : Template p I) (j : I) (c : Corn) (x : v.PackStack N) - (i k : v.PackSlot) (he : sees v j c i) (hk : sees v j c k) : - scoreR x i k=scoreR (scatter v.t N (yieldK v j c x)) i.2 k.2 := by - classical - have h z : (scatter v.t N (yieldK v j c x)).1 z i.2=x.1 z i := yield_view v j c x i he true z - have hh z : (scatter v.t N (yieldK v j c x)).2 z k.2=x.2 z k := yield_view v j c x k hk false z - unfold scoreR; simp only [Matrix.mul_apply,transpose_apply,h,hh] - -omit [Fintype I] in -theorem seam_score_fixed (v : Template p I) (q : I→F) (x y : Keys (p:=p) v.t N) - (hx : ownPart (p:=p) v.t q x) (hy : ownPart (p:=p) v.t q y) (a b : v.PackSlot) - (h : v.seam a=v.seam b) : - scoreR (scatter v.t N x) a.2 b.2=scoreR (scatter v.t N y) a.2 b.2 := by - have ht : ownPort (p:=p) v.t a.2 = ownPort (p:=p) v.t b.2 := congrArg Prod.snd h - let c := ownPort (p:=p) v.t a.2 - let i : Port (ownPort (p:=p) v.t) c := ⟨a.2,rfl⟩ - let j : Port (ownPort (p:=p) v.t) c := ⟨b.2,ht.symm⟩ - exact ((part_scores (scatter v.t N x) (ownMap (p:=p) v.t q)).mp hx c i j).trans - (((part_scores ..).mp hy c i j).symm) - -def gatedStack (v : Template p I) (j : I) (q : I→F) (x : v.PackStack N) := - ∀ i:Corn,ownPart (p:=p) v.t q (yieldK v j i x) - -theorem cant_bridge (v : Template p I) (j : I) (q : I→F) - (Z : GeoM v.seam) (x y : v.PackStack N) (hx : gatedStack v j q x) - (hy : gatedStack v j q y) (he : gramPart Z x) : - gramPart Z y ↔ traced y (cantRail v j) (cantVec v j Z) := by - classical - constructor - · intro hh - funext i - exact congr_fun ((match_crowd y _ Z).mpr hh) - (⟨i.val,((cant_mem ..).mp i.property).1⟩ : ↑(crowded v.seam)) - intro ht - refine (part_scores y Z).mpr fun i a b => ?_ - have hb : v.seam a.val=v.seam b.val := a.property.trans b.property.symm - have hi : (a.val,b.val)∈crowded v.seam := Finset.mem_filter.mpr ⟨mem_univ _,hb⟩ - rcases a with ⟨a,ha⟩; rcases b with ⟨b,hb'⟩ - subst i - by_cases hg : ∃ c, sees v j c a ∧ sees v j c b - · obtain ⟨c,hC,hB⟩ := hg - have hh : scoreR y a b=scoreR x a b := by - rw [scores_together v j c y a b hC hB,scores_together v j c x a b hC hB] - exact seam_score_fixed v q _ _ (hy c) (hx c) a b hb - exact hh.trans ((part_scores x Z).mp he _ ⟨a,rfl⟩ ⟨b,hb'⟩) - have hh : (a,b)∈cantRail v j := (cant_mem ..).mpr ⟨hi,hg⟩ - exact congr_fun ht (⟨(a,b),hh⟩ : ↑(cantRail v j)) - -def packSecs (v : Template p I) (j : I) (U : Wgt (Keys (p:=p) v.t N)) (x : v.PackStack N) := - ∏ i:Corn,U (yieldK v j i x) - -theorem pack_gate (v : Template p I) (j : I) (q : I→ F) {x : v.PackStack N} - (U : Wgt (Keys (p:=p) v.t N)) (h : carried U (ownPart (p:=p) v.t q)) - (hx : packSecs v j U x≠0) : - gatedStack v j q x := - fun i=> by_contra (fun he => hx (Finset.prod_eq_zero (mem_univ i) (h (yieldK v j i x) he))) - -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SinglePositionExpansion + +namespace OAI + +/-! # Four Corner Masks -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Filter Function +open scoped BigOperators +variable {p : Shape} {I : Type} [Fintype I] [DecidableEq I] {n N : ℕ} + +def wingpair (I : Type) : (Bool→ I)≃ I × I where + toFun x := (x true,x false) + invFun x := onSide x + left_inv i := by funext j; cases j <;> rfl + right_inv _ := rfl + +namespace Template +variable (v : Template p I) +abbrev PackSlot (v : Template p I) := Bool × KeySlots p v.t + +abbrev PackStack (v : Template p I) (N : ℕ) := Rack v.PackSlot N + +def untwin (v : Template p I) (N) : + v.PackStack N ≃ Keys (p:=p) v.t N × Keys (p:=p) v.t N := + let E:=scatter v.t N + ((relay Bool (KeySlots p v.t) N).trans (wingpair _)).trans (E.symm.prodCongr E.symm) + +def yieldK (v : Template p I) (j : I) (c : Corn) (x : v.PackStack N) := + criss (v.chairK j N) (v.untwin N x) c +def seam (v : Template p I) : Route v.PackSlot (Ports p) := tied (globPort p v.t v.aim) Bool + +def sees (v : Template p I) (j : I) (c : Corn) (w : v.PackSlot) := + arm j w.2.1 c=w.1 +instance (v : Template p I) (j c w) : Decidable (sees v j c w) := Classical.propDecidable _ + +def cantRail (v : Template p I) (j : I) := open Classical in + (crowded v.seam).filter (fun x => ¬∃ c,sees v j c x.1 ∧ sees v j c x.2) + +theorem cant_mem (v : Template p I) (j) (x) : + x∈cantRail v j ↔ x∈crowded v.seam ∧ ¬∃ c,sees v j c x.1 ∧ sees v j c x.2 := mem_filter + +def cantVec (v : Template p I) (j : I) (Z : GeoM v.seam) : Vec (cantRail v j) := + fun x => directions _ Z ⟨x.val,((cant_mem ..).mp x.property).1⟩ + +theorem yield_view (v : Template p I) (j) (c : Corn) (x : v.PackStack N) + (i : v.PackSlot) (he : sees v j c i) (b : Bool) (z : Fin N) : + yieldK v j c x i.2.1 i.2.2 b z= if b then x.1 z i else x.2 z i := by + classical + have hh : yieldK v j c x i.2.1=onSide (v.untwin N x) i.1 i.2.1 := by + have hg := chair_arm (X:=fun i=>AtomKey (p:=p) (v.t i) N) (v.untwin N x) j i.2.1 c + rw [show arm j i.2.1 c=i.1 from he] at hg + exact hg + rw [hh] + cases i with | mk r y => cases r <;> cases b <;> rfl + +theorem scores_together (v : Template p I) (j : I) (c : Corn) (x : v.PackStack N) + (i k : v.PackSlot) (he : sees v j c i) (hk : sees v j c k) : + scoreR x i k=scoreR (scatter v.t N (yieldK v j c x)) i.2 k.2 := by + classical + have h z : (scatter v.t N (yieldK v j c x)).1 z i.2=x.1 z i := yield_view v j c x i he true z + have hh z : (scatter v.t N (yieldK v j c x)).2 z k.2=x.2 z k := yield_view v j c x k hk false z + unfold scoreR; simp only [Matrix.mul_apply,transpose_apply,h,hh] + +omit [Fintype I] in +theorem seam_score_fixed (v : Template p I) (q : I→F) (x y : Keys (p:=p) v.t N) + (hx : ownPart (p:=p) v.t q x) (hy : ownPart (p:=p) v.t q y) (a b : v.PackSlot) + (h : v.seam a=v.seam b) : + scoreR (scatter v.t N x) a.2 b.2=scoreR (scatter v.t N y) a.2 b.2 := by + have ht : ownPort (p:=p) v.t a.2 = ownPort (p:=p) v.t b.2 := congrArg Prod.snd h + let c := ownPort (p:=p) v.t a.2 + let i : Port (ownPort (p:=p) v.t) c := ⟨a.2,rfl⟩ + let j : Port (ownPort (p:=p) v.t) c := ⟨b.2,ht.symm⟩ + exact ((part_scores (scatter v.t N x) (ownMap (p:=p) v.t q)).mp hx c i j).trans + (((part_scores ..).mp hy c i j).symm) + +def gatedStack (v : Template p I) (j : I) (q : I→F) (x : v.PackStack N) := + ∀ i:Corn,ownPart (p:=p) v.t q (yieldK v j i x) + +theorem cant_bridge (v : Template p I) (j : I) (q : I→F) + (Z : GeoM v.seam) (x y : v.PackStack N) (hx : gatedStack v j q x) + (hy : gatedStack v j q y) (he : gramPart Z x) : + gramPart Z y ↔ traced y (cantRail v j) (cantVec v j Z) := by + classical + constructor + · intro hh + funext i + exact congr_fun ((match_crowd y _ Z).mpr hh) + (⟨i.val,((cant_mem ..).mp i.property).1⟩ : ↑(crowded v.seam)) + intro ht + refine (part_scores y Z).mpr fun i a b => ?_ + have hb : v.seam a.val=v.seam b.val := a.property.trans b.property.symm + have hi : (a.val,b.val)∈crowded v.seam := Finset.mem_filter.mpr ⟨mem_univ _,hb⟩ + rcases a with ⟨a,ha⟩; rcases b with ⟨b,hb'⟩ + subst i + by_cases hg : ∃ c, sees v j c a ∧ sees v j c b + · obtain ⟨c,hC,hB⟩ := hg + have hh : scoreR y a b=scoreR x a b := by + rw [scores_together v j c y a b hC hB,scores_together v j c x a b hC hB] + exact seam_score_fixed v q _ _ (hy c) (hx c) a b hb + exact hh.trans ((part_scores x Z).mp he _ ⟨a,rfl⟩ ⟨b,hb'⟩) + have hh : (a,b)∈cantRail v j := (cant_mem ..).mpr ⟨hi,hg⟩ + exact congr_fun ht (⟨(a,b),hh⟩ : ↑(cantRail v j)) + +def packSecs (v : Template p I) (j : I) (U : Wgt (Keys (p:=p) v.t N)) (x : v.PackStack N) := + ∏ i:Corn,U (yieldK v j i x) + +theorem pack_gate (v : Template p I) (j : I) (q : I→ F) {x : v.PackStack N} + (U : Wgt (Keys (p:=p) v.t N)) (h : carried U (ownPart (p:=p) v.t q)) + (hx : packSecs v j U x≠0) : + gatedStack v j q x := + fun i=> by_contra (fun he => hx (Finset.prod_eq_zero (mem_univ i) (h (yieldK v j i x) he))) + +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FourCornerTrials.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FourCornerTrials.lean index 73f3c67edb9ebcd45378cb196cdf378874639b91..a919ecd63a226ddede7772136039d1450dd4bdaf 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FourCornerTrials.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FourCornerTrials.lean @@ -1,129 +1,129 @@ -import OAI.Combinatorics.HadwigerCounterexample.ConditionalFourCorners - -namespace OAI - -/-! # Four Corner Trials -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module LinearMap Function -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] - -omit [DecidableEq I] in -theorem winglaw (p : Wgt I) : - mapW (draws Bool p) (wingpair I)=pairW p p := by - classical - funext i - obtain ⟨i,rfl⟩ := (wingpair I).surjective i - rw [mapW_equiv_val, Equiv.symm_apply_apply] - simp only [draws,prodW,Fintype.prod_bool]; rfl - -theorem quart_bound {A B C : Type} (U : Wgt A) (hU : ∀ i, |U i|≤1) (e : A≃B×C) (i) : - |quart e U i|≤ 1 := by - unfold quart; rw [Finset.abs_prod] - exact (Finset.prod_le_prod₀ (fun i _ => abs_nonneg _) (fun i _=>hU _)).trans_eq (by simp) - -namespace Template -variable (v : Template p I) -def protean (v : Template p I) (T : Wgt (Inputs p n I)) - (U : Wgt (Keys (p:=p) v.t N)) (o : UnitType p n N) := - fun x => T x*U (v.resultKey o x) - -omit [Fintype I] in -theorem quart_prot (v : Template p I) (j : I) (T : Wgt (Inputs p n I)) - (U : Wgt (Keys (p:=p) v.t N)) (o : UnitType p n N) - (c : Inputs p n I × Inputs p n I) : - quart (v.chairI j n) (v.protean T U o) c= - quart (v.chairI j n) T c *quart (v.chairK j N) U - (Prod.map (v.resultKey o) (v.resultKey o) c) := by - unfold quart protean - rw [Finset.prod_mul_distrib] - simp_rw [key_quoin] - -def crane (v : Template p I) (j : I) (T : Wgt (Inputs p n I)) - (U : Wgt (Keys (p:=p) v.t N)) - (w : I → Wgt (Knobs p.g n)) (o : UnitType p n N) := - let x:= prodW w - avg (pairW x x) (quart (v.chairI j n) (v.protean T U o)) - -set_option maxHeartbeats 1000000 in -theorem crane_mean (v : Template p I) (j : I) (q : I → F) (U : Wgt (Keys (p:=p) v.t N)) - (T : Wgt (Inputs p n I)) (w : I→ Wgt (Knobs p.g n)) - (hw : ∀ i,IsLaw (w i)) (hz : ∀ i,mapW (w i) (freePart p)=unif) - (m : Mixer p n) (hN : 2*num (Full p n)h hg : ¬ ¬ p'.free y),add_zero] - have hh : avg ρ (Q y)=C*avg (rackStation Z N) (packSecs v j U) := by - rw [← hx,mapW_avg,←avg_mul'] - exact avg_congr fun i _=> hi i - rw [hh,abs_mul] - exact (mul_le_mul ht (pack_hot v j q U δ hδ hU h hW Z k hk hK) - (abs_nonneg _) zero_le_one).trans_eq (one_mul _) - rw [ind_one hg] - refine (avg_bound1 hp _ (fun i=>?_)).trans (le_add_of_nonneg_left hq) - rw [hi,abs_mul] - exact (mul_le_mul ht (pack_bound v j U hU _) (abs_nonneg _) zero_le_one).trans_eq (one_mul _) - let S := draws Bool (prodW w) - have hr : IsLaw S := draws_law (prodW_law hw) - have he : avg ρ (crane v j T U w)=avg S (fun y => avg ρ (Q y)) := by - rw [avg_avg] - apply avg_congr; intro i _ - change avg (pairW (prodW w) (prodW w)) _=_ - rw [←winglaw (prodW w),mapW_avg] - rw [he] - refine (abs_avg_le hr.nz).trans ((avg_mono hr.nz hh).trans ?_) - rw [avg_add,hr.avg_const] - exact add_le_add_right (free_price v n w hw hz (globPort p v.t v.aim) (glob_inj v)) _ -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ConditionalFourCorners + +namespace OAI + +/-! # Four Corner Trials -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module LinearMap Function +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] + +omit [DecidableEq I] in +theorem winglaw (p : Wgt I) : + mapW (draws Bool p) (wingpair I)=pairW p p := by + classical + funext i + obtain ⟨i,rfl⟩ := (wingpair I).surjective i + rw [mapW_equiv_val, Equiv.symm_apply_apply] + simp only [draws,prodW,Fintype.prod_bool]; rfl + +theorem quart_bound {A B C : Type} (U : Wgt A) (hU : ∀ i, |U i|≤1) (e : A≃B×C) (i) : + |quart e U i|≤ 1 := by + unfold quart; rw [Finset.abs_prod] + exact (Finset.prod_le_prod₀ (fun i _ => abs_nonneg _) (fun i _=>hU _)).trans_eq (by simp) + +namespace Template +variable (v : Template p I) +def protean (v : Template p I) (T : Wgt (Inputs p n I)) + (U : Wgt (Keys (p:=p) v.t N)) (o : UnitType p n N) := + fun x => T x*U (v.resultKey o x) + +omit [Fintype I] in +theorem quart_prot (v : Template p I) (j : I) (T : Wgt (Inputs p n I)) + (U : Wgt (Keys (p:=p) v.t N)) (o : UnitType p n N) + (c : Inputs p n I × Inputs p n I) : + quart (v.chairI j n) (v.protean T U o) c= + quart (v.chairI j n) T c *quart (v.chairK j N) U + (Prod.map (v.resultKey o) (v.resultKey o) c) := by + unfold quart protean + rw [Finset.prod_mul_distrib] + simp_rw [key_quoin] + +def crane (v : Template p I) (j : I) (T : Wgt (Inputs p n I)) + (U : Wgt (Keys (p:=p) v.t N)) + (w : I → Wgt (Knobs p.g n)) (o : UnitType p n N) := + let x:= prodW w + avg (pairW x x) (quart (v.chairI j n) (v.protean T U o)) + +set_option maxHeartbeats 1000000 in +theorem crane_mean (v : Template p I) (j : I) (q : I → F) (U : Wgt (Keys (p:=p) v.t N)) + (T : Wgt (Inputs p n I)) (w : I→ Wgt (Knobs p.g n)) + (hw : ∀ i,IsLaw (w i)) (hz : ∀ i,mapW (w i) (freePart p)=unif) + (m : Mixer p n) (hN : 2*num (Full p n)h hg : ¬ ¬ p'.free y),add_zero] + have hh : avg ρ (Q y)=C*avg (rackStation Z N) (packSecs v j U) := by + rw [← hx,mapW_avg,←avg_mul'] + exact avg_congr fun i _=> hi i + rw [hh,abs_mul] + exact (mul_le_mul ht (pack_hot v j q U δ hδ hU h hW Z k hk hK) + (abs_nonneg _) zero_le_one).trans_eq (one_mul _) + rw [ind_one hg] + refine (avg_bound1 hp _ (fun i=>?_)).trans (le_add_of_nonneg_left hq) + rw [hi,abs_mul] + exact (mul_le_mul ht (pack_bound v j U hU _) (abs_nonneg _) zero_le_one).trans_eq (one_mul _) + let S := draws Bool (prodW w) + have hr : IsLaw S := draws_law (prodW_law hw) + have he : avg ρ (crane v j T U w)=avg S (fun y => avg ρ (Q y)) := by + rw [avg_avg] + apply avg_congr; intro i _ + change avg (pairW (prodW w) (prodW w)) _=_ + rw [←winglaw (prodW w),mapW_avg] + rw [he] + refine (abs_avg_le hr.nz).trans ((avg_mono hr.nz hh).trans ?_) + rw [avg_add,hr.avg_const] + exact add_le_add_right (free_price v n w hw hz (globPort p v.t v.aim) (glob_inj v)) _ +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FourCornerViews.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FourCornerViews.lean index b4da45b83f5120a56fd34de4cf914dc99afa6a5d..b66175bfd8fdc20410e9f99f9c040395288a9834 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FourCornerViews.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FourCornerViews.lean @@ -1,126 +1,126 @@ -import OAI.Combinatorics.HadwigerCounterexample.RectangleRegularity - -namespace OAI - -/-! # Four Corner Views -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real Matrix Function -open scoped BigOperators -variable {A B C : Type} [Fintype A] [Fintype B] [Fintype C] - -abbrev Corn := Bool × Bool - -def criss (E : A ≃ B × C) (p : A × A) (x : Corn) := - E.symm ((onSide (Prod.map E E p) x.1).1,(onSide (Prod.map E E p) x.2).2) -def quart (E : A≃B×C) (U : Wgt A) (p : A×A) := - ∏ i:Corn,U (criss E p i) - -omit [Fintype A] [Fintype B] [Fintype C] in -theorem criss_pair (p : A × A) (a b : Bool) (E : A≃ B × C) : - E (criss E p (a,b))=((E (onSide p a)).1,(E (onSide p b)).2) := by - cases a <;> cases b <;> simp [criss,onSide] - -variable {E : A≃ B × C} - -def spread (U : Wgt (B× C)) (i : (B×C) × B×C) := - U (i.1.1,i.1.2)*U (i.1.1,i.2.2)* (U (i.2.1,i.1.2)*U (i.2.1,i.2.2)) - -theorem quart_shift (E : A ≃ B×C) (U : Wgt A) (p : Wgt A) : - avg (pairW p p) (quart E U) = - avg (pairW (mapW p E) (mapW p E)) (spread (U∘E.symm)) := by - classical - rw [←map_pair_law,mapW_avg] - refine avg_congr fun x hx => ?_ - unfold quart spread - rw [Fintype.prod_prod_type,Fintype.prod_bool,Fintype.prod_bool,Fintype.prod_bool] - rfl - -set_option maxHeartbeats 800000 in -theorem quart_small (E : A ≃ B×C) (U : Wgt A) (u : Wgt A) (p : Wgt B) (q : Wgt C) - (he : mapW u E=pairW p q) (hp : IsLaw p) (hq : IsLaw q) - (h : ∀ i,|U i|≤1) (δ : ℝ) (hh : thinCut u U (Prod.fst ∘ E) (Prod.snd ∘ E) δ) : - |avg (pairW u u) (quart E U)|≤δ := by - rw [quart_shift,he, pairW_avg,avg_avg] - let T := U∘E.symm - have ht (y : B × C) : - |avg (pairW p q) (fun i => spread T (i,y))|≤δ := by - let f j := T (j,y.2); let g i := T (y.1,i)*T y - have he' (i) : - spread T (E i,y)=U i*(f (E i).1*g (E i).2) := by - simp only [spread,T,f,g,Function.comp_apply] - rw [show E.symm ((E i).1,(E i).2)=i from E.symm_apply_apply _]; cases y; ring - have hU x : |g x|≤1 := by - unfold g; rw [abs_mul]; exact (mul_le_mul (h _) (h _) (abs_nonneg _) zero_le_one).trans_eq - (by ring) - rw [← he,mapW_avg]; simp_rw [he'] - exact hh f (fun i=>h _) _ hU - have hu := pairW_law hp hq - exact (abs_avg_le hu.nz).trans (hu.avg_le ht) - -set_option maxHeartbeats 800000 in -theorem spread_gain (u : Wgt B) (v : Wgt C) (f : Wgt (B×C)) (hu : IsLaw u) (hv : IsLaw v) - (p : Wgt B) (q : Wgt C) (hp : ∀ i,|p i|≤1) (hq : ∀ i,|q i|≤1): - |avg (pairW u v) (fun i=> f i*(p i.1*q i.2))|^4 ≤ - avg (pairW (pairW u v) (pairW u v)) (spread f) := by - classical - let U := fun i => avg v (fun j => f (i,j)*q j) - let T : Wgt (B×C) := fun i=> f i*(p i.1*q i.2) - have h : - avg (pairW u v) T =dip u p U := by - unfold T U dip; rw [pairW_avg]; simp_rw [mul_left_comm _ (p _),avg_mul'] - have h0 (x y : ℝ) (hx:|x|≤1) (hy:|y|≤1) : |x*y|≤1 := by rw [abs_mul]; exact - (mul_le_mul hx hy (abs_nonneg _) zero_le_one).trans_eq (by ring) - have hh {A : Type} [Fintype A] {w : Wgt A} (hw : IsLaw w) (p q : Wgt A) - (hp : ∀ i,|p i|≤1) : - dip w p q ^2 ≤ ode w q := by - have he : ode w p≤1 := (ode_upper hw.sub _ 1 hp).trans_eq (by ring) - apply le_trans _ ((mul_le_mul_of_nonneg_right he (ode_nonneg hw.nz q)).trans_eq (one_mul _)) - simpa only [dip,ode,pow_two] using avg_CS hw.nz p q - let V := pairW v v - have hV := pairW_law hv hv - let Y (j : C×C) (i:B) := f (i,j.1)*f (i,j.2) - let W (j) := avg u (Y j) - let Q (j : C×C) := q j.1*q j.2 - have he : ode u U=dip V Q W := by - have hi i : U i*U i=avg V (fun j => Q j*Y j i) := by - unfold U - rw [avg_prod]; apply avg_congr; intro j _ - unfold Q Y; ring - unfold ode dip; simp_rw [hi]; rw [avg_avg]; simp_rw [avg_mul']; rfl - let D (j : C×C) (i : B× B) := Y j i.1*Y j i.2 - have hw : ode V W= avg (pairW (pairW u v) (pairW u v)) (spread f) := by - have hi j : W j*W j=avg (pairW u u) (fun i => D j i) := avg_prod u _ _ - unfold ode dip; simp_rw [hi]; unfold V; simp_rw [pairW_avg] - conv_rhs => rw [avg_avg] - apply avg_congr; intro i _ - conv_rhs => - - skip - unfold D Y spread - - conv_lhs => rw [avg_avg] - refine avg_congr fun i _ => ?_ - rw [avg_avg] - change |avg (pairW u v) T|^4≤ _ - rw [h,←hw,show |dip u p U|^4=(dip u p U^2)^2 by rw [show |dip u p U|^4=(|dip u p U|^2)^2 by ring, - sq_abs]] - apply (pow_le_pow_left₀ (sq_nonneg _) (hh hu p U hp) 2).trans - rw [he] - exact hh hV Q W (fun i=>h0 _ _ (hq _) (hq _)) - -theorem quart_CS (E : A≃ B×C) (U : Wgt A) (u : Wgt A) (p : Wgt B) (q : Wgt C) - (he : mapW u E=pairW p q) (hp : IsLaw p) (hq : IsLaw q) - (f : Wgt B) (g : Wgt C) (hf : ∀ i,|f i|≤1) (hg : ∀ i,|g i|≤1) : - |avg u (fun i=>U i*(f (E i).1*g (E i).2))|^4 ≤ avg (pairW u u) (quart E U) := by - have hh := spread_gain p q (U∘E.symm) hp hq f g hf hg - rw [quart_shift] - rw [← he,mapW_avg] at hh - simp only [Function.comp_apply,Equiv.symm_apply_apply] at hh - exact hh -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RectangleRegularity + +namespace OAI + +/-! # Four Corner Views -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real Matrix Function +open scoped BigOperators +variable {A B C : Type} [Fintype A] [Fintype B] [Fintype C] + +abbrev Corn := Bool × Bool + +def criss (E : A ≃ B × C) (p : A × A) (x : Corn) := + E.symm ((onSide (Prod.map E E p) x.1).1,(onSide (Prod.map E E p) x.2).2) +def quart (E : A≃B×C) (U : Wgt A) (p : A×A) := + ∏ i:Corn,U (criss E p i) + +omit [Fintype A] [Fintype B] [Fintype C] in +theorem criss_pair (p : A × A) (a b : Bool) (E : A≃ B × C) : + E (criss E p (a,b))=((E (onSide p a)).1,(E (onSide p b)).2) := by + cases a <;> cases b <;> simp [criss,onSide] + +variable {E : A≃ B × C} + +def spread (U : Wgt (B× C)) (i : (B×C) × B×C) := + U (i.1.1,i.1.2)*U (i.1.1,i.2.2)* (U (i.2.1,i.1.2)*U (i.2.1,i.2.2)) + +theorem quart_shift (E : A ≃ B×C) (U : Wgt A) (p : Wgt A) : + avg (pairW p p) (quart E U) = + avg (pairW (mapW p E) (mapW p E)) (spread (U∘E.symm)) := by + classical + rw [←map_pair_law,mapW_avg] + refine avg_congr fun x hx => ?_ + unfold quart spread + rw [Fintype.prod_prod_type,Fintype.prod_bool,Fintype.prod_bool,Fintype.prod_bool] + rfl + +set_option maxHeartbeats 800000 in +theorem quart_small (E : A ≃ B×C) (U : Wgt A) (u : Wgt A) (p : Wgt B) (q : Wgt C) + (he : mapW u E=pairW p q) (hp : IsLaw p) (hq : IsLaw q) + (h : ∀ i,|U i|≤1) (δ : ℝ) (hh : thinCut u U (Prod.fst ∘ E) (Prod.snd ∘ E) δ) : + |avg (pairW u u) (quart E U)|≤δ := by + rw [quart_shift,he, pairW_avg,avg_avg] + let T := U∘E.symm + have ht (y : B × C) : + |avg (pairW p q) (fun i => spread T (i,y))|≤δ := by + let f j := T (j,y.2); let g i := T (y.1,i)*T y + have he' (i) : + spread T (E i,y)=U i*(f (E i).1*g (E i).2) := by + simp only [spread,T,f,g,Function.comp_apply] + rw [show E.symm ((E i).1,(E i).2)=i from E.symm_apply_apply _]; cases y; ring + have hU x : |g x|≤1 := by + unfold g; rw [abs_mul]; exact (mul_le_mul (h _) (h _) (abs_nonneg _) zero_le_one).trans_eq + (by ring) + rw [← he,mapW_avg]; simp_rw [he'] + exact hh f (fun i=>h _) _ hU + have hu := pairW_law hp hq + exact (abs_avg_le hu.nz).trans (hu.avg_le ht) + +set_option maxHeartbeats 800000 in +theorem spread_gain (u : Wgt B) (v : Wgt C) (f : Wgt (B×C)) (hu : IsLaw u) (hv : IsLaw v) + (p : Wgt B) (q : Wgt C) (hp : ∀ i,|p i|≤1) (hq : ∀ i,|q i|≤1): + |avg (pairW u v) (fun i=> f i*(p i.1*q i.2))|^4 ≤ + avg (pairW (pairW u v) (pairW u v)) (spread f) := by + classical + let U := fun i => avg v (fun j => f (i,j)*q j) + let T : Wgt (B×C) := fun i=> f i*(p i.1*q i.2) + have h : + avg (pairW u v) T =dip u p U := by + unfold T U dip; rw [pairW_avg]; simp_rw [mul_left_comm _ (p _),avg_mul'] + have h0 (x y : ℝ) (hx:|x|≤1) (hy:|y|≤1) : |x*y|≤1 := by rw [abs_mul]; exact + (mul_le_mul hx hy (abs_nonneg _) zero_le_one).trans_eq (by ring) + have hh {A : Type} [Fintype A] {w : Wgt A} (hw : IsLaw w) (p q : Wgt A) + (hp : ∀ i,|p i|≤1) : + dip w p q ^2 ≤ ode w q := by + have he : ode w p≤1 := (ode_upper hw.sub _ 1 hp).trans_eq (by ring) + apply le_trans _ ((mul_le_mul_of_nonneg_right he (ode_nonneg hw.nz q)).trans_eq (one_mul _)) + simpa only [dip,ode,pow_two] using avg_CS hw.nz p q + let V := pairW v v + have hV := pairW_law hv hv + let Y (j : C×C) (i:B) := f (i,j.1)*f (i,j.2) + let W (j) := avg u (Y j) + let Q (j : C×C) := q j.1*q j.2 + have he : ode u U=dip V Q W := by + have hi i : U i*U i=avg V (fun j => Q j*Y j i) := by + unfold U + rw [avg_prod]; apply avg_congr; intro j _ + unfold Q Y; ring + unfold ode dip; simp_rw [hi]; rw [avg_avg]; simp_rw [avg_mul']; rfl + let D (j : C×C) (i : B× B) := Y j i.1*Y j i.2 + have hw : ode V W= avg (pairW (pairW u v) (pairW u v)) (spread f) := by + have hi j : W j*W j=avg (pairW u u) (fun i => D j i) := avg_prod u _ _ + unfold ode dip; simp_rw [hi]; unfold V; simp_rw [pairW_avg] + conv_rhs => rw [avg_avg] + apply avg_congr; intro i _ + conv_rhs => + + skip + unfold D Y spread + + conv_lhs => rw [avg_avg] + refine avg_congr fun i _ => ?_ + rw [avg_avg] + change |avg (pairW u v) T|^4≤ _ + rw [h,←hw,show |dip u p U|^4=(dip u p U^2)^2 by rw [show |dip u p U|^4=(|dip u p U|^2)^2 by ring, + sq_abs]] + apply (pow_le_pow_left₀ (sq_nonneg _) (hh hu p U hp) 2).trans + rw [he] + exact hh hV Q W (fun i=>h0 _ _ (hq _) (hq _)) + +theorem quart_CS (E : A≃ B×C) (U : Wgt A) (u : Wgt A) (p : Wgt B) (q : Wgt C) + (he : mapW u E=pairW p q) (hp : IsLaw p) (hq : IsLaw q) + (f : Wgt B) (g : Wgt C) (hf : ∀ i,|f i|≤1) (hg : ∀ i,|g i|≤1) : + |avg u (fun i=>U i*(f (E i).1*g (E i).2))|^4 ≤ avg (pairW u u) (quart E U) := by + have hh := spread_gain p q (U∘E.symm) hp hq f g hf hg + rw [quart_shift] + rw [← he,mapW_avg] at hh + simp only [Function.comp_apply,Equiv.symm_apply_apply] at hh + exact hh +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FourEdgeFamilies.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FourEdgeFamilies.lean index 2acdf963efe862c000d3dd74fd8f67e4702644f1..8d3e6ed0831bae9c23d65aaa9b1b8394811d90de 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FourEdgeFamilies.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FourEdgeFamilies.lean @@ -1,79 +1,79 @@ -import OAI.Combinatorics.HadwigerCounterexample.ReservedLabels - -namespace OAI - -/-! # Four Edge Families -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Submodule Finset Function -open scoped BigOperators -namespace StatusAnalysis -variable {A B : Rates} {I : Grid→Type} {L : Type} [DecidableEq L] [∀ i,DecidableEq (I i)] -namespace Guild -open Club -variable (C : Congress I A B L) - -abbrev Bags (I : Grid→Type) := ∀ i,Finset (I i) -structure Parade (s : Straps L) (v : ∀ i,Suite A B i) (g : Bags I) (p : Finset Grid) : Prop where - batch (i) (h : i∈p) : - (C i).bundle (g i) s ∧ (C i).contents (g i)=v i∧ 1≤(g i).card∧(g i).card≤7 - mixed (i j) (hx : i∈p) (hy:j∈p) (he : i≠j) x (hX : x∈g i) y (hY : y∈g j) (b) : - (C i).addr x b ≠ (C j).addr y b - -set_option maxHeartbeats 800000 in -theorem full_parade (s : Straps L) {v : ∀ i,Suite A B i} - (ht : ∀ i:Grid,(C i).travels s 100 (view _ _) (chapter C s i)) - (hv : ∀ i, v i∈chapter C s i) : - ∃ g, Parade C s v g Finset.univ := by - classical - have he (p:Finset Grid) : - ∃ g, Parade C s v g p := by - induction p using Finset.induction_on with - | empty => - exact ⟨fun _=>∅,⟨fun i hi=> (notMem_empty i hi).elim, - fun i _ hi=> (notMem_empty i hi).elim⟩⟩ - | insert i p hi ih => - obtain ⟨g,hg⟩:=ih - let Q (b : Bool) := p.biUnion (fun i=> (C i).addrs (g i) b) - have hh (b) : (Q b).card≤28 := by - have he (i:Grid) (h:i∈p) : ((C i).addrs (g i) b).card≤7 := - Finset.card_image_le.trans (hg.batch i h).2.2.2 - refine (Finset.card_biUnion_le).trans ((Finset.sum_le_sum he).trans ?_) - have hh : p.card≤4 := p.card_le_univ.trans_eq (by simp [Grid,Nodes]) - simp only [Finset.sum_const,nsmul_eq_mul, Nat.cast_id]; omega - let V:= chapter C s i - have hr : (C i).travels (s⊔Q) 4 (view _ _) V := (C i).travel_more (ht i) Q hh (by norm_num) - obtain ⟨t,ht,hT,hA,hB⟩:=fresh_single (C i) hr (v i) (hv i) - let f:=update g i t - have hC (j) (h:j∈p) (x : I j) (hx:x∈f j) (y : I i) (hy:y∈t) (b) : - (C j).addr x b≠ (C i).addr y b := by - intro hz - apply ((ht.1 y hy).2 b) - refine Finset.mem_union_right _ (Finset.mem_biUnion.mpr ⟨j,h,?_⟩) - unfold f at hx - rw [Function.update_of_ne (show j ≠ i from fun e=>hi (e ▸ h))] at hx - exact Finset.mem_image.mpr ⟨x,hx,hz⟩ - refine ⟨f,⟨fun j hj=>?_,fun j k hj hk he x hx y hy b=>?_⟩⟩ - · rcases Finset.mem_insert.mp hj with hj|hj - · subst j; unfold f; rw [update_self] - exact ⟨Club.bundle_back _ le_sup_left ht,hT,hA,hB⟩ - unfold f; rw [update_of_ne (show j ≠ i from fun h=>hi (h ▸ hj))] - exact hg.batch j hj - rcases Finset.mem_insert.mp hj with hj|hj - · subst j; exact Ne.symm (hC k ((Finset.mem_insert.mp hk).resolve_left (Ne.symm he)) y hy x - (by simpa only [f,update_self] using hx) b) - rcases Finset.mem_insert.mp hk with hk|hk - · subst k; exact hC j hj x hx y (by simpa only [f,update_self] using hy) b - unfold f at hx hy - rw [update_of_ne (show j ≠ i from fun h=>hi (h ▸ hj))] at hx - rw [update_of_ne (show k ≠ i from fun h=>hi (h ▸ hk))] at hy - exact hg.mixed j k hj hk he x hx y hy b - exact he _ -end Guild -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ReservedLabels + +namespace OAI + +/-! # Four Edge Families -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Submodule Finset Function +open scoped BigOperators +namespace StatusAnalysis +variable {A B : Rates} {I : Grid→Type} {L : Type} [DecidableEq L] [∀ i,DecidableEq (I i)] +namespace Guild +open Club +variable (C : Congress I A B L) + +abbrev Bags (I : Grid→Type) := ∀ i,Finset (I i) +structure Parade (s : Straps L) (v : ∀ i,Suite A B i) (g : Bags I) (p : Finset Grid) : Prop where + batch (i) (h : i∈p) : + (C i).bundle (g i) s ∧ (C i).contents (g i)=v i∧ 1≤(g i).card∧(g i).card≤7 + mixed (i j) (hx : i∈p) (hy:j∈p) (he : i≠j) x (hX : x∈g i) y (hY : y∈g j) (b) : + (C i).addr x b ≠ (C j).addr y b + +set_option maxHeartbeats 800000 in +theorem full_parade (s : Straps L) {v : ∀ i,Suite A B i} + (ht : ∀ i:Grid,(C i).travels s 100 (view _ _) (chapter C s i)) + (hv : ∀ i, v i∈chapter C s i) : + ∃ g, Parade C s v g Finset.univ := by + classical + have he (p:Finset Grid) : + ∃ g, Parade C s v g p := by + induction p using Finset.induction_on with + | empty => + exact ⟨fun _=>∅,⟨fun i hi=> (notMem_empty i hi).elim, + fun i _ hi=> (notMem_empty i hi).elim⟩⟩ + | insert i p hi ih => + obtain ⟨g,hg⟩:=ih + let Q (b : Bool) := p.biUnion (fun i=> (C i).addrs (g i) b) + have hh (b) : (Q b).card≤28 := by + have he (i:Grid) (h:i∈p) : ((C i).addrs (g i) b).card≤7 := + Finset.card_image_le.trans (hg.batch i h).2.2.2 + refine (Finset.card_biUnion_le).trans ((Finset.sum_le_sum he).trans ?_) + have hh : p.card≤4 := p.card_le_univ.trans_eq (by simp [Grid,Nodes]) + simp only [Finset.sum_const,nsmul_eq_mul, Nat.cast_id]; omega + let V:= chapter C s i + have hr : (C i).travels (s⊔Q) 4 (view _ _) V := (C i).travel_more (ht i) Q hh (by norm_num) + obtain ⟨t,ht,hT,hA,hB⟩:=fresh_single (C i) hr (v i) (hv i) + let f:=update g i t + have hC (j) (h:j∈p) (x : I j) (hx:x∈f j) (y : I i) (hy:y∈t) (b) : + (C j).addr x b≠ (C i).addr y b := by + intro hz + apply ((ht.1 y hy).2 b) + refine Finset.mem_union_right _ (Finset.mem_biUnion.mpr ⟨j,h,?_⟩) + unfold f at hx + rw [Function.update_of_ne (show j ≠ i from fun e=>hi (e ▸ h))] at hx + exact Finset.mem_image.mpr ⟨x,hx,hz⟩ + refine ⟨f,⟨fun j hj=>?_,fun j k hj hk he x hx y hy b=>?_⟩⟩ + · rcases Finset.mem_insert.mp hj with hj|hj + · subst j; unfold f; rw [update_self] + exact ⟨Club.bundle_back _ le_sup_left ht,hT,hA,hB⟩ + unfold f; rw [update_of_ne (show j ≠ i from fun h=>hi (h ▸ hj))] + exact hg.batch j hj + rcases Finset.mem_insert.mp hj with hj|hj + · subst j; exact Ne.symm (hC k ((Finset.mem_insert.mp hk).resolve_left (Ne.symm he)) y hy x + (by simpa only [f,update_self] using hx) b) + rcases Finset.mem_insert.mp hk with hk|hk + · subst k; exact hC j hj x hx y (by simpa only [f,update_self] using hy) b + unfold f at hx hy + rw [update_of_ne (show j ≠ i from fun h=>hi (h ▸ hj))] at hx + rw [update_of_ne (show k ≠ i from fun h=>hi (h ▸ hk))] at hy + exact hg.mixed j k hj hk he x hx y hy b + exact he _ +end Guild +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FourPhaseBits.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FourPhaseBits.lean index 8e3fc3d2ff741a107b838a1d426afd3001eb5a0e..22f4191e9dab13e2a54963415e9fb3dba974ac29 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FourPhaseBits.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FourPhaseBits.lean @@ -1,200 +1,200 @@ -import OAI.Combinatorics.HadwigerCounterexample.PolynomialRankBounds - -namespace OAI - -/-! # Four Phase Bits -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module Finset -open scoped BigOperators -variable {p : Shape} {n N : ℕ} -abbrev Quad := Party × Party - -def quench (p : Shape) {n N} (Δ : UnitType p n N→ Ambient p N) - (x : UnitType p n N × UnitType p n N) : Quad := - (fun i => tone p x.2 (unary i) (Δ x.1),fun i => tone p x.1 (unary i) (Δ x.2)) - -def quadDot (x y : Quad) := dotProduct x.1 y.1 + dotProduct x.2 y.2 -def quadPhase (x y : Quad) := wsign (quadDot x y) - -private theorem party_card : Fintype.card Party = 4 := by simp [Party,Vec,F] -theorem quad_card : Fintype.card Quad=16 := by simp [Quad] -private theorem quad_rate (x : Quad) : unif x=(1:ℝ)/16 := by - rw [unif_apply,quad_card]; norm_num - -theorem quad_inv_zero (x : Quad) : avg unif (fun y => quadPhase y x)=ind (x=0) := by - classical - let B := (dotL x.1).coprod (dotL x.2) - have h (y) : quadPhase y x=wsign (B y) := by - change wsign (dotProduct y.1 x.1+dotProduct y.2 x.2)=wsign (dotProduct x.1 y.1+dotProduct x.2 y.2) - rw [dotProduct_comm x.1,dotProduct_comm x.2] - have he : B=0 ↔ x=0 := by - constructor - · intro he - have hl : dotL x.1=0 := LinearMap.ext fun z => by - have hf : dotL x.1 z+dotL x.2 0=0 := LinearMap.congr_fun he (z,0) - rwa [map_zero,add_zero] at hf - have hr : dotL x.2=0 := LinearMap.ext fun z => by - have hf : dotL x.1 0+dotL x.2 z=0 := LinearMap.congr_fun he (0,z) - rwa [map_zero,zero_add] at hf - refine Prod.ext (dot_ext_zero (fun y => ?_)) (dot_ext_zero (fun y => ?_)) - · rw [dotProduct_comm]; exact LinearMap.congr_fun hl y - rw [dotProduct_comm]; exact LinearMap.congr_fun hr y - · intro he - refine LinearMap.ext fun y => ?_ - unfold B; rw [he] - change dotProduct (0:Party) y.1 +dotProduct (0:Party) y.2=0 - rw [zero_dotProduct,zero_dotProduct]; simp - simp_rw [h,wsign_lin,he] - -theorem quad_inv (x y : Quad) : ind (x=y)=avg unif (fun S => quadPhase S x*quadPhase S y) := by - classical - have he (S) : quadPhase S (x+y) = quadPhase S x*quadPhase S y := by - unfold quadPhase quadDot - rw [← wsign_add] - simp only [Prod.fst_add,Prod.snd_add,dotProduct_add,add_comm,add_left_comm] - simp_rw [← he,quad_inv_zero] - apply congrArg ind - exact propext (by rw [← ZModModule.sub_eq_add,sub_eq_zero]) -private theorem joint_phase (p : Shape) {n N} (Δ : UnitType p n N→ Ambient p N) (x) (S) : - quadPhase S (quench p Δ x) = chant p Δ S.1 S.2 x := by - unfold quadPhase chant - unfold quadDot quench - dsimp only - rw [←tone_vec, ←tone_vec,add_comm] - -theorem quad_invert (p : Shape) {n N} (Δ : UnitType p n N→Ambient p N) (w) (s : Quad) : - pr (pairW w w) (fun x => quench p Δ x=s)= - avg unif (fun v : Quad => pitch p Δ w v.1 v.2 * quadPhase v s) := by - unfold pr - simp_rw [quad_inv, joint_phase] - rw [avg_avg] - simp_rw [avg_mul] - rfl - -theorem mix_pattern (p : Shape) {n N} (Δ : UnitType p n N→Ambient p N) (w) - (hw : IsLaw w) (h : tonalMix p Δ w) (s : Quad) : - 0.05 < pr (pairW w w) (fun x => quench p Δ x=s) := by - classical - rw [quad_invert] - let f := fun S : Quad => ind (S=0) - 0.005 - have hf S : f S≤pitch p Δ w S.1 S.2*quadPhase S s := by - by_cases hS : S=0 - · have h0 : pitch p Δ w 0 0=1 := by - unfold pitch - have hz (x : UnitType p n N) y : tone p x 0 (Δ y)=0 := by rw [tone_vec,zero_dotProduct] - simp_rw [hz,add_zero, wsign_zero]; exact (pairW_law hw hw).avg_const _ - rw [hS] - change f 0≤pitch p Δ w 0 0*quadPhase 0 s - rw [h0] - norm_num [f,quadPhase,quadDot] - · have hh := h _ _ (show S.1≠0 ∨ S.2≠0 from by - by_contra! he; exact hS (Prod.ext he.1 he.2)) - have he : |pitch p Δ w S.1 S.2*quadPhase S s| < 0.005 := by rwa [abs_mul,quadPhase,wsign_abs,mul_one] - simpa only [f,ind_zero hS,zero_sub] using (abs_lt.mp he).1.le - apply lt_of_lt_of_le _ (avg_mono unif_law.nz hf) - unfold f; rw [avg_sub, unif_law.avg_const] - change 0.05 < pr unif (fun S : Quad => S=0)-0.005 - rw [pr_point',quad_rate]; norm_num - -/-- common even relation on four scores. -/ -def repeated (x : Quad) := - dotProduct allSide x.1=0 ∧ dotProduct allSide x.2=0 - -def repeatQ (i : F) : Quad := (fun _ => i,fun _ => i) - -def evenP : Finset Party := {0,allSide} -def evenQ : Finset Quad := evenP×ˢevenP - -private theorem party_single (x : Party) (h : x∉evenP) : ∃ i,x=unary i := by - classical - rcases bit_cases (x true) with a|a <;> rcases bit_cases (x false) with b|b - · have he : x=0 := funext fun i => by cases i; exact b; exact a - simp [he,evenP] at h - · refine ⟨false,funext fun i => ?_⟩; cases i <;> simp [a,b,unary] - · refine ⟨true,funext fun i => ?_⟩; cases i <;> simp [a,b,unary] - have he : x=allSide := funext fun i => by cases i; exact b; exact a - simp [he,evenP] at h - -private theorem even_dot (_ : Quad) (v : Quad) (h : v∈evenQ) (j : F) : - quadPhase v (repeatQ j)=1 := by - classical - have he (b : Party) (h : b∈evenP) : dotProduct b (fun _ => j)=0 := by - have h : b=0 ∨ b=allSide := by simpa [evenP] using h - rcases h with h|h - · rw [h,zero_dotProduct] - simp only [h,dotProduct,Fintype.sum_bool,allSide,one_mul,char_two] - obtain ⟨ha,hb⟩ := Finset.mem_product.mp h - unfold quadPhase quadDot repeatQ - dsimp only - rw [he _ ha,he _ hb]; simp - -private theorem even_sum (x : Quad) (i : F) : - ∑ v∈evenQ,quadPhase v x*quadPhase v (repeatQ i)=4*ind (repeated x) := by - classical - let f (x : Party) (v : Party) := wsign (dotProduct v x) - have hh (x) : - ∑ v∈evenP,f x v=2*ind (dotProduct allSide x=0) := by - have hn : allSide≠0 := by - intro e - have hh := congr_fun e true - change (1:F)=0 at hh; simp at hh - simp only [evenP,Finset.sum_insert (show (0:Party)∉ ({allSide}:Finset _) from - fun h => hn (mem_singleton.mp h).symm),Finset.sum_singleton,f, zero_dotProduct, wsign_zero] - by_cases ht : dotProduct allSide x=0 - · norm_num [ind,ht] - norm_num [ind,ht,wsign] - have ht (v : Quad) (h : v∈evenQ) : quadPhase v x * quadPhase v (repeatQ i) - = f x.1 v.1 * f x.2 v.2 := by - rw [even_dot x _ h,mul_one,quadPhase,quadDot,wsign_add] - rw [Finset.sum_congr (g:=fun v => f x.1 v.1 * f x.2 v.2) rfl ht,evenQ, Finset.sum_product] - simp_rw [← Finset.mul_sum] - rw [← Finset.sum_mul,hh,hh,repeated,ind_and]; ring - -set_option maxHeartbeats 800000 in -theorem tiny_pattern (p : Shape) {n N} (Δ : UnitType p n N→Ambient p N) (w) - (i : F) {h : ℝ} (h0 : 0≤h) - (hw : ∀ i : Bool,∀ R, |pitch p Δ w (unary i) R|≤h) : - (1/4:ℝ)*pr (pairW w w) (fun x => repeated (quench p Δ x))-h ≤ - pr (pairW w w) (fun x => quench p Δ x=repeatQ i) := by - classical - let f (v : Quad) := pitch p Δ w v.1 v.2*quadPhase v (repeatQ i) - let μ := pairW w w - let g (S : Quad) := ind (S∈evenQ)*f S - have he (x : Quad) : g x - h ≤ f x := by - by_cases hx : x∈evenQ - · unfold g; rw [ind_one hx,one_mul] - exact sub_le_self _ h0 - have hi : |pitch p Δ w x.1 x.2|≤h := by - by_cases he : x.1∈evenP - · obtain ⟨i,hit⟩ := party_single x.2 (fun hh => hx (Finset.mem_product.mpr ⟨he,hh⟩)) - rw [hit,pitch_turn] - exact hw i _ - obtain ⟨i,hi⟩ := party_single _ he - rw [hi]; exact hw i _ - have hs : |f x|≤h := by unfold f quadPhase; rwa [abs_mul,wsign_abs,mul_one] - unfold g; rw [ind_zero hx,zero_mul,zero_sub] - exact (abs_le.mp hs).1 - have hg : avg unif g=(1/4:ℝ)*pr μ (fun x => repeated (quench p Δ x)) := by - have ht : ∑ x : Quad,g x= ∑ x∈evenQ,f x := by - symm - simp only [g,ind,ite_mul,one_mul,zero_mul,← Finset.sum_filter] - simp - have hB (x : Quad) : - f x=avg μ (fun y => quadPhase x (quench p Δ y)*quadPhase x (repeatQ i)) := by - rw [avg_mul]; simp_rw [joint_phase]; rfl - have hf : ∑ x∈evenQ,f x=4*pr μ (fun x => repeated (quench p Δ x)) := by - simp_rw [hB,← avg_sum,even_sum,avg_mul']; rfl - simp only [avg,quad_rate,← Finset.mul_sum, ht,hf] - unfold pr avg - ring - rw [quad_invert,show _*pr _ _=_ from hg.symm] - calc avg unif g - h = avg unif (fun x => g x-h) := by rw [avg_sub,unif_law.avg_const] - _ ≤ _ := avg_mono unif_law.nz he - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PolynomialRankBounds + +namespace OAI + +/-! # Four Phase Bits -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} +abbrev Quad := Party × Party + +def quench (p : Shape) {n N} (Δ : UnitType p n N→ Ambient p N) + (x : UnitType p n N × UnitType p n N) : Quad := + (fun i => tone p x.2 (unary i) (Δ x.1),fun i => tone p x.1 (unary i) (Δ x.2)) + +def quadDot (x y : Quad) := dotProduct x.1 y.1 + dotProduct x.2 y.2 +def quadPhase (x y : Quad) := wsign (quadDot x y) + +private theorem party_card : Fintype.card Party = 4 := by simp [Party,Vec,F] +theorem quad_card : Fintype.card Quad=16 := by simp [Quad] +private theorem quad_rate (x : Quad) : unif x=(1:ℝ)/16 := by + rw [unif_apply,quad_card]; norm_num + +theorem quad_inv_zero (x : Quad) : avg unif (fun y => quadPhase y x)=ind (x=0) := by + classical + let B := (dotL x.1).coprod (dotL x.2) + have h (y) : quadPhase y x=wsign (B y) := by + change wsign (dotProduct y.1 x.1+dotProduct y.2 x.2)=wsign (dotProduct x.1 y.1+dotProduct x.2 y.2) + rw [dotProduct_comm x.1,dotProduct_comm x.2] + have he : B=0 ↔ x=0 := by + constructor + · intro he + have hl : dotL x.1=0 := LinearMap.ext fun z => by + have hf : dotL x.1 z+dotL x.2 0=0 := LinearMap.congr_fun he (z,0) + rwa [map_zero,add_zero] at hf + have hr : dotL x.2=0 := LinearMap.ext fun z => by + have hf : dotL x.1 0+dotL x.2 z=0 := LinearMap.congr_fun he (0,z) + rwa [map_zero,zero_add] at hf + refine Prod.ext (dot_ext_zero (fun y => ?_)) (dot_ext_zero (fun y => ?_)) + · rw [dotProduct_comm]; exact LinearMap.congr_fun hl y + rw [dotProduct_comm]; exact LinearMap.congr_fun hr y + · intro he + refine LinearMap.ext fun y => ?_ + unfold B; rw [he] + change dotProduct (0:Party) y.1 +dotProduct (0:Party) y.2=0 + rw [zero_dotProduct,zero_dotProduct]; simp + simp_rw [h,wsign_lin,he] + +theorem quad_inv (x y : Quad) : ind (x=y)=avg unif (fun S => quadPhase S x*quadPhase S y) := by + classical + have he (S) : quadPhase S (x+y) = quadPhase S x*quadPhase S y := by + unfold quadPhase quadDot + rw [← wsign_add] + simp only [Prod.fst_add,Prod.snd_add,dotProduct_add,add_comm,add_left_comm] + simp_rw [← he,quad_inv_zero] + apply congrArg ind + exact propext (by rw [← ZModModule.sub_eq_add,sub_eq_zero]) +private theorem joint_phase (p : Shape) {n N} (Δ : UnitType p n N→ Ambient p N) (x) (S) : + quadPhase S (quench p Δ x) = chant p Δ S.1 S.2 x := by + unfold quadPhase chant + unfold quadDot quench + dsimp only + rw [←tone_vec, ←tone_vec,add_comm] + +theorem quad_invert (p : Shape) {n N} (Δ : UnitType p n N→Ambient p N) (w) (s : Quad) : + pr (pairW w w) (fun x => quench p Δ x=s)= + avg unif (fun v : Quad => pitch p Δ w v.1 v.2 * quadPhase v s) := by + unfold pr + simp_rw [quad_inv, joint_phase] + rw [avg_avg] + simp_rw [avg_mul] + rfl + +theorem mix_pattern (p : Shape) {n N} (Δ : UnitType p n N→Ambient p N) (w) + (hw : IsLaw w) (h : tonalMix p Δ w) (s : Quad) : + 0.05 < pr (pairW w w) (fun x => quench p Δ x=s) := by + classical + rw [quad_invert] + let f := fun S : Quad => ind (S=0) - 0.005 + have hf S : f S≤pitch p Δ w S.1 S.2*quadPhase S s := by + by_cases hS : S=0 + · have h0 : pitch p Δ w 0 0=1 := by + unfold pitch + have hz (x : UnitType p n N) y : tone p x 0 (Δ y)=0 := by rw [tone_vec,zero_dotProduct] + simp_rw [hz,add_zero, wsign_zero]; exact (pairW_law hw hw).avg_const _ + rw [hS] + change f 0≤pitch p Δ w 0 0*quadPhase 0 s + rw [h0] + norm_num [f,quadPhase,quadDot] + · have hh := h _ _ (show S.1≠0 ∨ S.2≠0 from by + by_contra! he; exact hS (Prod.ext he.1 he.2)) + have he : |pitch p Δ w S.1 S.2*quadPhase S s| < 0.005 := by rwa [abs_mul,quadPhase,wsign_abs,mul_one] + simpa only [f,ind_zero hS,zero_sub] using (abs_lt.mp he).1.le + apply lt_of_lt_of_le _ (avg_mono unif_law.nz hf) + unfold f; rw [avg_sub, unif_law.avg_const] + change 0.05 < pr unif (fun S : Quad => S=0)-0.005 + rw [pr_point',quad_rate]; norm_num + +/-- common even relation on four scores. -/ +def repeated (x : Quad) := + dotProduct allSide x.1=0 ∧ dotProduct allSide x.2=0 + +def repeatQ (i : F) : Quad := (fun _ => i,fun _ => i) + +def evenP : Finset Party := {0,allSide} +def evenQ : Finset Quad := evenP×ˢevenP + +private theorem party_single (x : Party) (h : x∉evenP) : ∃ i,x=unary i := by + classical + rcases bit_cases (x true) with a|a <;> rcases bit_cases (x false) with b|b + · have he : x=0 := funext fun i => by cases i; exact b; exact a + simp [he,evenP] at h + · refine ⟨false,funext fun i => ?_⟩; cases i <;> simp [a,b,unary] + · refine ⟨true,funext fun i => ?_⟩; cases i <;> simp [a,b,unary] + have he : x=allSide := funext fun i => by cases i; exact b; exact a + simp [he,evenP] at h + +private theorem even_dot (_ : Quad) (v : Quad) (h : v∈evenQ) (j : F) : + quadPhase v (repeatQ j)=1 := by + classical + have he (b : Party) (h : b∈evenP) : dotProduct b (fun _ => j)=0 := by + have h : b=0 ∨ b=allSide := by simpa [evenP] using h + rcases h with h|h + · rw [h,zero_dotProduct] + simp only [h,dotProduct,Fintype.sum_bool,allSide,one_mul,char_two] + obtain ⟨ha,hb⟩ := Finset.mem_product.mp h + unfold quadPhase quadDot repeatQ + dsimp only + rw [he _ ha,he _ hb]; simp + +private theorem even_sum (x : Quad) (i : F) : + ∑ v∈evenQ,quadPhase v x*quadPhase v (repeatQ i)=4*ind (repeated x) := by + classical + let f (x : Party) (v : Party) := wsign (dotProduct v x) + have hh (x) : + ∑ v∈evenP,f x v=2*ind (dotProduct allSide x=0) := by + have hn : allSide≠0 := by + intro e + have hh := congr_fun e true + change (1:F)=0 at hh; simp at hh + simp only [evenP,Finset.sum_insert (show (0:Party)∉ ({allSide}:Finset _) from + fun h => hn (mem_singleton.mp h).symm),Finset.sum_singleton,f, zero_dotProduct, wsign_zero] + by_cases ht : dotProduct allSide x=0 + · norm_num [ind,ht] + norm_num [ind,ht,wsign] + have ht (v : Quad) (h : v∈evenQ) : quadPhase v x * quadPhase v (repeatQ i) + = f x.1 v.1 * f x.2 v.2 := by + rw [even_dot x _ h,mul_one,quadPhase,quadDot,wsign_add] + rw [Finset.sum_congr (g:=fun v => f x.1 v.1 * f x.2 v.2) rfl ht,evenQ, Finset.sum_product] + simp_rw [← Finset.mul_sum] + rw [← Finset.sum_mul,hh,hh,repeated,ind_and]; ring + +set_option maxHeartbeats 800000 in +theorem tiny_pattern (p : Shape) {n N} (Δ : UnitType p n N→Ambient p N) (w) + (i : F) {h : ℝ} (h0 : 0≤h) + (hw : ∀ i : Bool,∀ R, |pitch p Δ w (unary i) R|≤h) : + (1/4:ℝ)*pr (pairW w w) (fun x => repeated (quench p Δ x))-h ≤ + pr (pairW w w) (fun x => quench p Δ x=repeatQ i) := by + classical + let f (v : Quad) := pitch p Δ w v.1 v.2*quadPhase v (repeatQ i) + let μ := pairW w w + let g (S : Quad) := ind (S∈evenQ)*f S + have he (x : Quad) : g x - h ≤ f x := by + by_cases hx : x∈evenQ + · unfold g; rw [ind_one hx,one_mul] + exact sub_le_self _ h0 + have hi : |pitch p Δ w x.1 x.2|≤h := by + by_cases he : x.1∈evenP + · obtain ⟨i,hit⟩ := party_single x.2 (fun hh => hx (Finset.mem_product.mpr ⟨he,hh⟩)) + rw [hit,pitch_turn] + exact hw i _ + obtain ⟨i,hi⟩ := party_single _ he + rw [hi]; exact hw i _ + have hs : |f x|≤h := by unfold f quadPhase; rwa [abs_mul,wsign_abs,mul_one] + unfold g; rw [ind_zero hx,zero_mul,zero_sub] + exact (abs_le.mp hs).1 + have hg : avg unif g=(1/4:ℝ)*pr μ (fun x => repeated (quench p Δ x)) := by + have ht : ∑ x : Quad,g x= ∑ x∈evenQ,f x := by + symm + simp only [g,ind,ite_mul,one_mul,zero_mul,← Finset.sum_filter] + simp + have hB (x : Quad) : + f x=avg μ (fun y => quadPhase x (quench p Δ y)*quadPhase x (repeatQ i)) := by + rw [avg_mul]; simp_rw [joint_phase]; rfl + have hf : ∑ x∈evenQ,f x=4*pr μ (fun x => repeated (quench p Δ x)) := by + simp_rw [hB,← avg_sum,even_sum,avg_mul']; rfl + simp only [avg,quad_rate,← Finset.mul_sum, ht,hf] + unfold pr avg + ring + rw [quad_invert,show _*pr _ _=_ from hg.symm] + calc avg unif g - h = avg unif (fun x => g x-h) := by rw [avg_sub,unif_law.avg_const] + _ ≤ _ := avg_mono unif_law.nz he + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FrameIntersectionBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FrameIntersectionBounds.lean index 32b8f44d3040c331968ec95594b1113e081c0283..a3107f65c22a6d8437d9e1f2e2bb42e0898c2553 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FrameIntersectionBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FrameIntersectionBounds.lean @@ -1,149 +1,149 @@ -import OAI.Combinatorics.HadwigerCounterexample.TensorIntersections -import OAI.Combinatorics.HadwigerCounterexample.ConstructionScales - -namespace OAI - -/-! # Frame Intersection Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap -open scoped BigOperators - -/-- Standard embedding padded by zeros. -/ -theorem pad_matrix_inj (a b : ℕ) (h : a ≤ b) : - ∃ M : Mat (Fin b) (Fin a), Function.Injective M.mulVec := by - let M : Mat (Fin b) (Fin a) := (1:Mat (Fin b) (Fin b)).submatrix _root_.id (Fin.castLE h) - have hf : Function.Injective (1:Mat (Fin b) (Fin b)).mulVec := by intro i j he; simpa using he - refine ⟨M,Matrix.mulVec_injective_iff.mpr ?_⟩ - exact (Matrix.mulVec_injective_iff.mp hf).comp (Fin.castLE h) (Fin.castLE_injective h) - -theorem bounded_pack {I : Type} [Fintype I] (S : Space (Vec I)) (k : ℕ) : - ∃ M : Mat I (Fin k), colSp M ≤ S ∧ dim (colSp M) = min (dim S) k := by - have h (M : Mat (Fin (dim S)) (Fin k)) : colSp (pack S*M) ≤ S := by - rw [colSp,mulVecLin_mul,LinearMap.range_comp] - apply le_trans (Submodule.map_mono (show _ ≤ ⊤ from le_top)) - rw [←LinearMap.range_eq_map] - exact (colSp_pack S).le - by_cases hs : dim S ≤ k - · obtain ⟨M,hM⟩ := pad_matrix_inj _ _ hs - refine ⟨pack S * Mᵀ,h _,?_⟩ - have hg : Function.Surjective Mᵀ.mulVecLin := transpose_surj_iff.mpr hM - have hh : colSp (pack S * Mᵀ) = S := by - rw [colSp,mulVecLin_mul,LinearMap.range_comp, - LinearMap.range_eq_top.mpr hg,← LinearMap.range_eq_map]; exact colSp_pack S - rw [hh,min_eq_left hs] - · obtain ⟨M,hM⟩ := pad_matrix_inj _ _ (by omega : k ≤ dim S) - refine ⟨pack S * M,h _,?_⟩ - have hh := mrk_inj.mp (inj_comp_mat _ _ (pack_inj S) hM) - rw [colSp_dim,hh,Fintype.card_fin,min_eq_right (by omega)] - -variable {p : Shape} {n N : ℕ} - -abbrev KCand (p : Shape) (n t : ℕ) := Comp p.g → Mat (JointIdx p n) (Fin t) - -def zeroPin {t : ℕ} (f : KCand p n t) : Pin p n N := - ⟨fun z => if z.2 then colSp (f z.1) else ⊥,0⟩ - -theorem largeJoin_pin {t : ℕ} {x : UnitType p n N} (h : t ≤ joins x) : - ∃ g : KCand p n t, - (t ≤ planRank (zeroPin (N:=N) g).sp) ∧ (zeroPin g).agree x := by - classical - choose M hM hg using (fun i : Comp p.g => - bounded_pack (ker (images x (i,true)).mulVecLin) t) - let d (i : Comp p.g) := dim (ker (images x (i,true)).mulVecLin) - refine ⟨M, ?_, ?_⟩ - · unfold planRank - rw [Fintype.sum_prod_type] - simp only [Fintype.sum_bool] - change t ≤ ∑ i : Comp p.g, (dim (colSp (M i))+dim (⊥ : Submodule F (Dir p n))) - have hb : dim (⊥ : Submodule F (Dir p n)) = 0 := finrank_bot _ _ - simp_rw [hb,add_zero,hg] - change t ≤ ∑ i, min (d i) t - by_cases hh : ∃ i, t ≤ d i - · obtain ⟨i,h⟩ := hh - exact (min_eq_right h).symm.le.trans - (Finset.single_le_sum (fun i _ => Nat.zero_le (min (d i) t)) (Finset.mem_univ _)) - · push Not at hh - simp_rw [min_eq_left (hh _).le]; exact h - · rintro ⟨i,_|_⟩ a ha - · change a ∈ (⊥ : Submodule _ _) at ha - have he : a = 0 := by simpa using ha - rw [he,Matrix.mulVec_zero,Matrix.mulVec_zero] - · have he := hM i (show a ∈ colSp (M i) from (by simpa only [zeroPin,↓reduceIte] using ha)) - change _ = (0:Mat _ _)*ᵥ_ - rw [Matrix.zero_mulVec] - exact he - -theorem num_kcand (p : Shape) (n t : ℕ) : - num (KCand p n t) = bp (num (Comp p.g) * (2*num (Full p n)) * t) := by - have heq : Fintype.card (KCand p n t) = - Fintype.card (Mat (JointIdx p n) (Fin t)) ^ Fintype.card (Comp p.g) := - Fintype.card_fun - unfold num; rw [heq] - push_cast - rw [card_space, dim_mat, ← bp_mul_nat] - have h : Fintype.card (JointIdx p n) = 2*Fintype.card (Full p n) := - (Fintype.card_sum ..).trans (two_mul _).symm - rw [h,Fintype.card_fin] - push_cast; ring_nf - -theorem raw_join_cap (m : Mixer p n) (H : ∀ a : Pin p n N, - pr (pairW (raw m N) (raw m N)) a.agree ≤ bp (-(1-1/8)*(planRank a.sp)*N)) (t : ℕ) : - pr (pairW (raw m N) (raw m N)) (fun x => t ≤ joins x) ≤ - bp (num (Comp p.g)*(2*num (Full p n))*t - (1-1/8)*t*N) := by - classical - let w := pairW (raw m N) (raw m N) - have hw (x) : 0 ≤ w x := mul_nonneg (raw_nonneg _ _) (raw_nonneg _ _) - have hh (c : KCand p n t) : - pr w (fun x => t ≤ planRank (zeroPin (N:=N) c).sp ∧ (zeroPin c).agree x) ≤ - bp (-(1-1/8)*(t:ℝ)*N) := by - by_cases h : t ≤ planRank (zeroPin (N:=N) c).sp - · simp only [h,true_and] - apply le_trans (H _) - apply bp_le - have ht : (t:ℝ) ≤ planRank (zeroPin (N:=N) c).sp := by exact_mod_cast h - apply mul_le_mul_of_nonneg_right _ (by positivity) - linarith only [ht] - · simp only [h,false_and,pr_false] - exact (bp_pos _).le - refine (le_trans (pr_mono (w:=w) hw (fun _ => largeJoin_pin)) (pr_exists_le hw _)).trans - ((Finset.sum_le_sum (fun i _ => hh i)).trans_eq ?_) - rw [sub_eq_add_neg (num (Comp p.g)*(2*num (Full p n))*t),bp_add,← num_kcand] - simp only [Finset.sum_const, Finset.card_univ,nsmul_eq_mul,num] - rw [neg_mul,neg_mul] - -open Filter -/-- The stronger join restriction is exponentially likely under the stated joint cap. -/ -theorem sparse_usual (p : Shape) (D : ℕ) (hd : 0 < D) : - ∀ᶠ M : ℕ in atTop, ∀ᶠ n : ℕ in atTop, let N := M*n; - ∀ (m : Mixer p n) (w : Wgt (UnitType p n N)), - (∀ x, w x ≤ bp ((D:ℝ)*N) * pairW (raw m N) (raw m N) x) → - pr w (fun x => 2*D < joins x) ≤ bp (-(D:ℝ)/2*N) := by - have H := raw_ready p (δ:=1/8) (by norm_num) - let a := num (Comp p.g)*4*D - have hd' : 0 < (D:ℝ)/4 := by positivity - have hA := columns_budget p hd' a 0 (by dsimp [a,num]; positivity) (by norm_num) - filter_upwards [H,hA] with M hM ha - filter_upwards [hM,eventually_ge_atTop 1] with n hn hn' - specialize ha n hn' - rw [add_zero] at ha - intro N m w h - let v := (pairW (raw m N) (raw m N)) - have hi := pr_cap (v:=v) h (fun x => 2*D < joins x) - refine hi.trans ?_ - have hv (x) : 0 ≤ v x := mul_nonneg (raw_nonneg _ _) (raw_nonneg _ _) - apply le_trans (mul_le_mul_of_nonneg_left (le_trans - (pr_mono hv (p:=fun x => 2*D 2*D≤joins x) (fun _ => le_of_lt)) - (raw_join_cap m (hn.2 m).2 (2*D))) (bp_pos _).le) - rw [←bp_add] - apply bp_le - unfold a at ha - unfold N; push_cast at ha ⊢ - linarith only [ha] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.TensorIntersections +import OAI.Combinatorics.HadwigerCounterexample.ConstructionScales + +namespace OAI + +/-! # Frame Intersection Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap +open scoped BigOperators + +/-- Standard embedding padded by zeros. -/ +theorem pad_matrix_inj (a b : ℕ) (h : a ≤ b) : + ∃ M : Mat (Fin b) (Fin a), Function.Injective M.mulVec := by + let M : Mat (Fin b) (Fin a) := (1:Mat (Fin b) (Fin b)).submatrix _root_.id (Fin.castLE h) + have hf : Function.Injective (1:Mat (Fin b) (Fin b)).mulVec := by intro i j he; simpa using he + refine ⟨M,Matrix.mulVec_injective_iff.mpr ?_⟩ + exact (Matrix.mulVec_injective_iff.mp hf).comp (Fin.castLE h) (Fin.castLE_injective h) + +theorem bounded_pack {I : Type} [Fintype I] (S : Space (Vec I)) (k : ℕ) : + ∃ M : Mat I (Fin k), colSp M ≤ S ∧ dim (colSp M) = min (dim S) k := by + have h (M : Mat (Fin (dim S)) (Fin k)) : colSp (pack S*M) ≤ S := by + rw [colSp,mulVecLin_mul,LinearMap.range_comp] + apply le_trans (Submodule.map_mono (show _ ≤ ⊤ from le_top)) + rw [←LinearMap.range_eq_map] + exact (colSp_pack S).le + by_cases hs : dim S ≤ k + · obtain ⟨M,hM⟩ := pad_matrix_inj _ _ hs + refine ⟨pack S * Mᵀ,h _,?_⟩ + have hg : Function.Surjective Mᵀ.mulVecLin := transpose_surj_iff.mpr hM + have hh : colSp (pack S * Mᵀ) = S := by + rw [colSp,mulVecLin_mul,LinearMap.range_comp, + LinearMap.range_eq_top.mpr hg,← LinearMap.range_eq_map]; exact colSp_pack S + rw [hh,min_eq_left hs] + · obtain ⟨M,hM⟩ := pad_matrix_inj _ _ (by omega : k ≤ dim S) + refine ⟨pack S * M,h _,?_⟩ + have hh := mrk_inj.mp (inj_comp_mat _ _ (pack_inj S) hM) + rw [colSp_dim,hh,Fintype.card_fin,min_eq_right (by omega)] + +variable {p : Shape} {n N : ℕ} + +abbrev KCand (p : Shape) (n t : ℕ) := Comp p.g → Mat (JointIdx p n) (Fin t) + +def zeroPin {t : ℕ} (f : KCand p n t) : Pin p n N := + ⟨fun z => if z.2 then colSp (f z.1) else ⊥,0⟩ + +theorem largeJoin_pin {t : ℕ} {x : UnitType p n N} (h : t ≤ joins x) : + ∃ g : KCand p n t, + (t ≤ planRank (zeroPin (N:=N) g).sp) ∧ (zeroPin g).agree x := by + classical + choose M hM hg using (fun i : Comp p.g => + bounded_pack (ker (images x (i,true)).mulVecLin) t) + let d (i : Comp p.g) := dim (ker (images x (i,true)).mulVecLin) + refine ⟨M, ?_, ?_⟩ + · unfold planRank + rw [Fintype.sum_prod_type] + simp only [Fintype.sum_bool] + change t ≤ ∑ i : Comp p.g, (dim (colSp (M i))+dim (⊥ : Submodule F (Dir p n))) + have hb : dim (⊥ : Submodule F (Dir p n)) = 0 := finrank_bot _ _ + simp_rw [hb,add_zero,hg] + change t ≤ ∑ i, min (d i) t + by_cases hh : ∃ i, t ≤ d i + · obtain ⟨i,h⟩ := hh + exact (min_eq_right h).symm.le.trans + (Finset.single_le_sum (fun i _ => Nat.zero_le (min (d i) t)) (Finset.mem_univ _)) + · push Not at hh + simp_rw [min_eq_left (hh _).le]; exact h + · rintro ⟨i,_|_⟩ a ha + · change a ∈ (⊥ : Submodule _ _) at ha + have he : a = 0 := by simpa using ha + rw [he,Matrix.mulVec_zero,Matrix.mulVec_zero] + · have he := hM i (show a ∈ colSp (M i) from (by simpa only [zeroPin,↓reduceIte] using ha)) + change _ = (0:Mat _ _)*ᵥ_ + rw [Matrix.zero_mulVec] + exact he + +theorem num_kcand (p : Shape) (n t : ℕ) : + num (KCand p n t) = bp (num (Comp p.g) * (2*num (Full p n)) * t) := by + have heq : Fintype.card (KCand p n t) = + Fintype.card (Mat (JointIdx p n) (Fin t)) ^ Fintype.card (Comp p.g) := + Fintype.card_fun + unfold num; rw [heq] + push_cast + rw [card_space, dim_mat, ← bp_mul_nat] + have h : Fintype.card (JointIdx p n) = 2*Fintype.card (Full p n) := + (Fintype.card_sum ..).trans (two_mul _).symm + rw [h,Fintype.card_fin] + push_cast; ring_nf + +theorem raw_join_cap (m : Mixer p n) (H : ∀ a : Pin p n N, + pr (pairW (raw m N) (raw m N)) a.agree ≤ bp (-(1-1/8)*(planRank a.sp)*N)) (t : ℕ) : + pr (pairW (raw m N) (raw m N)) (fun x => t ≤ joins x) ≤ + bp (num (Comp p.g)*(2*num (Full p n))*t - (1-1/8)*t*N) := by + classical + let w := pairW (raw m N) (raw m N) + have hw (x) : 0 ≤ w x := mul_nonneg (raw_nonneg _ _) (raw_nonneg _ _) + have hh (c : KCand p n t) : + pr w (fun x => t ≤ planRank (zeroPin (N:=N) c).sp ∧ (zeroPin c).agree x) ≤ + bp (-(1-1/8)*(t:ℝ)*N) := by + by_cases h : t ≤ planRank (zeroPin (N:=N) c).sp + · simp only [h,true_and] + apply le_trans (H _) + apply bp_le + have ht : (t:ℝ) ≤ planRank (zeroPin (N:=N) c).sp := by exact_mod_cast h + apply mul_le_mul_of_nonneg_right _ (by positivity) + linarith only [ht] + · simp only [h,false_and,pr_false] + exact (bp_pos _).le + refine (le_trans (pr_mono (w:=w) hw (fun _ => largeJoin_pin)) (pr_exists_le hw _)).trans + ((Finset.sum_le_sum (fun i _ => hh i)).trans_eq ?_) + rw [sub_eq_add_neg (num (Comp p.g)*(2*num (Full p n))*t),bp_add,← num_kcand] + simp only [Finset.sum_const, Finset.card_univ,nsmul_eq_mul,num] + rw [neg_mul,neg_mul] + +open Filter +/-- The stronger join restriction is exponentially likely under the stated joint cap. -/ +theorem sparse_usual (p : Shape) (D : ℕ) (hd : 0 < D) : + ∀ᶠ M : ℕ in atTop, ∀ᶠ n : ℕ in atTop, let N := M*n; + ∀ (m : Mixer p n) (w : Wgt (UnitType p n N)), + (∀ x, w x ≤ bp ((D:ℝ)*N) * pairW (raw m N) (raw m N) x) → + pr w (fun x => 2*D < joins x) ≤ bp (-(D:ℝ)/2*N) := by + have H := raw_ready p (δ:=1/8) (by norm_num) + let a := num (Comp p.g)*4*D + have hd' : 0 < (D:ℝ)/4 := by positivity + have hA := columns_budget p hd' a 0 (by dsimp [a,num]; positivity) (by norm_num) + filter_upwards [H,hA] with M hM ha + filter_upwards [hM,eventually_ge_atTop 1] with n hn hn' + specialize ha n hn' + rw [add_zero] at ha + intro N m w h + let v := (pairW (raw m N) (raw m N)) + have hi := pr_cap (v:=v) h (fun x => 2*D < joins x) + refine hi.trans ?_ + have hv (x) : 0 ≤ v x := mul_nonneg (raw_nonneg _ _) (raw_nonneg _ _) + apply le_trans (mul_le_mul_of_nonneg_left (le_trans + (pr_mono hv (p:=fun x => 2*D 2*D≤joins x) (fun _ => le_of_lt)) + (raw_join_cap m (hn.2 m).2 (2*D))) (bp_pos _).le) + rw [←bp_add] + apply bp_le + unfold a at ha + unfold N; push_cast at ha ⊢ + linarith only [ha] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FrameIntersectionCosts.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FrameIntersectionCosts.lean index e171888b2a8cc242f648625247d4374b0860d355..1637e7f00de976b8b001df5b8229e88fe65b0732 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FrameIntersectionCosts.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FrameIntersectionCosts.lean @@ -1,202 +1,202 @@ -import OAI.Combinatorics.HadwigerCounterexample.ProbePointMasses - -namespace OAI - -/-! # Frame Intersection Costs -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Finset Function -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I J K : Type} [Fintype I] [Fintype J] [Fintype K] - -private theorem prod_one {A I : Type} [Fintype I] [DecidableEq I] [Fintype A] - (f : I → Wgt A) (hf : ∀ i,IsLaw (f i)) (i : I) : - mapW (prodW f) (fun g => g i)=f i := by - classical - funext x - let q (j : I) (y : A) := if j=i then y=x else True - have hh : (fun f : I→A => f i=x)=fun f : I→A => ∀ j,q j (f j) := by - funext g - apply propext; constructor - · intro h j; unfold q; split_ifs with he - · rwa [he] - intro h; simpa only [q,ite_eq_left rfl] using h i - unfold mapW - rw [hh,prodW_pr f q,Finset.prod_eq_single i] - · simp [q] - · intro j _ hj - simp [q,hj,(hf j).total] - simp - -/-- Raw law of a single-sign observation of primary/channel columns. -/ -theorem raw_part (m : Mixer p n) (z : Place p) [DecidableEq I] - (hN : 2*num (Full p n)-N≤ -1) - {A : Mat (Full p n) I} (hA : Injective A.mulVec) : - mapW (raw m N) (fun x => takeSign (p:=p) (x z.1) z.2 * A)= - unifOn (fun x => Injective x.mulVec) := by - classical - let w := unifOn (FramesAt (U:=Fin N) (gramCond m)) - have he : 2*num (Full p n)-num (Fin N) ≤ -1 := by simpa only [num,Fintype.card_fin] using hN - have h : ∃ x : Oframe p n N, FramesAt (gramCond m) x := framesAt_exists - (gramCond_exists m) (by linarith only [he]) - have hF := prod_one (fun (_ : Comp p.g) => w) (fun _ => unifOn_law h) z.1 - let g := fun o : Oframe p n N => takeSign o z.2 * A - change mapW (raw m N) (g ∘ (fun x => x z.1))=_ - rw [← mapW_nested] - rw [show mapW (raw m N) (fun x => x z.1)=w from hF] - cases z with - | mk e c => - cases c; exact framesAt_observe_minus h hA; exact framesAt_observe_plus h hA - -private def ipPart (p : Shape) (n : ℕ) : Mat (Full p n) (Row p n) := - embedMat (.inl ·) - -theorem frameP_cap {w : Wgt (UnitType p n N)} (m : Mixer p n) {H : ℝ} (hH : 0≤H) - (h : bySide p w m H) (i : Bool) (z : Place p) (hN : 2*num (Full p n)-N≤ -1) : - ∀ y,mapW w (fun x => fpAt p (onSide x i) z) y≤H*(2 * unif y) := by - classical - intro y - let g := fun x : UnitType p n N => onSide x i - let f := fun x : Orient p n N => fpAt p x z - have hg : num (Row p n)-num (Fin N)≤ -1 := by - have hi : num (Row p n) ≤ num (Full p n) := by - have h := Fintype.card_le_of_injective _ (Sum.inl_injective (β:=Fin p.h) - (α:=Row p n)) - exact_mod_cast h - have hh : 0≤num (Full p n) := Nat.cast_nonneg _ - simp only [num,Fintype.card_fin] at hN hi hh ⊢; linarith - change mapW w (f ∘ g) _ ≤ _ - rw [← mapW_nested] - apply (mapW_cap (h i) f y).trans - have hf (x : Orient p n N) : - f x=takeSign (p:=p) (x z.1) z.2 * ipPart p n := by - rw [ipPart,mul_embedMat]; rfl - rw [show f=(fun x : Orient p n N => takeSign (p:=p) (x z.1) z.2 * ipPart p n) from funext hf] - rw [raw_part m z hN (A:=ipPart p n) (embedMat_inj Sum.inl_injective)] - exact mul_le_mul_of_nonneg_left (plus_le_unif hg y) hH - -theorem frameY_cap {w : Wgt (UnitType p n N)} (m : Mixer p n) {H : ℝ} (hH : 0≤H) - (h : bySide p w m H) (i : Bool) (z : Place p) (hN : 2*num (Full p n)-N≤ -1) : - ∀ y,mapW w (fun x => fyAt p (onSide x i) z) y≤H*(2 * unif y) := by - classical - intro y - let g := fun x : UnitType p n N => onSide x i - let f := fun x : Orient p n N => fyAt p x z - have hg : num (Fin p.h)-num (Fin N)≤ -1 := by - have hi : num (Fin p.h) ≤ num (Full p n) := by - have h := Fintype.card_le_of_injective _ (Sum.inr_injective (β:=Fin p.h) - (α:=Row p n)); exact_mod_cast h - have hh : 0≤num (Full p n) := Nat.cast_nonneg _ - simp only [num,Fintype.card_fin] at hN hi hh ⊢; linarith - change mapW w (f ∘ g) _ ≤ _ - rw [← mapW_nested] - apply (mapW_cap (h i) f y).trans - have hf (x : Orient p n N) : - f x=takeSign (p:=p) (x z.1) z.2 * intoChan p n := (intoChan_val ..).symm - rw [show f=(fun x : Orient p n N => takeSign (p:=p) (x z.1) z.2 * intoChan p n) from funext hf] - rw [raw_part m z hN (A:=intoChan p n) intoChan_inj] - exact mul_le_mul_of_nonneg_left (plus_le_unif hg y) hH - -variable [DecidableEq I] [DecidableEq J] [DecidableEq K] - -theorem any_span_hit (S : Space (Vec I)) : - pr unif (fun M : Mat I J => ¬ Disjoint (colSp M) S) ≤ bp (num J+dim S-num I) := by - classical - let P := fun (z : Vec J × S) (M : Mat I J) => z.1≠0 ∧ M *ᵥ z.1=z.2.val - have h (M : Mat I J) : ¬ Disjoint (colSp M) S → ∃ z,P z M := by - intro h - rw [Submodule.disjoint_def] at h - push Not at h - obtain ⟨x,⟨y,rfl⟩,hy,hx⟩ := h - have hh : y≠0 := fun h => hx (by rw [h,map_zero]) - exact ⟨(y,⟨_,hy⟩),hh,rfl⟩ - have he (z : Vec J × S) : pr unif (P z) ≤ bp (-num I) := by - by_cases hh : z.1=0 - · simp only [P,hh,ne_eq,not_true_eq_false,false_and,pr_false] - exact (bp_pos _).le - have h' := shift_pmax (@unif_subLaw (Mat I J) _) ⊤ (fun _ _ _ => rfl) hh z.2.val - rw [show dim (⊤ : Space (Vec I))=_ from (finrank_top ..).trans (dim_vec _)] at h' - simpa only [P,hh,ne_eq,not_false_eq_true,true_and] using h' - refine ((pr_mono unif_subLaw.nz h).trans (pr_exists_le unif_subLaw.nz P)).trans ?_ - refine (Finset.sum_le_sum fun i _ => he i).trans_eq ?_ - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,Fintype.card_prod, - Nat.cast_mul,card_space,dim_vec,bp_sub,bp_add,bp_neg,num,div_eq_mul_inv] - -def expand (P : Mat I J) (K : Type) : Mat I K →ₗ[F] Mat K J where - toFun X := Xᵀ*P - map_add' a b := by rw [Matrix.transpose_add,Matrix.add_mul] - map_smul' a b := by rw [Matrix.transpose_smul,Matrix.smul_mul]; rfl - -theorem transposed_uniform {P : Mat I J} (hp : Injective P.mulVec) : - mapW (unif : Wgt (Mat I K)) (fun x => xᵀ*P)=unif := by - obtain ⟨L,hL⟩ := mat_left_inv hp - apply map_unif_surjective (expand P K) - intro v - exact ⟨(v*L)ᵀ,by change ((v*L)ᵀ)ᵀ*P=v; rw [transpose_transpose,Matrix.mul_assoc,hL,Matrix.mul_one]⟩ - -/-- per fixed nominal offsets in one component/side -/ -theorem test_transpose {w : Wgt (UnitType p n N)} (m : Mixer p n) {H : ℝ} (hH : 0≤H) - (h : bySide p w m H) (i : Bool) (z : Place p) (hN : 2*num (Full p n)-N≤ -1) - (M : Mat (Fin N) I) (hM : Injective M.mulVec) : - ∀ x,mapW w (fun y => (fyAt p (onSide y i) z)ᵀ * M) x≤H*2 * unif x := by - intro x - let f (y : HMat p N) := yᵀ * M - let g (x : UnitType p n N) := fyAt p (onSide x i) z - change mapW w (f ∘ g) _ ≤ _ - rw [←mapW_nested] - have he := frameY_cap m hH h i z hN - simp_rw [← mul_assoc] at he - refine (mapW_cap he f x).trans_eq ?_ - rw [show mapW unif f=unif from transposed_uniform hM] - -def glimpsesBill (p : Shape) (k : ℕ) (H : ℝ) := - num (Place p)*(H*2*bp ((k:ℝ)-p.h)) - -theorem glimpse_failure {w : Wgt (UnitType p n N)} (m : Mixer p n) {H : ℝ} (hH : 0≤H) - (h : bySide p w m H) (hw : SubLaw w) (i : Bool) (hN : 2*num (Full p n)-N≤ -1) - {q : Place p→ℕ} (M : DTuple (p:=p) q N) (k : ℕ) (hm : ∀ z,Injective (M z).mulVec) - (hk : ∀ z,q z≤k) : - pr w (fun x => ¬ glimpse p x i M) ≤ glimpsesBill p k H := by - classical - let P (A : Place p) := - fun x => ¬Injective ((fyAt p (onSide (x : UnitType p n N) i) (flipZ p A))ᵀ * M A).mulVec - have he x : ¬ glimpse p x i M → ∃ z,P z x := by - intro h - unfold glimpse at h - push Not at h - exact h - have hi z : pr w (P z) ≤ H*2*bp ((k:ℝ)-p.h) := by - let f (x : UnitType p n N) := (fyAt p (onSide x i) (flipZ p z))ᵀ*M z - let Q := fun x : Mat (Chan p) (Fin (q z)) => ¬ Injective x.mulVec - change pr w (Q ∘ f) ≤ _ - rw [show pr w (Q ∘ f)=pr (mapW w f) Q from (mapW_pr w f Q).symm] - refine (pr_cap (test_transpose m hH h i (flipZ p z) hN _ (hm z)) Q).trans - (mul_le_mul_of_nonneg_left (unif_fail.trans ?_) (by positivity)) - apply bp_le - have hh : (q z:ℝ)≤k := by exact_mod_cast hk z - simpa [Chan,num] using sub_le_sub_right hh (p.h:ℝ) - refine ((pr_mono hw.nz he).trans (pr_exists_le hw.nz P)).trans ?_ - refine (Finset.sum_le_sum fun i _ => hi i).trans_eq ?_ - simp only [Finset.sum_const,Finset.card_univ, nsmul_eq_mul,glimpsesBill,num] - -/-- span of entire individual primary image in a fixed cover mode. -/ -theorem any_frame_hit {w : Wgt (UnitType p n N)} (m : Mixer p n) {H : ℝ} (hH : 0≤H) - (h : bySide p w m H) (i : Bool) (z : Place p) (hN : 2*num (Full p n)-N≤ -1) - (S : Space (Vec (Fin N))) : - pr w (fun x => ¬ Disjoint (imageP p x i z) S) ≤ - H*2*bp (num (Row p n)+dim S-N) := by - let P (M : Mat (Fin N) (Row p n)) := ¬ Disjoint (colSp M) S - let f (x : UnitType p n N) := fpAt p (onSide x i) z - change pr w (fun x => P (f x)) ≤ _ - rw [← mapW_pr w f P] - have he := frameP_cap m hH h i z hN - simp_rw [← mul_assoc] at he - refine (pr_cap he P).trans (mul_le_mul_of_nonneg_left ?_ (by positivity)) - simpa only [num,Fintype.card_fin] using any_span_hit (J:=Row p n) S - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ProbePointMasses + +namespace OAI + +/-! # Frame Intersection Costs -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Finset Function +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I J K : Type} [Fintype I] [Fintype J] [Fintype K] + +private theorem prod_one {A I : Type} [Fintype I] [DecidableEq I] [Fintype A] + (f : I → Wgt A) (hf : ∀ i,IsLaw (f i)) (i : I) : + mapW (prodW f) (fun g => g i)=f i := by + classical + funext x + let q (j : I) (y : A) := if j=i then y=x else True + have hh : (fun f : I→A => f i=x)=fun f : I→A => ∀ j,q j (f j) := by + funext g + apply propext; constructor + · intro h j; unfold q; split_ifs with he + · rwa [he] + intro h; simpa only [q,ite_eq_left rfl] using h i + unfold mapW + rw [hh,prodW_pr f q,Finset.prod_eq_single i] + · simp [q] + · intro j _ hj + simp [q,hj,(hf j).total] + simp + +/-- Raw law of a single-sign observation of primary/channel columns. -/ +theorem raw_part (m : Mixer p n) (z : Place p) [DecidableEq I] + (hN : 2*num (Full p n)-N≤ -1) + {A : Mat (Full p n) I} (hA : Injective A.mulVec) : + mapW (raw m N) (fun x => takeSign (p:=p) (x z.1) z.2 * A)= + unifOn (fun x => Injective x.mulVec) := by + classical + let w := unifOn (FramesAt (U:=Fin N) (gramCond m)) + have he : 2*num (Full p n)-num (Fin N) ≤ -1 := by simpa only [num,Fintype.card_fin] using hN + have h : ∃ x : Oframe p n N, FramesAt (gramCond m) x := framesAt_exists + (gramCond_exists m) (by linarith only [he]) + have hF := prod_one (fun (_ : Comp p.g) => w) (fun _ => unifOn_law h) z.1 + let g := fun o : Oframe p n N => takeSign o z.2 * A + change mapW (raw m N) (g ∘ (fun x => x z.1))=_ + rw [← mapW_nested] + rw [show mapW (raw m N) (fun x => x z.1)=w from hF] + cases z with + | mk e c => + cases c; exact framesAt_observe_minus h hA; exact framesAt_observe_plus h hA + +private def ipPart (p : Shape) (n : ℕ) : Mat (Full p n) (Row p n) := + embedMat (.inl ·) + +theorem frameP_cap {w : Wgt (UnitType p n N)} (m : Mixer p n) {H : ℝ} (hH : 0≤H) + (h : bySide p w m H) (i : Bool) (z : Place p) (hN : 2*num (Full p n)-N≤ -1) : + ∀ y,mapW w (fun x => fpAt p (onSide x i) z) y≤H*(2 * unif y) := by + classical + intro y + let g := fun x : UnitType p n N => onSide x i + let f := fun x : Orient p n N => fpAt p x z + have hg : num (Row p n)-num (Fin N)≤ -1 := by + have hi : num (Row p n) ≤ num (Full p n) := by + have h := Fintype.card_le_of_injective _ (Sum.inl_injective (β:=Fin p.h) + (α:=Row p n)) + exact_mod_cast h + have hh : 0≤num (Full p n) := Nat.cast_nonneg _ + simp only [num,Fintype.card_fin] at hN hi hh ⊢; linarith + change mapW w (f ∘ g) _ ≤ _ + rw [← mapW_nested] + apply (mapW_cap (h i) f y).trans + have hf (x : Orient p n N) : + f x=takeSign (p:=p) (x z.1) z.2 * ipPart p n := by + rw [ipPart,mul_embedMat]; rfl + rw [show f=(fun x : Orient p n N => takeSign (p:=p) (x z.1) z.2 * ipPart p n) from funext hf] + rw [raw_part m z hN (A:=ipPart p n) (embedMat_inj Sum.inl_injective)] + exact mul_le_mul_of_nonneg_left (plus_le_unif hg y) hH + +theorem frameY_cap {w : Wgt (UnitType p n N)} (m : Mixer p n) {H : ℝ} (hH : 0≤H) + (h : bySide p w m H) (i : Bool) (z : Place p) (hN : 2*num (Full p n)-N≤ -1) : + ∀ y,mapW w (fun x => fyAt p (onSide x i) z) y≤H*(2 * unif y) := by + classical + intro y + let g := fun x : UnitType p n N => onSide x i + let f := fun x : Orient p n N => fyAt p x z + have hg : num (Fin p.h)-num (Fin N)≤ -1 := by + have hi : num (Fin p.h) ≤ num (Full p n) := by + have h := Fintype.card_le_of_injective _ (Sum.inr_injective (β:=Fin p.h) + (α:=Row p n)); exact_mod_cast h + have hh : 0≤num (Full p n) := Nat.cast_nonneg _ + simp only [num,Fintype.card_fin] at hN hi hh ⊢; linarith + change mapW w (f ∘ g) _ ≤ _ + rw [← mapW_nested] + apply (mapW_cap (h i) f y).trans + have hf (x : Orient p n N) : + f x=takeSign (p:=p) (x z.1) z.2 * intoChan p n := (intoChan_val ..).symm + rw [show f=(fun x : Orient p n N => takeSign (p:=p) (x z.1) z.2 * intoChan p n) from funext hf] + rw [raw_part m z hN (A:=intoChan p n) intoChan_inj] + exact mul_le_mul_of_nonneg_left (plus_le_unif hg y) hH + +variable [DecidableEq I] [DecidableEq J] [DecidableEq K] + +theorem any_span_hit (S : Space (Vec I)) : + pr unif (fun M : Mat I J => ¬ Disjoint (colSp M) S) ≤ bp (num J+dim S-num I) := by + classical + let P := fun (z : Vec J × S) (M : Mat I J) => z.1≠0 ∧ M *ᵥ z.1=z.2.val + have h (M : Mat I J) : ¬ Disjoint (colSp M) S → ∃ z,P z M := by + intro h + rw [Submodule.disjoint_def] at h + push Not at h + obtain ⟨x,⟨y,rfl⟩,hy,hx⟩ := h + have hh : y≠0 := fun h => hx (by rw [h,map_zero]) + exact ⟨(y,⟨_,hy⟩),hh,rfl⟩ + have he (z : Vec J × S) : pr unif (P z) ≤ bp (-num I) := by + by_cases hh : z.1=0 + · simp only [P,hh,ne_eq,not_true_eq_false,false_and,pr_false] + exact (bp_pos _).le + have h' := shift_pmax (@unif_subLaw (Mat I J) _) ⊤ (fun _ _ _ => rfl) hh z.2.val + rw [show dim (⊤ : Space (Vec I))=_ from (finrank_top ..).trans (dim_vec _)] at h' + simpa only [P,hh,ne_eq,not_false_eq_true,true_and] using h' + refine ((pr_mono unif_subLaw.nz h).trans (pr_exists_le unif_subLaw.nz P)).trans ?_ + refine (Finset.sum_le_sum fun i _ => he i).trans_eq ?_ + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,Fintype.card_prod, + Nat.cast_mul,card_space,dim_vec,bp_sub,bp_add,bp_neg,num,div_eq_mul_inv] + +def expand (P : Mat I J) (K : Type) : Mat I K →ₗ[F] Mat K J where + toFun X := Xᵀ*P + map_add' a b := by rw [Matrix.transpose_add,Matrix.add_mul] + map_smul' a b := by rw [Matrix.transpose_smul,Matrix.smul_mul]; rfl + +theorem transposed_uniform {P : Mat I J} (hp : Injective P.mulVec) : + mapW (unif : Wgt (Mat I K)) (fun x => xᵀ*P)=unif := by + obtain ⟨L,hL⟩ := mat_left_inv hp + apply map_unif_surjective (expand P K) + intro v + exact ⟨(v*L)ᵀ,by change ((v*L)ᵀ)ᵀ*P=v; rw [transpose_transpose,Matrix.mul_assoc,hL,Matrix.mul_one]⟩ + +/-- per fixed nominal offsets in one component/side -/ +theorem test_transpose {w : Wgt (UnitType p n N)} (m : Mixer p n) {H : ℝ} (hH : 0≤H) + (h : bySide p w m H) (i : Bool) (z : Place p) (hN : 2*num (Full p n)-N≤ -1) + (M : Mat (Fin N) I) (hM : Injective M.mulVec) : + ∀ x,mapW w (fun y => (fyAt p (onSide y i) z)ᵀ * M) x≤H*2 * unif x := by + intro x + let f (y : HMat p N) := yᵀ * M + let g (x : UnitType p n N) := fyAt p (onSide x i) z + change mapW w (f ∘ g) _ ≤ _ + rw [←mapW_nested] + have he := frameY_cap m hH h i z hN + simp_rw [← mul_assoc] at he + refine (mapW_cap he f x).trans_eq ?_ + rw [show mapW unif f=unif from transposed_uniform hM] + +def glimpsesBill (p : Shape) (k : ℕ) (H : ℝ) := + num (Place p)*(H*2*bp ((k:ℝ)-p.h)) + +theorem glimpse_failure {w : Wgt (UnitType p n N)} (m : Mixer p n) {H : ℝ} (hH : 0≤H) + (h : bySide p w m H) (hw : SubLaw w) (i : Bool) (hN : 2*num (Full p n)-N≤ -1) + {q : Place p→ℕ} (M : DTuple (p:=p) q N) (k : ℕ) (hm : ∀ z,Injective (M z).mulVec) + (hk : ∀ z,q z≤k) : + pr w (fun x => ¬ glimpse p x i M) ≤ glimpsesBill p k H := by + classical + let P (A : Place p) := + fun x => ¬Injective ((fyAt p (onSide (x : UnitType p n N) i) (flipZ p A))ᵀ * M A).mulVec + have he x : ¬ glimpse p x i M → ∃ z,P z x := by + intro h + unfold glimpse at h + push Not at h + exact h + have hi z : pr w (P z) ≤ H*2*bp ((k:ℝ)-p.h) := by + let f (x : UnitType p n N) := (fyAt p (onSide x i) (flipZ p z))ᵀ*M z + let Q := fun x : Mat (Chan p) (Fin (q z)) => ¬ Injective x.mulVec + change pr w (Q ∘ f) ≤ _ + rw [show pr w (Q ∘ f)=pr (mapW w f) Q from (mapW_pr w f Q).symm] + refine (pr_cap (test_transpose m hH h i (flipZ p z) hN _ (hm z)) Q).trans + (mul_le_mul_of_nonneg_left (unif_fail.trans ?_) (by positivity)) + apply bp_le + have hh : (q z:ℝ)≤k := by exact_mod_cast hk z + simpa [Chan,num] using sub_le_sub_right hh (p.h:ℝ) + refine ((pr_mono hw.nz he).trans (pr_exists_le hw.nz P)).trans ?_ + refine (Finset.sum_le_sum fun i _ => hi i).trans_eq ?_ + simp only [Finset.sum_const,Finset.card_univ, nsmul_eq_mul,glimpsesBill,num] + +/-- span of entire individual primary image in a fixed cover mode. -/ +theorem any_frame_hit {w : Wgt (UnitType p n N)} (m : Mixer p n) {H : ℝ} (hH : 0≤H) + (h : bySide p w m H) (i : Bool) (z : Place p) (hN : 2*num (Full p n)-N≤ -1) + (S : Space (Vec (Fin N))) : + pr w (fun x => ¬ Disjoint (imageP p x i z) S) ≤ + H*2*bp (num (Row p n)+dim S-N) := by + let P (M : Mat (Fin N) (Row p n)) := ¬ Disjoint (colSp M) S + let f (x : UnitType p n N) := fpAt p (onSide x i) z + change pr w (fun x => P (f x)) ≤ _ + rw [← mapW_pr w f P] + have he := frameP_cap m hH h i z hN + simp_rw [← mul_assoc] at he + refine (pr_cap he P).trans (mul_le_mul_of_nonneg_left ?_ (by positivity)) + simpa only [num,Fintype.card_fin] using any_span_hit (J:=Row p n) S + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FrameOrbitLaws.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FrameOrbitLaws.lean index 55e122f2378c4af359257576d45b984fed051e35..5a6c1160bbff438b340324614c81820791ca43a0 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FrameOrbitLaws.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FrameOrbitLaws.lean @@ -1,155 +1,155 @@ -import OAI.Combinatorics.HadwigerCounterexample.GramProbabilities - -namespace OAI - -/-! # Frame Orbit Laws -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Function - -variable {U I J R S : Type} [Fintype U] [Fintype I] [Fintype J] [Fintype R] [Fintype S] - [DecidableEq U] - -def FramesAt (C : Mat I J → Prop) (x : Mat U I × Mat U J) := - C (x.1ᵀ * x.2) ∧ Injective x.1.mulVec ∧ Injective x.2.mulVec - -structure Move (U : Type) [Fintype U] [DecidableEq U] where - L : Mat U U - R : Mat U U - LR : L*R=1 - RL : R*L=1 - -namespace Move -variable (c : Move U) -def sym : Move U := ⟨c.R,c.L,c.RL,c.LR⟩ -def dual : Move U := ⟨c.Rᵀ,c.Lᵀ,by rw [← transpose_mul,c.LR, Matrix.transpose_one], - by rw [← transpose_mul,c.RL,Matrix.transpose_one]⟩ -def permMat (I : Type) : Mat U I ≃ Mat U I where - toFun A := c.L*A - invFun A := c.R*A - left_inv A := by simp only [← Matrix.mul_assoc, c.RL, Matrix.one_mul] - right_inv A := by simp only [← Matrix.mul_assoc, c.LR, Matrix.one_mul] -def perm (I J : Type) : Mat U I × Mat U J ≃ Mat U I × Mat U J := - (c.permMat I).prodCongr (c.dual.permMat J) - -omit [Fintype I] [Fintype J] in -theorem gram_invar (A : Mat U I) (B : Mat U J) : - (c.L*A)ᵀ * (c.Rᵀ*B) = Aᵀ*B := by - rw [transpose_mul,Matrix.mul_assoc,← Matrix.mul_assoc c.Lᵀ c.Rᵀ B,← transpose_mul,c.RL, - Matrix.transpose_one, Matrix.one_mul] - -theorem L_inj : Injective c.L.mulVec := by - intro x y h - have hi (x) : c.R *ᵥ (c.L *ᵥ x) = x := by rw [mulVec_mulVec,c.RL, Matrix.one_mulVec] - change c.L *ᵥ x = c.L *ᵥ y at h - rw [←hi x,h,hi y] - -theorem perm_inj (A : Mat U I) : Injective A.mulVec ↔ Injective (c.L*A).mulVec := by - refine ⟨inj_comp_mat _ _ c.L_inj, fun h => ?_⟩ - have hh := inj_comp_mat _ _ c.sym.L_inj h - change Injective (c.R*(c.L*A)).mulVec at hh - rwa [←Matrix.mul_assoc,c.RL,Matrix.one_mul] at hh - -theorem invar (C : Mat I J → Prop) (x : Mat U I × Mat U J) : - FramesAt C x ↔ FramesAt C (c.perm I J x) := by - unfold FramesAt - change _ ↔ C ((c.L*x.1)ᵀ * (c.Rᵀ*x.2)) ∧ _ - rw [gram_invar] - exact and_congr Iff.rfl (and_congr (c.perm_inj x.1) (c.dual.perm_inj x.2)) -end Move - -/-- Nonempty matrix family if super-dimension slack. -/ -theorem framesAt_exists [DecidableEq I] [DecidableEq J] - {C : Mat I J → Prop} (h : ∃ G, C G) (hn : num I+num J < num U) : - ∃ x : Mat U I × Mat U J, FramesAt C x := by - obtain ⟨G,hG⟩ := h - let v := (pairW unif unif : Wgt (Mat U I × Mat U J)) - have he (a : ℝ) (h : a < 0) : 0 < 1-bp a := sub_pos.mpr - ((bp_lt h).trans_eq bp_zero) - have hpos : 0 < pr v (gramGood G) := by - refine lt_of_lt_of_le ?_ (gram_norm G hn.le).2 - have hi : num I - num U < 0 := by - have hh : 0 ≤ num J := by unfold num; positivity - linarith - exact mul_pos (mul_pos (bp_pos _) (he _ hi)) (he _ (by linarith only [hn])) - obtain ⟨x,hx,_⟩ := exists_of_pr_pos (pairW_law unif_law unif_law).nz hpos - exact ⟨x,hx.1.symm ▸ hG,hx.2⟩ - -theorem move_exists (G : Mat I J) (x y : Mat U I × Mat U J) (hx : gramGood G x) - (hy : gramGood G y) : ∃ c : Move U, c.perm I J x = y := by - obtain ⟨L,R,H,F,E,T⟩ := frame_move hx.2.1 hy.2.1 hx.2.2 hy.2.2 (hx.1.trans hy.1.symm) - exact ⟨⟨L,R,H,F⟩,Prod.ext E T⟩ - -theorem move_exists_one {x y : Mat U I} (hx : Injective x.mulVec) - (hy : Injective y.mulVec) : ∃ c : Move U, c.permMat I x = y := by - let B := (0:Mat U Empty) - let G := (0:Mat I Empty) - have he {x : Mat U I} (hx : Injective x.mulVec) : gramGood G (x,B) := - ⟨Subsingleton.elim _ _, hx, fun a b _ => Subsingleton.elim a b⟩ - obtain ⟨c,hc⟩ := move_exists G _ _ (he hx) (he hy) - exact ⟨c,congrArg Prod.fst hc⟩ - -variable [DecidableEq I] [DecidableEq J] [DecidableEq R] [DecidableEq S] - -def observe (P : Mat I R) (Q : Mat J S) (x : Mat U I × Mat U J) : Mat U R × Mat U S := - (x.1 * P, x.2 * Q) - -/-- Uniform law of sub-batch with Gram fixed on the batch. -/ -theorem framesAt_observe {C : Mat I J → Prop} (hc : ∃ x : Mat U I × Mat U J, FramesAt C x) - (P : Mat I R) (Q : Mat J S) {G : Mat R S} (hP : Injective P.mulVec) - (hQ : Injective Q.mulVec) (h : ∀ M, C M → Pᵀ*M*Q=G) : - mapW (unifOn (FramesAt (U:=U) C)) (observe P Q) = unifOn (gramGood G) := by - apply uniform_orbit _ hc - · intro x hx - refine ⟨?_,inj_comp_mat _ _ hx.2.1 hP,inj_comp_mat _ _ hx.2.2 hQ⟩ - change (x.1 * P)ᵀ * (x.2 * Q) = G - rw [← h _ hx.1,transpose_mul] - simp only [Matrix.mul_assoc] - · intro y z hy hz - obtain ⟨c,hc'⟩ := move_exists G y z hy hz - refine ⟨c.perm I J,c.invar C, fun x => ?_⟩ - have hobs : observe P Q (c.perm I J x) = (c.perm R S) (observe P Q x) := - Prod.ext (Matrix.mul_assoc _ _ _) (Matrix.mul_assoc _ _ _) - rw [hobs,←hc'] - exact (c.perm R S).injective.eq_iff.symm - -/-- Uniform law of plus-only observation; in particular plus frames are -uniform injective. -/ -theorem framesAt_observe_plus {C : Mat I J → Prop} (hc : ∃ x : Mat U I × Mat U J, FramesAt C x) - {P : Mat I R} (hP : Injective P.mulVec) : - mapW (unifOn (FramesAt (U:=U) C)) (fun x => x.1*P) = - unifOn (fun x => Injective x.mulVec) := by - refine uniform_orbit _ hc ?_ ?_ - · intro x hx; exact inj_comp_mat _ _ hx.2.1 hP - intro y z hy hz - obtain ⟨c,hc⟩ := move_exists_one hy hz - refine ⟨c.perm I J,c.invar C, fun x => ?_⟩ - change x.1*P=y ↔ c.L*x.1*P=z - rw [Matrix.mul_assoc,←hc] - exact (c.permMat R).injective.eq_iff.symm - -theorem framesAt_observe_minus {C : Mat I J → Prop} (hc : ∃ x : Mat U I × Mat U J, FramesAt C x) - {Q : Mat J S} (hQ : Injective Q.mulVec) : - mapW (unifOn (FramesAt (U:=U) C)) (fun x => x.2*Q) = - unifOn (fun x => Injective x.mulVec) := by - refine uniform_orbit _ hc ?_ ?_ - · intro x hx; exact inj_comp_mat _ _ hx.2.2 hQ - intro y z hy hz - obtain ⟨c,hc⟩ := move_exists_one hy hz - refine ⟨c.dual.perm I J,c.dual.invar C, fun x => ?_⟩ - change x.2*Q=y ↔ c.L*x.2*Q=z - rw [Matrix.mul_assoc,←hc] - exact (c.permMat S).injective.eq_iff.symm - -theorem plus_marginal {C : Mat I J → Prop} (hc : ∃ x : Mat U I × Mat U J, FramesAt C x) : - mapW (unifOn (FramesAt (U:=U) C)) Prod.fst = - unifOn (fun x => Injective x.mulVec) := by - have he : Injective (1:Mat I I).mulVec := fun x y h => by simpa using h - simpa using framesAt_observe_plus hc he - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.GramProbabilities + +namespace OAI + +/-! # Frame Orbit Laws -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Function + +variable {U I J R S : Type} [Fintype U] [Fintype I] [Fintype J] [Fintype R] [Fintype S] + [DecidableEq U] + +def FramesAt (C : Mat I J → Prop) (x : Mat U I × Mat U J) := + C (x.1ᵀ * x.2) ∧ Injective x.1.mulVec ∧ Injective x.2.mulVec + +structure Move (U : Type) [Fintype U] [DecidableEq U] where + L : Mat U U + R : Mat U U + LR : L*R=1 + RL : R*L=1 + +namespace Move +variable (c : Move U) +def sym : Move U := ⟨c.R,c.L,c.RL,c.LR⟩ +def dual : Move U := ⟨c.Rᵀ,c.Lᵀ,by rw [← transpose_mul,c.LR, Matrix.transpose_one], + by rw [← transpose_mul,c.RL,Matrix.transpose_one]⟩ +def permMat (I : Type) : Mat U I ≃ Mat U I where + toFun A := c.L*A + invFun A := c.R*A + left_inv A := by simp only [← Matrix.mul_assoc, c.RL, Matrix.one_mul] + right_inv A := by simp only [← Matrix.mul_assoc, c.LR, Matrix.one_mul] +def perm (I J : Type) : Mat U I × Mat U J ≃ Mat U I × Mat U J := + (c.permMat I).prodCongr (c.dual.permMat J) + +omit [Fintype I] [Fintype J] in +theorem gram_invar (A : Mat U I) (B : Mat U J) : + (c.L*A)ᵀ * (c.Rᵀ*B) = Aᵀ*B := by + rw [transpose_mul,Matrix.mul_assoc,← Matrix.mul_assoc c.Lᵀ c.Rᵀ B,← transpose_mul,c.RL, + Matrix.transpose_one, Matrix.one_mul] + +theorem L_inj : Injective c.L.mulVec := by + intro x y h + have hi (x) : c.R *ᵥ (c.L *ᵥ x) = x := by rw [mulVec_mulVec,c.RL, Matrix.one_mulVec] + change c.L *ᵥ x = c.L *ᵥ y at h + rw [←hi x,h,hi y] + +theorem perm_inj (A : Mat U I) : Injective A.mulVec ↔ Injective (c.L*A).mulVec := by + refine ⟨inj_comp_mat _ _ c.L_inj, fun h => ?_⟩ + have hh := inj_comp_mat _ _ c.sym.L_inj h + change Injective (c.R*(c.L*A)).mulVec at hh + rwa [←Matrix.mul_assoc,c.RL,Matrix.one_mul] at hh + +theorem invar (C : Mat I J → Prop) (x : Mat U I × Mat U J) : + FramesAt C x ↔ FramesAt C (c.perm I J x) := by + unfold FramesAt + change _ ↔ C ((c.L*x.1)ᵀ * (c.Rᵀ*x.2)) ∧ _ + rw [gram_invar] + exact and_congr Iff.rfl (and_congr (c.perm_inj x.1) (c.dual.perm_inj x.2)) +end Move + +/-- Nonempty matrix family if super-dimension slack. -/ +theorem framesAt_exists [DecidableEq I] [DecidableEq J] + {C : Mat I J → Prop} (h : ∃ G, C G) (hn : num I+num J < num U) : + ∃ x : Mat U I × Mat U J, FramesAt C x := by + obtain ⟨G,hG⟩ := h + let v := (pairW unif unif : Wgt (Mat U I × Mat U J)) + have he (a : ℝ) (h : a < 0) : 0 < 1-bp a := sub_pos.mpr + ((bp_lt h).trans_eq bp_zero) + have hpos : 0 < pr v (gramGood G) := by + refine lt_of_lt_of_le ?_ (gram_norm G hn.le).2 + have hi : num I - num U < 0 := by + have hh : 0 ≤ num J := by unfold num; positivity + linarith + exact mul_pos (mul_pos (bp_pos _) (he _ hi)) (he _ (by linarith only [hn])) + obtain ⟨x,hx,_⟩ := exists_of_pr_pos (pairW_law unif_law unif_law).nz hpos + exact ⟨x,hx.1.symm ▸ hG,hx.2⟩ + +theorem move_exists (G : Mat I J) (x y : Mat U I × Mat U J) (hx : gramGood G x) + (hy : gramGood G y) : ∃ c : Move U, c.perm I J x = y := by + obtain ⟨L,R,H,F,E,T⟩ := frame_move hx.2.1 hy.2.1 hx.2.2 hy.2.2 (hx.1.trans hy.1.symm) + exact ⟨⟨L,R,H,F⟩,Prod.ext E T⟩ + +theorem move_exists_one {x y : Mat U I} (hx : Injective x.mulVec) + (hy : Injective y.mulVec) : ∃ c : Move U, c.permMat I x = y := by + let B := (0:Mat U Empty) + let G := (0:Mat I Empty) + have he {x : Mat U I} (hx : Injective x.mulVec) : gramGood G (x,B) := + ⟨Subsingleton.elim _ _, hx, fun a b _ => Subsingleton.elim a b⟩ + obtain ⟨c,hc⟩ := move_exists G _ _ (he hx) (he hy) + exact ⟨c,congrArg Prod.fst hc⟩ + +variable [DecidableEq I] [DecidableEq J] [DecidableEq R] [DecidableEq S] + +def observe (P : Mat I R) (Q : Mat J S) (x : Mat U I × Mat U J) : Mat U R × Mat U S := + (x.1 * P, x.2 * Q) + +/-- Uniform law of sub-batch with Gram fixed on the batch. -/ +theorem framesAt_observe {C : Mat I J → Prop} (hc : ∃ x : Mat U I × Mat U J, FramesAt C x) + (P : Mat I R) (Q : Mat J S) {G : Mat R S} (hP : Injective P.mulVec) + (hQ : Injective Q.mulVec) (h : ∀ M, C M → Pᵀ*M*Q=G) : + mapW (unifOn (FramesAt (U:=U) C)) (observe P Q) = unifOn (gramGood G) := by + apply uniform_orbit _ hc + · intro x hx + refine ⟨?_,inj_comp_mat _ _ hx.2.1 hP,inj_comp_mat _ _ hx.2.2 hQ⟩ + change (x.1 * P)ᵀ * (x.2 * Q) = G + rw [← h _ hx.1,transpose_mul] + simp only [Matrix.mul_assoc] + · intro y z hy hz + obtain ⟨c,hc'⟩ := move_exists G y z hy hz + refine ⟨c.perm I J,c.invar C, fun x => ?_⟩ + have hobs : observe P Q (c.perm I J x) = (c.perm R S) (observe P Q x) := + Prod.ext (Matrix.mul_assoc _ _ _) (Matrix.mul_assoc _ _ _) + rw [hobs,←hc'] + exact (c.perm R S).injective.eq_iff.symm + +/-- Uniform law of plus-only observation; in particular plus frames are +uniform injective. -/ +theorem framesAt_observe_plus {C : Mat I J → Prop} (hc : ∃ x : Mat U I × Mat U J, FramesAt C x) + {P : Mat I R} (hP : Injective P.mulVec) : + mapW (unifOn (FramesAt (U:=U) C)) (fun x => x.1*P) = + unifOn (fun x => Injective x.mulVec) := by + refine uniform_orbit _ hc ?_ ?_ + · intro x hx; exact inj_comp_mat _ _ hx.2.1 hP + intro y z hy hz + obtain ⟨c,hc⟩ := move_exists_one hy hz + refine ⟨c.perm I J,c.invar C, fun x => ?_⟩ + change x.1*P=y ↔ c.L*x.1*P=z + rw [Matrix.mul_assoc,←hc] + exact (c.permMat R).injective.eq_iff.symm + +theorem framesAt_observe_minus {C : Mat I J → Prop} (hc : ∃ x : Mat U I × Mat U J, FramesAt C x) + {Q : Mat J S} (hQ : Injective Q.mulVec) : + mapW (unifOn (FramesAt (U:=U) C)) (fun x => x.2*Q) = + unifOn (fun x => Injective x.mulVec) := by + refine uniform_orbit _ hc ?_ ?_ + · intro x hx; exact inj_comp_mat _ _ hx.2.2 hQ + intro y z hy hz + obtain ⟨c,hc⟩ := move_exists_one hy hz + refine ⟨c.dual.perm I J,c.dual.invar C, fun x => ?_⟩ + change x.2*Q=y ↔ c.L*x.2*Q=z + rw [Matrix.mul_assoc,←hc] + exact (c.permMat S).injective.eq_iff.symm + +theorem plus_marginal {C : Mat I J → Prop} (hc : ∃ x : Mat U I × Mat U J, FramesAt C x) : + mapW (unifOn (FramesAt (U:=U) C)) Prod.fst = + unifOn (fun x => Injective x.mulVec) := by + have he : Injective (1:Mat I I).mulVec := fun x y h => by simpa using h + simpa using framesAt_observe_plus hc he + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FrameRotations.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FrameRotations.lean index 26feb0a3f2fd328c8d56309cf30da81a4ca4e909..dda1436decab63c22b516ce62bf7b3c565bf4e8c 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FrameRotations.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FrameRotations.lean @@ -1,112 +1,112 @@ -import OAI.Combinatorics.HadwigerCounterexample.FreeBlockLinearAction - -namespace OAI - -/-! # Frame Rotations -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Function Finset -open scoped BigOperators -variable {p : Shape} {n N : ℕ} -namespace Move - -def vault (p : Shape) (c : Flit n) : - Knobs p.g n ≃ Knobs p.g n where - toFun x := doZ p c.L x - invFun x := doZ p c.R x - left_inv x := by simp only [doZ,update_self,mulVec_mulVec,c.RL,Matrix.one_mulVec]; simp - right_inv x := by simp only [doZ,update_self,mulVec_mulVec,c.LR,Matrix.one_mulVec]; simp -variable (c : Flit n) - -def boom (p : Shape) (c : Flit n) : Move (Full p n) where - L := Matrix.fromBlocks (blitz p c.L) 0 0 1 - R := Matrix.fromBlocks (blitz p c.R) 0 0 1 - LR := by simp [fromBlocks_multiply,←blitz_mul,c.LR,blitz_one] - RL := by simp [fromBlocks_multiply,←blitz_mul,c.RL,blitz_one] - -def fuse (p : Shape) (c : Flit n) (N : ℕ) : - Mat (Fin N) (Full p n) ≃ Mat (Fin N) (Full p n) where - toFun y := y*(boom p c).L - invFun y := y*(boom p c).R - left_inv y := by simp only [Matrix.mul_assoc,(boom p c).LR]; exact Matrix.mul_one _ - right_inv y := by simp only [Matrix.mul_assoc,(boom p c).RL]; exact Matrix.mul_one _ - -theorem boom_primary (y : Mat (Fin N) (Full p n)) : - primary (fuse p c N y)=primary y*blitz p c.L ∧ channel (fuse p c N y)=channel y := by - change primary (y*(boom p c).L)=_ ∧ channel (y*_)=_ - have hz : y*(boom p c).L = fromCols (primary y * blitz p c.L) (channel y) := by - unfold boom - conv_lhs => arg 1; rw [←fromCols_frame y] - simp only [fromCols_mul_fromBlocks,Matrix.mul_zero,Matrix.mul_one,zero_add,add_zero] - rw [hz]; exact ⟨rfl,rfl⟩ - -theorem fuse_inj (y : Mat (Fin N) (Full p n)) (h : Injective y.mulVec) : - Injective (fuse p c N y).mulVec := - inj_comp_mat _ _ h (boom p c).L_inj - -def kite (p : Shape) (c : Flit n) (N) : Orient p n N ≃ Orient p n N := - Equiv.piCongrRight (fun _ => (fuse p c N).prodCongr (fuse p c N)) - -theorem kite_move (m : Mixer p n) {y : Oframe p n N} - (h : FramesAt (gramCond m) y) : - FramesAt (gramCond m) (fuse p c N y.1,fuse p c N y.2) := by - obtain ⟨h1,h2,h3,h4,h5⟩ := (valid_iff ..).mpr h - refine (valid_iff ..).mp ⟨c.fuse_inj _ h1,c.fuse_inj _ h2,?_,?_,?_⟩ - · have ha := (boom_primary c y.1).1; have hb := (boom_primary c y.2).1 - let B := blitz p c.L; let E := selfM p n m.mixM - change (primary (fuse p c N y.1))ᵀ * primary (fuse p c N y.2)=_ - rw [ha,hb] - calc _ =pullM B B E := by unfold E; rw [pullM_def,←h3,transpose_mul]; simp only [Matrix.mul_assoc,B] - _ = E := blitz_fixes .. - · change (channel (fuse p c N y.1))ᵀ * primary (fuse p c N y.2)=_ - rw [(boom_primary c y.1).2,(boom_primary c y.2).1,←Matrix.mul_assoc,h4,Matrix.zero_mul] - change (primary (fuse p c N y.1))ᵀ*channel (fuse p c N y.2)=_ - rw [(boom_primary c y.1).1,(boom_primary c y.2).2,transpose_mul,Matrix.mul_assoc, - h5,Matrix.mul_zero] - -theorem kite_weights (m : Mixer p n) (x : Orient p n N) : - raw m N (kite p c N x)=raw m N x := by - unfold raw prodW - refine Finset.prod_congr rfl fun i _ => ?_ - let A := (kite p c N x) i - have h : FramesAt (gramCond m) A ↔ FramesAt (gramCond m) (x i) := by - constructor - · intro h - have ht := kite_move c.sym m h - have he : (fuse p c.sym N A.1,fuse p c.sym N A.2)=x i := Prod.ext ((fuse p c N).symm_apply_apply _) ((fuse p c N).symm_apply_apply _) - rwa [he] at ht - exact fun h => kite_move c m h - simp only [unifOn_val] - change ind (FramesAt _ A)/_=_ - rw [h] -theorem kite_keys (v : Template.Solo p) (x : Orient p n N) (z : Knobs p.g n) : - v.desc z (kite p c N x)=v.desc (vault p c z) x := by - let i := x - let R (e : TagStar (v.t ())) (b : Bool) : - takeSign (p:=p) ((kite p c N x) e.val) b = fuse p c N (takeSign (p:=p) - (x e.val) b) := by cases b <;> rfl - funext e b - let w (z : Knobs p.g n) := spring p (v.t ()) (v.s ()) (v.f ()) z - change primary _ *ᵥ w z = primary _ *ᵥ w _ - rw [R,(boom_primary c _).1,←mulVec_mulVec,sailsZ] - rfl -end Move - -def flowZ (p : Shape) (w : Wgt (Knobs p.g n)) := - ∀ i j,w (update i Block.Z j) = w i - -theorem scannedZ (p : Shape) (l : Tag p.g) (f : Flavor p.g) (w : Knobs p.g n) (v : Vec (Fin n)) : - scan p l f (update w Block.Z v)=scan p l f w := by - classical - funext i - have h : asBlock i≠Block.Z := by rcases i with (⟨i,j⟩|_) <;> simp [asBlock] - unfold scan; rw [update_of_ne h] - -theorem scanned_flow (p : Shape) (n l f z) : flowZ p (scopedScan p n l f z) := by - intro i j; simp only [scopedScan,onW_val,spins,← draws_unif,scannedZ,unif_apply] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FreeBlockLinearAction + +namespace OAI + +/-! # Frame Rotations -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Function Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} +namespace Move + +def vault (p : Shape) (c : Flit n) : + Knobs p.g n ≃ Knobs p.g n where + toFun x := doZ p c.L x + invFun x := doZ p c.R x + left_inv x := by simp only [doZ,update_self,mulVec_mulVec,c.RL,Matrix.one_mulVec]; simp + right_inv x := by simp only [doZ,update_self,mulVec_mulVec,c.LR,Matrix.one_mulVec]; simp +variable (c : Flit n) + +def boom (p : Shape) (c : Flit n) : Move (Full p n) where + L := Matrix.fromBlocks (blitz p c.L) 0 0 1 + R := Matrix.fromBlocks (blitz p c.R) 0 0 1 + LR := by simp [fromBlocks_multiply,←blitz_mul,c.LR,blitz_one] + RL := by simp [fromBlocks_multiply,←blitz_mul,c.RL,blitz_one] + +def fuse (p : Shape) (c : Flit n) (N : ℕ) : + Mat (Fin N) (Full p n) ≃ Mat (Fin N) (Full p n) where + toFun y := y*(boom p c).L + invFun y := y*(boom p c).R + left_inv y := by simp only [Matrix.mul_assoc,(boom p c).LR]; exact Matrix.mul_one _ + right_inv y := by simp only [Matrix.mul_assoc,(boom p c).RL]; exact Matrix.mul_one _ + +theorem boom_primary (y : Mat (Fin N) (Full p n)) : + primary (fuse p c N y)=primary y*blitz p c.L ∧ channel (fuse p c N y)=channel y := by + change primary (y*(boom p c).L)=_ ∧ channel (y*_)=_ + have hz : y*(boom p c).L = fromCols (primary y * blitz p c.L) (channel y) := by + unfold boom + conv_lhs => arg 1; rw [←fromCols_frame y] + simp only [fromCols_mul_fromBlocks,Matrix.mul_zero,Matrix.mul_one,zero_add,add_zero] + rw [hz]; exact ⟨rfl,rfl⟩ + +theorem fuse_inj (y : Mat (Fin N) (Full p n)) (h : Injective y.mulVec) : + Injective (fuse p c N y).mulVec := + inj_comp_mat _ _ h (boom p c).L_inj + +def kite (p : Shape) (c : Flit n) (N) : Orient p n N ≃ Orient p n N := + Equiv.piCongrRight (fun _ => (fuse p c N).prodCongr (fuse p c N)) + +theorem kite_move (m : Mixer p n) {y : Oframe p n N} + (h : FramesAt (gramCond m) y) : + FramesAt (gramCond m) (fuse p c N y.1,fuse p c N y.2) := by + obtain ⟨h1,h2,h3,h4,h5⟩ := (valid_iff ..).mpr h + refine (valid_iff ..).mp ⟨c.fuse_inj _ h1,c.fuse_inj _ h2,?_,?_,?_⟩ + · have ha := (boom_primary c y.1).1; have hb := (boom_primary c y.2).1 + let B := blitz p c.L; let E := selfM p n m.mixM + change (primary (fuse p c N y.1))ᵀ * primary (fuse p c N y.2)=_ + rw [ha,hb] + calc _ =pullM B B E := by unfold E; rw [pullM_def,←h3,transpose_mul]; simp only [Matrix.mul_assoc,B] + _ = E := blitz_fixes .. + · change (channel (fuse p c N y.1))ᵀ * primary (fuse p c N y.2)=_ + rw [(boom_primary c y.1).2,(boom_primary c y.2).1,←Matrix.mul_assoc,h4,Matrix.zero_mul] + change (primary (fuse p c N y.1))ᵀ*channel (fuse p c N y.2)=_ + rw [(boom_primary c y.1).1,(boom_primary c y.2).2,transpose_mul,Matrix.mul_assoc, + h5,Matrix.mul_zero] + +theorem kite_weights (m : Mixer p n) (x : Orient p n N) : + raw m N (kite p c N x)=raw m N x := by + unfold raw prodW + refine Finset.prod_congr rfl fun i _ => ?_ + let A := (kite p c N x) i + have h : FramesAt (gramCond m) A ↔ FramesAt (gramCond m) (x i) := by + constructor + · intro h + have ht := kite_move c.sym m h + have he : (fuse p c.sym N A.1,fuse p c.sym N A.2)=x i := Prod.ext ((fuse p c N).symm_apply_apply _) ((fuse p c N).symm_apply_apply _) + rwa [he] at ht + exact fun h => kite_move c m h + simp only [unifOn_val] + change ind (FramesAt _ A)/_=_ + rw [h] +theorem kite_keys (v : Template.Solo p) (x : Orient p n N) (z : Knobs p.g n) : + v.desc z (kite p c N x)=v.desc (vault p c z) x := by + let i := x + let R (e : TagStar (v.t ())) (b : Bool) : + takeSign (p:=p) ((kite p c N x) e.val) b = fuse p c N (takeSign (p:=p) + (x e.val) b) := by cases b <;> rfl + funext e b + let w (z : Knobs p.g n) := spring p (v.t ()) (v.s ()) (v.f ()) z + change primary _ *ᵥ w z = primary _ *ᵥ w _ + rw [R,(boom_primary c _).1,←mulVec_mulVec,sailsZ] + rfl +end Move + +def flowZ (p : Shape) (w : Wgt (Knobs p.g n)) := + ∀ i j,w (update i Block.Z j) = w i + +theorem scannedZ (p : Shape) (l : Tag p.g) (f : Flavor p.g) (w : Knobs p.g n) (v : Vec (Fin n)) : + scan p l f (update w Block.Z v)=scan p l f w := by + classical + funext i + have h : asBlock i≠Block.Z := by rcases i with (⟨i,j⟩|_) <;> simp [asBlock] + unfold scan; rw [update_of_ne h] + +theorem scanned_flow (p : Shape) (n l f z) : flowZ p (scopedScan p n l f z) := by + intro i j; simp only [scopedScan,onW_val,spins,← draws_unif,scannedZ,unif_apply] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FreeBlockFourier.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FreeBlockFourier.lean index 397c73a348bf323ae60f571f1295728e4d37141c..08668b9020b6361b1cf62398fe3881b1dddb1ee2 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FreeBlockFourier.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FreeBlockFourier.lean @@ -1,111 +1,111 @@ -import OAI.Combinatorics.HadwigerCounterexample.RandomLinearTransforms - -namespace OAI - -/-! # Free Block Fourier -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module LinearMap Filter Function -open scoped BigOperators -variable {p : Shape} {n : ℕ} {I A : Type} [Fintype I] [DecidableEq I] -variable [Fintype A] - -theorem zavg (p : Shape) (w : Wgt (Knobs p.g n)) (h : flowZ p w) - (f : Wgt (Knobs p.g n)) : - avg w f=avg w (fun x => avg unif (fun y => f (update x Block.Z y))) := by - classical - let A := Knobs p.g n - let v : Wgt A := unif - let k (f : Wgt A) (x : A) := f x * density v w x - have he (f : Wgt A) : avg w f=avg v (k f) := by - unfold avg; refine Finset.sum_congr rfl fun i _ => ?_ - have hv : v i ≠ 0 := by unfold v; rw [unif_apply]; positivity - unfold k density - field_simp - let b : Block p.g→ Wgt (Vec (Fin n)) := fun _ => unif - have hv : prodW b=v := draws_unif.symm - rw [he f,he (fun _ => avg _ _), ← hv,update_avg b Block.Z (k f) unif_law] - refine avg_congr fun i _ => ?_ - unfold k - have ht (x) : density v w (update i Block.Z x)=density v w i := by - unfold density; rw [h]; rfl - simp_rw [ht,avg_mul] - rfl - -def zhat (p : Shape) (f : Wgt (Knobs p.g n)) (x : Knobs p.g n) (i : Vec (Fin n)) := - avg unif (fun y => vectorPhase i y * f (update x Block.Z y)) -def zchar (p : Shape) (f : Wgt (Knobs p.g n)) (i : Vec (Fin n)) (x : Knobs p.g n) := - zhat p f x i * vectorPhase i (x Block.Z) -def zim (p : Shape) (f : Wgt (Knobs p.g n)) (s : Finset (Vec (Fin n))) (x) := - ∑ i∈s,zchar p f i x - -omit [DecidableEq I] in -private theorem vpsym (x y : Vec I) : vectorPhase x y=vectorPhase y x := - congrArg wsign (dotProduct_comm ..) -theorem hat_eqn (f : Wgt (Vec I)) (x : Vec I) : - ∑ i:Vec I,(avg unif (fun y => vectorPhase i y*f y))*vectorPhase i x=f x := by - classical - unfold avg; simp_rw [Finset.sum_mul] - rw [Finset.sum_comm] - have hi y : - ∑ i:Vec I,unif y*(vectorPhase i y*f y)*vectorPhase i x= - ind (y=x)*f y := by - rw [vector_expand] - simp only [avg,Finset.sum_mul] - exact Finset.sum_congr rfl fun i _ => by rw [unif_apply,unif_apply]; ring - simp_rw [hi]; simp [ind] - -theorem z_atlas (p : Shape) (f : Wgt (Knobs p.g n)) (x) : - zim p f univ x=f x := by - unfold zim zchar zhat - rw [hat_eqn (fun y => f (update x Block.Z y))] - simp - -theorem zhat_replay (p : Shape) (f : Wgt (Knobs p.g n)) (x) (y) (i) : - zhat p f (update x Block.Z y) i= zhat p f x i := by simp [zhat] - -theorem zchar_orth (p : Shape) (f g w : Wgt (Knobs p.g n)) (h : flowZ p w) - (i j : Vec (Fin n)) (he : i≠j) : - avg w (fun x => zchar p f i x * zchar p g j x)=0 := by - rw [zavg p w h] - have hh (x : Knobs p.g n) : - avg unif (fun y => zchar p f i (update x Block.Z y)*zchar p g j (update x Block.Z y))=0 := by - unfold zchar - simp_rw [zhat_replay,update_self] - have hi (x) : vectorPhase i x*vectorPhase j x = vectorPhase x i*vectorPhase x j := by - rw [vpsym i,vpsym j] - have ht (y : Vec (Fin n)) : - zhat p f x i * vectorPhase i y * (zhat p g x j * vectorPhase j y) = - zhat p f x i * zhat p g x j * (vectorPhase y i * vectorPhase y j) := by - rw [←hi]; ring - simp_rw [ht,avg_mul',←vector_expand,ind_zero he,mul_zero] - simp_rw [hh,avg_zero] - -theorem zsplit_orth (p : Shape) (f g w : Wgt (Knobs p.g n)) (h : flowZ p w) - (s t : Finset (Vec (Fin n))) (hh : Disjoint s t) : - avg w (fun x => zim p f s x*zim p g t x)=0 := by - unfold zim; simp_rw [Finset.sum_mul,Finset.mul_sum,avg_sum] - refine Finset.sum_eq_zero fun i hi => Finset.sum_eq_zero fun j hj => - zchar_orth p f g w h i j (fun e => Finset.disjoint_left.mp hh hi (e ▸ hj)) - -theorem zsplit_cost (p : Shape) (f w : Wgt (Knobs p.g n)) (h : flowZ p w) - (hw : ∀ i, 0 ≤ w i) (s : Finset (Vec (Fin n))) : - avg w (fun x => (zim p f s x)^2)≤avg w (fun x => f x^2) := by - classical - let t := univ\s - let A := zim p f s; let B := zim p f t - have hh x : f x^2 = A x^2+B x^2+2*(A x*B x) := by - have he : A x+B x=f x := by - unfold A B zim t - rw [add_comm, Finset.sum_sdiff (subset_univ s)]; exact z_atlas p f x - rw [← he]; ring - have h0 := zsplit_orth p f f w h s t (Finset.disjoint_left.mpr (fun j hj hk => - (mem_sdiff.mp hk).2 hj)) - simp_rw [hh,avg_add,avg_mul',show avg w (fun x => A x*B x)=0 from h0,mul_zero,add_zero] - exact le_add_of_nonneg_right (avg_nonneg hw (fun _ => sq_nonneg _)) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RandomLinearTransforms + +namespace OAI + +/-! # Free Block Fourier -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module LinearMap Filter Function +open scoped BigOperators +variable {p : Shape} {n : ℕ} {I A : Type} [Fintype I] [DecidableEq I] +variable [Fintype A] + +theorem zavg (p : Shape) (w : Wgt (Knobs p.g n)) (h : flowZ p w) + (f : Wgt (Knobs p.g n)) : + avg w f=avg w (fun x => avg unif (fun y => f (update x Block.Z y))) := by + classical + let A := Knobs p.g n + let v : Wgt A := unif + let k (f : Wgt A) (x : A) := f x * density v w x + have he (f : Wgt A) : avg w f=avg v (k f) := by + unfold avg; refine Finset.sum_congr rfl fun i _ => ?_ + have hv : v i ≠ 0 := by unfold v; rw [unif_apply]; positivity + unfold k density + field_simp + let b : Block p.g→ Wgt (Vec (Fin n)) := fun _ => unif + have hv : prodW b=v := draws_unif.symm + rw [he f,he (fun _ => avg _ _), ← hv,update_avg b Block.Z (k f) unif_law] + refine avg_congr fun i _ => ?_ + unfold k + have ht (x) : density v w (update i Block.Z x)=density v w i := by + unfold density; rw [h]; rfl + simp_rw [ht,avg_mul] + rfl + +def zhat (p : Shape) (f : Wgt (Knobs p.g n)) (x : Knobs p.g n) (i : Vec (Fin n)) := + avg unif (fun y => vectorPhase i y * f (update x Block.Z y)) +def zchar (p : Shape) (f : Wgt (Knobs p.g n)) (i : Vec (Fin n)) (x : Knobs p.g n) := + zhat p f x i * vectorPhase i (x Block.Z) +def zim (p : Shape) (f : Wgt (Knobs p.g n)) (s : Finset (Vec (Fin n))) (x) := + ∑ i∈s,zchar p f i x + +omit [DecidableEq I] in +private theorem vpsym (x y : Vec I) : vectorPhase x y=vectorPhase y x := + congrArg wsign (dotProduct_comm ..) +theorem hat_eqn (f : Wgt (Vec I)) (x : Vec I) : + ∑ i:Vec I,(avg unif (fun y => vectorPhase i y*f y))*vectorPhase i x=f x := by + classical + unfold avg; simp_rw [Finset.sum_mul] + rw [Finset.sum_comm] + have hi y : + ∑ i:Vec I,unif y*(vectorPhase i y*f y)*vectorPhase i x= + ind (y=x)*f y := by + rw [vector_expand] + simp only [avg,Finset.sum_mul] + exact Finset.sum_congr rfl fun i _ => by rw [unif_apply,unif_apply]; ring + simp_rw [hi]; simp [ind] + +theorem z_atlas (p : Shape) (f : Wgt (Knobs p.g n)) (x) : + zim p f univ x=f x := by + unfold zim zchar zhat + rw [hat_eqn (fun y => f (update x Block.Z y))] + simp + +theorem zhat_replay (p : Shape) (f : Wgt (Knobs p.g n)) (x) (y) (i) : + zhat p f (update x Block.Z y) i= zhat p f x i := by simp [zhat] + +theorem zchar_orth (p : Shape) (f g w : Wgt (Knobs p.g n)) (h : flowZ p w) + (i j : Vec (Fin n)) (he : i≠j) : + avg w (fun x => zchar p f i x * zchar p g j x)=0 := by + rw [zavg p w h] + have hh (x : Knobs p.g n) : + avg unif (fun y => zchar p f i (update x Block.Z y)*zchar p g j (update x Block.Z y))=0 := by + unfold zchar + simp_rw [zhat_replay,update_self] + have hi (x) : vectorPhase i x*vectorPhase j x = vectorPhase x i*vectorPhase x j := by + rw [vpsym i,vpsym j] + have ht (y : Vec (Fin n)) : + zhat p f x i * vectorPhase i y * (zhat p g x j * vectorPhase j y) = + zhat p f x i * zhat p g x j * (vectorPhase y i * vectorPhase y j) := by + rw [←hi]; ring + simp_rw [ht,avg_mul',←vector_expand,ind_zero he,mul_zero] + simp_rw [hh,avg_zero] + +theorem zsplit_orth (p : Shape) (f g w : Wgt (Knobs p.g n)) (h : flowZ p w) + (s t : Finset (Vec (Fin n))) (hh : Disjoint s t) : + avg w (fun x => zim p f s x*zim p g t x)=0 := by + unfold zim; simp_rw [Finset.sum_mul,Finset.mul_sum,avg_sum] + refine Finset.sum_eq_zero fun i hi => Finset.sum_eq_zero fun j hj => + zchar_orth p f g w h i j (fun e => Finset.disjoint_left.mp hh hi (e ▸ hj)) + +theorem zsplit_cost (p : Shape) (f w : Wgt (Knobs p.g n)) (h : flowZ p w) + (hw : ∀ i, 0 ≤ w i) (s : Finset (Vec (Fin n))) : + avg w (fun x => (zim p f s x)^2)≤avg w (fun x => f x^2) := by + classical + let t := univ\s + let A := zim p f s; let B := zim p f t + have hh x : f x^2 = A x^2+B x^2+2*(A x*B x) := by + have he : A x+B x=f x := by + unfold A B zim t + rw [add_comm, Finset.sum_sdiff (subset_univ s)]; exact z_atlas p f x + rw [← he]; ring + have h0 := zsplit_orth p f f w h s t (Finset.disjoint_left.mpr (fun j hj hk => + (mem_sdiff.mp hk).2 hj)) + simp_rw [hh,avg_add,avg_mul',show avg w (fun x => A x*B x)=0 from h0,mul_zero,add_zero] + exact le_add_of_nonneg_right (avg_nonneg hw (fun _ => sq_nonneg _)) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FreeBlockLinearAction.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FreeBlockLinearAction.lean index ee82925fe0fcbf63a8333f7793ac3c8b5fe94df8..85a1e2f42de79dba0add5aad0aa198f2d545746b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FreeBlockLinearAction.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FreeBlockLinearAction.lean @@ -1,137 +1,137 @@ -import OAI.Combinatorics.HadwigerCounterexample.UnaryQueryFrequencies - -namespace OAI - -/-! # Free Block Linear Action -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module Submodule Function Finset LinearMap -open scoped BigOperators -variable {p : Shape} {n N : ℕ} -abbrev Flit (n : ℕ) := Move (Fin n) - -def breeze (p : Shape) (M : Mat (Fin n) (Fin n)) (x : Ray p n) : Ray p n := - fun i => - match i.2 with - | none => x i - | some (B,j) => if B=Block.Z then (M *ᵥ (fun j => x (i.1,some (Block.Z,j)))) j else x i - -def blitzL (p : Shape) (M : Mat (Fin n) (Fin n)) : Ray p n →ₗ[F] Ray p n where - toFun := breeze p M - map_add' x y := by - have he (i : SelIdx p.b p.j) : - (fun j : Fin n => (x+y) (i,some (Block.Z,j)))= - ((fun j => x (i,some (Block.Z,j)))+ (fun j => y (i,some (Block.Z,j)))) := rfl - funext i; rcases i with ⟨i, _|⟨B,j⟩⟩ - · rfl - by_cases h : B=Block.Z - · simp only [breeze,h,ite_true,he,mulVec_add] - rfl - simp [breeze,h] - map_smul' a x := by - have he (i : SelIdx p.b p.j) : - (fun j : Fin n => (a•x) (i,some (Block.Z,j)))= - a • (fun j => x (i,some (Block.Z,j))) := rfl - funext i; rcases i with ⟨i, _|⟨B,j⟩⟩ - · rfl - by_cases h : B=Block.Z - · simp only [breeze,h,ite_true,he,mulVec_smul]; rfl - simp [breeze,h] - -def blitz (p : Shape) (M : Mat (Fin n) (Fin n)) := LinearMap.toMatrix' (blitzL p M) - -theorem blitz_val (p : Shape) (M : Mat (Fin n) (Fin n)) (x) : - blitz p M *ᵥ x=breeze p M x := by - change LinearMap.toMatrix' (blitzL p M)*ᵥ x=blitzL p M x - simp - -theorem blitz_mul (p : Shape) (M L : Mat (Fin n) (Fin n)) : - blitz p (M*L)=blitz p M*blitz p L := by - classical - apply coe_mv_inj - apply LinearMap.ext - intro x; simp_rw [mulVecLin_apply,← mulVec_mulVec,blitz_val] - funext i; rcases i with ⟨i, _|⟨B,j⟩⟩ - · rfl - by_cases h : B=Block.Z - · simp only [breeze,h,ite_true,←mulVec_mulVec] - simp [breeze,h] - -theorem blitz_one (p : Shape) (n : ℕ) : blitz p (1:Mat (Fin n) (Fin n))=1 := by - apply coe_mv_inj; apply LinearMap.ext; intro x - rw [mulVecLin_apply,mulVecLin_apply,Matrix.one_mulVec,blitz_val] - funext i; rcases i with ⟨i, _|⟨B,j⟩⟩ - · rfl - by_cases h : B=Block.Z <;> simp [breeze,h] - -theorem blitz_pick (p : Shape) (M : Mat (Fin n) (Fin n)) (s : SelIdx p.b p.j) - (B : Block p.g) (h : B≠Block.Z) (i : ℕ) : - (blitz p M)ᵀ *ᵥ pick p n s B i=pick p n s B i := by - classical - apply sub_eq_zero.mp - apply dot_ext_zero; intro x - unfold pick - split - next hn => - rw [dotProduct_sub,dotProduct_transpose_mulVec,single_one_dotProduct,dotProduct_single, - blitz_val]; simp [breeze,h] - next => rw [Matrix.mulVec_zero,sub_zero,dotProduct_zero] - -set_option maxHeartbeats 600000 in -theorem blitz_fixes (p : Shape) (M : Mat (Fin n) (Fin n)) (m : Mixer p n) : - pullM (blitz p M) (blitz p M) (selfM p n m.mixM)=selfM p n m.mixM := by - classical - let T := blitz p M - have h1 (i j : Tag p.g) : Block.O i j ≠ Block.Z := by simp [Block.O,Block.Z] - have h2 : (@Block.S p.g) ≠ Block.Z := by simp [Block.S,Block.Z] - have h3 : (@Block.sharp p.g) ≠ Block.Z := by simp [Block.sharp,Block.Z] - have hh (B : Block p.g) (h : B ≠ Block.Z) : - pullM T T (testM p n B)=testM p n B := by - unfold pullM testM - simp_rw [map_sum, liftM_outer, T,blitz_pick p M _ B h] - have hr (a i) : Tᵀ*ᵥsharpPick p n a i=sharpPick p n a i := by - unfold sharpPick - split - next h => exact blitz_pick p M _ _ h3 _ - next h => rw [Matrix.mulVec_zero] - have ht : - pullM T T (sharpM p n m.mixM)=sharpM p n m.mixM := by - unfold sharpM pullM - simp_rw [map_sum,map_smul,map_add,liftM_outer,hr,T,blitz_pick p M _ _ h3] - unfold selfM - simp_rw [map_add,map_sum] - change ((∑ d:Tag p.g,∑ t:Tag p.g,pullM T T (testM p n (Block.O d t)))+ - pullM T T (testM p n Block.S))+pullM T T (sharpM p n m.mixM)=_ - rw [ht,hh _ h2] - simp_rw [hh _ (h1 _ _)] - -/-- knobs player. -/ -def doZ (p : Shape) (M : Mat (Fin n) (Fin n)) (x : Knobs p.g n) := - Function.update x Block.Z (M *ᵥ (x Block.Z)) - -theorem sailsZ (p : Shape) (M : Mat (Fin n) (Fin n)) (x : Knobs p.g n) - (l s f) : - blitz p M *ᵥ spring p l s f x=spring p l s f (doZ p M x) := by - classical - rw [blitz_val] - funext i; rcases i with ⟨i, _|⟨B,j⟩⟩ - · rfl - by_cases h : B=Block.Z - · subst B - let a := selV p.j s i - have he (x : Knobs p.g n) (v : Fin n) : - spring p l s f x (i,some (Block.Z,v))=a*x Block.Z v := by - simp [spring,point,putLab,baseV,a,lit,Flavor.keepZ] - unfold breeze - simp_rw [ite_true,he] - let K := x Block.Z - change (M *ᵥ (a • K)) j=a*doZ p M x Block.Z j - rw [mulVec_smul]; simp [doZ,K] - simp [breeze,spring,point,baseV,putLab,lit,doZ,h] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.UnaryQueryFrequencies + +namespace OAI + +/-! # Free Block Linear Action -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module Submodule Function Finset LinearMap +open scoped BigOperators +variable {p : Shape} {n N : ℕ} +abbrev Flit (n : ℕ) := Move (Fin n) + +def breeze (p : Shape) (M : Mat (Fin n) (Fin n)) (x : Ray p n) : Ray p n := + fun i => + match i.2 with + | none => x i + | some (B,j) => if B=Block.Z then (M *ᵥ (fun j => x (i.1,some (Block.Z,j)))) j else x i + +def blitzL (p : Shape) (M : Mat (Fin n) (Fin n)) : Ray p n →ₗ[F] Ray p n where + toFun := breeze p M + map_add' x y := by + have he (i : SelIdx p.b p.j) : + (fun j : Fin n => (x+y) (i,some (Block.Z,j)))= + ((fun j => x (i,some (Block.Z,j)))+ (fun j => y (i,some (Block.Z,j)))) := rfl + funext i; rcases i with ⟨i, _|⟨B,j⟩⟩ + · rfl + by_cases h : B=Block.Z + · simp only [breeze,h,ite_true,he,mulVec_add] + rfl + simp [breeze,h] + map_smul' a x := by + have he (i : SelIdx p.b p.j) : + (fun j : Fin n => (a•x) (i,some (Block.Z,j)))= + a • (fun j => x (i,some (Block.Z,j))) := rfl + funext i; rcases i with ⟨i, _|⟨B,j⟩⟩ + · rfl + by_cases h : B=Block.Z + · simp only [breeze,h,ite_true,he,mulVec_smul]; rfl + simp [breeze,h] + +def blitz (p : Shape) (M : Mat (Fin n) (Fin n)) := LinearMap.toMatrix' (blitzL p M) + +theorem blitz_val (p : Shape) (M : Mat (Fin n) (Fin n)) (x) : + blitz p M *ᵥ x=breeze p M x := by + change LinearMap.toMatrix' (blitzL p M)*ᵥ x=blitzL p M x + simp + +theorem blitz_mul (p : Shape) (M L : Mat (Fin n) (Fin n)) : + blitz p (M*L)=blitz p M*blitz p L := by + classical + apply coe_mv_inj + apply LinearMap.ext + intro x; simp_rw [mulVecLin_apply,← mulVec_mulVec,blitz_val] + funext i; rcases i with ⟨i, _|⟨B,j⟩⟩ + · rfl + by_cases h : B=Block.Z + · simp only [breeze,h,ite_true,←mulVec_mulVec] + simp [breeze,h] + +theorem blitz_one (p : Shape) (n : ℕ) : blitz p (1:Mat (Fin n) (Fin n))=1 := by + apply coe_mv_inj; apply LinearMap.ext; intro x + rw [mulVecLin_apply,mulVecLin_apply,Matrix.one_mulVec,blitz_val] + funext i; rcases i with ⟨i, _|⟨B,j⟩⟩ + · rfl + by_cases h : B=Block.Z <;> simp [breeze,h] + +theorem blitz_pick (p : Shape) (M : Mat (Fin n) (Fin n)) (s : SelIdx p.b p.j) + (B : Block p.g) (h : B≠Block.Z) (i : ℕ) : + (blitz p M)ᵀ *ᵥ pick p n s B i=pick p n s B i := by + classical + apply sub_eq_zero.mp + apply dot_ext_zero; intro x + unfold pick + split + next hn => + rw [dotProduct_sub,dotProduct_transpose_mulVec,single_one_dotProduct,dotProduct_single, + blitz_val]; simp [breeze,h] + next => rw [Matrix.mulVec_zero,sub_zero,dotProduct_zero] + +set_option maxHeartbeats 600000 in +theorem blitz_fixes (p : Shape) (M : Mat (Fin n) (Fin n)) (m : Mixer p n) : + pullM (blitz p M) (blitz p M) (selfM p n m.mixM)=selfM p n m.mixM := by + classical + let T := blitz p M + have h1 (i j : Tag p.g) : Block.O i j ≠ Block.Z := by simp [Block.O,Block.Z] + have h2 : (@Block.S p.g) ≠ Block.Z := by simp [Block.S,Block.Z] + have h3 : (@Block.sharp p.g) ≠ Block.Z := by simp [Block.sharp,Block.Z] + have hh (B : Block p.g) (h : B ≠ Block.Z) : + pullM T T (testM p n B)=testM p n B := by + unfold pullM testM + simp_rw [map_sum, liftM_outer, T,blitz_pick p M _ B h] + have hr (a i) : Tᵀ*ᵥsharpPick p n a i=sharpPick p n a i := by + unfold sharpPick + split + next h => exact blitz_pick p M _ _ h3 _ + next h => rw [Matrix.mulVec_zero] + have ht : + pullM T T (sharpM p n m.mixM)=sharpM p n m.mixM := by + unfold sharpM pullM + simp_rw [map_sum,map_smul,map_add,liftM_outer,hr,T,blitz_pick p M _ _ h3] + unfold selfM + simp_rw [map_add,map_sum] + change ((∑ d:Tag p.g,∑ t:Tag p.g,pullM T T (testM p n (Block.O d t)))+ + pullM T T (testM p n Block.S))+pullM T T (sharpM p n m.mixM)=_ + rw [ht,hh _ h2] + simp_rw [hh _ (h1 _ _)] + +/-- knobs player. -/ +def doZ (p : Shape) (M : Mat (Fin n) (Fin n)) (x : Knobs p.g n) := + Function.update x Block.Z (M *ᵥ (x Block.Z)) + +theorem sailsZ (p : Shape) (M : Mat (Fin n) (Fin n)) (x : Knobs p.g n) + (l s f) : + blitz p M *ᵥ spring p l s f x=spring p l s f (doZ p M x) := by + classical + rw [blitz_val] + funext i; rcases i with ⟨i, _|⟨B,j⟩⟩ + · rfl + by_cases h : B=Block.Z + · subst B + let a := selV p.j s i + have he (x : Knobs p.g n) (v : Fin n) : + spring p l s f x (i,some (Block.Z,v))=a*x Block.Z v := by + simp [spring,point,putLab,baseV,a,lit,Flavor.keepZ] + unfold breeze + simp_rw [ite_true,he] + let K := x Block.Z + change (M *ᵥ (a • K)) j=a*doZ p M x Block.Z j + rw [mulVec_smul]; simp [doZ,K] + simp [breeze,spring,point,baseV,putLab,lit,doZ,h] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FreshGeneratorCorrection.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FreshGeneratorCorrection.lean index efc5ef22f42038e6355960e19c11f63c17308ab1..0b0a4b5ac5a3980a1978e17b3aff1e6b667b8fc7 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FreshGeneratorCorrection.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FreshGeneratorCorrection.lean @@ -1,120 +1,120 @@ -import OAI.Combinatorics.HadwigerCounterexample.LabeledGenerators - -namespace OAI - -/-! # Fresh Generator Correction -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Function LinearMap Submodule Module -open scoped BigOperators -namespace StatusAnalysis -variable {L I X Y : Type} [DecidableEq L] [DecidableEq I] -variable [AddCommGroup X] [Module F X] [AddCommGroup Y] [Module F Y] -namespace Club -variable (C : Club I X L) - -omit [DecidableEq L] [DecidableEq I] [AddCommGroup X] [Module F X] in -theorem bundle_back {p : Finset I} {s t : Straps L} (ht : s≤t) (h : bundle C p t) : - bundle C p s := ⟨fun i hi=> zone_smaller C ht i (h.1 i hi),h.2⟩ -omit [AddCommGroup X] [Module F X] in -theorem bundle_combine {p q : Finset I} {s : Straps L} (h : bundle C p s) - (hQ : bundle C q (s⊔addrs C p)) : - bundle C (p∪q) s∧ Disjoint p q := by - classical - have he {i j} (hi:i∈q) (hj:j∈p) : different C i j := fun b ht => (hQ.1 i hi).2 b - (mem_union_right _ (mem_image.mpr ⟨j,hj,Eq.symm ht⟩)) - refine ⟨⟨fun i h'=>?_, fun b i hi j hj ht=>?_⟩, - Finset.disjoint_left.mpr (fun i hi ht=> (he ht hi) true rfl)⟩ - · rcases mem_union.mp h' with hp|hp - · exact h.1 i hp - exact (bundle_back C le_sup_left hQ).1 i hp - rcases mem_union.mp hi with hi|hi <;> rcases mem_union.mp hj with hj|hj - · exact h.2 b hi hj ht - · exact (he hj hi b ht.symm).elim - · exact (he hi hj b ht).elim - exact hQ.2 b hi hj ht - -private theorem binary_word {x z : X} (h : z∈ Submodule.span F {x}) : - z=0 ∨ z=x := by - obtain ⟨a,ha⟩ := (Submodule.mem_span_singleton.mp h) - rcases bit_cases a with h|h <;> simpa [h,eq_comm,ha] using (by - simp [h] at ha; tauto : z=0∨z=x) - -abbrev sizeB (t : Straps L) (r : ℕ) := ∀ i,(t i).card≤ r - -def travels (s : Straps L) (n : ℕ) (π : X →ₗ[F] Y) (V : Space X) := - ∀ t:Straps L,sizeB t n→ C.band (s⊔t)=V ∧ C.yield3 (s⊔t) π - -omit [DecidableEq I] in -theorem travel_more {s : Straps L} {a b : ℕ} {π : X→ₗ[F] Y} {V} - (h : C.travels s a π V) {n : ℕ} (t : Straps L) (ht : sizeB t b) (hh : n+b ≤ a) : - C.travels (s⊔t) n π V := by - intro u hu - rw [sup_assoc] - apply h - exact fun i=> (Finset.card_union_le ..).trans - ((Nat.add_le_add (ht i) (hu i)).trans (add_comm b n ▸ hh)) -omit [DecidableEq I] in -theorem travel_now {s : Straps L} {a : ℕ} {π : X→ₗ[F] Y} {V} (h : C.travels s a π V) : - band C s=V ∧ yield3 C s π := by simpa using h ⊥ (by intro i; change (∅:Finset L).card≤_; simp) - -theorem length3_rich {s : Straps L} {a : ℕ} {π : X→ₗ[F] Y} {V} (h : C.travels s a π V) : - Submodule.span F (C.length3 s π) = V⊓LinearMap.ker π := - (ration_eq C s π (travel_now C h).2).trans (congrArg (·⊓LinearMap.ker π) (travel_now C h).1) - -variable [Module.Finite F X] -set_option maxHeartbeats 1000000 in -theorem jump_two {s : Straps L} {π : X →ₗ[F] Y} {V : Space X} - (h : C.travels s 3 π V) - (he : dim (V ⊓ LinearMap.ker π : Space X) ≤ 2) (x : X) (hx : x∈ V⊓LinearMap.ker π) : - ∃ p:Finset I,C.bundle p s∧p.card≤6∧C.contents p=x := by - classical - by_cases h0 : x=0 - · obtain ⟨p,h1,h2,h3,_⟩:=length3_zero C s π - exact ⟨p,h1,h2.trans (by decide),h3.trans h0.symm⟩ - let R := V⊓LinearMap.ker π - have hh {t : Straps L} {i : ℕ} (h : C.travels t i π V) - (Q : Space X) (e : x∉Q) : - ∃ y,y∈R∧C.length3 t π y∧y∉Q := by - rw [←length3_rich C h] at hx - by_contra! hg - apply e - exact (Submodule.span_le.mpr (fun i (hi : C.length3 _ _ _) => - hg i ((length3_rich C h).le (Submodule.subset_span hi)) hi)) hx - obtain ⟨y,hy,⟨p,hp,hP,hQ,hd⟩,ht⟩:=hh h ⊥ (by simpa using h0) - have hy' : y≠0 := by simpa using ht - let S:=Submodule.span F {y} - by_cases hh1 : x∈ S - · exact ⟨p,hp,hP.trans (by decide),hQ.trans (((binary_word hh1).resolve_left h0).symm)⟩ - let T:=s⊔C.addrs p - have hT : C.travels T 0 π V := travel_more C h (C.addrs p) - (fun i=>card_image_le.trans hP) (Nat.le_refl 3) - obtain ⟨z,hz,⟨q,hq,hq',hZ,_⟩,hv⟩:=hh hT S hh1 - let B:=Submodule.span F {z} - have hm : S⊔B=R := by - have hk : S⊔B≤ R := sup_le ((Submodule.span_singleton_le_iff_mem ..).mpr hy) - ((Submodule.span_singleton_le_iff_mem ..).mpr hz) - have hh:= Submodule.finrank_sup_span_singleton hv - have ht : dim S=1 := finrank_span_singleton hy' - exact Submodule.eq_of_le_of_finrank_le hk (by - change dim R≤dim (S⊔B : Space X) - change dim (S⊔B : Space X) = dim S+1 at hh - rw [hh,ht]; exact he) - obtain ⟨u,hu,t,ht,hx⟩:= Submodule.mem_sup.mp (show x∈ S⊔B from hm.symm ▸ hx) - rcases binary_word hu with hA|hA <;> rcases binary_word ht with hB|hB - · rw [hA,hB,zero_add] at hx; exact (h0 hx.symm).elim - · rw [hA,hB,zero_add] at hx - exact ⟨q,bundle_back C le_sup_left hq,hq'.trans (by decide),hZ.trans hx⟩ - · rw [hA,hB,add_zero] at hx; exact ⟨p,hp,hP.trans (by decide),hQ.trans hx⟩ - obtain ⟨hg,hD⟩:=bundle_combine C hp hq - refine ⟨p∪q,hg,(card_union_le ..).trans (by omega),?_⟩ - rw [contents,Finset.sum_union hD]; change C.contents _+_=_ - exact (congrArg₂ (·+·) (hQ.trans hA.symm) (hZ.trans hB.symm)).trans hx -end Club -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.LabeledGenerators + +namespace OAI + +/-! # Fresh Generator Correction -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Function LinearMap Submodule Module +open scoped BigOperators +namespace StatusAnalysis +variable {L I X Y : Type} [DecidableEq L] [DecidableEq I] +variable [AddCommGroup X] [Module F X] [AddCommGroup Y] [Module F Y] +namespace Club +variable (C : Club I X L) + +omit [DecidableEq L] [DecidableEq I] [AddCommGroup X] [Module F X] in +theorem bundle_back {p : Finset I} {s t : Straps L} (ht : s≤t) (h : bundle C p t) : + bundle C p s := ⟨fun i hi=> zone_smaller C ht i (h.1 i hi),h.2⟩ +omit [AddCommGroup X] [Module F X] in +theorem bundle_combine {p q : Finset I} {s : Straps L} (h : bundle C p s) + (hQ : bundle C q (s⊔addrs C p)) : + bundle C (p∪q) s∧ Disjoint p q := by + classical + have he {i j} (hi:i∈q) (hj:j∈p) : different C i j := fun b ht => (hQ.1 i hi).2 b + (mem_union_right _ (mem_image.mpr ⟨j,hj,Eq.symm ht⟩)) + refine ⟨⟨fun i h'=>?_, fun b i hi j hj ht=>?_⟩, + Finset.disjoint_left.mpr (fun i hi ht=> (he ht hi) true rfl)⟩ + · rcases mem_union.mp h' with hp|hp + · exact h.1 i hp + exact (bundle_back C le_sup_left hQ).1 i hp + rcases mem_union.mp hi with hi|hi <;> rcases mem_union.mp hj with hj|hj + · exact h.2 b hi hj ht + · exact (he hj hi b ht.symm).elim + · exact (he hi hj b ht).elim + exact hQ.2 b hi hj ht + +private theorem binary_word {x z : X} (h : z∈ Submodule.span F {x}) : + z=0 ∨ z=x := by + obtain ⟨a,ha⟩ := (Submodule.mem_span_singleton.mp h) + rcases bit_cases a with h|h <;> simpa [h,eq_comm,ha] using (by + simp [h] at ha; tauto : z=0∨z=x) + +abbrev sizeB (t : Straps L) (r : ℕ) := ∀ i,(t i).card≤ r + +def travels (s : Straps L) (n : ℕ) (π : X →ₗ[F] Y) (V : Space X) := + ∀ t:Straps L,sizeB t n→ C.band (s⊔t)=V ∧ C.yield3 (s⊔t) π + +omit [DecidableEq I] in +theorem travel_more {s : Straps L} {a b : ℕ} {π : X→ₗ[F] Y} {V} + (h : C.travels s a π V) {n : ℕ} (t : Straps L) (ht : sizeB t b) (hh : n+b ≤ a) : + C.travels (s⊔t) n π V := by + intro u hu + rw [sup_assoc] + apply h + exact fun i=> (Finset.card_union_le ..).trans + ((Nat.add_le_add (ht i) (hu i)).trans (add_comm b n ▸ hh)) +omit [DecidableEq I] in +theorem travel_now {s : Straps L} {a : ℕ} {π : X→ₗ[F] Y} {V} (h : C.travels s a π V) : + band C s=V ∧ yield3 C s π := by simpa using h ⊥ (by intro i; change (∅:Finset L).card≤_; simp) + +theorem length3_rich {s : Straps L} {a : ℕ} {π : X→ₗ[F] Y} {V} (h : C.travels s a π V) : + Submodule.span F (C.length3 s π) = V⊓LinearMap.ker π := + (ration_eq C s π (travel_now C h).2).trans (congrArg (·⊓LinearMap.ker π) (travel_now C h).1) + +variable [Module.Finite F X] +set_option maxHeartbeats 1000000 in +theorem jump_two {s : Straps L} {π : X →ₗ[F] Y} {V : Space X} + (h : C.travels s 3 π V) + (he : dim (V ⊓ LinearMap.ker π : Space X) ≤ 2) (x : X) (hx : x∈ V⊓LinearMap.ker π) : + ∃ p:Finset I,C.bundle p s∧p.card≤6∧C.contents p=x := by + classical + by_cases h0 : x=0 + · obtain ⟨p,h1,h2,h3,_⟩:=length3_zero C s π + exact ⟨p,h1,h2.trans (by decide),h3.trans h0.symm⟩ + let R := V⊓LinearMap.ker π + have hh {t : Straps L} {i : ℕ} (h : C.travels t i π V) + (Q : Space X) (e : x∉Q) : + ∃ y,y∈R∧C.length3 t π y∧y∉Q := by + rw [←length3_rich C h] at hx + by_contra! hg + apply e + exact (Submodule.span_le.mpr (fun i (hi : C.length3 _ _ _) => + hg i ((length3_rich C h).le (Submodule.subset_span hi)) hi)) hx + obtain ⟨y,hy,⟨p,hp,hP,hQ,hd⟩,ht⟩:=hh h ⊥ (by simpa using h0) + have hy' : y≠0 := by simpa using ht + let S:=Submodule.span F {y} + by_cases hh1 : x∈ S + · exact ⟨p,hp,hP.trans (by decide),hQ.trans (((binary_word hh1).resolve_left h0).symm)⟩ + let T:=s⊔C.addrs p + have hT : C.travels T 0 π V := travel_more C h (C.addrs p) + (fun i=>card_image_le.trans hP) (Nat.le_refl 3) + obtain ⟨z,hz,⟨q,hq,hq',hZ,_⟩,hv⟩:=hh hT S hh1 + let B:=Submodule.span F {z} + have hm : S⊔B=R := by + have hk : S⊔B≤ R := sup_le ((Submodule.span_singleton_le_iff_mem ..).mpr hy) + ((Submodule.span_singleton_le_iff_mem ..).mpr hz) + have hh:= Submodule.finrank_sup_span_singleton hv + have ht : dim S=1 := finrank_span_singleton hy' + exact Submodule.eq_of_le_of_finrank_le hk (by + change dim R≤dim (S⊔B : Space X) + change dim (S⊔B : Space X) = dim S+1 at hh + rw [hh,ht]; exact he) + obtain ⟨u,hu,t,ht,hx⟩:= Submodule.mem_sup.mp (show x∈ S⊔B from hm.symm ▸ hx) + rcases binary_word hu with hA|hA <;> rcases binary_word ht with hB|hB + · rw [hA,hB,zero_add] at hx; exact (h0 hx.symm).elim + · rw [hA,hB,zero_add] at hx + exact ⟨q,bundle_back C le_sup_left hq,hq'.trans (by decide),hZ.trans hx⟩ + · rw [hA,hB,add_zero] at hx; exact ⟨p,hp,hP.trans (by decide),hQ.trans hx⟩ + obtain ⟨hg,hD⟩:=bundle_combine C hp hq + refine ⟨p∪q,hg,(card_union_le ..).trans (by omega),?_⟩ + rw [contents,Finset.sum_union hD]; change C.contents _+_=_ + exact (congrArg₂ (·+·) (hQ.trans hA.symm) (hZ.trans hB.symm)).trans hx +end Club +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FrozenProjections.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FrozenProjections.lean index 7ad803872423b1c5aaed3d39abe3850a865a6b76..03f28f1849e771f1f89e0cd1a1079a31eeb68978 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FrozenProjections.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FrozenProjections.lean @@ -1,175 +1,175 @@ -import OAI.Combinatorics.HadwigerCounterexample.LinearResponse -import OAI.Combinatorics.HadwigerCounterexample.GradientRankBounds - -namespace OAI - -/-! # Frozen Projections -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Submodule Module Finset -open scoped BigOperators -variable {p : Shape} {n : ℕ} - -variable {I : Type} [Fintype I] -namespace Volley -variable (v : Volley p n I) - -/-- D + attack directions. -/ -def frozen (a : Plan p n) (t : Tagging p I) : Plan p n := a⊔v.keyPlan t - -/-- All labels at one endpoint. -/ -def marked (i : Bool) := (v.here i).image v.sel - -theorem marked_mem (x : I) : v.sel x ∈ v.marked (v.obj x) := by - classical exact Finset.mem_image_of_mem _ (by simp [here]) - -theorem marked_card {w : I → Bool} (hv : v.bounded w) (i : Bool) : - (v.marked i).card ≤14 := by - classical exact Finset.card_image_le.trans (v.here_card hv i) - -/-- project matrix of active key rays to one endpoint under attack -/ -def visitH (t : Tagging p I) (i : Bool) (e : Comp p.g) : Finset (visits p t e) := - Finset.univ.filter (fun j => v.obj j.val=i) - -theorem visitH_here (t : Tagging p I) (i : Bool) (e : Comp p.g) - {j : visits p t e} : - j ∈ v.visitH t i e ↔ j.val ∈ v.here i := by simp [visitH,here] - -theorem visitH_card {w : I → Bool} (hv : v.bounded w) - (t : Tagging p I) (i : Bool) (e : Comp p.g) : - (v.visitH t i e).card ≤14 := by - classical - rw [← Finset.card_image_of_injective _ (@Subtype.val_injective _ _)] - refine (Finset.card_le_card ?_).trans (v.here_card hv i) - rintro x hx - obtain ⟨j,hj,rfl⟩ := Finset.mem_image.mp hx - exact (v.visitH_here ..).mp hj - -theorem key_proj (t : Tagging p I) (i : Bool) (e : Comp p.g) (x : Vec (visits p t e)) : - (IP p n i)ᵀ *ᵥ (v.keyM t e *ᵥ x)= ∑ j∈v.visitH t i e,x j • v.rayAt j.val := by - classical - have he : v.keyM t e *ᵥ x = ∑ j : visits p t e,x j • (v.rayLoc j.val) := by - rw [mulVec_eq_sum] - simp_rw [op_smul_eq_smul] - rfl - change ((IP p n i)ᵀ.mulVecLin _) = _ - rw [he,map_sum,visitH,Finset.sum_filter] - refine sum_congr rfl fun j _ => ?_ - rw [map_smul,mulVecLin_apply,rayLoc,mulVec_mulVec] - by_cases hj : v.obj j.val=i - · rw [ite_eq_left hj,hj,IP_self,one_mulVec] - rw [ite_eq_right hj,IP_cross (Ne.symm hj),zero_mulVec,smul_zero] - -theorem key_here_dim {w : I→Bool} (hv : v.bounded w) (t : Tagging p I) - (i : Bool) (z : Place p) : - dim (sPin (v.keyPlan t) z i) ≤14 := by - classical - let S := v.visitH t i z.1 - let M : Mat (Row p n) S := Matrix.of fun i j => v.rayAt j.val.val i - have hM : M.rank ≤14 := M.rank_le_card_width.trans - (Fintype.card_coe S ▸ (v.visitH_card hv t i z.1)) - refine (Submodule.finrank_mono (show sPin (v.keyPlan t) z i≤colSp M from ?_)).trans hM - rintro y ⟨x,⟨a,rfl⟩,rfl⟩ - let b (j:S) := a j.val - refine ⟨b,?_⟩ - change M *ᵥ b=(IP p n i)ᵀ *ᵥ _ - rw [mulVecLin_apply,v.key_proj,mulVec_eq_sum] - simp_rw [op_smul_eq_smul] - change (∑ j:S,b j • v.rayAt j.val.val)=∑ j∈S,a j • v.rayAt j.val - exact Finset.sum_coe_sort S (fun i => a i • v.rayAt i.val) - -theorem key_dim {w : I→Bool} (hv : v.bounded w) (t : Tagging p I) (z : Place p) : - dim (v.keyPlan t z) ≤28 := by - classical - exact (v.keyM t z.1).rank_le_card_width.trans ((Fintype.card_le_of_injective (@Subtype.val _ _) Subtype.val_injective).trans (v.call_count hv)) - -theorem sPin_frozen (a : Plan p n) (t : Tagging p I) (i : Bool) (z : Place p) : - sPin (v.frozen a t) z i=sPin a z i⊔sPin (v.keyPlan t) z i := - Submodule.map_sup _ _ _ - -theorem hPin_frozen (a : Plan p n) (t : Tagging p I) (i : Bool) (z : Place p) : - hPin (v.frozen a t) z i=hPin a z i := by - have h : hPin (v.keyPlan t) z i≤(⊥ : Space _) := by - rintro x ⟨y,hy,rfl⟩ - have he := primal_proj i ((keyPlane v t z) hy) - rw [LinearMap.mem_ker] at he - rw [he]; exact Submodule.zero_mem _ - change hPin (v.frozen a t) z i=hPin a z i - rw [show hPin (v.frozen a t) z i=hPin a z i⊔ hPin (v.keyPlan t) z i from - Submodule.map_sup _ _ _, le_bot_iff.mp h,sup_bot_eq] - -theorem frozen_here_dim {w : I→ Bool} (hv : v.bounded w) - (a : Plan p n) (t : Tagging p I) (i z) : - dim (sPin (v.frozen a t) z i) ≤ planRank a + 14 := by - rw [v.sPin_frozen] - exact (Submodule.finrank_add_le_finrank_add_finrank ..).trans - (Nat.add_le_add ((sPin_dim ..).trans (dim_le_plan ..)) (v.key_here_dim hv t i z)) -end Volley - -theorem ip_annih {f : Plan p n} (i : Bool) (z : Place p) (x : Ray p n) : - IP p n i *ᵥ x∈annih (f z) ↔ x∈ annih (sPin f z i) := by - rw [annih_mem,annih_mem] - have hh (y : Dir p n) : dotProduct (IP p n i *ᵥ x) y= dotProduct x ((IP p n i)ᵀ *ᵥ y) := by - rw [dotProduct_transpose_mulVec,dotProduct_comm] - constructor - · rintro he y ⟨y,hy,rfl⟩ - rw [mulVecLin_apply,← hh] - exact he y hy - intro h y hy - rw [hh] - exact h _ ⟨y,hy,rfl⟩ - -theorem orth_pair_sym (x : Xpair p n) (e : Comp p.g) (i : Bool) : - ((x i).val e)ᵀ=(x i).val e := by - obtain ⟨w,h,hx⟩ := mem_X.mp (x i).property - rw [←hx] - exact Wspace_sym ((Wspace p n).add_mem ((Wtag_le _) (h e.val.1)) ((Wtag_le _) (h e.val.2))) - -theorem purePair_sym (x : Xpair p n) (e : Comp p.g) : - (purePair p n x e)ᵀ = purePair p n x e := by - simp only [purePair,Finset.sum_apply,Fintype.sum_bool,transpose_add,liftM_transpose, - orth_pair_sym] - -theorem pure_ip (x : Xpair p n) (e : Comp p.g) (i : Bool) (v : Ray p n) : - purePair p n x e *ᵥ (IP p n i *ᵥ v)=IP p n i *ᵥ ((x i).val e *ᵥ v) := by - classical - simp only [purePair,Finset.sum_apply,Fintype.sum_bool,Matrix.add_mulVec,liftM_def, - ← Matrix.mulVec_mulVec] - cases i <;> - (simp_rw [Matrix.mulVec_mulVec v (IP p n _)ᵀ] - simp only [IP_self,IP_cross (show false≠true by decide),IP_cross (show true≠false by decide), - Matrix.zero_mulVec, Matrix.one_mulVec,Matrix.mulVec_zero,zero_add,add_zero]) - -theorem vanish_one {f b : Plan p n} {x : Xpair p n} {C : ChanOut p n} {j} - (h : orth p C f b j x) (i : Bool) (e : Comp p.g) : - vanish (sPin f (e,true) i) (sPin f (e,false) i) ((x i).val e) := by - intro u hu v hv - have he := orth_pure h e (IP p n i *ᵥ u) ((ip_annih i _ u).mpr hu) (IP p n i *ᵥ v) - ((ip_annih i _ v).mpr hv) - rw [evmat,pure_ip, ← dotProduct_transpose_mulVec, mulVec_mulVec, - IP_self, Matrix.one_mulVec,dotProduct_comm] at he - exact he - -/-- For an annihilator cut pair, testing a right or left primal -functional on endpoint i annihilating projected pins-and-keys produces -an entire vector in the opposite frozen space. -/ -theorem orth_ip_frozen {f b : Plan p n} {x : Xpair p n} {C : ChanOut p n} {j} - (h : orth p C f b j x) (i : Bool) (z : Place p) (φ : Ray p n) - (hh : φ∈annih (sPin f (flipZ p z) i)) : - IP p n i *ᵥ ((x i).val z.1 *ᵥ φ) ∈ f z := by - rw [← pure_ip,← annih_annih (f z),annih_mem] - intro ψ hψ - have hr := (ip_annih i _ _).mpr hh - rw [dotProduct_comm] - rcases z with ⟨e,c|c⟩ - · have he := orth_pure h e _ hr _ hψ - rw [← evmat_transpose,purePair_sym] at he - exact he - exact orth_pure h e _ hψ _ hr - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.LinearResponse +import OAI.Combinatorics.HadwigerCounterexample.GradientRankBounds + +namespace OAI + +/-! # Frozen Projections -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Submodule Module Finset +open scoped BigOperators +variable {p : Shape} {n : ℕ} + +variable {I : Type} [Fintype I] +namespace Volley +variable (v : Volley p n I) + +/-- D + attack directions. -/ +def frozen (a : Plan p n) (t : Tagging p I) : Plan p n := a⊔v.keyPlan t + +/-- All labels at one endpoint. -/ +def marked (i : Bool) := (v.here i).image v.sel + +theorem marked_mem (x : I) : v.sel x ∈ v.marked (v.obj x) := by + classical exact Finset.mem_image_of_mem _ (by simp [here]) + +theorem marked_card {w : I → Bool} (hv : v.bounded w) (i : Bool) : + (v.marked i).card ≤14 := by + classical exact Finset.card_image_le.trans (v.here_card hv i) + +/-- project matrix of active key rays to one endpoint under attack -/ +def visitH (t : Tagging p I) (i : Bool) (e : Comp p.g) : Finset (visits p t e) := + Finset.univ.filter (fun j => v.obj j.val=i) + +theorem visitH_here (t : Tagging p I) (i : Bool) (e : Comp p.g) + {j : visits p t e} : + j ∈ v.visitH t i e ↔ j.val ∈ v.here i := by simp [visitH,here] + +theorem visitH_card {w : I → Bool} (hv : v.bounded w) + (t : Tagging p I) (i : Bool) (e : Comp p.g) : + (v.visitH t i e).card ≤14 := by + classical + rw [← Finset.card_image_of_injective _ (@Subtype.val_injective _ _)] + refine (Finset.card_le_card ?_).trans (v.here_card hv i) + rintro x hx + obtain ⟨j,hj,rfl⟩ := Finset.mem_image.mp hx + exact (v.visitH_here ..).mp hj + +theorem key_proj (t : Tagging p I) (i : Bool) (e : Comp p.g) (x : Vec (visits p t e)) : + (IP p n i)ᵀ *ᵥ (v.keyM t e *ᵥ x)= ∑ j∈v.visitH t i e,x j • v.rayAt j.val := by + classical + have he : v.keyM t e *ᵥ x = ∑ j : visits p t e,x j • (v.rayLoc j.val) := by + rw [mulVec_eq_sum] + simp_rw [op_smul_eq_smul] + rfl + change ((IP p n i)ᵀ.mulVecLin _) = _ + rw [he,map_sum,visitH,Finset.sum_filter] + refine sum_congr rfl fun j _ => ?_ + rw [map_smul,mulVecLin_apply,rayLoc,mulVec_mulVec] + by_cases hj : v.obj j.val=i + · rw [ite_eq_left hj,hj,IP_self,one_mulVec] + rw [ite_eq_right hj,IP_cross (Ne.symm hj),zero_mulVec,smul_zero] + +theorem key_here_dim {w : I→Bool} (hv : v.bounded w) (t : Tagging p I) + (i : Bool) (z : Place p) : + dim (sPin (v.keyPlan t) z i) ≤14 := by + classical + let S := v.visitH t i z.1 + let M : Mat (Row p n) S := Matrix.of fun i j => v.rayAt j.val.val i + have hM : M.rank ≤14 := M.rank_le_card_width.trans + (Fintype.card_coe S ▸ (v.visitH_card hv t i z.1)) + refine (Submodule.finrank_mono (show sPin (v.keyPlan t) z i≤colSp M from ?_)).trans hM + rintro y ⟨x,⟨a,rfl⟩,rfl⟩ + let b (j:S) := a j.val + refine ⟨b,?_⟩ + change M *ᵥ b=(IP p n i)ᵀ *ᵥ _ + rw [mulVecLin_apply,v.key_proj,mulVec_eq_sum] + simp_rw [op_smul_eq_smul] + change (∑ j:S,b j • v.rayAt j.val.val)=∑ j∈S,a j • v.rayAt j.val + exact Finset.sum_coe_sort S (fun i => a i • v.rayAt i.val) + +theorem key_dim {w : I→Bool} (hv : v.bounded w) (t : Tagging p I) (z : Place p) : + dim (v.keyPlan t z) ≤28 := by + classical + exact (v.keyM t z.1).rank_le_card_width.trans ((Fintype.card_le_of_injective (@Subtype.val _ _) Subtype.val_injective).trans (v.call_count hv)) + +theorem sPin_frozen (a : Plan p n) (t : Tagging p I) (i : Bool) (z : Place p) : + sPin (v.frozen a t) z i=sPin a z i⊔sPin (v.keyPlan t) z i := + Submodule.map_sup _ _ _ + +theorem hPin_frozen (a : Plan p n) (t : Tagging p I) (i : Bool) (z : Place p) : + hPin (v.frozen a t) z i=hPin a z i := by + have h : hPin (v.keyPlan t) z i≤(⊥ : Space _) := by + rintro x ⟨y,hy,rfl⟩ + have he := primal_proj i ((keyPlane v t z) hy) + rw [LinearMap.mem_ker] at he + rw [he]; exact Submodule.zero_mem _ + change hPin (v.frozen a t) z i=hPin a z i + rw [show hPin (v.frozen a t) z i=hPin a z i⊔ hPin (v.keyPlan t) z i from + Submodule.map_sup _ _ _, le_bot_iff.mp h,sup_bot_eq] + +theorem frozen_here_dim {w : I→ Bool} (hv : v.bounded w) + (a : Plan p n) (t : Tagging p I) (i z) : + dim (sPin (v.frozen a t) z i) ≤ planRank a + 14 := by + rw [v.sPin_frozen] + exact (Submodule.finrank_add_le_finrank_add_finrank ..).trans + (Nat.add_le_add ((sPin_dim ..).trans (dim_le_plan ..)) (v.key_here_dim hv t i z)) +end Volley + +theorem ip_annih {f : Plan p n} (i : Bool) (z : Place p) (x : Ray p n) : + IP p n i *ᵥ x∈annih (f z) ↔ x∈ annih (sPin f z i) := by + rw [annih_mem,annih_mem] + have hh (y : Dir p n) : dotProduct (IP p n i *ᵥ x) y= dotProduct x ((IP p n i)ᵀ *ᵥ y) := by + rw [dotProduct_transpose_mulVec,dotProduct_comm] + constructor + · rintro he y ⟨y,hy,rfl⟩ + rw [mulVecLin_apply,← hh] + exact he y hy + intro h y hy + rw [hh] + exact h _ ⟨y,hy,rfl⟩ + +theorem orth_pair_sym (x : Xpair p n) (e : Comp p.g) (i : Bool) : + ((x i).val e)ᵀ=(x i).val e := by + obtain ⟨w,h,hx⟩ := mem_X.mp (x i).property + rw [←hx] + exact Wspace_sym ((Wspace p n).add_mem ((Wtag_le _) (h e.val.1)) ((Wtag_le _) (h e.val.2))) + +theorem purePair_sym (x : Xpair p n) (e : Comp p.g) : + (purePair p n x e)ᵀ = purePair p n x e := by + simp only [purePair,Finset.sum_apply,Fintype.sum_bool,transpose_add,liftM_transpose, + orth_pair_sym] + +theorem pure_ip (x : Xpair p n) (e : Comp p.g) (i : Bool) (v : Ray p n) : + purePair p n x e *ᵥ (IP p n i *ᵥ v)=IP p n i *ᵥ ((x i).val e *ᵥ v) := by + classical + simp only [purePair,Finset.sum_apply,Fintype.sum_bool,Matrix.add_mulVec,liftM_def, + ← Matrix.mulVec_mulVec] + cases i <;> + (simp_rw [Matrix.mulVec_mulVec v (IP p n _)ᵀ] + simp only [IP_self,IP_cross (show false≠true by decide),IP_cross (show true≠false by decide), + Matrix.zero_mulVec, Matrix.one_mulVec,Matrix.mulVec_zero,zero_add,add_zero]) + +theorem vanish_one {f b : Plan p n} {x : Xpair p n} {C : ChanOut p n} {j} + (h : orth p C f b j x) (i : Bool) (e : Comp p.g) : + vanish (sPin f (e,true) i) (sPin f (e,false) i) ((x i).val e) := by + intro u hu v hv + have he := orth_pure h e (IP p n i *ᵥ u) ((ip_annih i _ u).mpr hu) (IP p n i *ᵥ v) + ((ip_annih i _ v).mpr hv) + rw [evmat,pure_ip, ← dotProduct_transpose_mulVec, mulVec_mulVec, + IP_self, Matrix.one_mulVec,dotProduct_comm] at he + exact he + +/-- For an annihilator cut pair, testing a right or left primal +functional on endpoint i annihilating projected pins-and-keys produces +an entire vector in the opposite frozen space. -/ +theorem orth_ip_frozen {f b : Plan p n} {x : Xpair p n} {C : ChanOut p n} {j} + (h : orth p C f b j x) (i : Bool) (z : Place p) (φ : Ray p n) + (hh : φ∈annih (sPin f (flipZ p z) i)) : + IP p n i *ᵥ ((x i).val z.1 *ᵥ φ) ∈ f z := by + rw [← pure_ip,← annih_annih (f z),annih_mem] + intro ψ hψ + have hr := (ip_annih i _ _).mpr hh + rw [dotProduct_comm] + rcases z with ⟨e,c|c⟩ + · have he := orth_pure h e _ hr _ hψ + rw [← evmat_transpose,purePair_sym] at he + exact he + exact orth_pure h e _ hψ _ hr + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/FullTemplateComparison.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/FullTemplateComparison.lean index 650b79b23dc9649d87b901be21b50006edb87f5a..10549d248d431dae6a1932d929e415ab29ea5a4b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/FullTemplateComparison.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/FullTemplateComparison.lean @@ -1,118 +1,118 @@ -import OAI.Combinatorics.HadwigerCounterexample.FixedPositionTests - -namespace OAI - -/-! # Full Template Comparison -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Function LinearMap -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I J A B : Type} [Fintype I] [DecidableEq I] - -theorem ab_cut (p : Prop) (x : ℝ) (hx : |x|≤1) : |ind p*x|≤1 := by - classical - by_cases h : p - · rwa [ind_one h,one_mul] - rw [ind_zero h,zero_mul]; norm_num - -theorem lift_window [Fintype A] [Fintype B] {u : Wgt A} (hu : IsLaw u) - (v : Wgt B) (r : Wgt (A×B)) (s : Wgt A) (g : A→ Wgt B) - (hr : ∀ i, r i = s i.1*g i.1 i.2) (hs : ∀ i, |s i|≤1) (ε : ℝ) - (hh : ∀ i, |avg v (g i)| ≤ ε) : |avg (pairW u v) r|≤ ε := by - rw [pairW_avg] - simp_rw [hr,avg_mul'] - apply (abs_avg_le hu.nz).trans - exact hu.avg_le (fun i => by - rw [abs_mul]; exact (mul_le_mul (hs _) (hh _) (abs_nonneg _) zero_le_one).trans_eq (one_mul _)) - -namespace Template -variable (v : Template p I) - -set_option maxHeartbeats 800000 in -theorem patched_board (v : Template p I) (j : I) (q : I→ F) (a : AtomKey (p:=p) (v.t j) N→ J) - (B : J → Wgt (Keys (p:=p) (v.beyond j).t N)) (ε : ℝ) - (h : ∀ i, shadowed (v.beyond j) (v.boundTail j q) (B i) ε) : - shadowed v q (patched v j a B) ε := by - classical - intro f hf - let t:=v.beyond j; let Q:=v.boundTail j q - let E := chairK v j N - let F (x : Keys (p:=p) v.t N) := - v.curtain q (v.patched j a B) x * prodW f x - let s (x : AtomKey (p:=p) (v.t j) N) := ind (ownOne p _ (q j) x)*f j x - let g (x : AtomKey (p:=p) (v.t j) N) : Localist t N := fun i z=> ind (v.bolts x z)*f i.val z - let G x (y : Keys (p:=p) t.t N) := curtain t Q (B (a x)) y * prodW (g x) y - have he k : (F ∘ E.symm) k=s k.1 * G k.1 k.2 := by - obtain ⟨k,rfl⟩ := E.surjective k - simp only [Function.comp_apply,Equiv.symm_apply_apply] - unfold F curtain - rw [bolts_split v j,chair_split _ _ j]; simp only [ind_and,ind_all] - change _ * v.patched _ _ _ k * (f j (k j)* _)=s (k j)*G (k j) (E k).2 - unfold s G patched curtain g - unfold prodW - rw [Finset.prod_mul_distrib] - exact (show ∀ (a b c d e f : ℝ), a*(b*c)*d*(e*f)=(a*e)*(c*d*(b*f)) from by intro a b c d e f; ring) _ _ _ _ _ _ - have hh (x) : |avg unif (G x)|≤ε := h (a x) _ (fun i y=>ab_cut _ _ (hf _ _)) - have hz (x) : |s x|≤1 := ab_cut _ _ (hf _ _) - have ht : mapW unif E= pairW unif unif := by rw [←pair_unif,unif_equiv] - have hl := lift_window unif_law unif _ _ _ he hz ε hh - rw [←ht,mapW_avg] at hl - simp only [Function.comp_apply,Equiv.symm_apply_apply] at hl; exact hl - -set_option maxHeartbeats 800000 in -theorem patched_exceed (v : Template p I) (j : I) (q : I→F) (a : AtomKey (p:=p) (v.t j) N→J) - (B : J → Wgt (Keys (p:=p) (v.beyond j).t N)) (ε : ℝ) - (w : I→Wgt (Knobs p.g n)) (hw : ∀ i,IsLaw (w i)) - (s : Script p I) (m : Mixer p n) (o : UnitType p n N) - (h : ∀ i,¬ exceeds (v.beyond j) (v.boundTail j q) (B i) (scriptTail s j) - m (fun i => w i.val) ε o) : - ¬ exceeds v q (patched v j a B) s m w ε o := by - classical - rintro ⟨f,hf,hZ⟩ - let x' := patched v j a B - apply not_lt_of_ge _ hZ - change |astonish v q x' s m w f o|≤ε - rw [astonish_val] - let v' := v.beyond j; let Q := v.boundTail j q - let E := chairI v j n - let R := scriptTail s j - let U (i : Inputs p n I) := ind (earns v s m q o i)*x' (v.resultKey o i)*prodW f i - let K := Knobs p.g n - let x (z : K) := nib v o j z - let g (i : K) (t : Aside j) (z : K) := ind (v.lintel j m s o i t z)*f t.val z - let C (i) := ind (ownOne p _ (q j) (x i))*f j i - let G i (y : Inputs p n (Aside j)) := - ind (earns v' R m Q o y)*B (a (x i)) (v'.resultKey o y)*prodW (g i) y - have he k : (U ∘ E.symm) k=C k.1*G k.1 k.2 := by - obtain ⟨k,rfl⟩ := E.surjective k - simp only [Function.comp_apply,Equiv.symm_apply_apply] - unfold U - rw [earns_split v j,chair_split _ _ j]; simp only [ind_and,ind_all] - unfold x' patched; rw [key_split] - unfold C G g prodW - rw [Finset.prod_mul_distrib] - dsimp only [x,E,v',R,chairI,chair] - change _ * B (a (nib v o j (k j))) _ * _ = _ - unfold nib - dsimp only [Q,Equiv.piSplitAt,Equiv.coe_fn_mk] - ring - let W := prodW (fun i:Aside j=> w i.val) - have hh (i) : |avg W (G i)|≤ ε := by - have hz (k z) : |g i k z|≤1 := ab_cut _ _ (hf _ _) - have hb : |astonish v' Q (B (a (x i))) R m (fun i=>w i.val) (g i) o|≤ε := - le_of_not_gt (fun hb=>h (a (x i)) ⟨g i,hz,hb⟩) - rw [astonish_val] at hb; exact hb - have hC i : |C i|≤1 := ab_cut _ _ (hf _ _) - have ht : mapW (prodW w) E=pairW (w j) W := chair_weight w j - have hz := lift_window (hw j) W _ _ _ he hC ε hh - rw [←ht,mapW_avg] at hz - simp only [Function.comp_apply,Equiv.symm_apply_apply] at hz - exact hz - -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FixedPositionTests + +namespace OAI + +/-! # Full Template Comparison -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Function LinearMap +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I J A B : Type} [Fintype I] [DecidableEq I] + +theorem ab_cut (p : Prop) (x : ℝ) (hx : |x|≤1) : |ind p*x|≤1 := by + classical + by_cases h : p + · rwa [ind_one h,one_mul] + rw [ind_zero h,zero_mul]; norm_num + +theorem lift_window [Fintype A] [Fintype B] {u : Wgt A} (hu : IsLaw u) + (v : Wgt B) (r : Wgt (A×B)) (s : Wgt A) (g : A→ Wgt B) + (hr : ∀ i, r i = s i.1*g i.1 i.2) (hs : ∀ i, |s i|≤1) (ε : ℝ) + (hh : ∀ i, |avg v (g i)| ≤ ε) : |avg (pairW u v) r|≤ ε := by + rw [pairW_avg] + simp_rw [hr,avg_mul'] + apply (abs_avg_le hu.nz).trans + exact hu.avg_le (fun i => by + rw [abs_mul]; exact (mul_le_mul (hs _) (hh _) (abs_nonneg _) zero_le_one).trans_eq (one_mul _)) + +namespace Template +variable (v : Template p I) + +set_option maxHeartbeats 800000 in +theorem patched_board (v : Template p I) (j : I) (q : I→ F) (a : AtomKey (p:=p) (v.t j) N→ J) + (B : J → Wgt (Keys (p:=p) (v.beyond j).t N)) (ε : ℝ) + (h : ∀ i, shadowed (v.beyond j) (v.boundTail j q) (B i) ε) : + shadowed v q (patched v j a B) ε := by + classical + intro f hf + let t:=v.beyond j; let Q:=v.boundTail j q + let E := chairK v j N + let F (x : Keys (p:=p) v.t N) := + v.curtain q (v.patched j a B) x * prodW f x + let s (x : AtomKey (p:=p) (v.t j) N) := ind (ownOne p _ (q j) x)*f j x + let g (x : AtomKey (p:=p) (v.t j) N) : Localist t N := fun i z=> ind (v.bolts x z)*f i.val z + let G x (y : Keys (p:=p) t.t N) := curtain t Q (B (a x)) y * prodW (g x) y + have he k : (F ∘ E.symm) k=s k.1 * G k.1 k.2 := by + obtain ⟨k,rfl⟩ := E.surjective k + simp only [Function.comp_apply,Equiv.symm_apply_apply] + unfold F curtain + rw [bolts_split v j,chair_split _ _ j]; simp only [ind_and,ind_all] + change _ * v.patched _ _ _ k * (f j (k j)* _)=s (k j)*G (k j) (E k).2 + unfold s G patched curtain g + unfold prodW + rw [Finset.prod_mul_distrib] + exact (show ∀ (a b c d e f : ℝ), a*(b*c)*d*(e*f)=(a*e)*(c*d*(b*f)) from by intro a b c d e f; ring) _ _ _ _ _ _ + have hh (x) : |avg unif (G x)|≤ε := h (a x) _ (fun i y=>ab_cut _ _ (hf _ _)) + have hz (x) : |s x|≤1 := ab_cut _ _ (hf _ _) + have ht : mapW unif E= pairW unif unif := by rw [←pair_unif,unif_equiv] + have hl := lift_window unif_law unif _ _ _ he hz ε hh + rw [←ht,mapW_avg] at hl + simp only [Function.comp_apply,Equiv.symm_apply_apply] at hl; exact hl + +set_option maxHeartbeats 800000 in +theorem patched_exceed (v : Template p I) (j : I) (q : I→F) (a : AtomKey (p:=p) (v.t j) N→J) + (B : J → Wgt (Keys (p:=p) (v.beyond j).t N)) (ε : ℝ) + (w : I→Wgt (Knobs p.g n)) (hw : ∀ i,IsLaw (w i)) + (s : Script p I) (m : Mixer p n) (o : UnitType p n N) + (h : ∀ i,¬ exceeds (v.beyond j) (v.boundTail j q) (B i) (scriptTail s j) + m (fun i => w i.val) ε o) : + ¬ exceeds v q (patched v j a B) s m w ε o := by + classical + rintro ⟨f,hf,hZ⟩ + let x' := patched v j a B + apply not_lt_of_ge _ hZ + change |astonish v q x' s m w f o|≤ε + rw [astonish_val] + let v' := v.beyond j; let Q := v.boundTail j q + let E := chairI v j n + let R := scriptTail s j + let U (i : Inputs p n I) := ind (earns v s m q o i)*x' (v.resultKey o i)*prodW f i + let K := Knobs p.g n + let x (z : K) := nib v o j z + let g (i : K) (t : Aside j) (z : K) := ind (v.lintel j m s o i t z)*f t.val z + let C (i) := ind (ownOne p _ (q j) (x i))*f j i + let G i (y : Inputs p n (Aside j)) := + ind (earns v' R m Q o y)*B (a (x i)) (v'.resultKey o y)*prodW (g i) y + have he k : (U ∘ E.symm) k=C k.1*G k.1 k.2 := by + obtain ⟨k,rfl⟩ := E.surjective k + simp only [Function.comp_apply,Equiv.symm_apply_apply] + unfold U + rw [earns_split v j,chair_split _ _ j]; simp only [ind_and,ind_all] + unfold x' patched; rw [key_split] + unfold C G g prodW + rw [Finset.prod_mul_distrib] + dsimp only [x,E,v',R,chairI,chair] + change _ * B (a (nib v o j (k j))) _ * _ = _ + unfold nib + dsimp only [Q,Equiv.piSplitAt,Equiv.coe_fn_mk] + ring + let W := prodW (fun i:Aside j=> w i.val) + have hh (i) : |avg W (G i)|≤ ε := by + have hz (k z) : |g i k z|≤1 := ab_cut _ _ (hf _ _) + have hb : |astonish v' Q (B (a (x i))) R m (fun i=>w i.val) (g i) o|≤ε := + le_of_not_gt (fun hb=>h (a (x i)) ⟨g i,hz,hb⟩) + rw [astonish_val] at hb; exact hb + have hC i : |C i|≤1 := ab_cut _ _ (hf _ _) + have ht : mapW (prodW w) E=pairW (w j) W := chair_weight w j + have hz := lift_window (hw j) W _ _ _ he hC ε hh + rw [←ht,mapW_avg] at hz + simp only [Function.comp_apply,Equiv.symm_apply_apply] at hz + exact hz + +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/GradientRankBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/GradientRankBounds.lean index 3c0b40d5878cffbd859fae441764038d878d269f..475f174bde840136ea032d38beed43e5b71d80b2 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/GradientRankBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/GradientRankBounds.lean @@ -1,296 +1,296 @@ -import OAI.Combinatorics.HadwigerCounterexample.RealizationConditions -import OAI.Combinatorics.HadwigerCounterexample.MomentLabelSupport - -namespace OAI - -/-! # Gradient Rank Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix -open scoped BigOperators -variable {p : Shape} {n : ℕ} - -private theorem part_formula_single (i j : Tag p.g) (e : Comp p.g) (M : Moment p n) : - getPair p n i j (Pi.single e M) = - (if i=e.val.1 ∧ j=e.val.2 then M else 0) + - (if i=e.val.2 ∧ j=e.val.1 then M else 0) := by - classical - rcases e with ⟨⟨u,v⟩,hu⟩ - by_cases h : i=j - · subst j - have hv : u≠v := hu.ne - have hu : ¬ (i=u ∧ i=v) := fun ⟨e,g⟩ => hv (e.symm.trans g) - have hw : ¬ (i=v ∧ i=u) := by tauto - simp [getPair,hu,hw] - rw [getPair_edge i j h] - change (Pi.single (⟨(u,v),hu⟩:Comp p.g) M : Profile p n) (edge i j h) = (if i=u ∧ j=v then M else 0)+ - (if i=v ∧ j=u then M else 0) - rcases lt_or_gt_of_ne h with ht|ht - · have ha : ¬ (i=v∧j=u) := by - rintro ⟨rfl,rfl⟩; exact hu.asymm ht - simp [edge,ht,Pi.single_apply,ha] - · have ha : ¬ (i=u∧j=v) := by - rintro ⟨rfl,rfl⟩; exact hu.asymm ht - simp [edge,not_lt.mpr ht.le,Pi.single_apply,ha,and_comm] - -private theorem shared_at (t : Tag p.g) (e : Comp p.g) (M : Moment p n) : - ∃ s : F, - s = sharedT p n t (Pi.single e M) ∧ - s = (if t=e.val.2 then etab p n Block.S M else 0) + - if t=e.val.1 then etab p n Block.S M else 0 := by - refine ⟨_,rfl,?_⟩ - simp only [sharedT,LinearMap.sum_apply,LinearMap.comp_apply,part_formula_single, - map_add,Finset.sum_add_distrib] - let u := fun i => etab p n Block.S i - have hi (a b : Tag p.g) : - ∑ l, u (if l=a ∧ t=b then M else 0) = - if t=b then u M else 0 := by - rw [Finset.sum_eq_single a] - · split <;> simp_all [u] - · intro b _ hb; simp [hb,u] - simp - exact congrArg₂ (·+·) (hi _ _) (hi _ _) - -private def routed (p : Shape) (n : ℕ) (t a d : Tag p.g) := - if allowed d a then testM p n (Block.O d t) else 0 - -private theorem role_at (t : Tag p.g) (e : Comp p.g) (M : Moment p n) : - roleT p n t (Pi.single e M) = - mpair (routed p n t e.val.1 e.val.2 + routed p n t e.val.2 e.val.1) M := by - classical - simp only [roleT,LinearMap.sum_apply,LinearMap.comp_apply,part_formula_single,map_add, - Finset.sum_add_distrib,mpair_add] - let u := fun d => etab p n (Block.O d t) - have hh (i j : Tag p.g) : - ∑ (l : Tag p.g), ∑ d ∈ Finset.univ.filter (fun d => allowed d l), - u d (if l=i ∧ d=j then M else 0) = mpair (routed p n t i j) M := by - simp_rw [Finset.sum_filter] - rw [Finset.sum_eq_single i] - · rw [Finset.sum_eq_single j] - · by_cases h : allowed j i - · simp [h,u,routed,etab] - simp [h,routed]; rw [mpair_comm,map_zero] - · intro d _ hd - simp [u,hd] - simp - · intro l _ hl - simp [u,hl] - simp - exact congrArg₂ (·+·) (hh _ _) (hh _ _) - -private theorem test_rank (d : Block p.g) : (testM p n d).rank ≤ p.r := by - apply le_trans (mrk_sum_le ..) - refine (Finset.sum_le_sum (g:=fun _ => 1) (fun i _ => Matrix.rank_vecMulVec_le ..)).trans_eq ?_ - simp - -def Represents (m : Profile p n →ₗ[F] F) (A : Profile p n) := - ∀ x, m x=∑ i,mpair (A i) (x i) - -theorem rep_single {m : Profile p n →ₗ[F] F} {A : Profile p n} - (h : ∀ (e : Comp p.g) (M : Moment p n), m (Pi.single e M)=mpair (A e) M) : - Represents m A := by - intro x - have heq : m x=m (∑ e, Pi.single e (x e)) := by rw [Finset.univ_sum_single] - rw [heq,map_sum] - exact Finset.sum_congr rfl fun i _ => h _ _ - -theorem tmix_small (m : Mixer p n) (x : Profile p n) (K : ℕ) (hK : ∀ e,(x e).rank≤K) : - ∃ A, Represents (Tmix m x) A ∧ ∀ e,(A e).rank≤2*p.J*Fintype.card (Comp p.g)*K := by - let f (e) := ∑ (j : Fin p.J), ∑ i : Comp p.g, - (liftM (m.mixL j i e)ᵀ (m.mixR j i e)ᵀ (x i) + - liftM (m.mixL j e i) (m.mixR j e i) (x i)) - refine ⟨f,fun y => ?_,fun e => ?_⟩ - · let F j i e := mpair (liftM (m.mixL j i e)ᵀ (m.mixR j i e)ᵀ (x i)) (y e) - let G j i e := mpair (liftM (m.mixL j e i) (m.mixR j e i) (x i)) (y e) - have he : Tmix m x y = - (∑ j,∑ i, ∑ e,F j i e) + ∑ j,∑ e,∑ i,G j i e := by - change (∑ j,∑ i,∑ e, mpair (x i) (liftM (m.mixL j i e) (m.mixR j i e) (y e)))+ - (∑ j,∑ e,∑ i, mpair (y e) (liftM (m.mixL j e i) (m.mixR j e i) (x i)))=_ - refine congrArg₂ _ ?_ ?_ - · simp_rw [mpair_liftM]; rfl - exact Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => - Finset.sum_congr rfl fun _ _ => mpair_comm _ _ - rw [he] - simp only [f,mpair_sum,mpair_add,Finset.sum_add_distrib] - change _ = (∑ e,∑ j,∑ i,F j i e) + ∑ e,∑ j,∑ i,G j i e - refine congrArg₂ _ ?_ (Finset.sum_comm) - conv_rhs => rw [Finset.sum_comm] - exact Finset.sum_congr rfl fun i _ => Finset.sum_comm - · apply le_trans (mrk_sum_le ..) - let E := Fintype.card (Comp p.g) - refine (Finset.sum_le_sum (g:=fun _ => E*(2*K)) (fun j _ => ?_)).trans_eq ?_ - · apply le_trans (mrk_sum_le ..) - refine (Finset.sum_le_sum (g:=fun _ => 2*K) (fun i _ => ?_)).trans_eq (by simp [E]) - exact (mrk_add_le ..).trans ((Nat.add_le_add ((rank_lift_le ..).trans (hK i)) - ((rank_lift_le ..).trans (hK i))).trans_eq (two_mul _).symm) - simp [E]; ring - -private def Xrep (p : Shape) (n : ℕ) (w : Tag p.g → Moment p n) := - ∀ l,w l∈ Wtag p n l - -set_option maxHeartbeats 800000 in -theorem grad_small {m : Mixer p n} {v : Tag p.g → Moment p n} - (hg : Odd p.g) (hv : ∀ l,v l∈ Wtag p n l) (hs : parityW v=1) - (hz : (nonzeroTags v).card ≤ 7) (hr : ∀ e,(cut p n v e).rank ≤ 7) : - ∃ A, Represents (grad m (cut p n v)) A ∧ - ∀ e,(A e).rank ≤ 15*p.r + 14*p.J * Fintype.card (Comp p.g) := by - let x := cut p n v - let d t := etab p n Block.S (v t) - obtain ⟨A,hA,hR⟩ := tmix_small m x 7 hr - let h : Profile p n →ₗ[F] F := role p n + T0 p n x - have hf : h = (∑ t,d t • roleT p n t)+ ∑ t, roleT p n t x • sharedT p n t := by - have hc : role p n x + ∑ t,d t=1 := by - simp only [parityW,eta,LinearMap.add_apply,Finset.sum_add_distrib] at hs - rw [show x=cut p n v from rfl,role_cut _ v hv] - exact hs - have hcoef (t : Tag p.g) : 1+role p n x + sharedT p n t x = d t := by - unfold x - rw [sharedT_cut p hg] - change 1+role p n x + ((∑ i,d i)+d t) = _ - rw [←add_assoc,add_assoc 1,hc,char_two,zero_add] - refine LinearMap.ext fun y => ?_ - change role p n y+T0 p n x y = _ - simp only [T0_val,LinearMap.add_apply,LinearMap.sum_apply, - Finset.sum_add_distrib,LinearMap.smul_apply,smul_eq_mul] - calc role p n y + - (role p n x * role p n y + - ((∑ x_1 : Tag p.g,roleT p n x_1 x*sharedT p n x_1 y)+ - ∑ x_1 : Tag p.g,sharedT p n x_1 x*roleT p n x_1 y)) - _ = (∑ t : Tag p.g,(1+role p n x+sharedT p n t x)* roleT p n t y)+ - ∑ x_1 : Tag p.g,roleT p n x_1 x*sharedT p n x_1 y := by - simp only [add_mul,one_mul,Finset.sum_add_distrib, - ← Finset.mul_sum]; simp only [role,LinearMap.sum_apply]; ring - _ = _ := by simp_rw [hcoef] - let Y (e : Comp p.g) (i : Tag p.g) := - routed p n i e.val.1 e.val.2 + routed p n i e.val.2 e.val.1 - let P (e : Comp p.g) := - ∑ i∈nonzeroTags v,d i • Y e i - let a (e : Comp p.g) := roleT p n e.val.1 x + roleT p n e.val.2 x - let Q (e : Comp p.g) := a e • testM p n Block.S - have he : Represents h (fun e => P e+Q e) := by - apply rep_single - intro e M - rw [hf,mpair_add] - simp only [LinearMap.add_apply,LinearMap.sum_apply,LinearMap.smul_apply, - smul_eq_mul] - refine congrArg₂ _ ?_ ?_ - · simp only [P,Y,role_at,mpair_sum,mpair_smul] - refine (Finset.sum_subset (Finset.subset_univ _) (fun i _ hi => ?_)).symm - have hg : v i=0 := by rwa [mem_nonzeroTags,not_not] at hi - rw [show d i=0 from (by unfold d; rw [hg,map_zero]),zero_mul] - · have hh (i : Tag p.g) : - sharedT p n i (Pi.single e M) = - (if i=e.val.2 then etab p n Block.S M else 0)+(if i=e.val.1 then - etab p n Block.S M else 0) := by - obtain ⟨s,h1,h2⟩ := shared_at i e M; rw [← h1,h2] - simp_rw [hh,mul_add,Finset.sum_add_distrib,Q,mpair_smul,a,add_mul] - simp only [mul_ite,mul_zero,Finset.sum_ite_eq', - Finset.mem_univ,ite_true,etab] - exact add_comm _ _ - refine ⟨fun e => P e+Q e+A e,fun y => ?_, fun e => ?_⟩ - · simp only [mpair_add,Finset.sum_add_distrib] - have hx : grad m x y=h y+Tmix m x y := (add_assoc (role p n y) (T0 p n x y) (Tmix m x y)).symm - rw [show grad m (cut p n v) y=_ from hx,he y,hA y] - simp only [mpair_add,Finset.sum_add_distrib] - · have hi : (P e).rank ≤ 14*p.r := by - have hr (i a b : Tag p.g) : (routed p n i a b).rank ≤ p.r := by - unfold routed - split - · exact test_rank _ - simp - have hy (i) : (d i • Y e i).rank ≤ 2*p.r := by - rcases bit_cases (d i) with h|h - · simp [h] - rw [h,one_smul,two_mul] - exact (mrk_add_le ..).trans (Nat.add_le_add (hr ..) (hr ..)) - refine (mrk_sum_le ..).trans ((Finset.sum_le_sum (fun i _ => hy i)).trans ?_) - simp only [Finset.sum_const,nsmul_eq_mul,Nat.cast_id]; nlinarith - have hj : (Q e).rank ≤ p.r := by - rcases bit_cases (a e) with h|h - · simp [Q,h] - unfold Q; rw [h,one_smul]; exact test_rank _ - refine le_trans (mrk_add_le ..) ((Nat.add_le_add ((mrk_add_le (P e) _).trans - (Nat.add_le_add hi hj)) (hR e)).trans ?_) - apply le_of_eq; ring - -namespace Volley -variable {I : Type} [Fintype I] [DecidableEq I] (v : Volley p n I) - -omit [DecidableEq I] in -theorem gradient_rep (m : Mixer p n) {t : Tagging p I} {w : I → Bool} {i j : Bool} - (hg : Odd p.g) (h : v.legal t) (hb : (v.shoots w i j).card ≤ 7) - (hd : ∑ a∈v.shoots w i j,v.diagonalAt a=1) : - ∃ A, Represents (grad m (v.sumAt t w i j)) A ∧ - ∀ e,(A e).rank ≤ 15*p.r+14*p.J*Fintype.card (Comp p.g) := by - classical - let S := v.shoots w i j - let w' (a : I) : Tag p.g → Moment p n := - Pi.single (t a) (mom p (v.sel a) (v.par a)) - let C := ∑ i∈S,w' i - have h1 (a) : atomAt v t a=cut p n (w' a) := rfl - have he : sumAt v t w i j=cut p n C := by - change (∑ i∈S,_) = cut p n (∑ i∈S,_) - simp_rw [h1,map_sum] - rw [he] - apply grad_small hg - · intro l - change (∑ i∈S, w' i) l ∈ _ - rw [Finset.sum_apply] - apply Submodule.sum_mem - intro a _ - by_cases e : l=t a - · subst l - simp only [w',Pi.single_eq_same] - exact Submodule.subset_span ⟨_,_,h a,rfl⟩ - simp [w',Pi.single_eq_of_ne e] - · unfold parityW - simp only [C,Finset.sum_apply,map_sum] - rw [Finset.sum_comm] - refine (Finset.sum_congr (g:=fun a => v.diagonalAt a) rfl fun a _ => ?_).trans hd - rw [Finset.sum_eq_single (t a)] - · rw [show w' a (t a)=_ from Pi.single_eq_same _ _] - rfl - · intro l _ hl; simp [w',Pi.single_eq_of_ne hl] - simp - · have hC : nonzeroTags C ⊆ S.image t := by - intro l hl - by_contra hn - apply mem_nonzeroTags l C |>.mp hl - simp only [C,Finset.sum_apply] - apply Finset.sum_eq_zero - intro a ha - simp [w',Pi.single_eq_of_ne (show l≠t a from fun h0 => hn - (Finset.mem_image.mpr ⟨a,ha,h0.symm⟩))] - exact (Finset.card_le_card hC).trans (Finset.card_image_le.trans hb) - intro e - rw [← he,Volley.sumAt, Finset.sum_apply] - apply le_trans (mrk_sum_le ..) - refine le_trans ((Finset.sum_le_sum (g:=fun _ => 1) fun _ _ => ?_).trans_eq ?_) hb - · rw [atomAt,atom_def] - split - · apply Matrix.rank_vecMulVec_le - · simp - · simp - -theorem here_card {w : I → Bool} (h : v.bounded w) (i : Bool) : (v.here i).card≤14 := by - have he : v.here i ⊆ v.shoots w i true ∪ v.shoots w i false := - fun j hj => by - have hi : v.obj j=i := (Finset.mem_filter.mp hj).2 - cases h : w j <;> simp [shoots,hi,h] - exact le_trans ((Finset.card_le_card he).trans (Finset.card_union_le _ _)) - (Nat.add_le_add (h _ _).2 (h _ _).2) - -theorem call_count {w : I→Bool} (h : v.bounded w) : Fintype.card I ≤ 28 := by - have he : Finset.univ ⊆ v.here true ∪ v.here false := - fun j _ => by cases h : v.obj j <;> simp [here,h] - have hh := (Finset.card_le_card he).trans ((Finset.card_union_le _ _).trans - (Nat.add_le_add (here_card _ h true) (here_card _ h false))) - exact (Finset.card_univ.symm.le.trans hh) - -end Volley -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RealizationConditions +import OAI.Combinatorics.HadwigerCounterexample.MomentLabelSupport + +namespace OAI + +/-! # Gradient Rank Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix +open scoped BigOperators +variable {p : Shape} {n : ℕ} + +private theorem part_formula_single (i j : Tag p.g) (e : Comp p.g) (M : Moment p n) : + getPair p n i j (Pi.single e M) = + (if i=e.val.1 ∧ j=e.val.2 then M else 0) + + (if i=e.val.2 ∧ j=e.val.1 then M else 0) := by + classical + rcases e with ⟨⟨u,v⟩,hu⟩ + by_cases h : i=j + · subst j + have hv : u≠v := hu.ne + have hu : ¬ (i=u ∧ i=v) := fun ⟨e,g⟩ => hv (e.symm.trans g) + have hw : ¬ (i=v ∧ i=u) := by tauto + simp [getPair,hu,hw] + rw [getPair_edge i j h] + change (Pi.single (⟨(u,v),hu⟩:Comp p.g) M : Profile p n) (edge i j h) = (if i=u ∧ j=v then M else 0)+ + (if i=v ∧ j=u then M else 0) + rcases lt_or_gt_of_ne h with ht|ht + · have ha : ¬ (i=v∧j=u) := by + rintro ⟨rfl,rfl⟩; exact hu.asymm ht + simp [edge,ht,Pi.single_apply,ha] + · have ha : ¬ (i=u∧j=v) := by + rintro ⟨rfl,rfl⟩; exact hu.asymm ht + simp [edge,not_lt.mpr ht.le,Pi.single_apply,ha,and_comm] + +private theorem shared_at (t : Tag p.g) (e : Comp p.g) (M : Moment p n) : + ∃ s : F, + s = sharedT p n t (Pi.single e M) ∧ + s = (if t=e.val.2 then etab p n Block.S M else 0) + + if t=e.val.1 then etab p n Block.S M else 0 := by + refine ⟨_,rfl,?_⟩ + simp only [sharedT,LinearMap.sum_apply,LinearMap.comp_apply,part_formula_single, + map_add,Finset.sum_add_distrib] + let u := fun i => etab p n Block.S i + have hi (a b : Tag p.g) : + ∑ l, u (if l=a ∧ t=b then M else 0) = + if t=b then u M else 0 := by + rw [Finset.sum_eq_single a] + · split <;> simp_all [u] + · intro b _ hb; simp [hb,u] + simp + exact congrArg₂ (·+·) (hi _ _) (hi _ _) + +private def routed (p : Shape) (n : ℕ) (t a d : Tag p.g) := + if allowed d a then testM p n (Block.O d t) else 0 + +private theorem role_at (t : Tag p.g) (e : Comp p.g) (M : Moment p n) : + roleT p n t (Pi.single e M) = + mpair (routed p n t e.val.1 e.val.2 + routed p n t e.val.2 e.val.1) M := by + classical + simp only [roleT,LinearMap.sum_apply,LinearMap.comp_apply,part_formula_single,map_add, + Finset.sum_add_distrib,mpair_add] + let u := fun d => etab p n (Block.O d t) + have hh (i j : Tag p.g) : + ∑ (l : Tag p.g), ∑ d ∈ Finset.univ.filter (fun d => allowed d l), + u d (if l=i ∧ d=j then M else 0) = mpair (routed p n t i j) M := by + simp_rw [Finset.sum_filter] + rw [Finset.sum_eq_single i] + · rw [Finset.sum_eq_single j] + · by_cases h : allowed j i + · simp [h,u,routed,etab] + simp [h,routed]; rw [mpair_comm,map_zero] + · intro d _ hd + simp [u,hd] + simp + · intro l _ hl + simp [u,hl] + simp + exact congrArg₂ (·+·) (hh _ _) (hh _ _) + +private theorem test_rank (d : Block p.g) : (testM p n d).rank ≤ p.r := by + apply le_trans (mrk_sum_le ..) + refine (Finset.sum_le_sum (g:=fun _ => 1) (fun i _ => Matrix.rank_vecMulVec_le ..)).trans_eq ?_ + simp + +def Represents (m : Profile p n →ₗ[F] F) (A : Profile p n) := + ∀ x, m x=∑ i,mpair (A i) (x i) + +theorem rep_single {m : Profile p n →ₗ[F] F} {A : Profile p n} + (h : ∀ (e : Comp p.g) (M : Moment p n), m (Pi.single e M)=mpair (A e) M) : + Represents m A := by + intro x + have heq : m x=m (∑ e, Pi.single e (x e)) := by rw [Finset.univ_sum_single] + rw [heq,map_sum] + exact Finset.sum_congr rfl fun i _ => h _ _ + +theorem tmix_small (m : Mixer p n) (x : Profile p n) (K : ℕ) (hK : ∀ e,(x e).rank≤K) : + ∃ A, Represents (Tmix m x) A ∧ ∀ e,(A e).rank≤2*p.J*Fintype.card (Comp p.g)*K := by + let f (e) := ∑ (j : Fin p.J), ∑ i : Comp p.g, + (liftM (m.mixL j i e)ᵀ (m.mixR j i e)ᵀ (x i) + + liftM (m.mixL j e i) (m.mixR j e i) (x i)) + refine ⟨f,fun y => ?_,fun e => ?_⟩ + · let F j i e := mpair (liftM (m.mixL j i e)ᵀ (m.mixR j i e)ᵀ (x i)) (y e) + let G j i e := mpair (liftM (m.mixL j e i) (m.mixR j e i) (x i)) (y e) + have he : Tmix m x y = + (∑ j,∑ i, ∑ e,F j i e) + ∑ j,∑ e,∑ i,G j i e := by + change (∑ j,∑ i,∑ e, mpair (x i) (liftM (m.mixL j i e) (m.mixR j i e) (y e)))+ + (∑ j,∑ e,∑ i, mpair (y e) (liftM (m.mixL j e i) (m.mixR j e i) (x i)))=_ + refine congrArg₂ _ ?_ ?_ + · simp_rw [mpair_liftM]; rfl + exact Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => + Finset.sum_congr rfl fun _ _ => mpair_comm _ _ + rw [he] + simp only [f,mpair_sum,mpair_add,Finset.sum_add_distrib] + change _ = (∑ e,∑ j,∑ i,F j i e) + ∑ e,∑ j,∑ i,G j i e + refine congrArg₂ _ ?_ (Finset.sum_comm) + conv_rhs => rw [Finset.sum_comm] + exact Finset.sum_congr rfl fun i _ => Finset.sum_comm + · apply le_trans (mrk_sum_le ..) + let E := Fintype.card (Comp p.g) + refine (Finset.sum_le_sum (g:=fun _ => E*(2*K)) (fun j _ => ?_)).trans_eq ?_ + · apply le_trans (mrk_sum_le ..) + refine (Finset.sum_le_sum (g:=fun _ => 2*K) (fun i _ => ?_)).trans_eq (by simp [E]) + exact (mrk_add_le ..).trans ((Nat.add_le_add ((rank_lift_le ..).trans (hK i)) + ((rank_lift_le ..).trans (hK i))).trans_eq (two_mul _).symm) + simp [E]; ring + +private def Xrep (p : Shape) (n : ℕ) (w : Tag p.g → Moment p n) := + ∀ l,w l∈ Wtag p n l + +set_option maxHeartbeats 800000 in +theorem grad_small {m : Mixer p n} {v : Tag p.g → Moment p n} + (hg : Odd p.g) (hv : ∀ l,v l∈ Wtag p n l) (hs : parityW v=1) + (hz : (nonzeroTags v).card ≤ 7) (hr : ∀ e,(cut p n v e).rank ≤ 7) : + ∃ A, Represents (grad m (cut p n v)) A ∧ + ∀ e,(A e).rank ≤ 15*p.r + 14*p.J * Fintype.card (Comp p.g) := by + let x := cut p n v + let d t := etab p n Block.S (v t) + obtain ⟨A,hA,hR⟩ := tmix_small m x 7 hr + let h : Profile p n →ₗ[F] F := role p n + T0 p n x + have hf : h = (∑ t,d t • roleT p n t)+ ∑ t, roleT p n t x • sharedT p n t := by + have hc : role p n x + ∑ t,d t=1 := by + simp only [parityW,eta,LinearMap.add_apply,Finset.sum_add_distrib] at hs + rw [show x=cut p n v from rfl,role_cut _ v hv] + exact hs + have hcoef (t : Tag p.g) : 1+role p n x + sharedT p n t x = d t := by + unfold x + rw [sharedT_cut p hg] + change 1+role p n x + ((∑ i,d i)+d t) = _ + rw [←add_assoc,add_assoc 1,hc,char_two,zero_add] + refine LinearMap.ext fun y => ?_ + change role p n y+T0 p n x y = _ + simp only [T0_val,LinearMap.add_apply,LinearMap.sum_apply, + Finset.sum_add_distrib,LinearMap.smul_apply,smul_eq_mul] + calc role p n y + + (role p n x * role p n y + + ((∑ x_1 : Tag p.g,roleT p n x_1 x*sharedT p n x_1 y)+ + ∑ x_1 : Tag p.g,sharedT p n x_1 x*roleT p n x_1 y)) + _ = (∑ t : Tag p.g,(1+role p n x+sharedT p n t x)* roleT p n t y)+ + ∑ x_1 : Tag p.g,roleT p n x_1 x*sharedT p n x_1 y := by + simp only [add_mul,one_mul,Finset.sum_add_distrib, + ← Finset.mul_sum]; simp only [role,LinearMap.sum_apply]; ring + _ = _ := by simp_rw [hcoef] + let Y (e : Comp p.g) (i : Tag p.g) := + routed p n i e.val.1 e.val.2 + routed p n i e.val.2 e.val.1 + let P (e : Comp p.g) := + ∑ i∈nonzeroTags v,d i • Y e i + let a (e : Comp p.g) := roleT p n e.val.1 x + roleT p n e.val.2 x + let Q (e : Comp p.g) := a e • testM p n Block.S + have he : Represents h (fun e => P e+Q e) := by + apply rep_single + intro e M + rw [hf,mpair_add] + simp only [LinearMap.add_apply,LinearMap.sum_apply,LinearMap.smul_apply, + smul_eq_mul] + refine congrArg₂ _ ?_ ?_ + · simp only [P,Y,role_at,mpair_sum,mpair_smul] + refine (Finset.sum_subset (Finset.subset_univ _) (fun i _ hi => ?_)).symm + have hg : v i=0 := by rwa [mem_nonzeroTags,not_not] at hi + rw [show d i=0 from (by unfold d; rw [hg,map_zero]),zero_mul] + · have hh (i : Tag p.g) : + sharedT p n i (Pi.single e M) = + (if i=e.val.2 then etab p n Block.S M else 0)+(if i=e.val.1 then + etab p n Block.S M else 0) := by + obtain ⟨s,h1,h2⟩ := shared_at i e M; rw [← h1,h2] + simp_rw [hh,mul_add,Finset.sum_add_distrib,Q,mpair_smul,a,add_mul] + simp only [mul_ite,mul_zero,Finset.sum_ite_eq', + Finset.mem_univ,ite_true,etab] + exact add_comm _ _ + refine ⟨fun e => P e+Q e+A e,fun y => ?_, fun e => ?_⟩ + · simp only [mpair_add,Finset.sum_add_distrib] + have hx : grad m x y=h y+Tmix m x y := (add_assoc (role p n y) (T0 p n x y) (Tmix m x y)).symm + rw [show grad m (cut p n v) y=_ from hx,he y,hA y] + simp only [mpair_add,Finset.sum_add_distrib] + · have hi : (P e).rank ≤ 14*p.r := by + have hr (i a b : Tag p.g) : (routed p n i a b).rank ≤ p.r := by + unfold routed + split + · exact test_rank _ + simp + have hy (i) : (d i • Y e i).rank ≤ 2*p.r := by + rcases bit_cases (d i) with h|h + · simp [h] + rw [h,one_smul,two_mul] + exact (mrk_add_le ..).trans (Nat.add_le_add (hr ..) (hr ..)) + refine (mrk_sum_le ..).trans ((Finset.sum_le_sum (fun i _ => hy i)).trans ?_) + simp only [Finset.sum_const,nsmul_eq_mul,Nat.cast_id]; nlinarith + have hj : (Q e).rank ≤ p.r := by + rcases bit_cases (a e) with h|h + · simp [Q,h] + unfold Q; rw [h,one_smul]; exact test_rank _ + refine le_trans (mrk_add_le ..) ((Nat.add_le_add ((mrk_add_le (P e) _).trans + (Nat.add_le_add hi hj)) (hR e)).trans ?_) + apply le_of_eq; ring + +namespace Volley +variable {I : Type} [Fintype I] [DecidableEq I] (v : Volley p n I) + +omit [DecidableEq I] in +theorem gradient_rep (m : Mixer p n) {t : Tagging p I} {w : I → Bool} {i j : Bool} + (hg : Odd p.g) (h : v.legal t) (hb : (v.shoots w i j).card ≤ 7) + (hd : ∑ a∈v.shoots w i j,v.diagonalAt a=1) : + ∃ A, Represents (grad m (v.sumAt t w i j)) A ∧ + ∀ e,(A e).rank ≤ 15*p.r+14*p.J*Fintype.card (Comp p.g) := by + classical + let S := v.shoots w i j + let w' (a : I) : Tag p.g → Moment p n := + Pi.single (t a) (mom p (v.sel a) (v.par a)) + let C := ∑ i∈S,w' i + have h1 (a) : atomAt v t a=cut p n (w' a) := rfl + have he : sumAt v t w i j=cut p n C := by + change (∑ i∈S,_) = cut p n (∑ i∈S,_) + simp_rw [h1,map_sum] + rw [he] + apply grad_small hg + · intro l + change (∑ i∈S, w' i) l ∈ _ + rw [Finset.sum_apply] + apply Submodule.sum_mem + intro a _ + by_cases e : l=t a + · subst l + simp only [w',Pi.single_eq_same] + exact Submodule.subset_span ⟨_,_,h a,rfl⟩ + simp [w',Pi.single_eq_of_ne e] + · unfold parityW + simp only [C,Finset.sum_apply,map_sum] + rw [Finset.sum_comm] + refine (Finset.sum_congr (g:=fun a => v.diagonalAt a) rfl fun a _ => ?_).trans hd + rw [Finset.sum_eq_single (t a)] + · rw [show w' a (t a)=_ from Pi.single_eq_same _ _] + rfl + · intro l _ hl; simp [w',Pi.single_eq_of_ne hl] + simp + · have hC : nonzeroTags C ⊆ S.image t := by + intro l hl + by_contra hn + apply mem_nonzeroTags l C |>.mp hl + simp only [C,Finset.sum_apply] + apply Finset.sum_eq_zero + intro a ha + simp [w',Pi.single_eq_of_ne (show l≠t a from fun h0 => hn + (Finset.mem_image.mpr ⟨a,ha,h0.symm⟩))] + exact (Finset.card_le_card hC).trans (Finset.card_image_le.trans hb) + intro e + rw [← he,Volley.sumAt, Finset.sum_apply] + apply le_trans (mrk_sum_le ..) + refine le_trans ((Finset.sum_le_sum (g:=fun _ => 1) fun _ _ => ?_).trans_eq ?_) hb + · rw [atomAt,atom_def] + split + · apply Matrix.rank_vecMulVec_le + · simp + · simp + +theorem here_card {w : I → Bool} (h : v.bounded w) (i : Bool) : (v.here i).card≤14 := by + have he : v.here i ⊆ v.shoots w i true ∪ v.shoots w i false := + fun j hj => by + have hi : v.obj j=i := (Finset.mem_filter.mp hj).2 + cases h : w j <;> simp [shoots,hi,h] + exact le_trans ((Finset.card_le_card he).trans (Finset.card_union_le _ _)) + (Nat.add_le_add (h _ _).2 (h _ _).2) + +theorem call_count {w : I→Bool} (h : v.bounded w) : Fintype.card I ≤ 28 := by + have he : Finset.univ ⊆ v.here true ∪ v.here false := + fun j _ => by cases h : v.obj j <;> simp [here,h] + have hh := (Finset.card_le_card he).trans ((Finset.card_union_le _ _).trans + (Nat.add_le_add (here_card _ h true) (here_card _ h false))) + exact (Finset.card_univ.symm.le.trans hh) + +end Volley +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/GradientRealization.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/GradientRealization.lean index 4a393b53e658e8fd57ecc3d658faf42b97478b0f..b37fcda40adf58b39e6a28208946de39e6ed133c 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/GradientRealization.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/GradientRealization.lean @@ -1,191 +1,191 @@ -import OAI.Combinatorics.HadwigerCounterexample.ChannelFactorization - -namespace OAI - -/-! # Gradient Realization -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Submodule Module Finset -open scoped BigOperators -variable {p : Shape} {n N : ℕ} -def Rorth (K : ℕ) := 2*(K+20) -def qorth (K : ℕ) := Rorth K+14 -def rankInit (p : Shape) := 15*p.r+14*p.J*ncComp p -def rankRes (K : ℕ) := 2*(K+14)+3*blin K -def rankAll (p : Shape) (K : ℕ) := - 2*rankInit p+dqBound p (K+14) K (rankRes K) - -structure realizeAssum (p : Shape) (K : ℕ) : Prop where - odd : Odd p.g - sel : 6*Rorth K+4≤p.j - cap : rankAll p K+2*(K+2*(3*blin K))≤p.h - -variable {I : Type} [Fintype I] -namespace Volley -set_option maxHeartbeats 600000 in -private theorem realize_one (v w : Volley p n I) {t : Tagging p I} (m : Mixer p n) - (x y : UnitType p n N) (a b : Plan p n) (T B : Cross p n) - (K : ℕ) (h : realizeAssum p K) - (hb : v.bounded w.obj) (ht : v.legal t) - (hv : v.avoids a (qorth K)) (hK : planRank a≤K) (hL : planRank b≤K) - (hB : fitsTable a b B T) (hT : tableInj a b T) - (hf : rowAgree (v.frozen a t) B (actual p x y)) (hC : lowCross (blin K) B) - (hR : v.scalarRecipe w t m x a T) (hk : v.keys t x=w.keys t y) - (hy : ∀ i, frameLaw m (onSide y i)) - (hS : v.attackGrad w t m y) (j : Bool) : - ∃ D∈deltaSpace p (v.frozen a t) b j, - obsPair p (chanInner p (channelOut p B j+D) (channelOut p B j+D))= - combineF p (v.demand w t m j) := by - classical - let G := v.demand w t m j - let L := blin K - let R := rankInit p - obtain ⟨D,hD,P,hP,hZ⟩ := v.realize_linear w m x y a b T B hb ht (qorth K) (Rorth K) hv h.sel - (by unfold Rorth; omega) (Nat.le_refl (qorth K)) hB hT hf hR hk hy hS j - let C := channelOut p B j - let f := v.frozen a t - have he (z i) : dim (sPin f z i) ≤ K+14 := - (v.frozen_here_dim hb a t i z).trans (Nat.add_le_add_right hK 14) - obtain ⟨M,hM,hA⟩ : - ∃ M : Individual p n, obsI p M=combineF p G ∧ ∀ i e,(M i e).rank≤R := by - choose M hM hA using fun i : Bool => - v.gradient_rep (w:=w.obj) (i:=i) (j:=j) m h.odd ht (hb _ _).2 (hR.summ i j) - refine ⟨M,?_,hA⟩ - have he : repF p M=G := by - funext i - exact LinearMap.ext fun x => (repF_rep M i x).trans (hM i x).symm - change combineF p (repF p M)=_ - rw [he] - obtain ⟨D,Q,V,X,hV,hQ,hW,hU,hX,hG,hF,hE⟩ := split_linear R (K+14) L he hA - (outSmall_low hC j) hD hP (hZ.trans hM.symm) - obtain ⟨Q',hq,hO,hN⟩ := shrink_pure (K+14) K (rankRes K) he (fun z i => by - unfold f; rw [v.hPin_frozen]; exact ((hPin_dim ..).trans (dim_le_plan a z)).trans hK) - hE hQ hF - have hJ (i) : ((Q'+V) i).rank≤rankAll p K := (mrk_add_le ..).trans ((add_le_add - (hN i) (hX i)).trans_eq (add_comm _ _)) - obtain ⟨Z,hY,hZ⟩ := chan_factor (3*L) (rankAll p K) K hU - (fun z => ((hPin_dim ..).trans (dim_le_plan b z)).trans hL) h.cap - ((pureSpace p f).add_mem hq hW) hJ - refine ⟨D+Z,(deltaSpace p f b j).add_mem hV hY,?_⟩ - rw [← add_assoc,hZ,map_add,hO,←map_add,hG,hM] - -end Volley - -/-- Lift the derivative changes into one actual abstract cross Gram -(on column channel arguments only). -/ -def addChan (p : Shape) {n} (D : Bool → ChanOut p n) : Cross p n := - fun z => ∑ j : Bool,(D j z)ᵀ * (IH p n j)ᵀ - -private theorem addChan_val (M : Cross p n) (D : Bool → ChanOut p n) (i : Bool) : - channelOut p (M+addChan p D) i= channelOut p M i+D i := by - funext z - unfold addChan channelOut - simp only [Fintype.sum_bool,Pi.add_apply,Matrix.transpose_add,Matrix.add_mul,Matrix.mul_assoc] - cases i <;> simp only [IH_self,IH_cross (show false≠true by decide), - IH_cross (show true≠false by decide),Matrix.mul_zero,Matrix.mul_one,transpose_zero, - transpose_transpose,zero_add,add_zero] - -def zeroRow (p : Shape) {n} (f : Plan p n) (M : Cross p n) := - ∀ z,∀ v∈f z, (M z)ᵀ *ᵥ v=0 - -theorem row_add {M B C : Cross p n} {f : Plan p n} (h : rowAgree f B C) - (hf : zeroRow p f M) : - rowAgree f (B+M) C := by - intro z v hv u - rw [Pi.add_apply, evmat_addM,h z v hv,← evmat_transpose (M z),evmat,evmat,hf z v hv, - dotProduct_zero,add_zero] - -private theorem addChan_zero {D : Bool → ChanOut p n} {f b : Plan p n} - (h : ∀ i,D i∈deltaSpace p f b i) : - zeroRow p f (addChan p D) ∧ zeroRow p b (reciprocal p (addChan p D)) := by - have hh (z : Place p) (i : Bool) := - box_kill.mp ((deltaSpace_mem _).mp (h i) z) - constructor - · intro z v hv - unfold addChan - simp only [Fintype.sum_bool,transpose_add, transpose_mul,transpose_transpose, - Matrix.add_mulVec,← Matrix.mulVec_mulVec,(hh z _).2 v hv,mulVec_zero,zero_add] - intro z v hv - unfold reciprocal addChan - have ht (i) : (IH p n i)ᵀ *ᵥ v ∈ hPin b (flipZ p (flipZ p z)) i := by - rw [flipZ_flip]; exact ⟨v,hv,rfl⟩ - have he i := (hh (flipZ p z) i).1 _ (ht i) - simp only [Fintype.sum_bool, Matrix.transpose_transpose,Matrix.add_mulVec, - ← Matrix.mulVec_mulVec,he,zero_add] - -private theorem recip_effect (B : Cross p n) (D : Bool → ChanOut p n) : - scalarBlocks p (B+reciprocal p (addChan p D))=scalarBlocks p B := by - funext z i j - unfold scalarBlocks channelOut reciprocal addChan - simp only [Pi.add_apply,Fintype.sum_bool,Matrix.transpose_add,Matrix.add_mul,Matrix.transpose_mul, - Matrix.transpose_transpose,Matrix.mul_assoc,IH_IP,Matrix.mul_zero,add_zero] - -private theorem delta_frozen {b f : Plan p n} (v : Volley p n I) (t : Tagging p I) (i : Bool) : - deltaSpace p f (v.frozen b t) i=deltaSpace p f b i := by - unfold deltaSpace - simp_rw [v.hPin_frozen] - -private theorem recip_add (B C : Cross p n) : - reciprocal p (B+C) = reciprocal p B+reciprocal p C := by - funext i; exact Matrix.transpose_add _ _ - -namespace Volley -private theorem realized_changes (v w : Volley p n I) (t : Tagging p I) - (m : Mixer p n) {D E : Bool → ChanOut p n} {B : Cross p n} - (h : ∀ j,obsPair p (chanInner p (channelOut p B j+D j) (channelOut p B j+D j))= - combineF p (v.demand w t m j)) : - v.realized w t m (B+addChan p D+reciprocal p (addChan p E)) := by - intro i j x hx - let B' := B+addChan p D - have he := h j - rw [← addChan_val B D j,obsPair_chan] at he - rw [contract_scalars _ _ (recip_effect _ E)] - exact ((combineF_same ..).mp he i x hx).symm -end Volley - -set_option maxHeartbeats 800000 in -theorem gradient_realization (v w : Volley p n I) {t : Tagging p I} (m : Mixer p n) - (x y : UnitType p n N) (a b : Pin p n N) (T : Cross p n) (K : ℕ) - (h : realizeAssum p K) - (hA : v.bounded w.obj) (hB : w.bounded v.obj) - (ht : v.legal t) (ht' : w.legal t) - (hv : v.avoids a.sp (qorth K)) (hw : w.avoids b.sp (qorth K)) - (hK : planRank a.sp ≤ K) (hL : planRank b.sp ≤ K) - (h1 : a.agree x) (h2 : b.agree y) - (h3 : tableFlag a b T x) (h4 : tableFlag b a (reciprocal p T) y) - (hT : tableInj a.sp b.sp T) (hT' : tableInj b.sp a.sp (reciprocal p T)) - (hR : v.scalarRecipe w t m x a.sp T) (hR' : w.scalarRecipe v t m y b.sp (reciprocal p T)) - (hk : v.keys t x=w.keys t y) - (hx : ∀ i,frameLaw m (onSide x i)) (hy : ∀ i, frameLaw m (onSide y i)) - (hS : v.attackGrad w t m y) (hS' : w.attackGrad v t m x) : - ∃ Q : Cross p n, v.realized w t m Q ∧ w.realized v t m (reciprocal p Q) ∧ - rowAgree (v.frozen a.sp t) Q (actual p x y) ∧ - rowAgree (w.frozen b.sp t) (reciprocal p Q) (actual p y x) := by - classical - obtain ⟨M,hQ,hD,hD',hM,hM'⟩ := start_form a b x y T - (v.keyPlan t) (w.keyPlan t) (keyPlane v t) (keyPlane w t) - (fun z => (v.key_independent t hv z).2.symm) (fun z => (w.key_independent t hw z).2.symm) - h1 h2 h3 h4 K hK hL (v.key_dim hA t) (w.key_dim hB t) - choose D hDA hG using fun j => Volley.realize_one v w m x y a.sp b.sp T M K h - hA ht hv hK hL hQ hT hD hM hR hk hy hS j - choose E hEA hF using fun j => Volley.realize_one w v m y x b.sp a.sp (reciprocal p T) - (reciprocal p M) K h hB ht' hw hL hK (fits_recip hQ) hT' hD' hM' hR' hk.symm hx hS' j - let Q := M+addChan p D+reciprocal p (addChan p E) - have he : reciprocal p Q = reciprocal p M+addChan p E+reciprocal p (addChan p D) := by - unfold Q - rw [recip_add,recip_add,reciprocal_twice]; ac_rfl - obtain ⟨hN,hN'⟩ := addChan_zero (D:=D) (f:=v.frozen a.sp t) (b:=w.frozen b.sp t) - (fun i => by rw [delta_frozen w t i]; exact hDA i) - obtain ⟨hO,hO'⟩ := addChan_zero (D:=E) (f:=w.frozen b.sp t) (b:=v.frozen a.sp t) - (fun i => by rw [delta_frozen v t i]; exact hEA i) - refine ⟨Q,Volley.realized_changes v w t m hG,?_,row_add (row_add hD hN) hO',?_⟩ - · rw [he] - exact Volley.realized_changes w v t m hF - rw [he]; exact row_add (row_add hD' hO) hN' - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ChannelFactorization + +namespace OAI + +/-! # Gradient Realization -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Submodule Module Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} +def Rorth (K : ℕ) := 2*(K+20) +def qorth (K : ℕ) := Rorth K+14 +def rankInit (p : Shape) := 15*p.r+14*p.J*ncComp p +def rankRes (K : ℕ) := 2*(K+14)+3*blin K +def rankAll (p : Shape) (K : ℕ) := + 2*rankInit p+dqBound p (K+14) K (rankRes K) + +structure realizeAssum (p : Shape) (K : ℕ) : Prop where + odd : Odd p.g + sel : 6*Rorth K+4≤p.j + cap : rankAll p K+2*(K+2*(3*blin K))≤p.h + +variable {I : Type} [Fintype I] +namespace Volley +set_option maxHeartbeats 600000 in +private theorem realize_one (v w : Volley p n I) {t : Tagging p I} (m : Mixer p n) + (x y : UnitType p n N) (a b : Plan p n) (T B : Cross p n) + (K : ℕ) (h : realizeAssum p K) + (hb : v.bounded w.obj) (ht : v.legal t) + (hv : v.avoids a (qorth K)) (hK : planRank a≤K) (hL : planRank b≤K) + (hB : fitsTable a b B T) (hT : tableInj a b T) + (hf : rowAgree (v.frozen a t) B (actual p x y)) (hC : lowCross (blin K) B) + (hR : v.scalarRecipe w t m x a T) (hk : v.keys t x=w.keys t y) + (hy : ∀ i, frameLaw m (onSide y i)) + (hS : v.attackGrad w t m y) (j : Bool) : + ∃ D∈deltaSpace p (v.frozen a t) b j, + obsPair p (chanInner p (channelOut p B j+D) (channelOut p B j+D))= + combineF p (v.demand w t m j) := by + classical + let G := v.demand w t m j + let L := blin K + let R := rankInit p + obtain ⟨D,hD,P,hP,hZ⟩ := v.realize_linear w m x y a b T B hb ht (qorth K) (Rorth K) hv h.sel + (by unfold Rorth; omega) (Nat.le_refl (qorth K)) hB hT hf hR hk hy hS j + let C := channelOut p B j + let f := v.frozen a t + have he (z i) : dim (sPin f z i) ≤ K+14 := + (v.frozen_here_dim hb a t i z).trans (Nat.add_le_add_right hK 14) + obtain ⟨M,hM,hA⟩ : + ∃ M : Individual p n, obsI p M=combineF p G ∧ ∀ i e,(M i e).rank≤R := by + choose M hM hA using fun i : Bool => + v.gradient_rep (w:=w.obj) (i:=i) (j:=j) m h.odd ht (hb _ _).2 (hR.summ i j) + refine ⟨M,?_,hA⟩ + have he : repF p M=G := by + funext i + exact LinearMap.ext fun x => (repF_rep M i x).trans (hM i x).symm + change combineF p (repF p M)=_ + rw [he] + obtain ⟨D,Q,V,X,hV,hQ,hW,hU,hX,hG,hF,hE⟩ := split_linear R (K+14) L he hA + (outSmall_low hC j) hD hP (hZ.trans hM.symm) + obtain ⟨Q',hq,hO,hN⟩ := shrink_pure (K+14) K (rankRes K) he (fun z i => by + unfold f; rw [v.hPin_frozen]; exact ((hPin_dim ..).trans (dim_le_plan a z)).trans hK) + hE hQ hF + have hJ (i) : ((Q'+V) i).rank≤rankAll p K := (mrk_add_le ..).trans ((add_le_add + (hN i) (hX i)).trans_eq (add_comm _ _)) + obtain ⟨Z,hY,hZ⟩ := chan_factor (3*L) (rankAll p K) K hU + (fun z => ((hPin_dim ..).trans (dim_le_plan b z)).trans hL) h.cap + ((pureSpace p f).add_mem hq hW) hJ + refine ⟨D+Z,(deltaSpace p f b j).add_mem hV hY,?_⟩ + rw [← add_assoc,hZ,map_add,hO,←map_add,hG,hM] + +end Volley + +/-- Lift the derivative changes into one actual abstract cross Gram +(on column channel arguments only). -/ +def addChan (p : Shape) {n} (D : Bool → ChanOut p n) : Cross p n := + fun z => ∑ j : Bool,(D j z)ᵀ * (IH p n j)ᵀ + +private theorem addChan_val (M : Cross p n) (D : Bool → ChanOut p n) (i : Bool) : + channelOut p (M+addChan p D) i= channelOut p M i+D i := by + funext z + unfold addChan channelOut + simp only [Fintype.sum_bool,Pi.add_apply,Matrix.transpose_add,Matrix.add_mul,Matrix.mul_assoc] + cases i <;> simp only [IH_self,IH_cross (show false≠true by decide), + IH_cross (show true≠false by decide),Matrix.mul_zero,Matrix.mul_one,transpose_zero, + transpose_transpose,zero_add,add_zero] + +def zeroRow (p : Shape) {n} (f : Plan p n) (M : Cross p n) := + ∀ z,∀ v∈f z, (M z)ᵀ *ᵥ v=0 + +theorem row_add {M B C : Cross p n} {f : Plan p n} (h : rowAgree f B C) + (hf : zeroRow p f M) : + rowAgree f (B+M) C := by + intro z v hv u + rw [Pi.add_apply, evmat_addM,h z v hv,← evmat_transpose (M z),evmat,evmat,hf z v hv, + dotProduct_zero,add_zero] + +private theorem addChan_zero {D : Bool → ChanOut p n} {f b : Plan p n} + (h : ∀ i,D i∈deltaSpace p f b i) : + zeroRow p f (addChan p D) ∧ zeroRow p b (reciprocal p (addChan p D)) := by + have hh (z : Place p) (i : Bool) := + box_kill.mp ((deltaSpace_mem _).mp (h i) z) + constructor + · intro z v hv + unfold addChan + simp only [Fintype.sum_bool,transpose_add, transpose_mul,transpose_transpose, + Matrix.add_mulVec,← Matrix.mulVec_mulVec,(hh z _).2 v hv,mulVec_zero,zero_add] + intro z v hv + unfold reciprocal addChan + have ht (i) : (IH p n i)ᵀ *ᵥ v ∈ hPin b (flipZ p (flipZ p z)) i := by + rw [flipZ_flip]; exact ⟨v,hv,rfl⟩ + have he i := (hh (flipZ p z) i).1 _ (ht i) + simp only [Fintype.sum_bool, Matrix.transpose_transpose,Matrix.add_mulVec, + ← Matrix.mulVec_mulVec,he,zero_add] + +private theorem recip_effect (B : Cross p n) (D : Bool → ChanOut p n) : + scalarBlocks p (B+reciprocal p (addChan p D))=scalarBlocks p B := by + funext z i j + unfold scalarBlocks channelOut reciprocal addChan + simp only [Pi.add_apply,Fintype.sum_bool,Matrix.transpose_add,Matrix.add_mul,Matrix.transpose_mul, + Matrix.transpose_transpose,Matrix.mul_assoc,IH_IP,Matrix.mul_zero,add_zero] + +private theorem delta_frozen {b f : Plan p n} (v : Volley p n I) (t : Tagging p I) (i : Bool) : + deltaSpace p f (v.frozen b t) i=deltaSpace p f b i := by + unfold deltaSpace + simp_rw [v.hPin_frozen] + +private theorem recip_add (B C : Cross p n) : + reciprocal p (B+C) = reciprocal p B+reciprocal p C := by + funext i; exact Matrix.transpose_add _ _ + +namespace Volley +private theorem realized_changes (v w : Volley p n I) (t : Tagging p I) + (m : Mixer p n) {D E : Bool → ChanOut p n} {B : Cross p n} + (h : ∀ j,obsPair p (chanInner p (channelOut p B j+D j) (channelOut p B j+D j))= + combineF p (v.demand w t m j)) : + v.realized w t m (B+addChan p D+reciprocal p (addChan p E)) := by + intro i j x hx + let B' := B+addChan p D + have he := h j + rw [← addChan_val B D j,obsPair_chan] at he + rw [contract_scalars _ _ (recip_effect _ E)] + exact ((combineF_same ..).mp he i x hx).symm +end Volley + +set_option maxHeartbeats 800000 in +theorem gradient_realization (v w : Volley p n I) {t : Tagging p I} (m : Mixer p n) + (x y : UnitType p n N) (a b : Pin p n N) (T : Cross p n) (K : ℕ) + (h : realizeAssum p K) + (hA : v.bounded w.obj) (hB : w.bounded v.obj) + (ht : v.legal t) (ht' : w.legal t) + (hv : v.avoids a.sp (qorth K)) (hw : w.avoids b.sp (qorth K)) + (hK : planRank a.sp ≤ K) (hL : planRank b.sp ≤ K) + (h1 : a.agree x) (h2 : b.agree y) + (h3 : tableFlag a b T x) (h4 : tableFlag b a (reciprocal p T) y) + (hT : tableInj a.sp b.sp T) (hT' : tableInj b.sp a.sp (reciprocal p T)) + (hR : v.scalarRecipe w t m x a.sp T) (hR' : w.scalarRecipe v t m y b.sp (reciprocal p T)) + (hk : v.keys t x=w.keys t y) + (hx : ∀ i,frameLaw m (onSide x i)) (hy : ∀ i, frameLaw m (onSide y i)) + (hS : v.attackGrad w t m y) (hS' : w.attackGrad v t m x) : + ∃ Q : Cross p n, v.realized w t m Q ∧ w.realized v t m (reciprocal p Q) ∧ + rowAgree (v.frozen a.sp t) Q (actual p x y) ∧ + rowAgree (w.frozen b.sp t) (reciprocal p Q) (actual p y x) := by + classical + obtain ⟨M,hQ,hD,hD',hM,hM'⟩ := start_form a b x y T + (v.keyPlan t) (w.keyPlan t) (keyPlane v t) (keyPlane w t) + (fun z => (v.key_independent t hv z).2.symm) (fun z => (w.key_independent t hw z).2.symm) + h1 h2 h3 h4 K hK hL (v.key_dim hA t) (w.key_dim hB t) + choose D hDA hG using fun j => Volley.realize_one v w m x y a.sp b.sp T M K h + hA ht hv hK hL hQ hT hD hM hR hk hy hS j + choose E hEA hF using fun j => Volley.realize_one w v m y x b.sp a.sp (reciprocal p T) + (reciprocal p M) K h hB ht' hw hL hK (fits_recip hQ) hT' hD' hM' hR' hk.symm hx hS' j + let Q := M+addChan p D+reciprocal p (addChan p E) + have he : reciprocal p Q = reciprocal p M+addChan p E+reciprocal p (addChan p D) := by + unfold Q + rw [recip_add,recip_add,reciprocal_twice]; ac_rfl + obtain ⟨hN,hN'⟩ := addChan_zero (D:=D) (f:=v.frozen a.sp t) (b:=w.frozen b.sp t) + (fun i => by rw [delta_frozen w t i]; exact hDA i) + obtain ⟨hO,hO'⟩ := addChan_zero (D:=E) (f:=w.frozen b.sp t) (b:=v.frozen a.sp t) + (fun i => by rw [delta_frozen v t i]; exact hEA i) + refine ⟨Q,Volley.realized_changes v w t m hG,?_,row_add (row_add hD hN) hO',?_⟩ + · rw [he] + exact Volley.realized_changes w v t m hF + rw [he]; exact row_add (row_add hD' hO) hN' + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/GramArrayConcentration.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/GramArrayConcentration.lean index 1ce5e5813a02e7025c6766655adffc1ef87b700b..3e65993f92010c32eb79656101f54cb53bbe9c8e 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/GramArrayConcentration.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/GramArrayConcentration.lean @@ -1,99 +1,99 @@ -import OAI.Combinatorics.HadwigerCounterexample.SyntheticSliceComparison - -namespace OAI - -/-! # Gram Array Concentration -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module LinearMap Function Filter -open scoped BigOperators Topology -variable {p : Shape} {I : Type} [Fintype I] [DecidableEq I] {n N : ℕ} -def magazine (p : Shape) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) - (P : Display p I N→Prop) (a : I→ Tickets p) (o : Orient p n N) := - pr (sketchLaw p n a) (fun i => P (drill p (incision p l s f i) o)) - -set_option maxHeartbeats 1000000 in -theorem magazine_var (p : Shape) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) - (P : Display p I N → Prop) (a : I → Tickets p) (m : Mixer p n) - (h : 2*num (Full p n) (magazine p l s f P a i - pr V P)^2) ≤ - 2 * netFact g * twinkle g k N + bp (num Bool*num I - n) := by - classical - let Z := labGram p l f a - let W := sketchLaw p n a - let μ := raw m N - have hw : IsLaw W:= sketch_law p n a hn - have hμ : IsLaw μ := raw_law m h - have hs := display_law p Z N hN - intro g V - let U i := ind (P i)-pr V P - have he : avg V U=0 := by unfold U; rw [avg_sub,hs.avg_const]; exact sub_self _ - have hh (i) : |U i| ≤1 := by - have hl := pr_nonneg (p:=P) hs.nz; have ht := (pr_le_tot (p:=P) hs.nz).trans hs.total.le - unfold U; rw [abs_le]; constructor <;> linarith only [ind_nonneg (P i),ind_le_one (P i),hl,ht] - let A (x : I → Knobs p.g n) := incision p l s f x - let F (i : Orient p n N) x := U (drill p (A x) i) - have heq (i) : - magazine p l s f P a i-pr V P = avg W (F i) := by - unfold F U; rw [avg_sub,hw.avg_const]; rfl - let w := draws Bool W; have hW : IsLaw w := draws_law hw - let E := 2*netFact g * twinkle g k N - have hp0 : 0 ≤ E := by - have hg : 0 F o (x true)*F o (x false)) ≤ E+ind (¬bloom p x) := by - by_cases ht : bloom p x - · have ha (i : Bool) : avg μ (fun o=> F o (x i))=0 := by - let M := incision p l s f (x i) - have he' := drill_law p (bloom_incision p n x l s f ht i) m h - rw [sketch_matrix p l s f m a hj _ (draw_elem x i hx)] at he' - change avg μ (fun o=>U (drill p M o))=0 - rw [←mapW_avg]; exact (congrArg (fun w=>avg w U) he').trans he - let D i:=drQuery (p:=p) (A (x i)) - let W i:=U (relay (Comp p.g) I N i) - have hg := bloom_drill p n x l s f ht - have hz := pooled_batch D D m h k (fun i=>(port_limit g i).trans hk) hK hg hg - (fun i=>W) (fun i y=>hh _) - simp_rw [Fintype.prod_bool] at hz - have heq (i : Bool) : - avg μ (fun o=> W (peekR p (drStage p I) (D i) (D i) o))=0 := by - specialize ha i - unfold F at ha; simp_rw [drill_view p] at ha; exact ha - change |_ - (avg μ _ * avg μ _)|≤_ at hz - rw [heq true,heq false,mul_zero,sub_zero] at hz - unfold F - simp_rw [drill_view p] - rw [ind_zero (fun hg=>hg ht),add_zero] - exact (le_abs_self _).trans hz - rw [ind_one ht] - refine (hμ.avg_le (b:=1) ?_).trans (le_add_of_nonneg_left hp0) - intro i - have ht (a b : ℝ) (ha : |a| ≤ 1) (hb : |b|≤1) : - a*b ≤1 := (le_abs_self _).trans (by rw [abs_mul]; exact - (mul_le_mul ha hb (abs_nonneg _) zero_le_one).trans_eq (by ring)) - exact ht _ _ (hh _) (hh _) - simp_rw [heq,avg_cross_sq]; rw [avg_avg] - have ht : - avg w (fun i=> E+ind (¬bloom p i))=E+pr w (fun i=>¬bloom p i) := by rw [avg_add,hW.avg_const]; - rfl - apply le_trans _ (add_le_add_right (buds p n (fun i=>rung p n (a i)) - (fun i=>ticketFlow n _ hn)) E) - change _ ≤ E + pr w (fun i=>¬bloom p i) - rw [←ht]; unfold avg - refine Finset.sum_le_sum (fun i _=> ?_) - by_cases hi' : w i=0 - · change w i*_ ≤ w i*_ - simp only [hi',zero_mul,le_refl] - exact mul_le_mul_of_nonneg_left (hi i hi') (hW.nz _) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SyntheticSliceComparison + +namespace OAI + +/-! # Gram Array Concentration -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module LinearMap Function Filter +open scoped BigOperators Topology +variable {p : Shape} {I : Type} [Fintype I] [DecidableEq I] {n N : ℕ} +def magazine (p : Shape) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) + (P : Display p I N→Prop) (a : I→ Tickets p) (o : Orient p n N) := + pr (sketchLaw p n a) (fun i => P (drill p (incision p l s f i) o)) + +set_option maxHeartbeats 1000000 in +theorem magazine_var (p : Shape) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) + (P : Display p I N → Prop) (a : I → Tickets p) (m : Mixer p n) + (h : 2*num (Full p n) (magazine p l s f P a i - pr V P)^2) ≤ + 2 * netFact g * twinkle g k N + bp (num Bool*num I - n) := by + classical + let Z := labGram p l f a + let W := sketchLaw p n a + let μ := raw m N + have hw : IsLaw W:= sketch_law p n a hn + have hμ : IsLaw μ := raw_law m h + have hs := display_law p Z N hN + intro g V + let U i := ind (P i)-pr V P + have he : avg V U=0 := by unfold U; rw [avg_sub,hs.avg_const]; exact sub_self _ + have hh (i) : |U i| ≤1 := by + have hl := pr_nonneg (p:=P) hs.nz; have ht := (pr_le_tot (p:=P) hs.nz).trans hs.total.le + unfold U; rw [abs_le]; constructor <;> linarith only [ind_nonneg (P i),ind_le_one (P i),hl,ht] + let A (x : I → Knobs p.g n) := incision p l s f x + let F (i : Orient p n N) x := U (drill p (A x) i) + have heq (i) : + magazine p l s f P a i-pr V P = avg W (F i) := by + unfold F U; rw [avg_sub,hw.avg_const]; rfl + let w := draws Bool W; have hW : IsLaw w := draws_law hw + let E := 2*netFact g * twinkle g k N + have hp0 : 0 ≤ E := by + have hg : 0 F o (x true)*F o (x false)) ≤ E+ind (¬bloom p x) := by + by_cases ht : bloom p x + · have ha (i : Bool) : avg μ (fun o=> F o (x i))=0 := by + let M := incision p l s f (x i) + have he' := drill_law p (bloom_incision p n x l s f ht i) m h + rw [sketch_matrix p l s f m a hj _ (draw_elem x i hx)] at he' + change avg μ (fun o=>U (drill p M o))=0 + rw [←mapW_avg]; exact (congrArg (fun w=>avg w U) he').trans he + let D i:=drQuery (p:=p) (A (x i)) + let W i:=U (relay (Comp p.g) I N i) + have hg := bloom_drill p n x l s f ht + have hz := pooled_batch D D m h k (fun i=>(port_limit g i).trans hk) hK hg hg + (fun i=>W) (fun i y=>hh _) + simp_rw [Fintype.prod_bool] at hz + have heq (i : Bool) : + avg μ (fun o=> W (peekR p (drStage p I) (D i) (D i) o))=0 := by + specialize ha i + unfold F at ha; simp_rw [drill_view p] at ha; exact ha + change |_ - (avg μ _ * avg μ _)|≤_ at hz + rw [heq true,heq false,mul_zero,sub_zero] at hz + unfold F + simp_rw [drill_view p] + rw [ind_zero (fun hg=>hg ht),add_zero] + exact (le_abs_self _).trans hz + rw [ind_one ht] + refine (hμ.avg_le (b:=1) ?_).trans (le_add_of_nonneg_left hp0) + intro i + have ht (a b : ℝ) (ha : |a| ≤ 1) (hb : |b|≤1) : + a*b ≤1 := (le_abs_self _).trans (by rw [abs_mul]; exact + (mul_le_mul ha hb (abs_nonneg _) zero_le_one).trans_eq (by ring)) + exact ht _ _ (hh _) (hh _) + simp_rw [heq,avg_cross_sq]; rw [avg_avg] + have ht : + avg w (fun i=> E+ind (¬bloom p i))=E+pr w (fun i=>¬bloom p i) := by rw [avg_add,hW.avg_const]; + rfl + apply le_trans _ (add_le_add_right (buds p n (fun i=>rung p n (a i)) + (fun i=>ticketFlow n _ hn)) E) + change _ ≤ E + pr w (fun i=>¬bloom p i) + rw [←ht]; unfold avg + refine Finset.sum_le_sum (fun i _=> ?_) + by_cases hi' : w i=0 + · change w i*_ ≤ w i*_ + simp only [hi',zero_mul,le_refl] + exact mul_le_mul_of_nonneg_left (hi i hi') (hW.nz _) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/GramCharacterExpansion.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/GramCharacterExpansion.lean index 048c29f35b6a611596e15c2caa9f26c006f53bd6..cb026a0d38b401c7a147c20659afa915ff1d489b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/GramCharacterExpansion.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/GramCharacterExpansion.lean @@ -1,137 +1,137 @@ -import OAI.Combinatorics.HadwigerCounterexample.CrossPatternCorrelation - -namespace OAI - -/-! # Gram Character Expansion -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Function Finset -open scoped BigOperators -variable {I J : Type} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] - {N : ℕ} - -def vectorPhase (x y : Vec I) := wsign (dotProduct x y) - -theorem vector_expand (x y : Vec I) : - ind (x=y)=avg unif (fun z => vectorPhase z x*vectorPhase z y) := by - classical - have hh (z : Vec I) : vectorPhase z x * vectorPhase z y = wsign (dotL (x+y) z) := by - unfold vectorPhase - rw [← wsign_add] - change _ = wsign (dotProduct _ _) - rw [dotProduct_comm (x+y),dotProduct_add] - have hi : dotL (x+y)=0 ↔ x=y := by - have he : dotL (x+y)=0 ↔ x+y=0 := by - constructor - · intro h - refine dot_ext_zero fun z => ?_ - rw [dotProduct_comm]; exact LinearMap.congr_fun h z - intro h; rw [h]; exact LinearMap.ext fun z => zero_dotProduct z - rw [he,←ZModModule.sub_eq_add,sub_eq_zero] - simp_rw [hh,wsign_lin] - rw [hi] - -abbrev Rail (I : Type) := Finset (I × I) -variable {E : Rail I} - -def ledgerM (E : Rail I) (v : Vec E) : Mat I I := - Matrix.of (fun x y => if h:(x,y)∈E then v ⟨(x,y),h⟩ else 0) -def railsM (E : Rail I) (M : Mat I I) : Vec E := fun i => M i.val.1 i.val.2 - -def traced (x : Rack I N) (E : Rail I) (Z : Vec E) := - railsM E (x.1ᵀ*x.2)=Z - -def withinRail (M : Mat I I) (E : Rail I) := - ∀ i j, (i,j)∉ E→M i j=0 - -omit [Fintype I] in -theorem inLedger (E : Rail I) (v : Vec E) : railsM E (ledgerM E v)=v := by - classical - funext i; rcases i with ⟨⟨i,j⟩,h⟩ - simp [ledgerM,railsM,h] - -omit [Fintype I] in -theorem within_recorded (E : Rail I) (v : Vec E) : - withinRail (ledgerM E v) E := fun _ _ h => dite_eq_right h - -theorem rail_charge (x : Rack I N) (E : Rail I) (v : Vec E) : - vectorPhase v (railsM E (x.1ᵀ*x.2))=phasedBy (ledgerM E v) x := by - classical - unfold vectorPhase phasedBy - rw [layer_form] - let A := x.1ᵀ*x.2 - let r (i : I × I) := ledgerM E v i.1 i.2 * A i.1 i.2 - change wsign _ = wsign (∑ i:I,∑ j:I,r (i,j)) - rw [←Fintype.sum_prod_type] - congr 1 - change ∑ i:E,_ = ∑ i:I × I,r i - calc (∑ i:E,_) = ∑ i:E, r i.val := by - refine Finset.sum_congr rfl fun i _ => ?_ - unfold r - rw [show ledgerM E v i.val.1 i.val.2 =v i from congr_fun (inLedger E v) i] - rfl - _ = ∑ i ∈ E,r i := Finset.sum_coe_sort .. - _ = _ := Finset.sum_subset (Finset.subset_univ _) (fun i _ hi => by - rcases i with ⟨i,j⟩ - unfold r - simp only [ledgerM,Matrix.of_apply,dite_eq_right hi,zero_mul]) - -theorem rail_expand (x : Rack I N) (E : Rail I) (Z : Vec E) : - ind (traced x E Z) = - avg unif (fun v : Vec E => phasedBy (ledgerM E v) x*vectorPhase v Z) := by - unfold traced - rw [vector_expand] - simp_rw [rail_charge] - -omit [Fintype I] in -theorem ledger_zero (E : Rail I) : ledgerM E 0=0 := by - classical ext; simp [ledgerM] - -theorem phased_match (x : Rack I N) (E : Rail I) (Z v : Vec E) (h : traced x E Z) : - phasedBy (ledgerM E v) x=vectorPhase v Z := by rw [← rail_charge,h] - -def crowded (g : Route I J) : Rail I := Finset.univ.filter (fun x => g x.1=g x.2) - -def directions (g : Route I J) (A : GeoM g) : Vec (crowded g) := fun x => - A (g x.val.1) ⟨x.val.1,rfl⟩ ⟨x.val.2,(mem_filter.mp x.property).2.symm⟩ - -omit [Fintype J] [DecidableEq I] in -theorem match_crowd (x : Rack I N) (g : Route I J) (A : GeoM g) : - traced x (crowded g) (directions g A) ↔ gramPart A x := by - classical - rw [part_scores] - constructor - · intro h i a b - obtain ⟨a,ha⟩ := a - obtain ⟨b,hb⟩ := b - subst i - let y : crowded g := ⟨(a,b), mem_filter.mpr ⟨mem_univ _, hb.symm⟩⟩ - exact congr_fun h y - · intro h - funext i - exact h _ ⟨_,rfl⟩ ⟨i.val.2,(mem_filter.mp i.property).2.symm⟩ - -omit [DecidableEq I] in -theorem rail_count (g : Route I J) : - ((crowded g).card:ℝ)=netSize g := by - classical - let E := crowded g - let e : (Σ j,Port g j × Port g j) ≃ ↑E := - { toFun := fun i => ⟨(i.2.1.val,i.2.2.val),mem_filter.mpr ⟨mem_univ _,i.2.1.property.trans - i.2.2.property.symm⟩⟩ - invFun := fun i => ⟨g i.val.1,⟨_,rfl⟩,⟨i.val.2,(mem_filter.mp i.property).2.symm⟩⟩ - left_inv := by rintro ⟨j,⟨a,ha⟩,⟨b,hb⟩⟩; subst j; rfl - right_inv i := by rcases i with ⟨⟨i,j⟩,ha⟩; rfl } - have ht := Fintype.card_congr e - rw [Fintype.card_coe,Fintype.card_sigma] at ht - have hx : (crowded g).card=∑ i : J, (Fintype.card (Port g i)*Fintype.card (Port g i)) := by - rw [ht.symm]; exact Finset.sum_congr rfl fun i _ => Fintype.card_prod .. - rw [hx,netSize] - simp only [Nat.cast_sum,Nat.cast_mul,num] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CrossPatternCorrelation + +namespace OAI + +/-! # Gram Character Expansion -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Function Finset +open scoped BigOperators +variable {I J : Type} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] + {N : ℕ} + +def vectorPhase (x y : Vec I) := wsign (dotProduct x y) + +theorem vector_expand (x y : Vec I) : + ind (x=y)=avg unif (fun z => vectorPhase z x*vectorPhase z y) := by + classical + have hh (z : Vec I) : vectorPhase z x * vectorPhase z y = wsign (dotL (x+y) z) := by + unfold vectorPhase + rw [← wsign_add] + change _ = wsign (dotProduct _ _) + rw [dotProduct_comm (x+y),dotProduct_add] + have hi : dotL (x+y)=0 ↔ x=y := by + have he : dotL (x+y)=0 ↔ x+y=0 := by + constructor + · intro h + refine dot_ext_zero fun z => ?_ + rw [dotProduct_comm]; exact LinearMap.congr_fun h z + intro h; rw [h]; exact LinearMap.ext fun z => zero_dotProduct z + rw [he,←ZModModule.sub_eq_add,sub_eq_zero] + simp_rw [hh,wsign_lin] + rw [hi] + +abbrev Rail (I : Type) := Finset (I × I) +variable {E : Rail I} + +def ledgerM (E : Rail I) (v : Vec E) : Mat I I := + Matrix.of (fun x y => if h:(x,y)∈E then v ⟨(x,y),h⟩ else 0) +def railsM (E : Rail I) (M : Mat I I) : Vec E := fun i => M i.val.1 i.val.2 + +def traced (x : Rack I N) (E : Rail I) (Z : Vec E) := + railsM E (x.1ᵀ*x.2)=Z + +def withinRail (M : Mat I I) (E : Rail I) := + ∀ i j, (i,j)∉ E→M i j=0 + +omit [Fintype I] in +theorem inLedger (E : Rail I) (v : Vec E) : railsM E (ledgerM E v)=v := by + classical + funext i; rcases i with ⟨⟨i,j⟩,h⟩ + simp [ledgerM,railsM,h] + +omit [Fintype I] in +theorem within_recorded (E : Rail I) (v : Vec E) : + withinRail (ledgerM E v) E := fun _ _ h => dite_eq_right h + +theorem rail_charge (x : Rack I N) (E : Rail I) (v : Vec E) : + vectorPhase v (railsM E (x.1ᵀ*x.2))=phasedBy (ledgerM E v) x := by + classical + unfold vectorPhase phasedBy + rw [layer_form] + let A := x.1ᵀ*x.2 + let r (i : I × I) := ledgerM E v i.1 i.2 * A i.1 i.2 + change wsign _ = wsign (∑ i:I,∑ j:I,r (i,j)) + rw [←Fintype.sum_prod_type] + congr 1 + change ∑ i:E,_ = ∑ i:I × I,r i + calc (∑ i:E,_) = ∑ i:E, r i.val := by + refine Finset.sum_congr rfl fun i _ => ?_ + unfold r + rw [show ledgerM E v i.val.1 i.val.2 =v i from congr_fun (inLedger E v) i] + rfl + _ = ∑ i ∈ E,r i := Finset.sum_coe_sort .. + _ = _ := Finset.sum_subset (Finset.subset_univ _) (fun i _ hi => by + rcases i with ⟨i,j⟩ + unfold r + simp only [ledgerM,Matrix.of_apply,dite_eq_right hi,zero_mul]) + +theorem rail_expand (x : Rack I N) (E : Rail I) (Z : Vec E) : + ind (traced x E Z) = + avg unif (fun v : Vec E => phasedBy (ledgerM E v) x*vectorPhase v Z) := by + unfold traced + rw [vector_expand] + simp_rw [rail_charge] + +omit [Fintype I] in +theorem ledger_zero (E : Rail I) : ledgerM E 0=0 := by + classical ext; simp [ledgerM] + +theorem phased_match (x : Rack I N) (E : Rail I) (Z v : Vec E) (h : traced x E Z) : + phasedBy (ledgerM E v) x=vectorPhase v Z := by rw [← rail_charge,h] + +def crowded (g : Route I J) : Rail I := Finset.univ.filter (fun x => g x.1=g x.2) + +def directions (g : Route I J) (A : GeoM g) : Vec (crowded g) := fun x => + A (g x.val.1) ⟨x.val.1,rfl⟩ ⟨x.val.2,(mem_filter.mp x.property).2.symm⟩ + +omit [Fintype J] [DecidableEq I] in +theorem match_crowd (x : Rack I N) (g : Route I J) (A : GeoM g) : + traced x (crowded g) (directions g A) ↔ gramPart A x := by + classical + rw [part_scores] + constructor + · intro h i a b + obtain ⟨a,ha⟩ := a + obtain ⟨b,hb⟩ := b + subst i + let y : crowded g := ⟨(a,b), mem_filter.mpr ⟨mem_univ _, hb.symm⟩⟩ + exact congr_fun h y + · intro h + funext i + exact h _ ⟨_,rfl⟩ ⟨i.val.2,(mem_filter.mp i.property).2.symm⟩ + +omit [DecidableEq I] in +theorem rail_count (g : Route I J) : + ((crowded g).card:ℝ)=netSize g := by + classical + let E := crowded g + let e : (Σ j,Port g j × Port g j) ≃ ↑E := + { toFun := fun i => ⟨(i.2.1.val,i.2.2.val),mem_filter.mpr ⟨mem_univ _,i.2.1.property.trans + i.2.2.property.symm⟩⟩ + invFun := fun i => ⟨g i.val.1,⟨_,rfl⟩,⟨i.val.2,(mem_filter.mp i.property).2.symm⟩⟩ + left_inv := by rintro ⟨j,⟨a,ha⟩,⟨b,hb⟩⟩; subst j; rfl + right_inv i := by rcases i with ⟨⟨i,j⟩,ha⟩; rfl } + have ht := Fintype.card_congr e + rw [Fintype.card_coe,Fintype.card_sigma] at ht + have hx : (crowded g).card=∑ i : J, (Fintype.card (Port g i)*Fintype.card (Port g i)) := by + rw [ht.symm]; exact Finset.sum_congr rfl fun i _ => Fintype.card_prod .. + rw [hx,netSize] + simp only [Nat.cast_sum,Nat.cast_mul,num] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/GramCharacterQuotients.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/GramCharacterQuotients.lean index 20a60b8ebca50ba43f242086aef1da6f80ff8972..0d1c3f63bbea98004694cd12bc0b8c0a67ab09b0 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/GramCharacterQuotients.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/GramCharacterQuotients.lean @@ -1,159 +1,159 @@ -import OAI.Combinatorics.HadwigerCounterexample.ImageCharacterBounds - -namespace OAI - -/-! # Gram Character Quotients -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Finset -open scoped BigOperators -variable {p : Shape} {n N : ℕ} - -def cpDual (p : Shape) {n} (A : Cross p n) : - Cross p n →ₗ[F] F := - ∑ z : Place p, mpair (A z) ∘ₗ LinearMap.proj z - -theorem cpDual_val (A B : Cross p n) : - cpDual p A B=∑ z,mpair (A z) (B z) := by - unfold cpDual; rw [LinearMap.sum_apply]; rfl - -variable {I J L U : Type} [Fintype I] [Fintype J] [Fintype L] [Fintype U] - -private theorem pair_trace (A B : Mat I J) : mpair A B=(A*Bᵀ).trace := by - change ∑ i:I, ∑ j:J,A i j * B i j = _ - rfl - -private theorem pair_transfer (X : Mat U I) (Y : Mat U J) (A : Mat I L) (B : Mat J L) : - mpair (A*Bᵀ) (Xᵀ*Y)=mpair (X*A) (Y*B) := by - rw [pair_trace,pair_trace,Matrix.transpose_mul,Matrix.transpose_mul,Matrix.transpose_transpose] - rw [← Matrix.mul_assoc _ Yᵀ X,Matrix.trace_mul_comm _ X] - simp only [Matrix.mul_assoc] - -private theorem proj_opposite [DecidableEq I] (S : Space (Vec I)) : - ∃ A : Mat I I,(∀ x,x-A *ᵥ x∈S) ∧ Disjoint (colSp A) S := by - classical - obtain ⟨B,hB⟩ := proj_exists S ⊥ disjoint_bot_right - refine ⟨1-B,fun x => ?_,?_⟩ - · rw [Matrix.sub_mulVec,Matrix.one_mulVec,sub_sub_cancel] - exact hB.onto x - rw [disjoint_iff_inf_le] - rintro x ⟨⟨y,rfl⟩,hy⟩ - rw [mulVecLin_apply,Matrix.sub_mulVec,Matrix.one_mulVec] at hy ⊢ - have hx := hB.fixes _ hy - rw [Matrix.mulVec_sub,hB.fixes (B *ᵥ y) (hB.onto _),sub_self] at hx - rw [←hx]; exact Submodule.zero_mem _ - -private theorem free_pull (p : Shape) {n} (A : Cross p n) (s t : Plan p n) : - ∃ P : Cross p n,(∀ z, Disjoint (colSp (P z)) (s z) ∧ - Disjoint (colSp (P z)ᵀ) (t (flipZ p z))) ∧ - ∀ X Y, rowAgree s X Y → rowAgree t (reciprocal p X) (reciprocal p Y) → - cpDual p A (X-Y) = cpDual p P (X-Y) := by - classical - choose S hS hL using fun z => proj_opposite (s z) - choose T hT hR using fun z => proj_opposite (t (flipZ p z)) - let P (z : Place p) := liftM (S z) (T z) (A z) - refine ⟨P,fun z => ⟨(hL z).mono_left (colSp_lift_le ..),by - unfold P; rw [liftM_transpose]; exact (hR z).mono_left (colSp_lift_le ..)⟩,fun X Y hX hY => ?_⟩ - rw [cpDual_val,cpDual_val] - refine Finset.sum_congr rfl fun z _ => ?_ - let M := X z-Y z - have he : pullM (S z) (T z) M=M := by - apply evmat_ext; intro x y - rw [evmat_pull] - let x' := S z *ᵥ x - let y' := T z *ᵥ y - have hL : evmat M (x-x') y=0 := by - rw [show M=X z-Y z from rfl,evmat_subM,hX z _ (hS z x),sub_self] - have hR : evmat M x' (y-y')=0 := by - have h := hY (flipZ p z) _ (hT z y) x' - simp only [reciprocal,flipZ_flip,evmat_transpose] at h - rw [show M=X z-Y z from rfl,evmat_subM,h,sub_self] - unfold evmat at hL hR ⊢ - rw [sub_dotProduct,sub_eq_zero] at hL - rw [Matrix.mulVec_sub, dotProduct_sub,sub_eq_zero] at hR - exact hR.symm.trans hL.symm - change mpair (A z) M=mpair (liftM _ _ _) M - rw [mpair_comm (A z)] - rw [mpair_comm (liftM _ _ _),mpair_liftM,show liftM (S z)ᵀ (T z)ᵀ M=M from he] - -theorem factor_free {A : Cross p n} (s t : Plan p n) - (h : ∀ z, Disjoint (colSp (A z)) (s z) ∧ Disjoint (colSp (A z)ᵀ) (t (flipZ p z))) : - ∃ (r : Place p→ℕ) (B C : WTuple (p:=p) r n), (∀ z,r z=(A z).rank) ∧ - (∀ z,Function.Injective (B z).mulVec ∧ Disjoint (colSp (B z)) (s z)) ∧ - (∀ z,Function.Injective (C z).mulVec ∧ Disjoint (colSp (C z)) (t (flipZ p z))) ∧ - (∀ z,A z=B z * (C z)ᵀ) := by - classical - choose B C hB hC hA using fun z => rank_product (A z) - let G (z : Place p) := (C z)ᵀ - have ht z : Function.Injective (G z).mulVec := - transpose_surj_iff.mp (by unfold G; rw [Matrix.transpose_transpose]; exact hC _) - refine ⟨_,B,G,fun _ => rfl,fun z => ⟨hB z,(h z).1.mono_left ?_⟩, - fun z => ⟨ht z,(h z).2.mono_left ?_⟩, - fun z => by unfold G; rw [Matrix.transpose_transpose,hA]⟩ - · rintro x ⟨v,rfl⟩ - obtain ⟨w,rfl⟩ := hC z v - refine ⟨w,?_⟩ - rw [mulVecLin_apply,mulVecLin_apply,Matrix.mulVec_mulVec,hA] - · rintro x ⟨v,rfl⟩ - obtain ⟨w,rfl⟩ := (transpose_surj_iff.mpr (hB z)) v - refine ⟨w,?_⟩ - rw [mulVecLin_apply,mulVecLin_apply] - unfold G; rw [Matrix.mulVec_mulVec,← transpose_mul,hA] - -theorem gramCharacter (Q M : Cross p n) {u w : Wgt (UnitType p n N)} - (hu : IsLaw u) (hw : IsLaw w) {f b : Pin p n N} - (hc : f.clear 0.05 u) (hd : b.clear 0.05 w) - (h : ∀ x,u x≠0 → ∀ y,w y≠0 → rowAgree f.sp (actual p x y) Q ∧ - rowAgree b.sp (actual p y x) (reciprocal p Q)) : - let Y := avg (pairW u w) (fun x => - wsign (cpDual p M (actual p x.1 x.2-Q))) - Y=1 ∨ |Y| ≤ bp (-0.45*N) := by - classical - dsimp only - obtain ⟨P,hP,hX⟩ := free_pull p M f.sp b.sp - obtain ⟨r,B,C,hr,hB,hC,hY⟩ := factor_free f.sp b.sp hP - let s := pairW u w - have he : - avg s (fun x => wsign (cpDual p M (actual p x.1 x.2-Q))) = - avg s (fun x => wsign (cpDual p P (actual p x.1 x.2-Q))) := by - refine avg_congr fun ⟨x,y⟩ hxy => ?_ - rw [show cpDual p M (actual p x y-Q)=_ from hX _ _ _ _] - · exact (h x (left_ne_zero_of_mul hxy) y (right_ne_zero_of_mul hxy)).1 - rw [reciprocal_actual]; exact (h x (left_ne_zero_of_mul hxy) y (right_ne_zero_of_mul hxy)).2 - rw [he] - by_cases hh : 1≤∑ z,r z - · right - let g := projTuple p r B (Equiv.refl _) (N:=N) - let g' := projTuple p r C (flipEquiv p) (N:=N) - let X (x : UnitType p n N × UnitType p n N) := tupleB p r N (g x.1) (g' x.2) - have hi x : - wsign (cpDual p P (actual p x.1 x.2-Q))=wsign (X x) * wsign (cpDual p P Q) := by - simp only [ZModModule.sub_eq_add,map_add,wsign_add] - have hv : cpDual p P (actual p x.1 x.2)=X x := by - unfold X; rw [cpDual_val,tupleB_val] - refine Finset.sum_congr rfl fun z _ => ?_ - rw [hY,actual,pair_transfer]; rfl - rw [hv] - simp_rw [hi]; rw [avg_mul,abs_mul,wsign_abs,mul_one] - exact charImages p r B C hu hw hc hd hB hC hh - left - have hZ z : P z=0 := by - have hc : r z ≤ ∑ i,r i := Finset.single_le_sum (fun z _ => Nat.zero_le (r z)) - (Finset.mem_univ _) - rw [hY] - have hz : r z=0 := by omega - have : IsEmpty (Fin (r z)) := hz ▸ Fin.isEmpty' - ext i j; simp [Matrix.mul_apply] - have hk x : wsign (cpDual p P x)=1 := by - rw [cpDual_val] - have hf z : mpair (P z) (x z)=0 := by rw [hZ,mpair_comm,map_zero] - simp_rw [hf] - simp - simp_rw [hk]; exact (pairW_law hu hw).avg_const _ - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ImageCharacterBounds + +namespace OAI + +/-! # Gram Character Quotients -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} + +def cpDual (p : Shape) {n} (A : Cross p n) : + Cross p n →ₗ[F] F := + ∑ z : Place p, mpair (A z) ∘ₗ LinearMap.proj z + +theorem cpDual_val (A B : Cross p n) : + cpDual p A B=∑ z,mpair (A z) (B z) := by + unfold cpDual; rw [LinearMap.sum_apply]; rfl + +variable {I J L U : Type} [Fintype I] [Fintype J] [Fintype L] [Fintype U] + +private theorem pair_trace (A B : Mat I J) : mpair A B=(A*Bᵀ).trace := by + change ∑ i:I, ∑ j:J,A i j * B i j = _ + rfl + +private theorem pair_transfer (X : Mat U I) (Y : Mat U J) (A : Mat I L) (B : Mat J L) : + mpair (A*Bᵀ) (Xᵀ*Y)=mpair (X*A) (Y*B) := by + rw [pair_trace,pair_trace,Matrix.transpose_mul,Matrix.transpose_mul,Matrix.transpose_transpose] + rw [← Matrix.mul_assoc _ Yᵀ X,Matrix.trace_mul_comm _ X] + simp only [Matrix.mul_assoc] + +private theorem proj_opposite [DecidableEq I] (S : Space (Vec I)) : + ∃ A : Mat I I,(∀ x,x-A *ᵥ x∈S) ∧ Disjoint (colSp A) S := by + classical + obtain ⟨B,hB⟩ := proj_exists S ⊥ disjoint_bot_right + refine ⟨1-B,fun x => ?_,?_⟩ + · rw [Matrix.sub_mulVec,Matrix.one_mulVec,sub_sub_cancel] + exact hB.onto x + rw [disjoint_iff_inf_le] + rintro x ⟨⟨y,rfl⟩,hy⟩ + rw [mulVecLin_apply,Matrix.sub_mulVec,Matrix.one_mulVec] at hy ⊢ + have hx := hB.fixes _ hy + rw [Matrix.mulVec_sub,hB.fixes (B *ᵥ y) (hB.onto _),sub_self] at hx + rw [←hx]; exact Submodule.zero_mem _ + +private theorem free_pull (p : Shape) {n} (A : Cross p n) (s t : Plan p n) : + ∃ P : Cross p n,(∀ z, Disjoint (colSp (P z)) (s z) ∧ + Disjoint (colSp (P z)ᵀ) (t (flipZ p z))) ∧ + ∀ X Y, rowAgree s X Y → rowAgree t (reciprocal p X) (reciprocal p Y) → + cpDual p A (X-Y) = cpDual p P (X-Y) := by + classical + choose S hS hL using fun z => proj_opposite (s z) + choose T hT hR using fun z => proj_opposite (t (flipZ p z)) + let P (z : Place p) := liftM (S z) (T z) (A z) + refine ⟨P,fun z => ⟨(hL z).mono_left (colSp_lift_le ..),by + unfold P; rw [liftM_transpose]; exact (hR z).mono_left (colSp_lift_le ..)⟩,fun X Y hX hY => ?_⟩ + rw [cpDual_val,cpDual_val] + refine Finset.sum_congr rfl fun z _ => ?_ + let M := X z-Y z + have he : pullM (S z) (T z) M=M := by + apply evmat_ext; intro x y + rw [evmat_pull] + let x' := S z *ᵥ x + let y' := T z *ᵥ y + have hL : evmat M (x-x') y=0 := by + rw [show M=X z-Y z from rfl,evmat_subM,hX z _ (hS z x),sub_self] + have hR : evmat M x' (y-y')=0 := by + have h := hY (flipZ p z) _ (hT z y) x' + simp only [reciprocal,flipZ_flip,evmat_transpose] at h + rw [show M=X z-Y z from rfl,evmat_subM,h,sub_self] + unfold evmat at hL hR ⊢ + rw [sub_dotProduct,sub_eq_zero] at hL + rw [Matrix.mulVec_sub, dotProduct_sub,sub_eq_zero] at hR + exact hR.symm.trans hL.symm + change mpair (A z) M=mpair (liftM _ _ _) M + rw [mpair_comm (A z)] + rw [mpair_comm (liftM _ _ _),mpair_liftM,show liftM (S z)ᵀ (T z)ᵀ M=M from he] + +theorem factor_free {A : Cross p n} (s t : Plan p n) + (h : ∀ z, Disjoint (colSp (A z)) (s z) ∧ Disjoint (colSp (A z)ᵀ) (t (flipZ p z))) : + ∃ (r : Place p→ℕ) (B C : WTuple (p:=p) r n), (∀ z,r z=(A z).rank) ∧ + (∀ z,Function.Injective (B z).mulVec ∧ Disjoint (colSp (B z)) (s z)) ∧ + (∀ z,Function.Injective (C z).mulVec ∧ Disjoint (colSp (C z)) (t (flipZ p z))) ∧ + (∀ z,A z=B z * (C z)ᵀ) := by + classical + choose B C hB hC hA using fun z => rank_product (A z) + let G (z : Place p) := (C z)ᵀ + have ht z : Function.Injective (G z).mulVec := + transpose_surj_iff.mp (by unfold G; rw [Matrix.transpose_transpose]; exact hC _) + refine ⟨_,B,G,fun _ => rfl,fun z => ⟨hB z,(h z).1.mono_left ?_⟩, + fun z => ⟨ht z,(h z).2.mono_left ?_⟩, + fun z => by unfold G; rw [Matrix.transpose_transpose,hA]⟩ + · rintro x ⟨v,rfl⟩ + obtain ⟨w,rfl⟩ := hC z v + refine ⟨w,?_⟩ + rw [mulVecLin_apply,mulVecLin_apply,Matrix.mulVec_mulVec,hA] + · rintro x ⟨v,rfl⟩ + obtain ⟨w,rfl⟩ := (transpose_surj_iff.mpr (hB z)) v + refine ⟨w,?_⟩ + rw [mulVecLin_apply,mulVecLin_apply] + unfold G; rw [Matrix.mulVec_mulVec,← transpose_mul,hA] + +theorem gramCharacter (Q M : Cross p n) {u w : Wgt (UnitType p n N)} + (hu : IsLaw u) (hw : IsLaw w) {f b : Pin p n N} + (hc : f.clear 0.05 u) (hd : b.clear 0.05 w) + (h : ∀ x,u x≠0 → ∀ y,w y≠0 → rowAgree f.sp (actual p x y) Q ∧ + rowAgree b.sp (actual p y x) (reciprocal p Q)) : + let Y := avg (pairW u w) (fun x => + wsign (cpDual p M (actual p x.1 x.2-Q))) + Y=1 ∨ |Y| ≤ bp (-0.45*N) := by + classical + dsimp only + obtain ⟨P,hP,hX⟩ := free_pull p M f.sp b.sp + obtain ⟨r,B,C,hr,hB,hC,hY⟩ := factor_free f.sp b.sp hP + let s := pairW u w + have he : + avg s (fun x => wsign (cpDual p M (actual p x.1 x.2-Q))) = + avg s (fun x => wsign (cpDual p P (actual p x.1 x.2-Q))) := by + refine avg_congr fun ⟨x,y⟩ hxy => ?_ + rw [show cpDual p M (actual p x y-Q)=_ from hX _ _ _ _] + · exact (h x (left_ne_zero_of_mul hxy) y (right_ne_zero_of_mul hxy)).1 + rw [reciprocal_actual]; exact (h x (left_ne_zero_of_mul hxy) y (right_ne_zero_of_mul hxy)).2 + rw [he] + by_cases hh : 1≤∑ z,r z + · right + let g := projTuple p r B (Equiv.refl _) (N:=N) + let g' := projTuple p r C (flipEquiv p) (N:=N) + let X (x : UnitType p n N × UnitType p n N) := tupleB p r N (g x.1) (g' x.2) + have hi x : + wsign (cpDual p P (actual p x.1 x.2-Q))=wsign (X x) * wsign (cpDual p P Q) := by + simp only [ZModModule.sub_eq_add,map_add,wsign_add] + have hv : cpDual p P (actual p x.1 x.2)=X x := by + unfold X; rw [cpDual_val,tupleB_val] + refine Finset.sum_congr rfl fun z _ => ?_ + rw [hY,actual,pair_transfer]; rfl + rw [hv] + simp_rw [hi]; rw [avg_mul,abs_mul,wsign_abs,mul_one] + exact charImages p r B C hu hw hc hd hB hC hh + left + have hZ z : P z=0 := by + have hc : r z ≤ ∑ i,r i := Finset.single_le_sum (fun z _ => Nat.zero_le (r z)) + (Finset.mem_univ _) + rw [hY] + have hz : r z=0 := by omega + have : IsEmpty (Fin (r z)) := hz ▸ Fin.isEmpty' + ext i j; simp [Matrix.mul_apply] + have hk x : wsign (cpDual p P x)=1 := by + rw [cpDual_val] + have hf z : mpair (P z) (x z)=0 := by rw [hZ,mpair_comm,map_zero] + simp_rw [hf] + simp + simp_rw [hk]; exact (pairW_law hu hw).avg_const _ + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/GramConditionedLaws.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/GramConditionedLaws.lean index 1910ff9463ad55a8b00bb29cabd56a4042fb1696..17c2e35a0648a1a15fb7619fdf220cdff1031b90 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/GramConditionedLaws.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/GramConditionedLaws.lean @@ -1,185 +1,185 @@ -import OAI.Combinatorics.HadwigerCounterexample.ConditionedBatchLaws - -namespace OAI - -/-! # Gram Conditioned Laws -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Module LinearMap Submodule Function Finset -variable {I J G H : Type} [Fintype I] [Fintype J] [Fintype G] [Fintype H] -variable [DecidableEq I] [DecidableEq J] [DecidableEq G] -variable {g : Route (I×J) G} {N : ℕ} - -omit [Fintype G] in -private theorem wav_iff (Z : GeoM g) (x : Rack (I×J) N) : - gramPart Z x ↔ (traced x (crossroads g) (outsideZ Z) ∧ - (∀ i,gramPart (laneM Z i) (led i x))) := by - classical - constructor - · intro h - constructor - · funext i - exact congr_fun ((match_crowd x g Z).mpr h) (⟨i.val,Finset.sdiff_subset i.property⟩ : - ↑(crowded g)) - intro i; refine (part_scores ..).mpr fun q a b => ?_ - exact (part_scores ..).mp h q (condLane g i q a) (condLane g i q b) - rintro ⟨ht,hH⟩ - refine (part_scores ..).mpr ?_ - intro i a b - rcases a with ⟨⟨l,x'⟩,hl⟩ - rcases b with ⟨⟨t,y⟩,hr⟩ - subst i - let j := g (l,x') - by_cases hh : l=t - · subst t - let a : Port (street g l) j := ⟨x',rfl⟩ - let b : Port (street g l) j := ⟨y,hr⟩ - exact (part_scores ..).mp (hH l) j a b - let z : I×J := (l,x') - let v : I×J := (t,y) - have hv : (z,v)∈crossroads g := Finset.mem_sdiff.mpr - ⟨Finset.mem_filter.mpr ⟨mem_univ _,hr.symm⟩,fun h => hh (mem_filter.mp h).2⟩ - exact congr_fun ht (⟨(z,v),hv⟩ : ↑(crossroads g)) - -def partMean (p : H→Prop) (f : Wgt H) := - avg unif (fun x => ind (p x)*f x) -theorem part_reset [Nonempty H] (p : H→Prop) (f : Wgt H) (h : 0 simp only [h,ind_true,ind_false,one_mul, - zero_mul]; exact hf i x; norm_num - have hE i (h : i∈E) : i.1.1≠i.2.1 := fun he => - (mem_sdiff.mp h).2 (mem_filter.mpr ⟨(mem_sdiff.mp h).1,he⟩) - have ht := speed_expand F hF E (outsideZ Z) hE - have hP : avg unif (brightProd F)=∏ i, partMean (gramPart (laneM Z i)) (f i) := - (led_uniform (prodW F)).trans (prodW_avg _ _) - let A x := ind (traced x E (outsideZ Z))*brightProd F x - have hi x : - ind (gramPart Z x) * brightProd f x= A x := by - rw [wav_iff]; unfold A F E - simp only [ind_and, ind_all,brightProd,Finset.prod_mul_distrib] - ring - rw [hP] at ht - change |avg unif _-_ *∏ i,partMean _ _|≤_ - simp_rw [hi] - exact ht - -omit [DecidableEq I] in -theorem wave_lane_norm (Z : GeoM g) (hN : ∀ i, 2*num (Port g i)-(N:ℝ)≤ -1) - (i : I) : 0 ((both_test ..).mp hx).1) - -theorem lane_collapse (A P u V e C : ℝ) - (h0 : 0 abs_nonneg _) - (fun i _ => (abs_avg_le (he i).nz).trans ((he i).avg_le zero_le_one (hf i)))).trans_eq ?_ - simp - have hh := wave_norm Z N hN - have h0 : 0 (1:ℝ) - have ht := wav_means Z F (by intro i x; simp [F]) - have he (i : I) : - partMean (gramPart (laneM Z i)) (F i)=B i := by simp only [F,partMean,mul_one]; rfl - have hx : - partMean (gramPart (N:=N) Z) (brightProd F)=A := by - simp only [F,brightProd,partMean,Finset.prod_const_one,mul_one,A,pr] - simp_rw [he,hx] at ht; exact ht - exact lane_collapse A P u V e _ netFact_pos hh hV h1 h2 - -set_option maxHeartbeats 500000 in -theorem compare_station {g : Route J G} (Z : GeoM g) (f : Wgt (Rack J N)) - (hf : ∀ x,|f x|≤1) (k : ℝ) (hk : ∀ i,num (Port g i)≤ k) - (hN : 2*k-(N:ℝ)≤ -1) : - |avg (rackStation Z N) f- avg (rackWave Z N) f| ≤ - 2 * netFact g * (num G*(2*bp (k-N))) := by - classical - have hh i : 2*num (Port g i)-(N:ℝ)≤ -1 := by linarith only [hk i,hN] - let A := pr unif (bothPart Z (N:=N)) - let B := pr unif (gramPart Z (N:=N)) - let Q := avg (rackWave Z N) f - let W := avg (rackStation Z N) f - let e := num G*(2*bp (k-N)) - have he (f : Wgt (Rack J N)) (hf : ∀ x,|f x|≤1) : - |partMean (bothPart Z) f-partMean (gramPart Z) f|≤ e := by - unfold partMean - rw [←avg_sub] - have hi (x : Rack J N) : - |ind (bothPart Z x)*f x-ind (gramPart Z x)*f x| ≤ ind (¬injPart g x) := by - rw [both_test] - by_cases h : injPart g x - · simp only [h,and_true,not_true,ind_false,sub_self,abs_zero,le_refl] - by_cases h' : gramPart Z x - · simpa [h,h',ind] using hf x - simp [h,h',ind] - exact (abs_avg_le unif_law.nz).trans - ((avg_mono unif_law.nz hi).trans (injPart_failure g N k hk)) - have hx := (net_norm Z N hh).1 - have hA : 0 1) (by intro i; norm_num) - simp only [partMean,mul_one] at ht - exact ht - have h := unifOn_sub (gramPart Z (N:=N)) - exact lane_collapse A B W Q e _ netFact_pos hx - ((abs_avg_le h.nz).trans (h.avg_le zero_le_one hf)) h1 h2 -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ConditionedBatchLaws + +namespace OAI + +/-! # Gram Conditioned Laws -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Module LinearMap Submodule Function Finset +variable {I J G H : Type} [Fintype I] [Fintype J] [Fintype G] [Fintype H] +variable [DecidableEq I] [DecidableEq J] [DecidableEq G] +variable {g : Route (I×J) G} {N : ℕ} + +omit [Fintype G] in +private theorem wav_iff (Z : GeoM g) (x : Rack (I×J) N) : + gramPart Z x ↔ (traced x (crossroads g) (outsideZ Z) ∧ + (∀ i,gramPart (laneM Z i) (led i x))) := by + classical + constructor + · intro h + constructor + · funext i + exact congr_fun ((match_crowd x g Z).mpr h) (⟨i.val,Finset.sdiff_subset i.property⟩ : + ↑(crowded g)) + intro i; refine (part_scores ..).mpr fun q a b => ?_ + exact (part_scores ..).mp h q (condLane g i q a) (condLane g i q b) + rintro ⟨ht,hH⟩ + refine (part_scores ..).mpr ?_ + intro i a b + rcases a with ⟨⟨l,x'⟩,hl⟩ + rcases b with ⟨⟨t,y⟩,hr⟩ + subst i + let j := g (l,x') + by_cases hh : l=t + · subst t + let a : Port (street g l) j := ⟨x',rfl⟩ + let b : Port (street g l) j := ⟨y,hr⟩ + exact (part_scores ..).mp (hH l) j a b + let z : I×J := (l,x') + let v : I×J := (t,y) + have hv : (z,v)∈crossroads g := Finset.mem_sdiff.mpr + ⟨Finset.mem_filter.mpr ⟨mem_univ _,hr.symm⟩,fun h => hh (mem_filter.mp h).2⟩ + exact congr_fun ht (⟨(z,v),hv⟩ : ↑(crossroads g)) + +def partMean (p : H→Prop) (f : Wgt H) := + avg unif (fun x => ind (p x)*f x) +theorem part_reset [Nonempty H] (p : H→Prop) (f : Wgt H) (h : 0 simp only [h,ind_true,ind_false,one_mul, + zero_mul]; exact hf i x; norm_num + have hE i (h : i∈E) : i.1.1≠i.2.1 := fun he => + (mem_sdiff.mp h).2 (mem_filter.mpr ⟨(mem_sdiff.mp h).1,he⟩) + have ht := speed_expand F hF E (outsideZ Z) hE + have hP : avg unif (brightProd F)=∏ i, partMean (gramPart (laneM Z i)) (f i) := + (led_uniform (prodW F)).trans (prodW_avg _ _) + let A x := ind (traced x E (outsideZ Z))*brightProd F x + have hi x : + ind (gramPart Z x) * brightProd f x= A x := by + rw [wav_iff]; unfold A F E + simp only [ind_and, ind_all,brightProd,Finset.prod_mul_distrib] + ring + rw [hP] at ht + change |avg unif _-_ *∏ i,partMean _ _|≤_ + simp_rw [hi] + exact ht + +omit [DecidableEq I] in +theorem wave_lane_norm (Z : GeoM g) (hN : ∀ i, 2*num (Port g i)-(N:ℝ)≤ -1) + (i : I) : 0 ((both_test ..).mp hx).1) + +theorem lane_collapse (A P u V e C : ℝ) + (h0 : 0 abs_nonneg _) + (fun i _ => (abs_avg_le (he i).nz).trans ((he i).avg_le zero_le_one (hf i)))).trans_eq ?_ + simp + have hh := wave_norm Z N hN + have h0 : 0 (1:ℝ) + have ht := wav_means Z F (by intro i x; simp [F]) + have he (i : I) : + partMean (gramPart (laneM Z i)) (F i)=B i := by simp only [F,partMean,mul_one]; rfl + have hx : + partMean (gramPart (N:=N) Z) (brightProd F)=A := by + simp only [F,brightProd,partMean,Finset.prod_const_one,mul_one,A,pr] + simp_rw [he,hx] at ht; exact ht + exact lane_collapse A P u V e _ netFact_pos hh hV h1 h2 + +set_option maxHeartbeats 500000 in +theorem compare_station {g : Route J G} (Z : GeoM g) (f : Wgt (Rack J N)) + (hf : ∀ x,|f x|≤1) (k : ℝ) (hk : ∀ i,num (Port g i)≤ k) + (hN : 2*k-(N:ℝ)≤ -1) : + |avg (rackStation Z N) f- avg (rackWave Z N) f| ≤ + 2 * netFact g * (num G*(2*bp (k-N))) := by + classical + have hh i : 2*num (Port g i)-(N:ℝ)≤ -1 := by linarith only [hk i,hN] + let A := pr unif (bothPart Z (N:=N)) + let B := pr unif (gramPart Z (N:=N)) + let Q := avg (rackWave Z N) f + let W := avg (rackStation Z N) f + let e := num G*(2*bp (k-N)) + have he (f : Wgt (Rack J N)) (hf : ∀ x,|f x|≤1) : + |partMean (bothPart Z) f-partMean (gramPart Z) f|≤ e := by + unfold partMean + rw [←avg_sub] + have hi (x : Rack J N) : + |ind (bothPart Z x)*f x-ind (gramPart Z x)*f x| ≤ ind (¬injPart g x) := by + rw [both_test] + by_cases h : injPart g x + · simp only [h,and_true,not_true,ind_false,sub_self,abs_zero,le_refl] + by_cases h' : gramPart Z x + · simpa [h,h',ind] using hf x + simp [h,h',ind] + exact (abs_avg_le unif_law.nz).trans + ((avg_mono unif_law.nz hi).trans (injPart_failure g N k hk)) + have hx := (net_norm Z N hh).1 + have hA : 0 1) (by intro i; norm_num) + simp only [partMean,mul_one] at ht + exact ht + have h := unifOn_sub (gramPart Z (N:=N)) + exact lane_collapse A B W Q e _ netFact_pos hx + ((abs_avg_le h.nz).trans (h.avg_le zero_le_one hf)) h1 h2 +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/GramProbabilities.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/GramProbabilities.lean index 365ddb81923de21810a495b389df6a82a030b5e3..3645c1ba966aa7fde7ce5a11b16de7fb1cc5b2e2 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/GramProbabilities.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/GramProbabilities.lean @@ -1,180 +1,180 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteAffineLaws - -namespace OAI - -/-! # Gram Probabilities -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Function LinearMap - -abbrev num (I : Type) [Fintype I] : ℝ := (Fintype.card I:ℝ) - -variable {I J U : Type} [Fintype I] [Fintype J] [Fintype U] - -def columnInv {w : Wgt (Mat U I)} (T : Space (Vec U)) := - ∀ M A : Mat U I, colSp A ≤ T → w (M+A) = w M - -omit [Fintype U] in -theorem outer_act (x : Vec U) (v z : Vec I) : - vecMulVec x v *ᵥ z = dotProduct v z • x := by rw [vecMulVec_mulVec,op_smul_eq_smul] - -omit [Fintype U] in -theorem colSp_outer {x : Vec U} {T : Space (Vec U)} (h : x ∈ T) (v : Vec I) : - colSp (vecMulVec x v) ≤ T := by - rintro y ⟨z,rfl⟩ - rw [mulVecLin_apply,outer_act] - exact T.smul_mem _ h - -variable [DecidableEq U] [DecidableEq I] [DecidableEq J] - -theorem shift_pmax {w : Wgt (Mat U I)} (hw : SubLaw w) (T : Space (Vec U)) - (h : columnInv (w:=w) T) {x : Vec I} (hx : x ≠ 0) (y : Vec U) : - pr w (fun M => M *ᵥ x = y) ≤ bp (-(dim T:ℝ)) := by - classical - have hh : ∃ v : Vec I, dotProduct v x = 1 := by - simp only [ne_eq,funext_iff,Pi.zero_apply, not_forall] at hx - obtain ⟨i,hi⟩ := hx - exact ⟨Pi.single i 1,(single_one_dotProduct _ _).trans ((bit_cases _).resolve_left hi)⟩ - obtain ⟨v,hv⟩ := hh - let f : Mat U I →ₗ[F] Vec U := (Matrix.mulVecBilin F F).flip x - let g : T ↪ Vec U := ⟨Subtype.val,Subtype.val_injective⟩ - have he : ∀ (t:T), ∃ A : Mat U I, f A = g t ∧ ∀ B, w (B+A)=w B := fun t => - ⟨vecMulVec t.val v,by change vecMulVec t.val v *ᵥ x = t.val; rw [outer_act,hv,one_smul], - fun B => h B _ (colSp_outer t.property _)⟩ - have h' := translate_cap hw f g he y - rw [bp_neg,← card_space] - exact h' - -theorem shift_fail {w : Wgt (Mat U I)} (hw : SubLaw w) (T : Space (Vec U)) - (h : columnInv (w:=w) T) : - pr w (fun M => ¬ Injective M.mulVec) ≤ bp (num I - dim T) := by - classical - let p (x : Vec I) (M : Mat U I) := x ≠ 0 ∧ M *ᵥ x = 0 - have e1 : pr w (fun M => ¬ Injective M.mulVec) ≤ ∑ i : Vec I, pr w (p i) := by - refine le_trans (pr_mono hw.nz (fun M hm => ?_)) (pr_exists_le hw.nz p) - rw [← coe_mulVecLin,← ker_eq_bot,ker_mulVecLin_eq_bot_iff] at hm - push Not at hm - obtain ⟨x,h1,h2⟩ := hm - exact ⟨x,h2,h1⟩ - have he (i : Vec I) : pr w (p i) ≤ bp (-(dim T:ℝ)) := by - by_cases hi : i = 0 - · simp only [p,hi,ne_eq,not_true,false_and,pr_false] - exact (bp_pos _).le - · simpa only [p,hi,true_and, ne_eq, not_false_eq_true] using shift_pmax hw T h hi 0 - refine e1.trans ((Finset.sum_le_sum (fun i _ => he i)).trans_eq ?_) - simp only [Finset.sum_const, Finset.card_univ,nsmul_eq_mul,card_space, - dim_vec,sub_eq_add_neg,bp_add,num] - -theorem unif_fail : - pr (unif : Wgt (Mat U I)) (fun M => ¬ Injective M.mulVec) ≤ bp (num I - num U) := by - have h := shift_fail (@unif_subLaw (Mat U I) _) ⊤ (fun _ _ _ => rfl) - unfold dim at h - rw [finrank_top,show Module.finrank F (Vec U) = Fintype.card U from dim_vec _] at h - exact h - -def gramGood (G : Mat I J) (q : Mat U I × Mat U J) := - q.1ᵀ*q.2 = G ∧ Injective q.1.mulVec ∧ Injective q.2.mulVec - -def GramL (J : Type) (P : Mat U I) : Mat U J →ₗ[F] Mat I J where - toFun M := Pᵀ * M - map_add' _ _ := Matrix.mul_add _ _ _ - map_smul' _ _ := Matrix.mul_smul _ _ _ - -omit [DecidableEq U] in -theorem gramL_surj (J : Type) {P : Mat U I} (h : Injective P.mulVec) : - Surjective (GramL J P) := by - obtain ⟨Q,hQ⟩ := mat_left_inv h - intro x - exact ⟨Qᵀ * x,by change Pᵀ * (Qᵀ * x) = x; rw [← Matrix.mul_assoc,← transpose_mul, - hQ,Matrix.transpose_one, Matrix.one_mul]⟩ - -theorem pr_gram_fixed {P : Mat U I} (h : Injective P.mulVec) (G : Mat I J) : - pr unif (fun Q : Mat U J => Pᵀ * Q = G) = bp (-num I * num J) := by - have hh := gramL_surj J h - have hf := pr_unif_lin (GramL J P) G - rw [ind_one (show G ∈ range _ from hh G),one_mul,rk_surj.mp hh,dim_mat] at hf - change pr unif _ = _ - exact hf.trans (congrArg bp (by push_cast; unfold num; ring)) - -omit [Fintype I] [DecidableEq I] in -/-- Conditional minus columns: adding columns in the annihilator of P -doesn't change the pre-injectivity Gram law. -/ -theorem gram_shift (P : Mat U I) (G : Mat I J) : - columnInv (w:=unifOn (fun Q : Mat U J => Pᵀ * Q = G)) (ker (Pᵀ.mulVecLin)) := by - intro M A hA - have h : Pᵀ * A = 0 := by - apply coe_mv_inj - change (Pᵀ * A).mulVecLin = (0:Mat I J).mulVecLin - rw [mulVecLin_mul,mulVecLin_zero] - exact LinearMap.ext fun x => hA (show A.mulVecLin x ∈ colSp A from ⟨x,rfl⟩) - rw [unifOn_val, Matrix.mul_add,h,add_zero,unifOn_val] - -theorem pr_gram_inj_fixed {P : Mat U I} (h : Injective P.mulVec) (G : Mat I J) : - bp (-num I * num J) * (1 - bp (num I + num J - num U)) ≤ - pr unif (fun Q : Mat U J => Pᵀ * Q = G ∧ Injective Q.mulVec) := by - let q (Q : Mat U J) := Pᵀ*Q = G - let f := unifOn q - have hf := unifOn_law (show ∃ Q : Mat U J, q Q from gramL_surj J h G) - let T := ker (Pᵀ.mulVecLin) - have hh := shift_fail hf.sub T (gram_shift _ _) - have he : num U = num I + dim T := by - have hj := Pᵀ.mulVecLin.finrank_range_add_finrank_ker - change rk (Pᵀ.mulVecLin)+dim T = dim (Vec U) at hj - have h' : Surjective Pᵀ.mulVecLin := transpose_surj_iff.mpr h - rw [rk_surj.mp h',dim_vec,dim_vec] at hj - exact_mod_cast hj.symm - have hi (p : Mat U J → Prop) : pr f (fun x => ¬p x) = 1-pr f p := by - rw [pr_not,hf.total] - change bp _ * (1-_) ≤ pr unif (fun x => q x ∧ Injective x.mulVec) - rw [pr_of_on unif_subLaw.nz q, on_unif, show pr unif q = _ from pr_gram_fixed h G] - apply mul_le_mul_of_nonneg_left _ (bp_pos _).le - change pr f _ ≤ _ at hh - rw [hi (fun x => Injective x.mulVec)] at hh - rw [show num I+num J-num U = num J - dim T by rw [he]; ring] - linarith only [hh] - -/-- Uniform lower and upper estimates including the full Gram normalization. -/ -theorem gram_norm (G : Mat I J) (hsize : num I + num J ≤ num U) : - let v := (pairW unif unif : Wgt (Mat U I × Mat U J)) - let p := bp (- num I * num J) - pr v (gramGood G) ≤ p ∧ - p * (1-bp (num I-num U)) * (1-bp (num I+num J-num U)) ≤ - pr v (gramGood G) := by - let f (P : Mat U I) := pr unif (fun Q : Mat U J => gramGood G (P,Q)) - let a := bp (-num I*num J) - let b := bp (num I+num J-num U) - dsimp only - rw [pr,pairW_avg] - change avg unif f ≤ a ∧ _ ≤ avg unif f - have h (P : Mat U I) : - f P ≤ a ∧ a*(1-b) * ind (Injective P.mulVec) ≤ f P := by - by_cases hp : Injective P.mulVec - · have e : f P = pr unif (fun Q : Mat U J => Pᵀ * Q = G ∧ Injective Q.mulVec) := by - simp [f,gramGood,hp] - rw [e,ind_one hp,mul_one] - exact ⟨(pr_mono unif_subLaw.nz fun _ => And.left).trans_eq (pr_gram_fixed hp G), - pr_gram_inj_fixed hp _⟩ - · have e : f P = 0 := by simp [f,gramGood,hp] - rw [e,ind_zero hp,mul_zero] - exact ⟨(bp_pos _).le,le_rfl⟩ - refine ⟨unif_law.avg_le (fun i => (h i).1),?_⟩ - apply le_trans _ (avg_mono unif_subLaw.nz fun i => (h i).2) - rw [avg_mul'] - have hi := @unif_fail I U _ _ _ _ - rw [pr_not,unif_law.total] at hi - have ha : 0 ≤ a*(1-b) := by - refine mul_nonneg (bp_pos _).le (sub_nonneg.mpr ?_) - simpa [b] using bp_le (show num I+num J-num U ≤ 0 by linarith) - have hh : 1 - bp (num I-num U) ≤ pr unif (fun M : Mat U I => Injective M.mulVec) := by - linarith only [hi] - exact (by - change a * (1 - bp _) * (1-b) ≤ a * (1-b) * pr _ _ - rw [mul_right_comm]; exact mul_le_mul_of_nonneg_left hh ha) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteAffineLaws + +namespace OAI + +/-! # Gram Probabilities -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Function LinearMap + +abbrev num (I : Type) [Fintype I] : ℝ := (Fintype.card I:ℝ) + +variable {I J U : Type} [Fintype I] [Fintype J] [Fintype U] + +def columnInv {w : Wgt (Mat U I)} (T : Space (Vec U)) := + ∀ M A : Mat U I, colSp A ≤ T → w (M+A) = w M + +omit [Fintype U] in +theorem outer_act (x : Vec U) (v z : Vec I) : + vecMulVec x v *ᵥ z = dotProduct v z • x := by rw [vecMulVec_mulVec,op_smul_eq_smul] + +omit [Fintype U] in +theorem colSp_outer {x : Vec U} {T : Space (Vec U)} (h : x ∈ T) (v : Vec I) : + colSp (vecMulVec x v) ≤ T := by + rintro y ⟨z,rfl⟩ + rw [mulVecLin_apply,outer_act] + exact T.smul_mem _ h + +variable [DecidableEq U] [DecidableEq I] [DecidableEq J] + +theorem shift_pmax {w : Wgt (Mat U I)} (hw : SubLaw w) (T : Space (Vec U)) + (h : columnInv (w:=w) T) {x : Vec I} (hx : x ≠ 0) (y : Vec U) : + pr w (fun M => M *ᵥ x = y) ≤ bp (-(dim T:ℝ)) := by + classical + have hh : ∃ v : Vec I, dotProduct v x = 1 := by + simp only [ne_eq,funext_iff,Pi.zero_apply, not_forall] at hx + obtain ⟨i,hi⟩ := hx + exact ⟨Pi.single i 1,(single_one_dotProduct _ _).trans ((bit_cases _).resolve_left hi)⟩ + obtain ⟨v,hv⟩ := hh + let f : Mat U I →ₗ[F] Vec U := (Matrix.mulVecBilin F F).flip x + let g : T ↪ Vec U := ⟨Subtype.val,Subtype.val_injective⟩ + have he : ∀ (t:T), ∃ A : Mat U I, f A = g t ∧ ∀ B, w (B+A)=w B := fun t => + ⟨vecMulVec t.val v,by change vecMulVec t.val v *ᵥ x = t.val; rw [outer_act,hv,one_smul], + fun B => h B _ (colSp_outer t.property _)⟩ + have h' := translate_cap hw f g he y + rw [bp_neg,← card_space] + exact h' + +theorem shift_fail {w : Wgt (Mat U I)} (hw : SubLaw w) (T : Space (Vec U)) + (h : columnInv (w:=w) T) : + pr w (fun M => ¬ Injective M.mulVec) ≤ bp (num I - dim T) := by + classical + let p (x : Vec I) (M : Mat U I) := x ≠ 0 ∧ M *ᵥ x = 0 + have e1 : pr w (fun M => ¬ Injective M.mulVec) ≤ ∑ i : Vec I, pr w (p i) := by + refine le_trans (pr_mono hw.nz (fun M hm => ?_)) (pr_exists_le hw.nz p) + rw [← coe_mulVecLin,← ker_eq_bot,ker_mulVecLin_eq_bot_iff] at hm + push Not at hm + obtain ⟨x,h1,h2⟩ := hm + exact ⟨x,h2,h1⟩ + have he (i : Vec I) : pr w (p i) ≤ bp (-(dim T:ℝ)) := by + by_cases hi : i = 0 + · simp only [p,hi,ne_eq,not_true,false_and,pr_false] + exact (bp_pos _).le + · simpa only [p,hi,true_and, ne_eq, not_false_eq_true] using shift_pmax hw T h hi 0 + refine e1.trans ((Finset.sum_le_sum (fun i _ => he i)).trans_eq ?_) + simp only [Finset.sum_const, Finset.card_univ,nsmul_eq_mul,card_space, + dim_vec,sub_eq_add_neg,bp_add,num] + +theorem unif_fail : + pr (unif : Wgt (Mat U I)) (fun M => ¬ Injective M.mulVec) ≤ bp (num I - num U) := by + have h := shift_fail (@unif_subLaw (Mat U I) _) ⊤ (fun _ _ _ => rfl) + unfold dim at h + rw [finrank_top,show Module.finrank F (Vec U) = Fintype.card U from dim_vec _] at h + exact h + +def gramGood (G : Mat I J) (q : Mat U I × Mat U J) := + q.1ᵀ*q.2 = G ∧ Injective q.1.mulVec ∧ Injective q.2.mulVec + +def GramL (J : Type) (P : Mat U I) : Mat U J →ₗ[F] Mat I J where + toFun M := Pᵀ * M + map_add' _ _ := Matrix.mul_add _ _ _ + map_smul' _ _ := Matrix.mul_smul _ _ _ + +omit [DecidableEq U] in +theorem gramL_surj (J : Type) {P : Mat U I} (h : Injective P.mulVec) : + Surjective (GramL J P) := by + obtain ⟨Q,hQ⟩ := mat_left_inv h + intro x + exact ⟨Qᵀ * x,by change Pᵀ * (Qᵀ * x) = x; rw [← Matrix.mul_assoc,← transpose_mul, + hQ,Matrix.transpose_one, Matrix.one_mul]⟩ + +theorem pr_gram_fixed {P : Mat U I} (h : Injective P.mulVec) (G : Mat I J) : + pr unif (fun Q : Mat U J => Pᵀ * Q = G) = bp (-num I * num J) := by + have hh := gramL_surj J h + have hf := pr_unif_lin (GramL J P) G + rw [ind_one (show G ∈ range _ from hh G),one_mul,rk_surj.mp hh,dim_mat] at hf + change pr unif _ = _ + exact hf.trans (congrArg bp (by push_cast; unfold num; ring)) + +omit [Fintype I] [DecidableEq I] in +/-- Conditional minus columns: adding columns in the annihilator of P +doesn't change the pre-injectivity Gram law. -/ +theorem gram_shift (P : Mat U I) (G : Mat I J) : + columnInv (w:=unifOn (fun Q : Mat U J => Pᵀ * Q = G)) (ker (Pᵀ.mulVecLin)) := by + intro M A hA + have h : Pᵀ * A = 0 := by + apply coe_mv_inj + change (Pᵀ * A).mulVecLin = (0:Mat I J).mulVecLin + rw [mulVecLin_mul,mulVecLin_zero] + exact LinearMap.ext fun x => hA (show A.mulVecLin x ∈ colSp A from ⟨x,rfl⟩) + rw [unifOn_val, Matrix.mul_add,h,add_zero,unifOn_val] + +theorem pr_gram_inj_fixed {P : Mat U I} (h : Injective P.mulVec) (G : Mat I J) : + bp (-num I * num J) * (1 - bp (num I + num J - num U)) ≤ + pr unif (fun Q : Mat U J => Pᵀ * Q = G ∧ Injective Q.mulVec) := by + let q (Q : Mat U J) := Pᵀ*Q = G + let f := unifOn q + have hf := unifOn_law (show ∃ Q : Mat U J, q Q from gramL_surj J h G) + let T := ker (Pᵀ.mulVecLin) + have hh := shift_fail hf.sub T (gram_shift _ _) + have he : num U = num I + dim T := by + have hj := Pᵀ.mulVecLin.finrank_range_add_finrank_ker + change rk (Pᵀ.mulVecLin)+dim T = dim (Vec U) at hj + have h' : Surjective Pᵀ.mulVecLin := transpose_surj_iff.mpr h + rw [rk_surj.mp h',dim_vec,dim_vec] at hj + exact_mod_cast hj.symm + have hi (p : Mat U J → Prop) : pr f (fun x => ¬p x) = 1-pr f p := by + rw [pr_not,hf.total] + change bp _ * (1-_) ≤ pr unif (fun x => q x ∧ Injective x.mulVec) + rw [pr_of_on unif_subLaw.nz q, on_unif, show pr unif q = _ from pr_gram_fixed h G] + apply mul_le_mul_of_nonneg_left _ (bp_pos _).le + change pr f _ ≤ _ at hh + rw [hi (fun x => Injective x.mulVec)] at hh + rw [show num I+num J-num U = num J - dim T by rw [he]; ring] + linarith only [hh] + +/-- Uniform lower and upper estimates including the full Gram normalization. -/ +theorem gram_norm (G : Mat I J) (hsize : num I + num J ≤ num U) : + let v := (pairW unif unif : Wgt (Mat U I × Mat U J)) + let p := bp (- num I * num J) + pr v (gramGood G) ≤ p ∧ + p * (1-bp (num I-num U)) * (1-bp (num I+num J-num U)) ≤ + pr v (gramGood G) := by + let f (P : Mat U I) := pr unif (fun Q : Mat U J => gramGood G (P,Q)) + let a := bp (-num I*num J) + let b := bp (num I+num J-num U) + dsimp only + rw [pr,pairW_avg] + change avg unif f ≤ a ∧ _ ≤ avg unif f + have h (P : Mat U I) : + f P ≤ a ∧ a*(1-b) * ind (Injective P.mulVec) ≤ f P := by + by_cases hp : Injective P.mulVec + · have e : f P = pr unif (fun Q : Mat U J => Pᵀ * Q = G ∧ Injective Q.mulVec) := by + simp [f,gramGood,hp] + rw [e,ind_one hp,mul_one] + exact ⟨(pr_mono unif_subLaw.nz fun _ => And.left).trans_eq (pr_gram_fixed hp G), + pr_gram_inj_fixed hp _⟩ + · have e : f P = 0 := by simp [f,gramGood,hp] + rw [e,ind_zero hp,mul_zero] + exact ⟨(bp_pos _).le,le_rfl⟩ + refine ⟨unif_law.avg_le (fun i => (h i).1),?_⟩ + apply le_trans _ (avg_mono unif_subLaw.nz fun i => (h i).2) + rw [avg_mul'] + have hi := @unif_fail I U _ _ _ _ + rw [pr_not,unif_law.total] at hi + have ha : 0 ≤ a*(1-b) := by + refine mul_nonneg (bp_pos _).le (sub_nonneg.mpr ?_) + simpa [b] using bp_le (show num I+num J-num U ≤ 0 by linarith) + have hh : 1 - bp (num I-num U) ≤ pr unif (fun M : Mat U I => Injective M.mulVec) := by + linarith only [hi] + exact (by + change a * (1 - bp _) * (1-b) ≤ a * (1-b) * pr _ _ + rw [mul_right_comm]; exact mul_le_mul_of_nonneg_left hh ha) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/GreedyExposures.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/GreedyExposures.lean index c23463acd211fa137445a1b0de93cd31859659e6..78644d7791cb8024d2d565dead481d89d1c00f7c 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/GreedyExposures.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/GreedyExposures.lean @@ -1,185 +1,185 @@ -import OAI.Combinatorics.HadwigerCounterexample.SpanDeficits - -namespace OAI - -/-! # Greedy Exposures -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Submodule Module Finset -open scoped BigOperators -variable {p : Shape} {N : ℕ} {I : Type} [DecidableEq I] - -def price (f : I → Ambient p N) (S : Cov p N) (W : Finset I) := - W.sup (fun i => tax p S (matter p (f i))) - -private theorem tax_comp (a b c : Cov p N) : - tax p a (b⊔c)=tax p a b + tax p (a⊔b) c := by - have h1 := tax_before (p:=p) a (b⊔c) - have h2 := tax_before (p:=p) a b - have h3 := tax_before (p:=p) (a⊔b) c - rw [sup_assoc] at h3 - omega - -omit [DecidableEq I] in -private theorem price_drop (f : I → Ambient p N) (S T : Cov p N) (W R : Finset I) - (h : S ≤ T) (g : R⊆ W) : - price f T R ≤ price f S W := by - refine Finset.sup_le fun i hi => (tax_antitone p S T (matter p (f i)) h).trans ?_ - exact (@Finset.le_sup _ _ _ _ W (fun i => tax p S (matter p (f i))) i (g hi)) - -private theorem union_arrange (f : I→Ambient p N) (W R : Finset I) : - arrange p f (W∪R)= arrange p f W⊔arrange p f R := Finset.sup_union - -private theorem grow (p : Shape) {N} (f : I→Ambient p N) (S : Cov p N) (W : Finset I) - (r : ℕ) (h : r≤W.card) : - ∃ E R : Finset I, W=E∪R ∧ Disjoint E R ∧ E.card=r ∧ - r*price f (S⊔ arrange p f E) R ≤ tax p S (arrange p f E) := by - classical - induction r generalizing W S with - | zero => exact ⟨∅,W,by simp⟩ - | succ r ih => - obtain ⟨x,hx,hP⟩ := Finset.exists_mem_eq_sup W - (Finset.card_pos.mp (show 0 tax p S (matter p (f i))) - let U := W.erase x - let X := matter p (f x) - have hU : U.card+1=W.card := Finset.card_erase_add_one hx - obtain ⟨E,R,hE,hd,hT,hK⟩ := ih (S⊔X) U (by omega) - have hx' : x∉E := fun H => Finset.notMem_erase _ _ (hE.symm ▸ Finset.mem_union_left R H) - have hx'' : x∉R := fun H => Finset.notMem_erase _ _ (hE.symm ▸ Finset.mem_union_right E H) - refine ⟨insert x E,R,?_,?_,?_,?_⟩ - · rw [Finset.insert_union,← hE,Finset.insert_erase hx] - · rw [Finset.disjoint_insert_left] - exact ⟨hx'',hd⟩ - · rw [Finset.card_insert_of_notMem hx',hT] - · have hg : arrange p f (insert x E)=X⊔arrange p f E := Finset.sup_insert - rw [hg,tax_comp (p:=p),←sup_assoc,Nat.add_mul,Nat.one_mul] - have hi := price_drop f S (S⊔X⊔arrange p f E) W R - (le_trans le_sup_left le_sup_left) - (Finset.Subset.trans (show R⊆U from hE.symm ▸ Finset.subset_union_right) - (Finset.erase_subset ..)) - have h1 : price f S W=tax p S X := hP - rw [h1] at hi - refine (Nat.add_le_add hK hi).trans_eq (Nat.add_comm ..) - -/-- Dyadic selection if potential is strictly too low to sustain -all bad tail deficit ratios -/ -private theorem greedy_expose (f : I→Ambient p N) (S : Cov p N) (W : Finset I) - (b m : ℕ) (hW : W.card=2^m*b) - (hg : 4*(W.card*price f S W+tax p S (arrange p f W)) < W.card*m) : - ∃ E R : Finset I, W=E∪R ∧ Disjoint E R ∧ b≤R.card ∧ - let s' := S⊔arrange p f E - 4*(R.card*price f s' R) ≤ 4*tax p s' (arrange p f R)+R.card := by - classical - induction m generalizing W S with - | zero => omega - | succ m ih => - by_cases he : 4*(W.card*price f S W)≤ 4*tax p S (arrange p f W)+W.card - · have h1 : b ≤ W.card := by rw [hW]; exact Nat.le_mul_of_pos_left b (by positivity) - exact ⟨∅,W,by simpa [arrange,h1] using he⟩ - let k := 2^m*b - have h1 : W.card=2*k := by rw [hW,pow_succ]; unfold k; ring - obtain ⟨E,R,hE,hD,hT,hB⟩ := grow p f S W k (by omega) - have hk : R.card=k := by rw [hE,Finset.card_union_of_disjoint hD] at h1; omega - let X := S⊔arrange p f E - have hX : - tax p S (arrange p f W)=tax p S (arrange p f E)+tax p X (arrange p f R) := by - rw [hE,union_arrange,tax_comp (p:=p)] - have hh : 4*(R.card*price f X R+ tax p X (arrange p f R)) - have h : cdSign p (N:=N) ⊥ i=0 := Finset.sum_eq_zero fun e _ => finrank_bot .. - rw [arrange,Finset.sup_empty,Finset.sum_empty,h] - | insert x W hx hi => - rw [show arrange p f (insert x W)=matter p (f x)⊔arrange p f W from Finset.sup_insert, - Finset.sum_insert hx] - calc cdSign p _ i ≤ cdSign p (matter p (f x)) i+cdSign p (arrange p f W) i := by - unfold cdSign - rw [← Finset.sum_add_distrib] - exact Finset.sum_le_sum fun i _ => - Submodule.finrank_add_le_finrank_add_finrank .. - _ ≤ _ := by rw [matter_dim]; exact add_le_add (le_refl _) hi - -theorem arrange_bound (f : I→Ambient p N) (W : Finset I) (k : ℕ) (h : ∀ i ∈ W,epoch p (f i) ≤ k) - (i : Bool) : - cdSign p (arrange p f W) i ≤ W.card*k := - (sum_charge_sign f W i).trans ((Finset.sum_le_sum fun j hj => h j hj).trans_eq (by simp)) - -theorem sparse_covered (f : I→ Ambient p N) (W : Finset I) - (m b r : ℕ) (hW : W.card=2^m*(2*b)) - (hb : 1 ≤ b) (hm : 16*r < m) (hf : ∀ i∈W,epoch p (f i) ≤ r) - (h : 2 * epoch p (∑ i∈W,f i) ≤ b) : - ∃ E T : Finset I,E⊆ W ∧ T⊆ W ∧ Disjoint E T ∧ T.card=b ∧ - ∀ i∈T,covered p (arrange p f E) (f i) := by - classical - have htax (C : Cov p N) : tax p ⊥ C = cdim p C := by rw [tax,cdim_bot,bot_sup_eq,Nat.sub_zero] - have hx : price f ⊥ W ≤ 2*r := by - refine Finset.sup_le fun i hi => ?_ - rw [htax,cdim_sign,matter_dim,matter_dim,two_mul] - exact add_le_add (hf i hi) (hf i hi) - have hh : - 4*(W.card*price f ⊥ W + tax p ⊥ (arrange p f W)) - covered_part (S:=S) (show matter p (f i) ≤ - E.sup (fun j => matter p (f j)) from (@Finset.le_sup _ _ _ _ _ (fun j => matter p (f j)) _ hi)) - have h1 : (∑ i∈R, erased p S (f i))=erased p S (∑ i∈W,f i) := by - rw [hE,Finset.sum_union hD,map_add,map_sum,map_sum,hh,zero_add] - rw [h1]; exact epoch_erased .. - have hu : J.card≤ ∑ i∈R,epoch p (erased p S (f i)) := by - calc J.card = ∑ i∈R, (if P i then (1:ℕ) else 0) := by rw [←Finset.sum_filter]; simp [J] - _ ≤ _ := Finset.sum_le_sum fun j _ => by - split - · rename_i hh - exact Nat.one_le_iff_ne_zero.mpr (fun h => hh ((epoch_eq_zero _).mp h)) - exact Nat.zero_le _ - have hp : (∑ i∈R,tax p S (matter p (f i))) ≤ R.card*price f S R := by - refine (Finset.sum_le_sum (g:=fun i => price f S R) fun i hi => ?_).trans_eq (by simp) - exact (@Finset.le_sup _ _ _ _ _ (fun i => tax p S (matter p (f i))) i hi) - have ht := (epoch_charge f S R).2 - have hb' : b≤ (R\ J).card := by - rw [Finset.card_sdiff_of_subset (Finset.filter_subset P _)] - change b ≤ R.card-J.card - have heq : J.card≤ R.card := Finset.card_le_card (Finset.filter_subset _ _) - change 4*(R.card*price f S R) ≤ 4*tax p S (arrange p f R)+R.card at hL - omega - obtain ⟨T,hT,hb'⟩ := Finset.exists_subset_card_eq hb' - have hz : T ⊆ R := hT.trans Finset.sdiff_subset - refine ⟨E,T,hE.symm ▸ Finset.subset_union_left,hE.symm ▸ hz.trans Finset.subset_union_right, - Disjoint.mono_right hz hD,hb',fun i hi => ?_⟩ - exact Classical.byContradiction fun h => - (Finset.mem_sdiff.mp (hT hi)).2 (Finset.mem_filter.mpr ⟨hz hi,h⟩) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SpanDeficits + +namespace OAI + +/-! # Greedy Exposures -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Submodule Module Finset +open scoped BigOperators +variable {p : Shape} {N : ℕ} {I : Type} [DecidableEq I] + +def price (f : I → Ambient p N) (S : Cov p N) (W : Finset I) := + W.sup (fun i => tax p S (matter p (f i))) + +private theorem tax_comp (a b c : Cov p N) : + tax p a (b⊔c)=tax p a b + tax p (a⊔b) c := by + have h1 := tax_before (p:=p) a (b⊔c) + have h2 := tax_before (p:=p) a b + have h3 := tax_before (p:=p) (a⊔b) c + rw [sup_assoc] at h3 + omega + +omit [DecidableEq I] in +private theorem price_drop (f : I → Ambient p N) (S T : Cov p N) (W R : Finset I) + (h : S ≤ T) (g : R⊆ W) : + price f T R ≤ price f S W := by + refine Finset.sup_le fun i hi => (tax_antitone p S T (matter p (f i)) h).trans ?_ + exact (@Finset.le_sup _ _ _ _ W (fun i => tax p S (matter p (f i))) i (g hi)) + +private theorem union_arrange (f : I→Ambient p N) (W R : Finset I) : + arrange p f (W∪R)= arrange p f W⊔arrange p f R := Finset.sup_union + +private theorem grow (p : Shape) {N} (f : I→Ambient p N) (S : Cov p N) (W : Finset I) + (r : ℕ) (h : r≤W.card) : + ∃ E R : Finset I, W=E∪R ∧ Disjoint E R ∧ E.card=r ∧ + r*price f (S⊔ arrange p f E) R ≤ tax p S (arrange p f E) := by + classical + induction r generalizing W S with + | zero => exact ⟨∅,W,by simp⟩ + | succ r ih => + obtain ⟨x,hx,hP⟩ := Finset.exists_mem_eq_sup W + (Finset.card_pos.mp (show 0 tax p S (matter p (f i))) + let U := W.erase x + let X := matter p (f x) + have hU : U.card+1=W.card := Finset.card_erase_add_one hx + obtain ⟨E,R,hE,hd,hT,hK⟩ := ih (S⊔X) U (by omega) + have hx' : x∉E := fun H => Finset.notMem_erase _ _ (hE.symm ▸ Finset.mem_union_left R H) + have hx'' : x∉R := fun H => Finset.notMem_erase _ _ (hE.symm ▸ Finset.mem_union_right E H) + refine ⟨insert x E,R,?_,?_,?_,?_⟩ + · rw [Finset.insert_union,← hE,Finset.insert_erase hx] + · rw [Finset.disjoint_insert_left] + exact ⟨hx'',hd⟩ + · rw [Finset.card_insert_of_notMem hx',hT] + · have hg : arrange p f (insert x E)=X⊔arrange p f E := Finset.sup_insert + rw [hg,tax_comp (p:=p),←sup_assoc,Nat.add_mul,Nat.one_mul] + have hi := price_drop f S (S⊔X⊔arrange p f E) W R + (le_trans le_sup_left le_sup_left) + (Finset.Subset.trans (show R⊆U from hE.symm ▸ Finset.subset_union_right) + (Finset.erase_subset ..)) + have h1 : price f S W=tax p S X := hP + rw [h1] at hi + refine (Nat.add_le_add hK hi).trans_eq (Nat.add_comm ..) + +/-- Dyadic selection if potential is strictly too low to sustain +all bad tail deficit ratios -/ +private theorem greedy_expose (f : I→Ambient p N) (S : Cov p N) (W : Finset I) + (b m : ℕ) (hW : W.card=2^m*b) + (hg : 4*(W.card*price f S W+tax p S (arrange p f W)) < W.card*m) : + ∃ E R : Finset I, W=E∪R ∧ Disjoint E R ∧ b≤R.card ∧ + let s' := S⊔arrange p f E + 4*(R.card*price f s' R) ≤ 4*tax p s' (arrange p f R)+R.card := by + classical + induction m generalizing W S with + | zero => omega + | succ m ih => + by_cases he : 4*(W.card*price f S W)≤ 4*tax p S (arrange p f W)+W.card + · have h1 : b ≤ W.card := by rw [hW]; exact Nat.le_mul_of_pos_left b (by positivity) + exact ⟨∅,W,by simpa [arrange,h1] using he⟩ + let k := 2^m*b + have h1 : W.card=2*k := by rw [hW,pow_succ]; unfold k; ring + obtain ⟨E,R,hE,hD,hT,hB⟩ := grow p f S W k (by omega) + have hk : R.card=k := by rw [hE,Finset.card_union_of_disjoint hD] at h1; omega + let X := S⊔arrange p f E + have hX : + tax p S (arrange p f W)=tax p S (arrange p f E)+tax p X (arrange p f R) := by + rw [hE,union_arrange,tax_comp (p:=p)] + have hh : 4*(R.card*price f X R+ tax p X (arrange p f R)) + have h : cdSign p (N:=N) ⊥ i=0 := Finset.sum_eq_zero fun e _ => finrank_bot .. + rw [arrange,Finset.sup_empty,Finset.sum_empty,h] + | insert x W hx hi => + rw [show arrange p f (insert x W)=matter p (f x)⊔arrange p f W from Finset.sup_insert, + Finset.sum_insert hx] + calc cdSign p _ i ≤ cdSign p (matter p (f x)) i+cdSign p (arrange p f W) i := by + unfold cdSign + rw [← Finset.sum_add_distrib] + exact Finset.sum_le_sum fun i _ => + Submodule.finrank_add_le_finrank_add_finrank .. + _ ≤ _ := by rw [matter_dim]; exact add_le_add (le_refl _) hi + +theorem arrange_bound (f : I→Ambient p N) (W : Finset I) (k : ℕ) (h : ∀ i ∈ W,epoch p (f i) ≤ k) + (i : Bool) : + cdSign p (arrange p f W) i ≤ W.card*k := + (sum_charge_sign f W i).trans ((Finset.sum_le_sum fun j hj => h j hj).trans_eq (by simp)) + +theorem sparse_covered (f : I→ Ambient p N) (W : Finset I) + (m b r : ℕ) (hW : W.card=2^m*(2*b)) + (hb : 1 ≤ b) (hm : 16*r < m) (hf : ∀ i∈W,epoch p (f i) ≤ r) + (h : 2 * epoch p (∑ i∈W,f i) ≤ b) : + ∃ E T : Finset I,E⊆ W ∧ T⊆ W ∧ Disjoint E T ∧ T.card=b ∧ + ∀ i∈T,covered p (arrange p f E) (f i) := by + classical + have htax (C : Cov p N) : tax p ⊥ C = cdim p C := by rw [tax,cdim_bot,bot_sup_eq,Nat.sub_zero] + have hx : price f ⊥ W ≤ 2*r := by + refine Finset.sup_le fun i hi => ?_ + rw [htax,cdim_sign,matter_dim,matter_dim,two_mul] + exact add_le_add (hf i hi) (hf i hi) + have hh : + 4*(W.card*price f ⊥ W + tax p ⊥ (arrange p f W)) + covered_part (S:=S) (show matter p (f i) ≤ + E.sup (fun j => matter p (f j)) from (@Finset.le_sup _ _ _ _ _ (fun j => matter p (f j)) _ hi)) + have h1 : (∑ i∈R, erased p S (f i))=erased p S (∑ i∈W,f i) := by + rw [hE,Finset.sum_union hD,map_add,map_sum,map_sum,hh,zero_add] + rw [h1]; exact epoch_erased .. + have hu : J.card≤ ∑ i∈R,epoch p (erased p S (f i)) := by + calc J.card = ∑ i∈R, (if P i then (1:ℕ) else 0) := by rw [←Finset.sum_filter]; simp [J] + _ ≤ _ := Finset.sum_le_sum fun j _ => by + split + · rename_i hh + exact Nat.one_le_iff_ne_zero.mpr (fun h => hh ((epoch_eq_zero _).mp h)) + exact Nat.zero_le _ + have hp : (∑ i∈R,tax p S (matter p (f i))) ≤ R.card*price f S R := by + refine (Finset.sum_le_sum (g:=fun i => price f S R) fun i hi => ?_).trans_eq (by simp) + exact (@Finset.le_sup _ _ _ _ _ (fun i => tax p S (matter p (f i))) i hi) + have ht := (epoch_charge f S R).2 + have hb' : b≤ (R\ J).card := by + rw [Finset.card_sdiff_of_subset (Finset.filter_subset P _)] + change b ≤ R.card-J.card + have heq : J.card≤ R.card := Finset.card_le_card (Finset.filter_subset _ _) + change 4*(R.card*price f S R) ≤ 4*tax p S (arrange p f R)+R.card at hL + omega + obtain ⟨T,hT,hb'⟩ := Finset.exists_subset_card_eq hb' + have hz : T ⊆ R := hT.trans Finset.sdiff_subset + refine ⟨E,T,hE.symm ▸ Finset.subset_union_left,hE.symm ▸ hz.trans Finset.subset_union_right, + Disjoint.mono_right hz hD,hb',fun i hi => ?_⟩ + exact Classical.byContradiction fun h => + (Finset.mem_sdiff.mp (hT hi)).2 (Finset.mem_filter.mpr ⟨hz hi,h⟩) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/GroupedQueryIndependence.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/GroupedQueryIndependence.lean index bf71c06e820bdc4b8bf1e333383273c8bc2c1202..f8f3b49e60f4aebe53538d9ffe3996c3412b912d 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/GroupedQueryIndependence.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/GroupedQueryIndependence.lean @@ -1,164 +1,164 @@ -import OAI.Combinatorics.HadwigerCounterexample.RepeatedBatchLaws - -namespace OAI - -/-! # Grouped Query Independence -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix LinearMap Module Submodule Function Finset -variable {p : Shape} {n N : ℕ} -variable {I J G : Type} [Fintype I] [Fintype J] [Fintype G] -variable [DecidableEq I] [DecidableEq J] [DecidableEq G] - -instance knFin (g n : ℕ) : Fintype (Knobs g n) := inferInstanceAs (Fintype (Knobs g n)) -def freePart (p : Shape) {n} (x : Knobs p.g n) := x Block.Z - -def frozenZ (p : Shape) {n} (P : Knobs p.g n → Prop) := - ∀ x y, (P x ↔ P (x+Pi.single Block.Z y)) - -theorem spin_scan_free (p : Shape) (n) (l) (f : Flavor p.g) : - ∀ (x : Knobs p.g n) y,scan p l f (x+Pi.single Block.Z y)=scan p l f x := by - classical - intro x y; funext i - have hx : asBlock i ≠ Block.Z := by rcases i with (⟨i,j⟩|_) <;> simp [asBlock] - simp only [scan,Pi.add_apply,Pi.single_eq_of_ne hx,add_zero] - -theorem fresh_Z (p : Shape) (n) (P : Knobs p.g n→ Prop) - (h : frozenZ p P) (hh : IsLaw (onW (spins p n) P)) : - mapW (onW (spins p n) P) (freePart p) = unif := by - classical - let w := onW (spins p n) P - have he (c : Vec (Fin n)) (x : Knobs p.g n) : - w (x+Pi.single Block.Z c)=w x := by - have hv (x : Knobs p.g n) : spins p n x=unif x := congr_fun - (Eq.symm draws_unif) x - simp only [w,onW_val,hv,unif_apply,← h x c] - have hv (x y : Vec (Fin n)) : - mapW w (freePart p) x=mapW w (freePart p) y := by - let t : Knobs p.g n := Pi.single Block.Z (x-y) - let e : Knobs p.g n ≃ Knobs p.g n := - { toFun := (·+t) - invFun := (·-t) - left_inv a := add_sub_cancel_right .. - right_inv a := sub_add_cancel .. } - have hh (b : Knobs p.g n) : - freePart p (e b)=x ↔ freePart p b=y := by - unfold freePart - change b Block.Z+t Block.Z=x ↔ _ - rw [show t Block.Z=x-y from Pi.single_eq_same _ _]; constructor <;> intro h - · apply add_right_cancel (b:=x-y) - rw [h,add_sub_cancel] - rw [h,add_sub_cancel] - unfold mapW pr - rw [← avg_bij e] - have hf i : w (e i)=w i := he _ i - simp_rw [hf,hh] - rw [←unifOn_true (A:=Vec (Fin n))] - exact uniform_support (mapW_law hh _) (by intro x h; exact (h trivial).elim) (fun i j _ _ => hv i j) - -theorem scopedZ_bit (p : Shape) (n l f x) (h : IsLaw (scopedBit p n l f x)) : - mapW (scopedBit p n l f x) (freePart p)=unif := - fresh_Z p n _ (fun v y => by - simp only [dialed,spin_scan_free]) h - -theorem scopedZ_scan (p : Shape) (n l f x) (h : IsLaw (scopedScan p n l f x)) : - mapW (scopedScan p n l f x) (freePart p)=unif := - fresh_Z p n _ (fun v y => by simp only [spin_scan_free]) h - -def freeNet (p : Shape) {n} (x : J→ Inputs p n I) : - PlusRack (J × I) n := - Matrix.of (fun i j => freePart p (x j.1 j.2) i) - -theorem law_probes (p : Shape) (n) - (w : I→ Wgt (Knobs p.g n)) (hw : ∀ i,mapW (w i) (freePart p)=unif) : - mapW (draws J (prodW w)) (freeNet p (n:=n) (I:=I))=unif := by - classical - let X (x : Inputs p n I) : I → Vec (Fin n) := fun i => freePart p (x i) - have he := mapW_repeat w (f:=fun i => freePart p (n:=n)) - simp_rw [hw] at he - have hh : mapW (prodW w) X=unif := he.trans (Eq.symm draws_unif) - let E : (J→I→Vec (Fin n))≃PlusRack (J×I) n := - { toFun := fun x => Matrix.of (fun i j => x j.1 j.2 i) - invFun := fun x j i k => x k (j,i) - left_inv _ := rfl - right_inv _ := rfl } - let Y (x : J→ Inputs p n I) := fun i => X (x i) - have h : mapW (draws J (prodW w)) Y=unif := by - have hY := mapW_repeat (fun (_ : J) => prodW w) (fun _ => X) - simp_rw [hh] at hY - exact hY.trans (Eq.symm draws_unif) - change mapW _ (E ∘ Y) = _ - rw [←mapW_nested,h,unif_equiv] - -def bloom (p : Shape) {n} (x : J→Inputs p n I) := - Injective (freeNet p x).mulVec - -theorem buds (p : Shape) (n) - (w : I→ Wgt (Knobs p.g n)) (hw : ∀ i,mapW (w i) (freePart p)=unif) : - pr (draws J (prodW w)) (fun x => ¬bloom p x) ≤ bp (num J*num I-n) := by - classical - unfold bloom - rw [show pr _ _ = pr (mapW (draws J (prodW w)) (freeNet p)) (fun x : PlusRack (J×I) n => - ¬Injective x.mulVec) from (mapW_pr ..).symm,law_probes _ _ _ hw] - simpa only [num,Fintype.card_prod,Fintype.card_fin,Nat.cast_mul] - using (@unif_fail (J×I) (Fin n) _ _ _ _) - -omit [DecidableEq I] in -theorem inject_column_slice {f : I→J} (M : PlusRack J n) - (h : Injective M.mulVec) (hf : Injective f) : - Injective (M.submatrix _root_.id f).mulVec := by - rw [← mul_embedMat] - exact inj_comp_mat _ _ h (embedMat_inj hf) - -variable {g : Route I G} - -omit [Fintype G] [DecidableEq J] in -theorem ray_bloom {f : Route J G} {b : J → I} - {A : NomQuery p n f} (e : G) (V : PlusRack I n) - (h : Injective V.mulVec) (he : Injective (fun i : Port f e => b i.val)) - (hm : ∀ i : Port f e, ∀ j : Fin n,A e (emptySel,some (Block.Z,j)) i=V j (b i.val)) : - Injective (A e).mulVec := by - intro x y hx - apply inject_column_slice V h he - funext j - have hh := congr_fun hx (emptySel,some (Block.Z,j)) - change ∑ i:Port f e,_=∑ i:Port f e,_ at * - simp_rw [hm] at hh; exact hh - -namespace Template - -variable (v : Template p I) - -def queryLaw (x : Inputs p n I) - {g : Route (KeySlots p v.t) G} : NomQuery p n g := - fun _ => Matrix.of (fun j k => (v.draw x).rayAt k.val.1 j) - -omit [Fintype G] in -/-- covers endpoint variants whenever a position only visits each port once -/ -theorem queries_bloom (x : J→ Inputs p n I) (g : Route (KeySlots p v.t) G) - (h : bloom p x) (he : ∀ e : G,Injective (fun i : Port g e => i.val.1)) - (i : G) : - Injective (pooled (fun i => queryLaw v (x i) (g:=g)) i).mulVec := by - classical - let r : J × KeySlots p v.t → J×I := fun y => (y.1,y.2.1) - have hr : Injective (fun a : Port (tied g J) i => r a.val) := by - rintro ⟨⟨j,a⟩,ha⟩ ⟨⟨j',b⟩,hb⟩ heq - have hA : j=j' := congrArg Prod.fst heq - have hK : a=b := congrArg Subtype.val (he i (show (⟨a,ha⟩:Port g i).val.1= - (⟨b,hb⟩:Port g i).val.1 from congrArg Prod.snd heq)) - exact Subtype.ext (Prod.ext hA hK) - refine ray_bloom (b:=r) _ _ h hr ?_ - rintro a j - let t := a.val.1 - let i := a.val.2.1 - change point p _ _ (emptySel,some (Block.Z,j))=freeNet p x j (t,i) - rw [point_base_eval]; exact ite_eq_left (Flavor.keepZ _ _) -end Template - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RepeatedBatchLaws + +namespace OAI + +/-! # Grouped Query Independence -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix LinearMap Module Submodule Function Finset +variable {p : Shape} {n N : ℕ} +variable {I J G : Type} [Fintype I] [Fintype J] [Fintype G] +variable [DecidableEq I] [DecidableEq J] [DecidableEq G] + +instance knFin (g n : ℕ) : Fintype (Knobs g n) := inferInstanceAs (Fintype (Knobs g n)) +def freePart (p : Shape) {n} (x : Knobs p.g n) := x Block.Z + +def frozenZ (p : Shape) {n} (P : Knobs p.g n → Prop) := + ∀ x y, (P x ↔ P (x+Pi.single Block.Z y)) + +theorem spin_scan_free (p : Shape) (n) (l) (f : Flavor p.g) : + ∀ (x : Knobs p.g n) y,scan p l f (x+Pi.single Block.Z y)=scan p l f x := by + classical + intro x y; funext i + have hx : asBlock i ≠ Block.Z := by rcases i with (⟨i,j⟩|_) <;> simp [asBlock] + simp only [scan,Pi.add_apply,Pi.single_eq_of_ne hx,add_zero] + +theorem fresh_Z (p : Shape) (n) (P : Knobs p.g n→ Prop) + (h : frozenZ p P) (hh : IsLaw (onW (spins p n) P)) : + mapW (onW (spins p n) P) (freePart p) = unif := by + classical + let w := onW (spins p n) P + have he (c : Vec (Fin n)) (x : Knobs p.g n) : + w (x+Pi.single Block.Z c)=w x := by + have hv (x : Knobs p.g n) : spins p n x=unif x := congr_fun + (Eq.symm draws_unif) x + simp only [w,onW_val,hv,unif_apply,← h x c] + have hv (x y : Vec (Fin n)) : + mapW w (freePart p) x=mapW w (freePart p) y := by + let t : Knobs p.g n := Pi.single Block.Z (x-y) + let e : Knobs p.g n ≃ Knobs p.g n := + { toFun := (·+t) + invFun := (·-t) + left_inv a := add_sub_cancel_right .. + right_inv a := sub_add_cancel .. } + have hh (b : Knobs p.g n) : + freePart p (e b)=x ↔ freePart p b=y := by + unfold freePart + change b Block.Z+t Block.Z=x ↔ _ + rw [show t Block.Z=x-y from Pi.single_eq_same _ _]; constructor <;> intro h + · apply add_right_cancel (b:=x-y) + rw [h,add_sub_cancel] + rw [h,add_sub_cancel] + unfold mapW pr + rw [← avg_bij e] + have hf i : w (e i)=w i := he _ i + simp_rw [hf,hh] + rw [←unifOn_true (A:=Vec (Fin n))] + exact uniform_support (mapW_law hh _) (by intro x h; exact (h trivial).elim) (fun i j _ _ => hv i j) + +theorem scopedZ_bit (p : Shape) (n l f x) (h : IsLaw (scopedBit p n l f x)) : + mapW (scopedBit p n l f x) (freePart p)=unif := + fresh_Z p n _ (fun v y => by + simp only [dialed,spin_scan_free]) h + +theorem scopedZ_scan (p : Shape) (n l f x) (h : IsLaw (scopedScan p n l f x)) : + mapW (scopedScan p n l f x) (freePart p)=unif := + fresh_Z p n _ (fun v y => by simp only [spin_scan_free]) h + +def freeNet (p : Shape) {n} (x : J→ Inputs p n I) : + PlusRack (J × I) n := + Matrix.of (fun i j => freePart p (x j.1 j.2) i) + +theorem law_probes (p : Shape) (n) + (w : I→ Wgt (Knobs p.g n)) (hw : ∀ i,mapW (w i) (freePart p)=unif) : + mapW (draws J (prodW w)) (freeNet p (n:=n) (I:=I))=unif := by + classical + let X (x : Inputs p n I) : I → Vec (Fin n) := fun i => freePart p (x i) + have he := mapW_repeat w (f:=fun i => freePart p (n:=n)) + simp_rw [hw] at he + have hh : mapW (prodW w) X=unif := he.trans (Eq.symm draws_unif) + let E : (J→I→Vec (Fin n))≃PlusRack (J×I) n := + { toFun := fun x => Matrix.of (fun i j => x j.1 j.2 i) + invFun := fun x j i k => x k (j,i) + left_inv _ := rfl + right_inv _ := rfl } + let Y (x : J→ Inputs p n I) := fun i => X (x i) + have h : mapW (draws J (prodW w)) Y=unif := by + have hY := mapW_repeat (fun (_ : J) => prodW w) (fun _ => X) + simp_rw [hh] at hY + exact hY.trans (Eq.symm draws_unif) + change mapW _ (E ∘ Y) = _ + rw [←mapW_nested,h,unif_equiv] + +def bloom (p : Shape) {n} (x : J→Inputs p n I) := + Injective (freeNet p x).mulVec + +theorem buds (p : Shape) (n) + (w : I→ Wgt (Knobs p.g n)) (hw : ∀ i,mapW (w i) (freePart p)=unif) : + pr (draws J (prodW w)) (fun x => ¬bloom p x) ≤ bp (num J*num I-n) := by + classical + unfold bloom + rw [show pr _ _ = pr (mapW (draws J (prodW w)) (freeNet p)) (fun x : PlusRack (J×I) n => + ¬Injective x.mulVec) from (mapW_pr ..).symm,law_probes _ _ _ hw] + simpa only [num,Fintype.card_prod,Fintype.card_fin,Nat.cast_mul] + using (@unif_fail (J×I) (Fin n) _ _ _ _) + +omit [DecidableEq I] in +theorem inject_column_slice {f : I→J} (M : PlusRack J n) + (h : Injective M.mulVec) (hf : Injective f) : + Injective (M.submatrix _root_.id f).mulVec := by + rw [← mul_embedMat] + exact inj_comp_mat _ _ h (embedMat_inj hf) + +variable {g : Route I G} + +omit [Fintype G] [DecidableEq J] in +theorem ray_bloom {f : Route J G} {b : J → I} + {A : NomQuery p n f} (e : G) (V : PlusRack I n) + (h : Injective V.mulVec) (he : Injective (fun i : Port f e => b i.val)) + (hm : ∀ i : Port f e, ∀ j : Fin n,A e (emptySel,some (Block.Z,j)) i=V j (b i.val)) : + Injective (A e).mulVec := by + intro x y hx + apply inject_column_slice V h he + funext j + have hh := congr_fun hx (emptySel,some (Block.Z,j)) + change ∑ i:Port f e,_=∑ i:Port f e,_ at * + simp_rw [hm] at hh; exact hh + +namespace Template + +variable (v : Template p I) + +def queryLaw (x : Inputs p n I) + {g : Route (KeySlots p v.t) G} : NomQuery p n g := + fun _ => Matrix.of (fun j k => (v.draw x).rayAt k.val.1 j) + +omit [Fintype G] in +/-- covers endpoint variants whenever a position only visits each port once -/ +theorem queries_bloom (x : J→ Inputs p n I) (g : Route (KeySlots p v.t) G) + (h : bloom p x) (he : ∀ e : G,Injective (fun i : Port g e => i.val.1)) + (i : G) : + Injective (pooled (fun i => queryLaw v (x i) (g:=g)) i).mulVec := by + classical + let r : J × KeySlots p v.t → J×I := fun y => (y.1,y.2.1) + have hr : Injective (fun a : Port (tied g J) i => r a.val) := by + rintro ⟨⟨j,a⟩,ha⟩ ⟨⟨j',b⟩,hb⟩ heq + have hA : j=j' := congrArg Prod.fst heq + have hK : a=b := congrArg Subtype.val (he i (show (⟨a,ha⟩:Port g i).val.1= + (⟨b,hb⟩:Port g i).val.1 from congrArg Prod.snd heq)) + exact Subtype.ext (Prod.ext hA hK) + refine ray_bloom (b:=r) _ _ h hr ?_ + rintro a j + let t := a.val.1 + let i := a.val.2.1 + change point p _ _ (emptySel,some (Block.Z,j))=freeNet p x j (t,i) + rw [point_base_eval]; exact ite_eq_left (Flavor.keepZ _ _) +end Template + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/HeadPartitionComparison.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/HeadPartitionComparison.lean index 36f591afd28710d97d0c90902963b144ab5a0acb..c029ab1ea06e13e7c0355c81efd77474c4f93ced 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/HeadPartitionComparison.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/HeadPartitionComparison.lean @@ -1,95 +1,95 @@ -import OAI.Combinatorics.HadwigerCounterexample.FullTemplateComparison - -namespace OAI - -/-! # Head Partition Comparison -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Filter Function -open scoped BigOperators -variable {p : Shape} {n N M : ℕ} {I : Type} [Fintype I] [DecidableEq I] - -namespace Template -variable (v : Template p I) - -set_option maxHeartbeats 800000 in -theorem shattered (v : Template p I) (j : I) - (B L δ : ℝ) (hL : 0?_⟩ - let A:=Keys (p:=p) v.t N - let E:=chairK v j N - let f := Prod.fst ∘ E; let g:=Prod.snd ∘ E - let P := ownPart (p:=p) v.t q (N:=N) - let w := subW unif P - have hw : SubLaw w := subLaw_sub unif_law.sub _ - obtain ⟨l,hl,a,b,he⟩ := hr A _ _ w U f g hw hU - let T:= doubleBook f g a b - let B' (i : Fin l) (x) := cashbook w T U (i,b x) - have hx (i x) : |B' i x|≤B := cashbook_bound w hw.nz T U B hB hU _ - refine ⟨l,hl,a,B',hx,?_,?_,?_⟩ - · intro k - change |ind (P k)* (U k-B' (a (k j)) ((E k).2))/L|≤1 - rw [abs_div,abs_of_pos hL,div_le_iff₀ hL,one_mul] - by_cases hz : P k - · rw [ind_one hz,one_mul] - exact ((abs_sub ..).trans ((add_le_add (hU _) (hx _ _)).trans_eq (two_mul _).symm)).trans h - rw [ind_zero hz,zero_mul,abs_zero]; exact hL.le - · intro u hu t ht - have hi : - patched v j a B'=banner w T U := rfl - let W (k:A) := (U k-banner w T U k)*(u (f k)*t (g k)) - have hh : - avg unif (fun k:A=> curtain v q (U - patched v j a B') k / L * (u (f k)*t (g k))) = - avg w W/L := by - rw [hi] - unfold avg curtain W w P; simp only [div_eq_mul_inv,Finset.sum_mul]; unfold subW - exact sum_congr rfl fun i _=> by simp only [Pi.sub_apply]; ring - change |avg unif (fun k:A=> curtain v q (U - patched v j a B') k / L * (u (f k)*t (g k)))|≤_ - rw [hh,abs_div,abs_of_pos hL,div_le_iff₀ hL] - exact he u hu t ht - intro i hi - change ind _ * _/L=0; rw [ind_zero hi,zero_mul,zero_div] - -theorem chair_board (v : Template p I) (j : I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) - (L δ : ℝ) (hL : 0 curtain v q U i/L) δ) : - shadowed v q U (δ*L) := by - classical - intro f hf - let E:=chairK v j N; let t:=fun i : Aside j=> f i.val - let g := prodW t - have hg (x): |g x|≤1 := by - unfold g prodW; rw [abs_prod] - exact (prod_le_prod₀ (fun _ _=>abs_nonneg _) (fun i _=>hf _ _)).trans_eq (by simp) - let R := fun i=> curtain v q U i/L - let V (i:Keys (p:=p) v.t N) := R i*(f j (E i).1*g (E i).2) - have hh : |avg unif V|≤δ := h (f j) (hf j) g hg - have hi : board v q U f=avg unif V*L := by - unfold board; rw [←avg_mul] - apply avg_congr; intro i _ - rw [chair_split _ _ j] - change curtain v q U i*(f j (E i).1*g (E i).2)=_ - unfold V R; field_simp - rw [hi,abs_mul,abs_of_pos hL] - exact mul_le_mul_of_nonneg_right hh hL.le - -theorem put_back (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) (L : ℝ) - (s : Script p I) (m : Mixer p n) (w f : I→Wgt (Knobs p.g n)) - (o : UnitType p n N) : - scene v (propel v s m) (fun i=> curtain v q U i/L) w f o= - astonish v q U s m w f o / L := by - unfold astonish scene; rw [← avg_div]; exact avg_congr fun x _=>by unfold protean; ring -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FullTemplateComparison + +namespace OAI + +/-! # Head Partition Comparison -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Filter Function +open scoped BigOperators +variable {p : Shape} {n N M : ℕ} {I : Type} [Fintype I] [DecidableEq I] + +namespace Template +variable (v : Template p I) + +set_option maxHeartbeats 800000 in +theorem shattered (v : Template p I) (j : I) + (B L δ : ℝ) (hL : 0?_⟩ + let A:=Keys (p:=p) v.t N + let E:=chairK v j N + let f := Prod.fst ∘ E; let g:=Prod.snd ∘ E + let P := ownPart (p:=p) v.t q (N:=N) + let w := subW unif P + have hw : SubLaw w := subLaw_sub unif_law.sub _ + obtain ⟨l,hl,a,b,he⟩ := hr A _ _ w U f g hw hU + let T:= doubleBook f g a b + let B' (i : Fin l) (x) := cashbook w T U (i,b x) + have hx (i x) : |B' i x|≤B := cashbook_bound w hw.nz T U B hB hU _ + refine ⟨l,hl,a,B',hx,?_,?_,?_⟩ + · intro k + change |ind (P k)* (U k-B' (a (k j)) ((E k).2))/L|≤1 + rw [abs_div,abs_of_pos hL,div_le_iff₀ hL,one_mul] + by_cases hz : P k + · rw [ind_one hz,one_mul] + exact ((abs_sub ..).trans ((add_le_add (hU _) (hx _ _)).trans_eq (two_mul _).symm)).trans h + rw [ind_zero hz,zero_mul,abs_zero]; exact hL.le + · intro u hu t ht + have hi : + patched v j a B'=banner w T U := rfl + let W (k:A) := (U k-banner w T U k)*(u (f k)*t (g k)) + have hh : + avg unif (fun k:A=> curtain v q (U - patched v j a B') k / L * (u (f k)*t (g k))) = + avg w W/L := by + rw [hi] + unfold avg curtain W w P; simp only [div_eq_mul_inv,Finset.sum_mul]; unfold subW + exact sum_congr rfl fun i _=> by simp only [Pi.sub_apply]; ring + change |avg unif (fun k:A=> curtain v q (U - patched v j a B') k / L * (u (f k)*t (g k)))|≤_ + rw [hh,abs_div,abs_of_pos hL,div_le_iff₀ hL] + exact he u hu t ht + intro i hi + change ind _ * _/L=0; rw [ind_zero hi,zero_mul,zero_div] + +theorem chair_board (v : Template p I) (j : I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) + (L δ : ℝ) (hL : 0 curtain v q U i/L) δ) : + shadowed v q U (δ*L) := by + classical + intro f hf + let E:=chairK v j N; let t:=fun i : Aside j=> f i.val + let g := prodW t + have hg (x): |g x|≤1 := by + unfold g prodW; rw [abs_prod] + exact (prod_le_prod₀ (fun _ _=>abs_nonneg _) (fun i _=>hf _ _)).trans_eq (by simp) + let R := fun i=> curtain v q U i/L + let V (i:Keys (p:=p) v.t N) := R i*(f j (E i).1*g (E i).2) + have hh : |avg unif V|≤δ := h (f j) (hf j) g hg + have hi : board v q U f=avg unif V*L := by + unfold board; rw [←avg_mul] + apply avg_congr; intro i _ + rw [chair_split _ _ j] + change curtain v q U i*(f j (E i).1*g (E i).2)=_ + unfold V R; field_simp + rw [hi,abs_mul,abs_of_pos hL] + exact mul_le_mul_of_nonneg_right hh hL.le + +theorem put_back (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) (L : ℝ) + (s : Script p I) (m : Mixer p n) (w f : I→Wgt (Knobs p.g n)) + (o : UnitType p n N) : + scene v (propel v s m) (fun i=> curtain v q U i/L) w f o= + astonish v q U s m w f o / L := by + unfold astonish scene; rw [← avg_div]; exact avg_congr fun x _=>by unfold protean; ring +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/HistogramBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/HistogramBounds.lean index 322747f45c00ec7c99ba1a90e40188b480d0400f..f6a1fff77731e0c50c200dc4b2b03203b278fb41 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/HistogramBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/HistogramBounds.lean @@ -1,79 +1,79 @@ -import OAI.Combinatorics.HadwigerCounterexample.RestrictedComparisonLaws - -namespace OAI - -/-! # Histogram Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real Filter -open scoped BigOperators -variable {A X B C Y : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype X] [Fintype Y] - -def fromFlags (μ : Wgt A) (w : Wgt X) (v : A→X→Y) (K : A→X→B) := - fun z => ∃ P:A→ Y→ Prop,z=flaggedW μ w v K P - -def Haberdash (Q : Wgt B→ Prop) (r : ℕ) (δ R η ε : ℝ) := - (∀ p,Q p→SubLaw p) ∧ roster Q r ε ∧ smallSet Q unif δ η ∧ - ∀ P : B→Prop, - let v := unifOn P - let H := hung Q P - roster H r ε ∧ smallSet H v δ η ∧ rosterTail H v R η - -variable {I : Type} [Fintype I] [DecidableEq I] {p : Shape} - -namespace Template -set_option maxHeartbeats 1200000 in -theorem controls (v : Template p I) (M : ℕ) (hM : 1≤M) - (Y : Type) [Fintype Y] [Nonempty Y] - (C η ε : ℝ) (hC : 0≤C) (hη : 0<η) (hε : 0<ε) : - ∃ (r : ℕ) (δ R : ℝ), 0<δ ∧ 0 - (pr_mono_left (hu.cat_dom i (h3 i ht)).2 S).trans (hh (A×Y) B μ q hu h2 S hS) - exact ⟨h4,hi,hj,fun P => ⟨hung_roster Q P _ _ hi,hung_small Q P _ _ hj,hung_tail Q P h4 - _ _ hδ hj⟩⟩ -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RestrictedComparisonLaws + +namespace OAI + +/-! # Histogram Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real Filter +open scoped BigOperators +variable {A X B C Y : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype X] [Fintype Y] + +def fromFlags (μ : Wgt A) (w : Wgt X) (v : A→X→Y) (K : A→X→B) := + fun z => ∃ P:A→ Y→ Prop,z=flaggedW μ w v K P + +def Haberdash (Q : Wgt B→ Prop) (r : ℕ) (δ R η ε : ℝ) := + (∀ p,Q p→SubLaw p) ∧ roster Q r ε ∧ smallSet Q unif δ η ∧ + ∀ P : B→Prop, + let v := unifOn P + let H := hung Q P + roster H r ε ∧ smallSet H v δ η ∧ rosterTail H v R η + +variable {I : Type} [Fintype I] [DecidableEq I] {p : Shape} + +namespace Template +set_option maxHeartbeats 1200000 in +theorem controls (v : Template p I) (M : ℕ) (hM : 1≤M) + (Y : Type) [Fintype Y] [Nonempty Y] + (C η ε : ℝ) (hC : 0≤C) (hη : 0<η) (hε : 0<ε) : + ∃ (r : ℕ) (δ R : ℝ), 0<δ ∧ 0 + (pr_mono_left (hu.cat_dom i (h3 i ht)).2 S).trans (hh (A×Y) B μ q hu h2 S hS) + exact ⟨h4,hi,hj,fun P => ⟨hung_roster Q P _ _ hi,hung_small Q P _ _ hj,hung_tail Q P h4 + _ _ hδ hj⟩⟩ +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/HistogramEnergyScales.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/HistogramEnergyScales.lean index e8f171aa5fce16bfbb9648cc536cc9dbac7d3896..c0ae310e2d134048615669389d542307b2a66ec3 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/HistogramEnergyScales.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/HistogramEnergyScales.lean @@ -1,145 +1,145 @@ -import OAI.Combinatorics.HadwigerCounterexample.RepeatedQueryEnergy -import OAI.Combinatorics.HadwigerCounterexample.TemplateTypicality - -namespace OAI - -/-! # Histogram Energy Scales -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real Filter -open scoped BigOperators Topology -variable {I J G : Type} [Fintype I] [Fintype J] [Fintype G] -variable [DecidableEq I] [DecidableEq J] [DecidableEq G] - -theorem log_thrift (r : ℝ) (hr : 0≤r) : - ∀ᶠ l : ℕ in atTop,r * Real.log ((l:ℝ)+1)≤(l:ℝ) := by - have h2 := Real.log_pos (x:=2) (by norm_num) - let a := (1:ℝ)/(log 2*(r+1)) - have hr' : 0 n / d) atTop atTop := tendsto_atTop.mpr fun b => - (eventually_ge_atTop (b*d)).mono fun _ h => (Nat.le_div_iff_mul_le hd).mpr h - -structure TollBar (M : ℕ) (C : ℝ) (I J G : Type) [Fintype I] [Fintype J] - [Fintype G] [DecidableEq G] (g : Route J G) (n l : ℕ) - (r u E V : ℝ) : Prop where - pos : 0 ?_⟩ - have ht := div_grows s hs' - let B := (4:ℝ)^Fintype.card G - filter_upwards [ht.eventually (eventually_ge_atTop 1), - ht.eventually (bp_poly_dom_nat (a:=1) (by norm_num) (B*(b+1)) 1),ht.eventually - (log_thrift r hr),ht.eventually ((tendsto_natCast_atTop_atTop (R:=ℝ)).eventually - (eventually_ge_atTop (max 2 (8*u)))),pay_nat (a:=1/2) u (b:=0) (by norm_num)] - with n hl hG hr hpeak hU - let l := n/s - have hl' : 1≤(l:ℝ) := by exact_mod_cast hl - have hsl : (s:ℝ)*l ≤ n := by - rw [mul_comm]; exact_mod_cast Nat.div_mul_le_self n s - have hnl : (n:ℝ) ≤ 2*s*l := by - have h := Nat.lt_mul_div_succ n hs' - change n n / d) atTop atTop := tendsto_atTop.mpr fun b => + (eventually_ge_atTop (b*d)).mono fun _ h => (Nat.le_div_iff_mul_le hd).mpr h + +structure TollBar (M : ℕ) (C : ℝ) (I J G : Type) [Fintype I] [Fintype J] + [Fintype G] [DecidableEq G] (g : Route J G) (n l : ℕ) + (r u E V : ℝ) : Prop where + pos : 0 ?_⟩ + have ht := div_grows s hs' + let B := (4:ℝ)^Fintype.card G + filter_upwards [ht.eventually (eventually_ge_atTop 1), + ht.eventually (bp_poly_dom_nat (a:=1) (by norm_num) (B*(b+1)) 1),ht.eventually + (log_thrift r hr),ht.eventually ((tendsto_natCast_atTop_atTop (R:=ℝ)).eventually + (eventually_ge_atTop (max 2 (8*u)))),pay_nat (a:=1/2) u (b:=0) (by norm_num)] + with n hl hG hr hpeak hU + let l := n/s + have hl' : 1≤(l:ℝ) := by exact_mod_cast hl + have hsl : (s:ℝ)*l ≤ n := by + rw [mul_comm]; exact_mod_cast Nat.div_mul_le_self n s + have hnl : (n:ℝ) ≤ 2*s*l := by + have h := Nat.lt_mul_div_succ n hs' + change n flipZ_flip i,fun i => flipZ_flip i⟩ - -variable {r : Place p→ℕ} - -theorem tuple_dim : - dim (DTuple (p:=p) r N)=N*∑ z : Place p,r z := by - unfold DTuple dim - rw [finrank_pi_fintype,Finset.mul_sum] - refine Finset.sum_congr rfl fun i _ => ?_ - exact (dim_mat _ _).trans (by simp) - -def projTuple (p : Shape) {n N} (r : Place p→ℕ) (A : WTuple (p:=p) r n) - (x : Place p ≃ Place p) (w : UnitType p n N) : DTuple (p:=p) r N := - fun z => images w (x z) * A z - -theorem cap_tuple (p : Shape) {n N} (r : Place p → ℕ) (A : WTuple (p:=p) r n) - (x : Place p ≃ Place p) {w : Wgt (UnitType p n N)} {f : Pin p n N} {ζ : ℝ} - (h : ∀ z, Function.Injective (A z).mulVec) - (hf : ∀ z, Disjoint (colSp (A z)) (f.sp (x z))) - (hw : SubLaw w) (hc : f.clear ζ w) : - ∀ y, mapW w (projTuple p r A x) y ≤ fee N ζ (∑ z,r z) := by - classical - intro y - let P := fun z : UnitType p n N => projTuple p r A x z=y - change pr w P ≤ _ - by_cases hP : 0 < pr w P - · obtain ⟨a,ha,hA⟩ := exists_of_pr_pos hw.nz hP - let D : Plan p n := fun z => colSp (A (x.symm z)) - let c := Pin.make D a - have h1 : pr w P ≤ pr w c.agree := by - refine pr_mono hw.nz fun w hw z t ht => ?_ - change t∈colSp (A (x.symm z)) at ht - obtain ⟨u,rfl⟩ := ht - change _ *ᵥ _ = images a z *ᵥ _ - have hh := congr_fun (hw.trans ha.symm) (x.symm z) - unfold projTuple at hh; rw [x.apply_symm_apply] at hh - rw [mulVecLin_apply,mulVec_mulVec,mulVec_mulVec,hh] - have h2 : planNew f.sp D=∑ z,r z := by - rw [plan_new_disjoint f.sp D] - · have hh (z) : dim (D z)=r (x.symm z) := (mrk_inj.mp (h (x.symm z))).trans - (Fintype.card_fin _) - unfold planRank - simp_rw [hh] - exact Equiv.sum_comp _ _ - · intro z - have hh := hf (x.symm z) - rw [x.apply_symm_apply] at hh; exact hh.symm - rw [← h2] - exact h1.trans (hc c) - exact (not_lt.mp hP).trans (bp_pos _).le - -variable {I J : Type} [Fintype I] [Fintype J] -theorem mpair_nondeg (M : Mat I J) (h : mpair M=0) : M=0 := by - classical - apply evmat_ext; intro x y - rw [←mpair_outer,h]; simp [evmat] - -def tupleB (p : Shape) (r : Place p → ℕ) (N : ℕ) : - DTuple (p:=p) r N →ₗ[F] DTuple (p:=p) r N →ₗ[F] F where - toFun x := ∑ z : Place p, mpair (x z) ∘ₗ LinearMap.proj z - map_add' x y := LinearMap.ext fun v => by - simp only [LinearMap.sum_apply,LinearMap.comp_apply,Pi.add_apply,LinearMap.add_apply, - mpair_add,Finset.sum_add_distrib] - map_smul' a x := LinearMap.ext fun v => by - simp only [LinearMap.sum_apply,LinearMap.comp_apply,Pi.smul_apply,RingHom.id_apply, - LinearMap.smul_apply,mpair_smul,Finset.mul_sum,smul_eq_mul] - -theorem tupleB_val (x y : DTuple (p:=p) r N) : - tupleB p r N x y=∑ z,mpair (x z) (y z) := by - simp only [tupleB,LinearMap.sum_apply,LinearMap.coe_mk,AddHom.coe_mk]; rfl - -theorem tupleB_inj (p : Shape) (r : Place p→ℕ) (N : ℕ) : - Function.Injective (tupleB p r N) := by - classical - rw [← LinearMap.ker_eq_bot] - refine le_bot_iff.mp (fun x hx => ?_) - change tupleB p r N x = 0 at hx - have hh (z : Place p) : mpair (x z)=0 := by - refine LinearMap.ext (fun M => ?_) - have he := LinearMap.congr_fun hx (Pi.single z M) - rw [tupleB_val,Finset.sum_eq_single z] at he - · rwa [Pi.single_eq_same] at he - · intro i _ hi; simp [hi] - simp - have h' : x=0 := funext fun z => mpair_nondeg _ (hh z) - rw [h']; exact Submodule.zero_mem _ - -theorem charImages (p : Shape) {n N} (r : Place p → ℕ) (A B : WTuple (p:=p) r n) - {u w : Wgt (UnitType p n N)} (hu : IsLaw u) (hw : IsLaw w) {f b : Pin p n N} - (hc : f.clear 0.05 u) (hd : b.clear 0.05 w) - (hA : ∀ z,Function.Injective (A z).mulVec ∧ Disjoint (colSp (A z)) (f.sp z)) - (hB : ∀ z,Function.Injective (B z).mulVec ∧ Disjoint (colSp (B z)) (b.sp (flipZ p z))) - (hr : 1 ≤ ∑ z,r z) : - |avg (pairW u w) (fun x => wsign (tupleB p r N (projTuple p r A (Equiv.refl _) x.1) - (projTuple p r B (flipEquiv p) x.2)))| ≤ bp (-0.45*N) := by - classical - let H := tupleB p r N - let g := projTuple p r A (Equiv.refl _) (N:=N) - let g' := projTuple p r B (flipEquiv p) (N:=N) - let q := mapW u g - let v := mapW w g' - let t := ∑ i,r i - have he : - avg (pairW u w) (fun x => wsign (H (g x.1) (g' x.2))) = - avg v (fun y => avg q (fun x => wsign (H x y))) := by - rw [pairW_avg] - unfold q v - rw [mapW_avg] - simp_rw [mapW_avg] - exact avg_avg .. - have hp (x) : q x ≤ fee N 0.05 t := - cap_tuple p r A (Equiv.refl _) (fun z => (hA z).1) (fun z => (hA z).2) hu.sub hc x - have hq (x) : v x ≤ fee N 0.05 t := - cap_tuple p r B (flipEquiv p) (fun z => (hB z).1) (fun z => (hB z).2) hw.sub hd x - have hh := walsh_mass H (tupleB_inj p r N) q v (fun _ => 1) (fun _ => 1) - (fun _ => by norm_num) (fun _ => by norm_num) (mapW_law hu g).sub (mapW_law hw g').sub hp hq - change |avg (pairW u w) _|≤_ - rw [he] - let R := avg v (fun y => avg q (fun x => wsign (H x y))) - have hi : R^2 ≤ (bp (-0.45*N))^2 := by - simp only [one_mul] at hh - apply le_trans hh - rw [card_space,tuple_dim] - unfold fee - change bp (↑(N*t))* _ * _ ≤ _ - rw [←bp_add,←bp_add,pow_two,←bp_add] - apply bp_le - have h' : 1 ≤ (t:ℝ) := by exact_mod_cast hr - push_cast - have hx := mul_le_mul_of_nonneg_left h' (show 0≤(N:ℝ) from Nat.cast_nonneg _) - linarith only [hx] - exact le_of_pow_le_pow_left₀ (show (2:ℕ) ≠ 0 by decide) (bp_pos _).le - (sq_abs R ▸ hi) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ConditionalCellEntropy + +namespace OAI + +/-! # Image Character Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} +abbrev DTuple {p : Shape} (r : Place p → ℕ) (N : ℕ) := + ∀ z, Mat (Fin N) (Fin (r z)) +abbrev WTuple {p : Shape} (r : Place p → ℕ) (n : ℕ) := + ∀ z, Mat (JointIdx p n) (Fin (r z)) + +def flipEquiv (p : Shape) : Place p ≃ Place p := + ⟨flipZ p,flipZ p,fun i => flipZ_flip i,fun i => flipZ_flip i⟩ + +variable {r : Place p→ℕ} + +theorem tuple_dim : + dim (DTuple (p:=p) r N)=N*∑ z : Place p,r z := by + unfold DTuple dim + rw [finrank_pi_fintype,Finset.mul_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + exact (dim_mat _ _).trans (by simp) + +def projTuple (p : Shape) {n N} (r : Place p→ℕ) (A : WTuple (p:=p) r n) + (x : Place p ≃ Place p) (w : UnitType p n N) : DTuple (p:=p) r N := + fun z => images w (x z) * A z + +theorem cap_tuple (p : Shape) {n N} (r : Place p → ℕ) (A : WTuple (p:=p) r n) + (x : Place p ≃ Place p) {w : Wgt (UnitType p n N)} {f : Pin p n N} {ζ : ℝ} + (h : ∀ z, Function.Injective (A z).mulVec) + (hf : ∀ z, Disjoint (colSp (A z)) (f.sp (x z))) + (hw : SubLaw w) (hc : f.clear ζ w) : + ∀ y, mapW w (projTuple p r A x) y ≤ fee N ζ (∑ z,r z) := by + classical + intro y + let P := fun z : UnitType p n N => projTuple p r A x z=y + change pr w P ≤ _ + by_cases hP : 0 < pr w P + · obtain ⟨a,ha,hA⟩ := exists_of_pr_pos hw.nz hP + let D : Plan p n := fun z => colSp (A (x.symm z)) + let c := Pin.make D a + have h1 : pr w P ≤ pr w c.agree := by + refine pr_mono hw.nz fun w hw z t ht => ?_ + change t∈colSp (A (x.symm z)) at ht + obtain ⟨u,rfl⟩ := ht + change _ *ᵥ _ = images a z *ᵥ _ + have hh := congr_fun (hw.trans ha.symm) (x.symm z) + unfold projTuple at hh; rw [x.apply_symm_apply] at hh + rw [mulVecLin_apply,mulVec_mulVec,mulVec_mulVec,hh] + have h2 : planNew f.sp D=∑ z,r z := by + rw [plan_new_disjoint f.sp D] + · have hh (z) : dim (D z)=r (x.symm z) := (mrk_inj.mp (h (x.symm z))).trans + (Fintype.card_fin _) + unfold planRank + simp_rw [hh] + exact Equiv.sum_comp _ _ + · intro z + have hh := hf (x.symm z) + rw [x.apply_symm_apply] at hh; exact hh.symm + rw [← h2] + exact h1.trans (hc c) + exact (not_lt.mp hP).trans (bp_pos _).le + +variable {I J : Type} [Fintype I] [Fintype J] +theorem mpair_nondeg (M : Mat I J) (h : mpair M=0) : M=0 := by + classical + apply evmat_ext; intro x y + rw [←mpair_outer,h]; simp [evmat] + +def tupleB (p : Shape) (r : Place p → ℕ) (N : ℕ) : + DTuple (p:=p) r N →ₗ[F] DTuple (p:=p) r N →ₗ[F] F where + toFun x := ∑ z : Place p, mpair (x z) ∘ₗ LinearMap.proj z + map_add' x y := LinearMap.ext fun v => by + simp only [LinearMap.sum_apply,LinearMap.comp_apply,Pi.add_apply,LinearMap.add_apply, + mpair_add,Finset.sum_add_distrib] + map_smul' a x := LinearMap.ext fun v => by + simp only [LinearMap.sum_apply,LinearMap.comp_apply,Pi.smul_apply,RingHom.id_apply, + LinearMap.smul_apply,mpair_smul,Finset.mul_sum,smul_eq_mul] + +theorem tupleB_val (x y : DTuple (p:=p) r N) : + tupleB p r N x y=∑ z,mpair (x z) (y z) := by + simp only [tupleB,LinearMap.sum_apply,LinearMap.coe_mk,AddHom.coe_mk]; rfl + +theorem tupleB_inj (p : Shape) (r : Place p→ℕ) (N : ℕ) : + Function.Injective (tupleB p r N) := by + classical + rw [← LinearMap.ker_eq_bot] + refine le_bot_iff.mp (fun x hx => ?_) + change tupleB p r N x = 0 at hx + have hh (z : Place p) : mpair (x z)=0 := by + refine LinearMap.ext (fun M => ?_) + have he := LinearMap.congr_fun hx (Pi.single z M) + rw [tupleB_val,Finset.sum_eq_single z] at he + · rwa [Pi.single_eq_same] at he + · intro i _ hi; simp [hi] + simp + have h' : x=0 := funext fun z => mpair_nondeg _ (hh z) + rw [h']; exact Submodule.zero_mem _ + +theorem charImages (p : Shape) {n N} (r : Place p → ℕ) (A B : WTuple (p:=p) r n) + {u w : Wgt (UnitType p n N)} (hu : IsLaw u) (hw : IsLaw w) {f b : Pin p n N} + (hc : f.clear 0.05 u) (hd : b.clear 0.05 w) + (hA : ∀ z,Function.Injective (A z).mulVec ∧ Disjoint (colSp (A z)) (f.sp z)) + (hB : ∀ z,Function.Injective (B z).mulVec ∧ Disjoint (colSp (B z)) (b.sp (flipZ p z))) + (hr : 1 ≤ ∑ z,r z) : + |avg (pairW u w) (fun x => wsign (tupleB p r N (projTuple p r A (Equiv.refl _) x.1) + (projTuple p r B (flipEquiv p) x.2)))| ≤ bp (-0.45*N) := by + classical + let H := tupleB p r N + let g := projTuple p r A (Equiv.refl _) (N:=N) + let g' := projTuple p r B (flipEquiv p) (N:=N) + let q := mapW u g + let v := mapW w g' + let t := ∑ i,r i + have he : + avg (pairW u w) (fun x => wsign (H (g x.1) (g' x.2))) = + avg v (fun y => avg q (fun x => wsign (H x y))) := by + rw [pairW_avg] + unfold q v + rw [mapW_avg] + simp_rw [mapW_avg] + exact avg_avg .. + have hp (x) : q x ≤ fee N 0.05 t := + cap_tuple p r A (Equiv.refl _) (fun z => (hA z).1) (fun z => (hA z).2) hu.sub hc x + have hq (x) : v x ≤ fee N 0.05 t := + cap_tuple p r B (flipEquiv p) (fun z => (hB z).1) (fun z => (hB z).2) hw.sub hd x + have hh := walsh_mass H (tupleB_inj p r N) q v (fun _ => 1) (fun _ => 1) + (fun _ => by norm_num) (fun _ => by norm_num) (mapW_law hu g).sub (mapW_law hw g').sub hp hq + change |avg (pairW u w) _|≤_ + rw [he] + let R := avg v (fun y => avg q (fun x => wsign (H x y))) + have hi : R^2 ≤ (bp (-0.45*N))^2 := by + simp only [one_mul] at hh + apply le_trans hh + rw [card_space,tuple_dim] + unfold fee + change bp (↑(N*t))* _ * _ ≤ _ + rw [←bp_add,←bp_add,pow_two,←bp_add] + apply bp_le + have h' : 1 ≤ (t:ℝ) := by exact_mod_cast hr + push_cast + have hx := mul_le_mul_of_nonneg_left h' (show 0≤(N:ℝ) from Nat.cast_nonneg _) + linarith only [hx] + exact le_of_pow_le_pow_left₀ (show (2:ℕ) ≠ 0 by decide) (bp_pos _).le + (sq_abs R ▸ hi) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ImagePartitions.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ImagePartitions.lean index 6b55e2bbb114d11d7f7a1b10c0ce11d13f5c5171..d5a8a2a2b92c5c151cc78bc27f22dfd5e53ce50e 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ImagePartitions.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ImagePartitions.lean @@ -1,209 +1,209 @@ -import OAI.Combinatorics.HadwigerCounterexample.RawFrameLaws - -namespace OAI - -/-! # Image Partitions -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix -open scoped BigOperators -variable {p : Shape} {n N : ℕ} - -theorem plan_mono {a b : Plan p n} (h : a ≤ b) : planRank a ≤ planRank b := - Finset.sum_le_sum fun i _ => Submodule.finrank_mono (h i) - -/-- Joint nominal rank modulo pins. -/ -def planNew (a b : Plan p n) := planRank (a⊔b) - planRank a - -theorem plan_add_rank (a b : Plan p n) : - planRank a + planNew a b = planRank (a⊔b) := - Nat.add_sub_of_le (plan_mono le_sup_left) - -theorem planNew_mono_add {a b c : Plan p n} (h : a ≤ b) : - planNew a b + planNew b c = planNew a (b⊔c) := by - have he := plan_add_rank a b - have hf := plan_add_rank b c - have hg := plan_add_rank a (b⊔c) - rw [sup_eq_right.mpr h] at he - rw [sup_eq_right.mpr (le_trans h le_sup_left)] at hg - omega - -def Pin.make (a : Plan p n) (x : UnitType p n N) : Pin p n N := ⟨a,images x⟩ - -theorem Pin.combine {a b : Pin p n N} {x y} (ha : a.agree x) (hb : b.agree x) : - (Pin.make (a.sp ⊔ b.sp) x).agree y ↔ a.agree y ∧ b.agree y := by - change (∀ i, ∀ v ∈ a.sp i ⊔ b.sp i, images y i *ᵥ v = images x i *ᵥ v) ↔ _ - constructor - · intro h - exact ⟨fun i v hv => (h i v (Submodule.mem_sup_left hv)).trans (ha _ v hv), - fun i v hv => (h i v (Submodule.mem_sup_right hv)).trans (hb _ v hv)⟩ - · rintro ⟨u,w⟩ i v hv - obtain ⟨l,hl,r,hr,rfl⟩ := Submodule.mem_sup.mp hv - rw [Matrix.mulVec_add,Matrix.mulVec_add,ha _ _ hl,hb _ _ hr,u _ _ hl,w _ _ hr] - -def fee (N : ℕ) (ζ : ℝ) (t : ℕ) := bp (-(1-ζ)*t*N) -def Pin.clear (a : Pin p n N) (ζ : ℝ) (w : Wgt (UnitType p n N)) := - ∀ b : Pin p n N, pr w b.agree ≤ fee N ζ (planNew a.sp b.sp) - -structure PeelCell (w r : Wgt (UnitType p n N)) (D ζ : ℝ) (K : ℕ) - (S : Finset (UnitType p n N)) (a b : Pin p n N) : Prop where - pos : 0 < pr w (fun x => x ∈ S) - fixpin : ∀ x ∈ S, b.agree x - extendsSp : a.sp ≤ b.sp - bound : planRank b.sp ≤ planRank a.sp + K - clear : b.clear ζ (onW w (fun x => x ∈ S)) - density x : onW w (fun x => x ∈ S) x ≤ bp ((D+K+1)*N) * r x - -theorem heavy_leaf {r w : Wgt (UnitType p n N)} - {D ζ : ℝ} (hz : 0 < ζ) (hz' : ζ < 1) (hn : 0 < N) - (hR : ∀ a : Pin p n N, pr r a.agree ≤ fee N (ζ/4) (planRank a.sp)) - (hc : ∀ x, w x ≤ bp (D*N)*r x) (hw : ∀ x, 0 ≤ w x) - (R : Finset (UnitType p n N)) (a : Pin p n N) (hf : ∀ x ∈ R, a.agree x) - {K : ℕ} (hK : D + ζ ≤ (ζ-ζ/4)*K) - (hpos : bp (-ζ*N) < pr w (fun x => x ∈ R)) : - ∃ S : Finset (UnitType p n N), S ⊆ R ∧ ∃ b : Pin p n N, - PeelCell w r D ζ K S a b := by - classical - have hn' : 0 < (N:ℝ) := by exact_mod_cast hn - have hr : ∀ x, 0 ≤ r x := by - intro x - by_contra! h - exact not_lt_of_ge ((hw x).trans (hc x)) (mul_neg_of_pos_of_neg (bp_pos _) h) - let cut := bp (-ζ*N) - let q (b : Pin p n N) := planNew a.sp b.sp - let s (b : Pin p n N) : Finset (UnitType p n N) := R.filter b.agree - let c (b : Pin p n N) := pr w (fun x => x ∈ s b) - let heavy (b : Pin p n N) := a.sp ≤ b.sp ∧ cut * fee N ζ (q b) < c b - let T := {t : ℕ | ∃ b, heavy b ∧ q b = t} - have e1 : heavy a := by - have ha : s a = R := by ext x; simp [s]; tauto - refine ⟨le_rfl,?_⟩ - simpa only [q,planNew,sup_idem,Nat.sub_self,cut,c,ha,fee,Nat.cast_zero, - mul_zero,zero_mul,bp_zero,mul_one] using hpos - have bound (b : Pin p n N) (hh : heavy b) : q b ≤ K := by - have hmo : (planRank b.sp : ℝ) ≥ q b := by - have hg := plan_add_rank a.sp b.sp - rw [sup_eq_right.mpr hh.1] at hg - have hh' : q b ≤ planRank b.sp := by unfold q; omega - exact_mod_cast hh' - have he : cut * fee N ζ (q b) < bp (D*N) * fee N (ζ/4) (q b) := by - refine hh.2.trans_le ?_ - calc - c b ≤ pr w b.agree := - pr_mono hw (fun x h => (Finset.mem_filter.mp h).2) - _ ≤ bp (D*N)* pr r b.agree := pr_cap hc _ - _ ≤ _ := mul_le_mul_of_nonneg_left ((hR b).trans (by - unfold fee - apply bp_le - apply mul_le_mul_of_nonneg_right _ hn'.le - exact mul_le_mul_of_nonpos_left hmo (by linarith))) (bp_pos _).le - unfold cut fee at he - rw [← bp_add,← bp_add] at he - have hg (x y : ℝ) (h : bp x - not_lt_of_ge (bp_le e) h) - have h' := hg _ _ he - have hi : (ζ-ζ/4)*(q b:ℝ) < D+ζ := by - apply (mul_lt_mul_iff_left₀ hn').mp - linarith only [h'] - have hj := (mul_lt_mul_iff_right₀ (show 0 < ζ-ζ/4 by linarith)).mp (hi.trans_le hK) - exact_mod_cast hj.le - obtain ⟨b,hb,hT⟩ : ∃ b, heavy b ∧ q b = sSup T := - Nat.sSup_mem (show T.Nonempty from ⟨_,a,e1,rfl⟩) - (show BddAbove T from ⟨K,fun t ⟨b,h,r⟩ => r ▸ bound b h⟩) - have hcut := bp_pos (-ζ*N) - have hmass : 0 < c b := (mul_pos hcut (bp_pos _)).trans hb.2 - let v := onW w (fun x => x ∈ s b) - have hv : IsLaw v := normW_law (subW_nonneg hw _) hmass - have hg := plan_add_rank a.sp b.sp - rw [sup_eq_right.mpr hb.1] at hg - have hp := bound b hb - refine ⟨s b,Finset.filter_subset _ _,b,hmass,fun x h => (Finset.mem_filter.mp h).2, - hb.1, ?_, fun B => ?_, fun x => ?_⟩ - · change planNew _ _ ≤ _ at hp - omega - · by_contra! he - have hB := bp_pos (-(1-ζ)*(planNew b.sp B.sp)*N) - change fee N ζ _ < pr v B.agree at he - have he' := pr_of_on hw (fun x => x ∈ s b) B.agree - change _ = c b * pr v B.agree at he' - have hhpos : 0 < pr w (fun x => x ∈ s b ∧ B.agree x) := - he'.symm ▸ mul_pos hmass (lt_trans hB he) - obtain ⟨x,⟨hx,hx'⟩,_⟩ := exists_of_pr_pos hw hhpos - let J := Pin.make (b.sp⊔B.sp) x - have hjoin : c J = c b * pr v B.agree := by - have hxy (y) : y ∈ s J ↔ y ∈ s b ∧ B.agree y := by - have hy := Pin.combine (Finset.mem_filter.mp hx).2 hx' (y:=y) - change J.agree y ↔ b.agree y ∧ B.agree y at hy - simp only [s,Finset.mem_filter,hy,and_assoc] - simp_rw [← he',c,hxy] - have hu : q b + planNew b.sp B.sp = q J := planNew_mono_add hb.1 - have hj : heavy J := by - refine ⟨le_trans hb.1 le_sup_left, ?_⟩ - have hi : - fee N ζ (q J) = fee N ζ (q b)* fee N ζ (planNew b.sp B.sp) := by - unfold fee; rw [← bp_add,← hu] - push_cast; ring_nf - rw [hjoin,hi,← mul_assoc] - apply lt_trans (mul_lt_mul_of_pos_right hb.2 hB) - exact mul_lt_mul_of_pos_left he hmass - have hd : 0 < planNew b.sp B.sp := by - by_contra! hi - rw [show planNew b.sp B.sp=0 from Nat.eq_zero_of_le_zero hi] at he - have hh := pr_le_tot (p:=B.agree) hv.nz - rw [hv.total] at hh - simp only [fee,Nat.cast_zero,mul_zero,zero_mul,bp_zero] at he - linarith - have ha : q J ≤ sSup T := le_csSup - (show BddAbove T from ⟨K,fun t ⟨b,h,r⟩ => r ▸ bound b h⟩) - ⟨J,hj,rfl⟩ - omega - · apply (on_mon hw (mul_pos hcut (bp_pos (-(1-ζ)*(q b)*N))) hb.2.le x).trans - apply (mul_le_mul_of_nonneg_left (hc x) (inv_nonneg_of_nonneg (mul_pos hcut (bp_pos _)).le)).trans - rw [← mul_assoc,← bp_add,← bp_neg,← bp_add] - apply mul_le_mul_of_nonneg_right _ (hr x) - apply bp_le - have hk1 : 0 ≤ (q b:ℝ) := Nat.cast_nonneg _ - have hh : (q b:ℝ) ≤ K := by exact_mod_cast hp - nlinarith only [mul_le_mul_of_nonneg_right hh hn'.le, mul_lt_mul_of_pos_right hz' hn', - mul_nonneg hk1 (mul_pos hz hn').le] - -theorem peel_family {r w : Wgt (UnitType p n N)} - {D ζ : ℝ} (hz : 0 < ζ) (hz' : ζ < 1) (hn : 0 < N) - (hR : ∀ a : Pin p n N, pr r a.agree ≤ fee N (ζ/4) (planRank a.sp)) - (hc : ∀ x, w x ≤ bp (D*N)*r x) (hw : ∀ x, 0 ≤ w x) - (R : Finset (UnitType p n N)) (a : Pin p n N) (hf : ∀ x ∈ R, a.agree x) - {K : ℕ} (hK : D + ζ ≤ (ζ-ζ/4)*K) : - ∃ G : Finset (Finset (UnitType p n N)), - (∀ S ∈ G, S⊆R ∧ ∃ b, PeelCell w r D ζ K S a b) ∧ - (∀ x, ∀ S ∈ G, ∀ J ∈ G, x∈S → x∈J → S=J) ∧ - pr w (fun x => x ∈ R ∧ ¬∃ S∈G,x∈S) ≤ bp (-ζ*N) := by - classical - induction R using Finset.strongInductionOn with | _ R ih - by_cases hr : pr w (fun x => x∈R) ≤ bp (-ζ*N) - · exact ⟨∅,by simpa using hr⟩ - obtain ⟨S,hS,b,hb⟩ := heavy_leaf hz hz' hn hR hc hw R a hf hK (lt_of_not_ge hr) - have he := exists_of_pr_pos hw hb.pos - obtain ⟨G,hG,hU,hW⟩ := ih (R\ S) (Finset.sdiff_ssubset hS - (show S.Nonempty from ⟨he.choose,he.choose_spec.1⟩)) - (fun x h => hf x (Finset.mem_sdiff.mp h).1) - refine ⟨insert S G, fun J h => ?_, fun x J h J' h' g g' => ?_,?_⟩ - · rcases Finset.mem_insert.mp h with rfl|h - · exact ⟨hS,b,hb⟩ - · exact ⟨(hG J h).1.trans (Finset.sdiff_subset), (hG J h).2⟩ - · have hi (J) (h : J∈G) (g : x∈J) : x∉S := (Finset.mem_sdiff.mp ((hG J h).1 g)).2 - rcases Finset.mem_insert.mp h with h|h <;> rcases Finset.mem_insert.mp h' with h'|h' - · rw [h,h'] - · exact ((hi _ h' g') (h ▸ g)).elim - · exact ((hi _ h g) (h' ▸ g')).elim - · exact hU _ _ h _ h' g g' - · refine le_trans (pr_mono hw ?_) hW - intro x h - simp only [Finset.exists_mem_insert,not_or] at h - exact ⟨Finset.mem_sdiff.mpr ⟨h.1,h.2.1⟩,h.2.2⟩ - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RawFrameLaws + +namespace OAI + +/-! # Image Partitions -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix +open scoped BigOperators +variable {p : Shape} {n N : ℕ} + +theorem plan_mono {a b : Plan p n} (h : a ≤ b) : planRank a ≤ planRank b := + Finset.sum_le_sum fun i _ => Submodule.finrank_mono (h i) + +/-- Joint nominal rank modulo pins. -/ +def planNew (a b : Plan p n) := planRank (a⊔b) - planRank a + +theorem plan_add_rank (a b : Plan p n) : + planRank a + planNew a b = planRank (a⊔b) := + Nat.add_sub_of_le (plan_mono le_sup_left) + +theorem planNew_mono_add {a b c : Plan p n} (h : a ≤ b) : + planNew a b + planNew b c = planNew a (b⊔c) := by + have he := plan_add_rank a b + have hf := plan_add_rank b c + have hg := plan_add_rank a (b⊔c) + rw [sup_eq_right.mpr h] at he + rw [sup_eq_right.mpr (le_trans h le_sup_left)] at hg + omega + +def Pin.make (a : Plan p n) (x : UnitType p n N) : Pin p n N := ⟨a,images x⟩ + +theorem Pin.combine {a b : Pin p n N} {x y} (ha : a.agree x) (hb : b.agree x) : + (Pin.make (a.sp ⊔ b.sp) x).agree y ↔ a.agree y ∧ b.agree y := by + change (∀ i, ∀ v ∈ a.sp i ⊔ b.sp i, images y i *ᵥ v = images x i *ᵥ v) ↔ _ + constructor + · intro h + exact ⟨fun i v hv => (h i v (Submodule.mem_sup_left hv)).trans (ha _ v hv), + fun i v hv => (h i v (Submodule.mem_sup_right hv)).trans (hb _ v hv)⟩ + · rintro ⟨u,w⟩ i v hv + obtain ⟨l,hl,r,hr,rfl⟩ := Submodule.mem_sup.mp hv + rw [Matrix.mulVec_add,Matrix.mulVec_add,ha _ _ hl,hb _ _ hr,u _ _ hl,w _ _ hr] + +def fee (N : ℕ) (ζ : ℝ) (t : ℕ) := bp (-(1-ζ)*t*N) +def Pin.clear (a : Pin p n N) (ζ : ℝ) (w : Wgt (UnitType p n N)) := + ∀ b : Pin p n N, pr w b.agree ≤ fee N ζ (planNew a.sp b.sp) + +structure PeelCell (w r : Wgt (UnitType p n N)) (D ζ : ℝ) (K : ℕ) + (S : Finset (UnitType p n N)) (a b : Pin p n N) : Prop where + pos : 0 < pr w (fun x => x ∈ S) + fixpin : ∀ x ∈ S, b.agree x + extendsSp : a.sp ≤ b.sp + bound : planRank b.sp ≤ planRank a.sp + K + clear : b.clear ζ (onW w (fun x => x ∈ S)) + density x : onW w (fun x => x ∈ S) x ≤ bp ((D+K+1)*N) * r x + +theorem heavy_leaf {r w : Wgt (UnitType p n N)} + {D ζ : ℝ} (hz : 0 < ζ) (hz' : ζ < 1) (hn : 0 < N) + (hR : ∀ a : Pin p n N, pr r a.agree ≤ fee N (ζ/4) (planRank a.sp)) + (hc : ∀ x, w x ≤ bp (D*N)*r x) (hw : ∀ x, 0 ≤ w x) + (R : Finset (UnitType p n N)) (a : Pin p n N) (hf : ∀ x ∈ R, a.agree x) + {K : ℕ} (hK : D + ζ ≤ (ζ-ζ/4)*K) + (hpos : bp (-ζ*N) < pr w (fun x => x ∈ R)) : + ∃ S : Finset (UnitType p n N), S ⊆ R ∧ ∃ b : Pin p n N, + PeelCell w r D ζ K S a b := by + classical + have hn' : 0 < (N:ℝ) := by exact_mod_cast hn + have hr : ∀ x, 0 ≤ r x := by + intro x + by_contra! h + exact not_lt_of_ge ((hw x).trans (hc x)) (mul_neg_of_pos_of_neg (bp_pos _) h) + let cut := bp (-ζ*N) + let q (b : Pin p n N) := planNew a.sp b.sp + let s (b : Pin p n N) : Finset (UnitType p n N) := R.filter b.agree + let c (b : Pin p n N) := pr w (fun x => x ∈ s b) + let heavy (b : Pin p n N) := a.sp ≤ b.sp ∧ cut * fee N ζ (q b) < c b + let T := {t : ℕ | ∃ b, heavy b ∧ q b = t} + have e1 : heavy a := by + have ha : s a = R := by ext x; simp [s]; tauto + refine ⟨le_rfl,?_⟩ + simpa only [q,planNew,sup_idem,Nat.sub_self,cut,c,ha,fee,Nat.cast_zero, + mul_zero,zero_mul,bp_zero,mul_one] using hpos + have bound (b : Pin p n N) (hh : heavy b) : q b ≤ K := by + have hmo : (planRank b.sp : ℝ) ≥ q b := by + have hg := plan_add_rank a.sp b.sp + rw [sup_eq_right.mpr hh.1] at hg + have hh' : q b ≤ planRank b.sp := by unfold q; omega + exact_mod_cast hh' + have he : cut * fee N ζ (q b) < bp (D*N) * fee N (ζ/4) (q b) := by + refine hh.2.trans_le ?_ + calc + c b ≤ pr w b.agree := + pr_mono hw (fun x h => (Finset.mem_filter.mp h).2) + _ ≤ bp (D*N)* pr r b.agree := pr_cap hc _ + _ ≤ _ := mul_le_mul_of_nonneg_left ((hR b).trans (by + unfold fee + apply bp_le + apply mul_le_mul_of_nonneg_right _ hn'.le + exact mul_le_mul_of_nonpos_left hmo (by linarith))) (bp_pos _).le + unfold cut fee at he + rw [← bp_add,← bp_add] at he + have hg (x y : ℝ) (h : bp x + not_lt_of_ge (bp_le e) h) + have h' := hg _ _ he + have hi : (ζ-ζ/4)*(q b:ℝ) < D+ζ := by + apply (mul_lt_mul_iff_left₀ hn').mp + linarith only [h'] + have hj := (mul_lt_mul_iff_right₀ (show 0 < ζ-ζ/4 by linarith)).mp (hi.trans_le hK) + exact_mod_cast hj.le + obtain ⟨b,hb,hT⟩ : ∃ b, heavy b ∧ q b = sSup T := + Nat.sSup_mem (show T.Nonempty from ⟨_,a,e1,rfl⟩) + (show BddAbove T from ⟨K,fun t ⟨b,h,r⟩ => r ▸ bound b h⟩) + have hcut := bp_pos (-ζ*N) + have hmass : 0 < c b := (mul_pos hcut (bp_pos _)).trans hb.2 + let v := onW w (fun x => x ∈ s b) + have hv : IsLaw v := normW_law (subW_nonneg hw _) hmass + have hg := plan_add_rank a.sp b.sp + rw [sup_eq_right.mpr hb.1] at hg + have hp := bound b hb + refine ⟨s b,Finset.filter_subset _ _,b,hmass,fun x h => (Finset.mem_filter.mp h).2, + hb.1, ?_, fun B => ?_, fun x => ?_⟩ + · change planNew _ _ ≤ _ at hp + omega + · by_contra! he + have hB := bp_pos (-(1-ζ)*(planNew b.sp B.sp)*N) + change fee N ζ _ < pr v B.agree at he + have he' := pr_of_on hw (fun x => x ∈ s b) B.agree + change _ = c b * pr v B.agree at he' + have hhpos : 0 < pr w (fun x => x ∈ s b ∧ B.agree x) := + he'.symm ▸ mul_pos hmass (lt_trans hB he) + obtain ⟨x,⟨hx,hx'⟩,_⟩ := exists_of_pr_pos hw hhpos + let J := Pin.make (b.sp⊔B.sp) x + have hjoin : c J = c b * pr v B.agree := by + have hxy (y) : y ∈ s J ↔ y ∈ s b ∧ B.agree y := by + have hy := Pin.combine (Finset.mem_filter.mp hx).2 hx' (y:=y) + change J.agree y ↔ b.agree y ∧ B.agree y at hy + simp only [s,Finset.mem_filter,hy,and_assoc] + simp_rw [← he',c,hxy] + have hu : q b + planNew b.sp B.sp = q J := planNew_mono_add hb.1 + have hj : heavy J := by + refine ⟨le_trans hb.1 le_sup_left, ?_⟩ + have hi : + fee N ζ (q J) = fee N ζ (q b)* fee N ζ (planNew b.sp B.sp) := by + unfold fee; rw [← bp_add,← hu] + push_cast; ring_nf + rw [hjoin,hi,← mul_assoc] + apply lt_trans (mul_lt_mul_of_pos_right hb.2 hB) + exact mul_lt_mul_of_pos_left he hmass + have hd : 0 < planNew b.sp B.sp := by + by_contra! hi + rw [show planNew b.sp B.sp=0 from Nat.eq_zero_of_le_zero hi] at he + have hh := pr_le_tot (p:=B.agree) hv.nz + rw [hv.total] at hh + simp only [fee,Nat.cast_zero,mul_zero,zero_mul,bp_zero] at he + linarith + have ha : q J ≤ sSup T := le_csSup + (show BddAbove T from ⟨K,fun t ⟨b,h,r⟩ => r ▸ bound b h⟩) + ⟨J,hj,rfl⟩ + omega + · apply (on_mon hw (mul_pos hcut (bp_pos (-(1-ζ)*(q b)*N))) hb.2.le x).trans + apply (mul_le_mul_of_nonneg_left (hc x) (inv_nonneg_of_nonneg (mul_pos hcut (bp_pos _)).le)).trans + rw [← mul_assoc,← bp_add,← bp_neg,← bp_add] + apply mul_le_mul_of_nonneg_right _ (hr x) + apply bp_le + have hk1 : 0 ≤ (q b:ℝ) := Nat.cast_nonneg _ + have hh : (q b:ℝ) ≤ K := by exact_mod_cast hp + nlinarith only [mul_le_mul_of_nonneg_right hh hn'.le, mul_lt_mul_of_pos_right hz' hn', + mul_nonneg hk1 (mul_pos hz hn').le] + +theorem peel_family {r w : Wgt (UnitType p n N)} + {D ζ : ℝ} (hz : 0 < ζ) (hz' : ζ < 1) (hn : 0 < N) + (hR : ∀ a : Pin p n N, pr r a.agree ≤ fee N (ζ/4) (planRank a.sp)) + (hc : ∀ x, w x ≤ bp (D*N)*r x) (hw : ∀ x, 0 ≤ w x) + (R : Finset (UnitType p n N)) (a : Pin p n N) (hf : ∀ x ∈ R, a.agree x) + {K : ℕ} (hK : D + ζ ≤ (ζ-ζ/4)*K) : + ∃ G : Finset (Finset (UnitType p n N)), + (∀ S ∈ G, S⊆R ∧ ∃ b, PeelCell w r D ζ K S a b) ∧ + (∀ x, ∀ S ∈ G, ∀ J ∈ G, x∈S → x∈J → S=J) ∧ + pr w (fun x => x ∈ R ∧ ¬∃ S∈G,x∈S) ≤ bp (-ζ*N) := by + classical + induction R using Finset.strongInductionOn with | _ R ih + by_cases hr : pr w (fun x => x∈R) ≤ bp (-ζ*N) + · exact ⟨∅,by simpa using hr⟩ + obtain ⟨S,hS,b,hb⟩ := heavy_leaf hz hz' hn hR hc hw R a hf hK (lt_of_not_ge hr) + have he := exists_of_pr_pos hw hb.pos + obtain ⟨G,hG,hU,hW⟩ := ih (R\ S) (Finset.sdiff_ssubset hS + (show S.Nonempty from ⟨he.choose,he.choose_spec.1⟩)) + (fun x h => hf x (Finset.mem_sdiff.mp h).1) + refine ⟨insert S G, fun J h => ?_, fun x J h J' h' g g' => ?_,?_⟩ + · rcases Finset.mem_insert.mp h with rfl|h + · exact ⟨hS,b,hb⟩ + · exact ⟨(hG J h).1.trans (Finset.sdiff_subset), (hG J h).2⟩ + · have hi (J) (h : J∈G) (g : x∈J) : x∉S := (Finset.mem_sdiff.mp ((hG J h).1 g)).2 + rcases Finset.mem_insert.mp h with h|h <;> rcases Finset.mem_insert.mp h' with h'|h' + · rw [h,h'] + · exact ((hi _ h' g') (h ▸ g)).elim + · exact ((hi _ h g) (h' ▸ g')).elim + · exact hU _ _ h _ h' g g' + · refine le_trans (pr_mono hw ?_) hW + intro x h + simp only [Finset.exists_mem_insert,not_or] at h + exact ⟨Finset.mem_sdiff.mpr ⟨h.1,h.2.1⟩,h.2.2⟩ + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/IncompatibleMassBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/IncompatibleMassBounds.lean index d92d1b238aa3b3e52ec64a57a6150daf72ffca0f..d29d0fffd557b04abe07ec0ba2592871561e6689 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/IncompatibleMassBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/IncompatibleMassBounds.lean @@ -1,147 +1,147 @@ -import OAI.Combinatorics.HadwigerCounterexample.CompatibleTableEvents - -namespace OAI - -/-! # Incompatible Mass Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix LinearMap Function -open scoped BigOperators Topology -open Template -namespace StatusAnalysis -open PreparationParameters Station PredictionClass -variable {p : Shape} {n N K M s0 : ℕ} {q : PreparationParameters} - -def feeSeal (p:Shape) (K:ℕ) := (1/4 : ℝ)/num (Fin (2^deckMax p K)) -theorem feeSeal_pos (p:Shape) (K:ℕ) : 0pr (pairW (f i.1) (f i.2)) P) := by - rw [←mix_data]; unfold pr; rw [mixW_avg] - -set_option maxHeartbeats 1400000 in -theorem sparks_extract (m:Mixer p n) (U:Wgt (UnitType p n N)) (z:BMark p n N) (r:F) - (w:LeafMixture p n N) (t: Station p n N q.pins w) (ht:t.bank) - (hE:AnalyticParameters p M q s0) - (h:Settled w m q U z r) - (hv:0P x∧¬secureAt p w.rooting x) + - ∑ i:Scrip p q.pins,t.berth i.2.2 m i.2.1 U (feeSeal p q.pins) := by - classical - intro P f v - obtain ⟨hp,hK,hw⟩:= h.readyC - obtain ⟨hx,hy⟩:= rebuild hp.nz hK.part (fun i hi=>(hK.leaf _ hi).pos) hv - let u:= portionW U w.T; let A (i:w.T):= partW U i.val; let W := pairW u u - have hm : IsLaw W:=pairW_law hx hx - have hu i:IsLaw (A i):=on_law hp.nz (hK.leaf _ i.property).pos - let X:= UnitType p n N; let P':=fun x:X×X=> P x ∧ ¬secureAt p w.rooting x - let J:=Scrip p q.pins - let G (j:J) (i:w.T×w.T):=charter t j.2.2 m j.2.1 U (feeSeal p q.pins) i - let S(i:w.T×w.T) := pairW (A i.1) (A i.2) - have he : - ∀ i:w.T×w.T,pr (S i) P ≤ 2*pr (S i) P'+ind (∃ j:J,G j i) := by - intro i - have hS:IsLaw (S i):=pairW_law (hu _) (hu _) - have hi (x:X×X) (hx:S i x ≠0) : x.1∈i.1.val ∧ x.2∈i.2.val := - ⟨(onW_ne (left_ne_zero_of_mul hx)).1,(onW_ne (right_ne_zero_of_mul hx)).1⟩ - by_cases hC : ∃ j:J,G j i - · rw [ind_one hC]; exact (pr_le_tot hS.nz).trans (hS.total.le.trans - (le_add_of_nonneg_left (mul_nonneg (by norm_num) (pr_nonneg hS.nz)))) - rw [ind_zero hC,add_zero] - by_cases he : pr (S i) P≤0 - · exact he.trans (mul_nonneg (by norm_num) (pr_nonneg hS.nz)) - · have he' : pr (S i) P=1 := by - obtain ⟨x,hx,hx'⟩:=exists_of_pr_pos hS.nz (lt_of_not_ge he) - obtain ⟨T,hT,hA,hB⟩:=h.hard - obtain ⟨b0,h1,_⟩:=hB _ i.1.property; obtain ⟨b2,h2,_⟩:=hB _ i.2.property - have hp' (y : X×X) (hy:S i y≠0):P y := by - obtain ⟨hβ,hβ'⟩:= hi x hx'.ne' - obtain ⟨ha,hb⟩:= hi y hy - have he:= phase_fixed z T _ _ _ _ h1 h2 ha hβ hb hβ' (hA _ i.1.property _ ha) - (hA _ i.2.property _ hb) - exact he.trans hx - have hf' : pr (S i) P=pr (S i) (fun _=>True):= avg_congr (fun i hi=> (ind_one (hp' _ hi)).trans - ind_true.symm) - rw [hf',pr_true,hS.total] - let B:= Fin (2^deckMax p q.pins) - let Q j (x:X×X):=P x∧ berthTicket (w.pin i.1.val) (w.pin i.2.val) (t.mails i.1 i.2 j) x - have hiP x (hx:S i x ≠0) (hP:P x):P' x∨∃ j,Q j x := by - by_cases hp :secureAt p w.rooting x - · right - obtain ⟨j,hj⟩:= issueTicket x.1 x.2 w t i.1 i.2 hK.part (hi x hx).1 (hi x hx).2 ht hp - exact ⟨j,hP,hj⟩ - exact Or.inl ⟨hP,hp⟩ - let a:=feeSeal p q.pins - have hD j: pr (S i) (Q j)<2*a:= lt_of_not_ge (fun h' => hC ( - invoke t i.1 i.2 U m z j r a (feeSeal_pos _ _) hE h ht h')) - have hz : pr (S i) P≤ pr (S i) P'+1/2 := by - refine ((pr_on_mono hS.nz hiP).trans (pr_or_le hS.nz)).trans (add_le_add_right ?_ _) - refine (pr_exists_le hS.nz _).trans ((Finset.sum_le_sum fun i _=>(hD i).le).trans_eq ?_) - simp only [sum_const,card_univ,nsmul_eq_mul]; unfold a feeSeal - change num B*(2*(1/4/num B))=_ - have hh : 0pr (S i) P) := by - have hy : f=mixW u A:=hy - unfold v; rw [hy] - exact mix_parade .. - rw [hz,hz] - refine (avg_mono hm.nz he).trans ?_ - rw [avg_add,avg_mul'] - exact add_le_add_right (pr_exists_le hm.nz G) _ - -variable {l:Filter ℕ} {m:cycleM p} {w:tale p M} {s:rhythms p M} - -set_option maxHeartbeats 1400000 in -theorem dim_end (h:veil p M q s0 l m s w) (t:Stations p M q.pins s) (ht:∀ᶠ n in l,(t n).bank) - (hL:l.NeBot) - (b:Sketch p M) (hb:q.bright l p M m s b) (hf:q.glimmer l p M w s b) : False := by - classical - obtain ⟨heq,δ,hδ,hU⟩:=hf - let N (n:ℕ):= M*n; let z n:=((N n):ℝ); let K:=q.pins; let J:= Scrip p q.pins; let a:= feeSeal p K - have hz : Tendsto (fun n:ℕ=>(n:ℝ)) l atTop:= tendsto_natCast_atTop_atTop.mono_left h.timeL - let Ω (j:J) n:= (t n).berth j.2.2 (m n) j.2.1 (w n) a *z n^4 - have ho (j:J) : Tendsto (Ω j) l (𝓝 0) := by - have hk := ((dimBerth t h j.2.2 j.2.1 (feeSeal_pos p K)).poly hz 4).lim hz - have hl := hk.mul_const ((M:ℝ)^4) - rw [zero_mul] at hl - exact hl.congr (fun i=>by unfold Ω z N; push_cast; ring) - have hz' := trend_sizes l h.timeL h.easel.enter.first.hM - have hR:= tendsto_finsetSum univ (fun j _=>ho j) - have he: ∀ᶠ i in l,∑ j:J,Ω j i<δ/2:=hR.eventually - (gt_mem_nhds (by simp only [sum_const_zero]; positivity)) - have hi : ∀ᶠ n in l,False := by - filter_upwards [h.moment,ht,h.durableS.mass.positive,h.durableS.shape, - hU,hb.engraved,hz'.2.eventually (eventually_gt_atTop 0),he] with n hn ht hM hK hL hB hz hT - obtain ⟨hh,hX,hF⟩:=hL - let W:=s n - have hv : Settled W (m n) q (w n) (b.m n) b.r := by - refine ⟨⟨hn.1.law,hK.1,fun i hi x hx=>?_⟩,hh⟩ - obtain ⟨hA,hB,hC⟩:=hB i hi x hx - exact ⟨hK.2 i hi x hx,hC heq,fun i=>(hA.1 i).2,hB⟩ - have hm : matchProg b n=shimmer (b.m n) b.r:= by unfold matchProg; rw [heq]; rfl - have heq := sparks_extract (m n) (w n) (b.m n) b.r W (t n) ht h.easel hv hM - dsimp only at heq; rw [← hm] at heq - let u:= glow s w b n - let B (j:J):=(t n).berth j.2.2 (m n) j.2.1 (w n) a - change u ≤ 2*gleam s w b n+∑ j:J,B j at heq - change ∑ j:J,B j*z n^4 <_ at hT - rw [← Finset.sum_mul] at hT - have hz :0< z n^4:=pow_pos hz _ - have hh := (lt_div_iff₀ hz).mpr hT - change δ/(z n^4)≤ u at hX - change _≤0.001*u at hF - rw [show δ/2/z n^4=δ/z n^4/2 from by ring] at hh - linarith only [hh,hX,hF,heq,div_pos hδ hz] - exact hi.exists.elim (fun _ h=>h) -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CompatibleTableEvents + +namespace OAI + +/-! # Incompatible Mass Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix LinearMap Function +open scoped BigOperators Topology +open Template +namespace StatusAnalysis +open PreparationParameters Station PredictionClass +variable {p : Shape} {n N K M s0 : ℕ} {q : PreparationParameters} + +def feeSeal (p:Shape) (K:ℕ) := (1/4 : ℝ)/num (Fin (2^deckMax p K)) +theorem feeSeal_pos (p:Shape) (K:ℕ) : 0pr (pairW (f i.1) (f i.2)) P) := by + rw [←mix_data]; unfold pr; rw [mixW_avg] + +set_option maxHeartbeats 1400000 in +theorem sparks_extract (m:Mixer p n) (U:Wgt (UnitType p n N)) (z:BMark p n N) (r:F) + (w:LeafMixture p n N) (t: Station p n N q.pins w) (ht:t.bank) + (hE:AnalyticParameters p M q s0) + (h:Settled w m q U z r) + (hv:0P x∧¬secureAt p w.rooting x) + + ∑ i:Scrip p q.pins,t.berth i.2.2 m i.2.1 U (feeSeal p q.pins) := by + classical + intro P f v + obtain ⟨hp,hK,hw⟩:= h.readyC + obtain ⟨hx,hy⟩:= rebuild hp.nz hK.part (fun i hi=>(hK.leaf _ hi).pos) hv + let u:= portionW U w.T; let A (i:w.T):= partW U i.val; let W := pairW u u + have hm : IsLaw W:=pairW_law hx hx + have hu i:IsLaw (A i):=on_law hp.nz (hK.leaf _ i.property).pos + let X:= UnitType p n N; let P':=fun x:X×X=> P x ∧ ¬secureAt p w.rooting x + let J:=Scrip p q.pins + let G (j:J) (i:w.T×w.T):=charter t j.2.2 m j.2.1 U (feeSeal p q.pins) i + let S(i:w.T×w.T) := pairW (A i.1) (A i.2) + have he : + ∀ i:w.T×w.T,pr (S i) P ≤ 2*pr (S i) P'+ind (∃ j:J,G j i) := by + intro i + have hS:IsLaw (S i):=pairW_law (hu _) (hu _) + have hi (x:X×X) (hx:S i x ≠0) : x.1∈i.1.val ∧ x.2∈i.2.val := + ⟨(onW_ne (left_ne_zero_of_mul hx)).1,(onW_ne (right_ne_zero_of_mul hx)).1⟩ + by_cases hC : ∃ j:J,G j i + · rw [ind_one hC]; exact (pr_le_tot hS.nz).trans (hS.total.le.trans + (le_add_of_nonneg_left (mul_nonneg (by norm_num) (pr_nonneg hS.nz)))) + rw [ind_zero hC,add_zero] + by_cases he : pr (S i) P≤0 + · exact he.trans (mul_nonneg (by norm_num) (pr_nonneg hS.nz)) + · have he' : pr (S i) P=1 := by + obtain ⟨x,hx,hx'⟩:=exists_of_pr_pos hS.nz (lt_of_not_ge he) + obtain ⟨T,hT,hA,hB⟩:=h.hard + obtain ⟨b0,h1,_⟩:=hB _ i.1.property; obtain ⟨b2,h2,_⟩:=hB _ i.2.property + have hp' (y : X×X) (hy:S i y≠0):P y := by + obtain ⟨hβ,hβ'⟩:= hi x hx'.ne' + obtain ⟨ha,hb⟩:= hi y hy + have he:= phase_fixed z T _ _ _ _ h1 h2 ha hβ hb hβ' (hA _ i.1.property _ ha) + (hA _ i.2.property _ hb) + exact he.trans hx + have hf' : pr (S i) P=pr (S i) (fun _=>True):= avg_congr (fun i hi=> (ind_one (hp' _ hi)).trans + ind_true.symm) + rw [hf',pr_true,hS.total] + let B:= Fin (2^deckMax p q.pins) + let Q j (x:X×X):=P x∧ berthTicket (w.pin i.1.val) (w.pin i.2.val) (t.mails i.1 i.2 j) x + have hiP x (hx:S i x ≠0) (hP:P x):P' x∨∃ j,Q j x := by + by_cases hp :secureAt p w.rooting x + · right + obtain ⟨j,hj⟩:= issueTicket x.1 x.2 w t i.1 i.2 hK.part (hi x hx).1 (hi x hx).2 ht hp + exact ⟨j,hP,hj⟩ + exact Or.inl ⟨hP,hp⟩ + let a:=feeSeal p q.pins + have hD j: pr (S i) (Q j)<2*a:= lt_of_not_ge (fun h' => hC ( + invoke t i.1 i.2 U m z j r a (feeSeal_pos _ _) hE h ht h')) + have hz : pr (S i) P≤ pr (S i) P'+1/2 := by + refine ((pr_on_mono hS.nz hiP).trans (pr_or_le hS.nz)).trans (add_le_add_right ?_ _) + refine (pr_exists_le hS.nz _).trans ((Finset.sum_le_sum fun i _=>(hD i).le).trans_eq ?_) + simp only [sum_const,card_univ,nsmul_eq_mul]; unfold a feeSeal + change num B*(2*(1/4/num B))=_ + have hh : 0pr (S i) P) := by + have hy : f=mixW u A:=hy + unfold v; rw [hy] + exact mix_parade .. + rw [hz,hz] + refine (avg_mono hm.nz he).trans ?_ + rw [avg_add,avg_mul'] + exact add_le_add_right (pr_exists_le hm.nz G) _ + +variable {l:Filter ℕ} {m:cycleM p} {w:tale p M} {s:rhythms p M} + +set_option maxHeartbeats 1400000 in +theorem dim_end (h:veil p M q s0 l m s w) (t:Stations p M q.pins s) (ht:∀ᶠ n in l,(t n).bank) + (hL:l.NeBot) + (b:Sketch p M) (hb:q.bright l p M m s b) (hf:q.glimmer l p M w s b) : False := by + classical + obtain ⟨heq,δ,hδ,hU⟩:=hf + let N (n:ℕ):= M*n; let z n:=((N n):ℝ); let K:=q.pins; let J:= Scrip p q.pins; let a:= feeSeal p K + have hz : Tendsto (fun n:ℕ=>(n:ℝ)) l atTop:= tendsto_natCast_atTop_atTop.mono_left h.timeL + let Ω (j:J) n:= (t n).berth j.2.2 (m n) j.2.1 (w n) a *z n^4 + have ho (j:J) : Tendsto (Ω j) l (𝓝 0) := by + have hk := ((dimBerth t h j.2.2 j.2.1 (feeSeal_pos p K)).poly hz 4).lim hz + have hl := hk.mul_const ((M:ℝ)^4) + rw [zero_mul] at hl + exact hl.congr (fun i=>by unfold Ω z N; push_cast; ring) + have hz' := trend_sizes l h.timeL h.easel.enter.first.hM + have hR:= tendsto_finsetSum univ (fun j _=>ho j) + have he: ∀ᶠ i in l,∑ j:J,Ω j i<δ/2:=hR.eventually + (gt_mem_nhds (by simp only [sum_const_zero]; positivity)) + have hi : ∀ᶠ n in l,False := by + filter_upwards [h.moment,ht,h.durableS.mass.positive,h.durableS.shape, + hU,hb.engraved,hz'.2.eventually (eventually_gt_atTop 0),he] with n hn ht hM hK hL hB hz hT + obtain ⟨hh,hX,hF⟩:=hL + let W:=s n + have hv : Settled W (m n) q (w n) (b.m n) b.r := by + refine ⟨⟨hn.1.law,hK.1,fun i hi x hx=>?_⟩,hh⟩ + obtain ⟨hA,hB,hC⟩:=hB i hi x hx + exact ⟨hK.2 i hi x hx,hC heq,fun i=>(hA.1 i).2,hB⟩ + have hm : matchProg b n=shimmer (b.m n) b.r:= by unfold matchProg; rw [heq]; rfl + have heq := sparks_extract (m n) (w n) (b.m n) b.r W (t n) ht h.easel hv hM + dsimp only at heq; rw [← hm] at heq + let u:= glow s w b n + let B (j:J):=(t n).berth j.2.2 (m n) j.2.1 (w n) a + change u ≤ 2*gleam s w b n+∑ j:J,B j at heq + change ∑ j:J,B j*z n^4 <_ at hT + rw [← Finset.sum_mul] at hT + have hz :0< z n^4:=pow_pos hz _ + have hh := (lt_div_iff₀ hz).mpr hT + change δ/(z n^4)≤ u at hX + change _≤0.001*u at hF + rw [show δ/2/z n^4=δ/z n^4/2 from by ring] at hh + linarith only [hh,hX,hF,heq,div_pos hδ hz] + exact hi.exists.elim (fun _ h=>h) +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentColumnBatches.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentColumnBatches.lean index 3a9818440b834b496dd999212aba7a9f61051a18..a25581c80d6bb519d774051179b323fa906a12d3 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentColumnBatches.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentColumnBatches.lean @@ -1,107 +1,107 @@ -import OAI.Combinatorics.HadwigerCounterexample.AmbientBatchSlots - -namespace OAI - -/-! # Independent Column Batches -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix LinearMap Module Finset Function -variable {I G J A B : Type} [Fintype I] [Fintype G] [Fintype J] [Fintype A] [Fintype B] -variable [DecidableEq I] [DecidableEq J] [DecidableEq G] -variable {p : Shape} {n N : ℕ} - -theorem joint_map {A B : I→ Type} [∀ i,Fintype (A i)] [∀ i,Fintype (B i)] - (w : ∀ i,Wgt (A i)) (f : ∀ i,A i→ B i) : - mapW (prodW w) (fun x i => f i (x i))=prodW (fun i => mapW (w i) (f i)) := by - classical - funext x - unfold mapW - simp_rw [funext_iff] - exact prodW_pr _ (fun i y => f i y=x i) - -def rawC (m : Mixer p n) (N : ℕ) : Wgt (Oframe p n N) := unifOn (FramesAt (gramCond m)) -def peer (p : Shape) {n} (A B : Mat (Row p n) I) {N} (x : Oframe p n N) : - Rack I N := (primary x.1*A,primary x.2*B) - -theorem peer_cap (m : Mixer p n) (N : ℕ) (hN : 2*num (Full p n) rawC m N) - -abbrev NomQuery (p : Shape) (n : ℕ) {I G : Type} (g : Route I G) := - ∀ i, Mat (Row p n) (Port g i) -variable {g : Route I G} -def peekR (p : Shape) {n} (g : Route I G) (A B : NomQuery p n g) - {N} (x : Forum p n N G) := - (rackEquiv g N).symm (fun i => peer p (A i) (B i) (x i)) -def database (m : Mixer p n) (A B : NomQuery p n g) : GeoM g := - fun i => pullM (A i) (B i) (selfM p n m.mixM) - -theorem law_peekR (m : Mixer p n) {N : ℕ} (hN : 2*num (Full p n) peer p (A i) (B i) (x i) - have h : mapW v f=mapW w E := by - unfold v f w E forumLaw - rw [joint_map (B:=fun i => Rack (Port g i) N) (w:=fun (_:G) => rawC m N) - (f:=fun i => peer p (A i) (B i)),station_split] - apply congrArg (prodW (ι:=G)) - funext i - exact peer_cap m N hN (ha i) (hb i) - change mapW v (E.symm ∘ f)=w - rw [←mapW_nested,h] - funext x - rw [mapW_equiv_val,mapW_equiv_val,Equiv.symm_symm,Equiv.symm_apply_apply] - -/-- Merge two endpoints of raw frame. Assign ports according -to their endpoint. -/ -abbrev Ports (p : Shape) := Bool × Comp p.g -def mergeR (p : Shape) {n N} : - UnitType p n N ≃ Forum p n N (Ports p) where - toFun x i := onSide x i.1 i.2 - invFun x := (fun i => x (true,i),fun i => x (false,i)) - left_inv _ := rfl - right_inv x := funext fun i => by rcases i with ⟨c|c,z⟩ <;> rfl - -theorem law_mergeR (m : Mixer p n) (N : ℕ) : - mapW (pairW (raw m N) (raw m N)) (mergeR p)=forumLaw m N := by - classical - funext x - rw [mapW_equiv_val,forumLaw,prodW,Fintype.prod_prod_type,Fintype.prod_bool] - rfl - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.AmbientBatchSlots + +namespace OAI + +/-! # Independent Column Batches -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix LinearMap Module Finset Function +variable {I G J A B : Type} [Fintype I] [Fintype G] [Fintype J] [Fintype A] [Fintype B] +variable [DecidableEq I] [DecidableEq J] [DecidableEq G] +variable {p : Shape} {n N : ℕ} + +theorem joint_map {A B : I→ Type} [∀ i,Fintype (A i)] [∀ i,Fintype (B i)] + (w : ∀ i,Wgt (A i)) (f : ∀ i,A i→ B i) : + mapW (prodW w) (fun x i => f i (x i))=prodW (fun i => mapW (w i) (f i)) := by + classical + funext x + unfold mapW + simp_rw [funext_iff] + exact prodW_pr _ (fun i y => f i y=x i) + +def rawC (m : Mixer p n) (N : ℕ) : Wgt (Oframe p n N) := unifOn (FramesAt (gramCond m)) +def peer (p : Shape) {n} (A B : Mat (Row p n) I) {N} (x : Oframe p n N) : + Rack I N := (primary x.1*A,primary x.2*B) + +theorem peer_cap (m : Mixer p n) (N : ℕ) (hN : 2*num (Full p n) rawC m N) + +abbrev NomQuery (p : Shape) (n : ℕ) {I G : Type} (g : Route I G) := + ∀ i, Mat (Row p n) (Port g i) +variable {g : Route I G} +def peekR (p : Shape) {n} (g : Route I G) (A B : NomQuery p n g) + {N} (x : Forum p n N G) := + (rackEquiv g N).symm (fun i => peer p (A i) (B i) (x i)) +def database (m : Mixer p n) (A B : NomQuery p n g) : GeoM g := + fun i => pullM (A i) (B i) (selfM p n m.mixM) + +theorem law_peekR (m : Mixer p n) {N : ℕ} (hN : 2*num (Full p n) peer p (A i) (B i) (x i) + have h : mapW v f=mapW w E := by + unfold v f w E forumLaw + rw [joint_map (B:=fun i => Rack (Port g i) N) (w:=fun (_:G) => rawC m N) + (f:=fun i => peer p (A i) (B i)),station_split] + apply congrArg (prodW (ι:=G)) + funext i + exact peer_cap m N hN (ha i) (hb i) + change mapW v (E.symm ∘ f)=w + rw [←mapW_nested,h] + funext x + rw [mapW_equiv_val,mapW_equiv_val,Equiv.symm_symm,Equiv.symm_apply_apply] + +/-- Merge two endpoints of raw frame. Assign ports according +to their endpoint. -/ +abbrev Ports (p : Shape) := Bool × Comp p.g +def mergeR (p : Shape) {n N} : + UnitType p n N ≃ Forum p n N (Ports p) where + toFun x i := onSide x i.1 i.2 + invFun x := (fun i => x (true,i),fun i => x (false,i)) + left_inv _ := rfl + right_inv x := funext fun i => by rcases i with ⟨c|c,z⟩ <;> rfl + +theorem law_mergeR (m : Mixer p n) (N : ℕ) : + mapW (pairW (raw m N) (raw m N)) (mergeR p)=forumLaw m N := by + classical + funext x + rw [mapW_equiv_val,forumLaw,prodW,Fintype.prod_prod_type,Fintype.prod_bool] + rfl + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentPhaseBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentPhaseBounds.lean index 68ebb1d707adc31e4bf0dee54502aeefa2b69f3a..8c826baf290c0f226e760e918ebf3aa6cc604b5b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentPhaseBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentPhaseBounds.lean @@ -1,169 +1,169 @@ -import OAI.Combinatorics.HadwigerCounterexample.ChannelFrameLaws -import OAI.Combinatorics.HadwigerCounterexample.PrimalChannelTests -import OAI.Combinatorics.HadwigerCounterexample.MatrixRankCounting - -namespace OAI - -/-! # Independent Phase Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Finset -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {J K : Type} [Fintype J] [Fintype K] - -abbrev PhasePair (p : Shape) (N : ℕ) := HCube p N × HCube p N -abbrev Party := Vec Bool - -def uPhase (p : Shape) {N} (v : HCube p N) : Ambient p N →ₗ[F] F := - ∑ e : Comp p.g, mpair ((v e).2*(v e).1ᵀ) ∘ₗ LinearMap.proj e - -def joinPhase (p : Shape) {N} (v : PhasePair p N) (o : Party) := - ∑ b : Bool, o b • uPhase p (onSide v b) - -/-- Read the whole channel frames of a unit. -/ -def listens (p : Shape) {n N} (x : UnitType p n N) : PhasePair p N := - Prod.map (hcube p) (hcube p) x - -def tone (p : Shape) {n N} (x : UnitType p n N) (S : Party) (T : Ambient p N) := - joinPhase p (listens p x) S T - -def pitch (p : Shape) {n N} (Δ : UnitType p n N → Ambient p N) - (w : Wgt (UnitType p n N)) (S R : Party) := - avg (pairW w w) (fun x => - wsign (tone p x.1 R (Δ x.2)+tone p x.2 S (Δ x.1))) - -theorem phase_actual (p : Shape) {n N} (x : Orient p n N) : - uPhase p (hcube p x)=ufun x := by - apply LinearMap.ext - intro v - simp only [uPhase,LinearMap.sum_apply]; rfl - -private theorem perm_pair (A B : Mat J K) (M : Mat J J) : - mpair (A*Bᵀ) M=mpair (M*B) A := by - - change (A*Bᵀ*Mᵀ).trace=(M*B*Aᵀ).trace - - rw [← Matrix.trace_transpose (M*B*Aᵀ),Matrix.transpose_mul,Matrix.transpose_mul, - Matrix.transpose_transpose,Matrix.mul_assoc] - -variable [DecidableEq J] [DecidableEq K] - -private theorem iid_prodM (M : Mat J J) : - avg (pairW (unif : Wgt (Mat J K)) unif) (fun x => wsign (mpair (x.2*x.1ᵀ) M)) = - bp (- (M.rank:ℝ) * num K) := by - classical - rw [pairW_avg] - obtain ⟨A,B,hA,hB,hM⟩ := rank_product M - have he (y : Mat J K) : - avg unif (fun a : Mat J K => wsign (mpair (a*yᵀ) M)) = ind (B*y=0) := by - have ht : mpair (M*y)=0 ↔ B*y=0 := by - rw [ show M*y=A*B*y from congrArg (·*y) hM.symm,Matrix.mul_assoc] - constructor - · intro h - have he := mpair_nondeg _ h - exact matrix_cancel_left hA (B*y) 0 (he.trans (Matrix.mul_zero A).symm) - intro h - rw [h,Matrix.mul_zero] - exact LinearMap.ext fun x => by rw [mpair_comm,map_zero,LinearMap.zero_apply] - simp_rw [perm_pair,wsign_lin] - rw [ht] - change avg unif (fun y => avg unif _) = _ - simp_rw [he] - change pr unif _ = _ - have hf : pr unif (fun y : Mat J K => B*y=0)=bp (-num (Fin M.rank)*num K) := by - have hx : Function.Injective Bᵀ.mulVec := - transpose_surj_iff.mp (by rw [transpose_transpose]; exact hB) - simpa only [Matrix.transpose_transpose] using - pr_gram_fixed hx (0:Mat (Fin M.rank) K) - rw [hf,num,Fintype.card_fin] - -omit [Fintype J] in -theorem wsign_sum (s : Finset J) (f : J → F) : - wsign (∑ i∈s,f i)=∏ i∈s,wsign (f i) := by - classical - induction s using Finset.induction with - | empty => simp - | insert a s h ih => rw [Finset.sum_insert h,Finset.prod_insert h,wsign_add,ih] - -theorem lawH_law (p : Shape) (N : ℕ) : IsLaw (lawH p N) := - prodW_law (fun _ => pairW_law unif_law unif_law) - -theorem lawH_phased (x : Ambient p N) : - avg (lawH p N) (fun y => wsign (uPhase p y x)) = bp (- (p.h:ℝ) * epoch p x) := by - classical - let w (i : Comp p.g) := (pairW unif unif : Wgt (HFrame p N)) - let f (i : Comp p.g) (x' : HFrame p N) := wsign (mpair (x'.2*x'.1ᵀ) (x i)) - have hh y : wsign (uPhase p y x)= prodW f y := by - rw [uPhase,LinearMap.sum_apply, wsign_sum]; rfl - change avg (prodW w) _ = _ - simp_rw [hh] - rw [prodW_avg] - have hg i : avg (w i) (f i)=bp (- (p.h:ℝ)*(x i).rank) := by - change avg (pairW unif unif) _ = _ - refine (iid_prodM (x i) (K:=Chan p)).trans ?_ - congr 1 - simp only [Chan,num,Fintype.card_fin] - ring - simp_rw [hg] - rw [←bp_sum,←Finset.mul_sum,←Nat.cast_sum,epoch] - -def freeH (p : Shape) (N : ℕ) := pairW (lawH p N) (lawH p N) - -theorem freeH_law (p : Shape) (N : ℕ) : IsLaw (freeH p N) := - pairW_law (lawH_law p N) (lawH_law p N) - -set_option maxHeartbeats 800000 in -theorem free_phase {S : Party} (x : Ambient p N) (h : S≠0) : - let Q := avg (freeH p N) (fun y => wsign (joinPhase p y S x)); - 0 ≤ Q ∧ Q ≤ bp (- (p.h:ℝ)* epoch p x) := by - classical - let T (b : F) := avg (lawH p N) (fun y => wsign (b*uPhase p y x)) - have he : - avg (freeH p N) (fun y => wsign (joinPhase p y S x))=T (S true)*T (S false) := by - have hh y : - wsign (joinPhase p y S x)= - wsign (S true*uPhase p y.1 x)*wsign (S false*uPhase p y.2 x) := by - rw [joinPhase, Fintype.sum_bool,LinearMap.add_apply,wsign_add] - rfl - simp_rw [hh] - exact pairW_separate (lawH p N) (fun y => wsign (S true*uPhase p y x)) - (lawH p N) (fun y => wsign (S false*uPhase p y x)) - rw [he] - let B := bp (- (p.h:ℝ) * epoch p x) - have h0 : T 0=1 := by - unfold T; simp only [zero_mul,wsign_zero, (lawH_law p N).avg_const] - have h1 : T 1=B := by unfold T; simp only [one_mul,lawH_phased,B] - have hz : 0≤ B := (bp_pos _).le - have hl : B ≤1 := by - unfold B - rw [←bp_zero] - exact bp_le (mul_nonpos_of_nonpos_of_nonneg (by simp) (Nat.cast_nonneg _)) - rcases bit_cases (S true) with hT|hT <;> - rcases bit_cases (S false) with hF|hF <;> rw [hT,hF] - · exact (h (by funext i; cases i <;> assumption)).elim - · rw [h0,h1,one_mul]; exact ⟨hz,le_rfl⟩ - · rw [h1,h0,mul_one]; exact ⟨hz,le_rfl⟩ - rw [h1]; exact ⟨mul_nonneg hz hz,(mul_le_mul_of_nonneg_left hl hz).trans_eq (mul_one B)⟩ - -/-- cap for channel cube pair from joint raw -/ -theorem phase_cap {w : Wgt (UnitType p n N)} {c : ℝ} (hc : 0≤c) - (m : Mixer p n) - (h : ∀ x,w x≤c*pairW (raw m N) (raw m N) x) - (hN : 2*num (Full p n)-N≤ -1) (y : PhasePair p N) : - mapW w (listens p) y≤c*chanPrice p^2 * freeH p N y := by - refine (mapW_cap h (listens p) _).trans ?_ - unfold listens - simp only [map_pair_law] - have hz (x) : 0≤mapW (raw m N) (hcube p) x := pr_nonneg (raw_nonneg m) - calc c*pairW _ _ y - _ ≤ c*((chanPrice p*lawH p N y.1)*(chanPrice p*lawH p N y.2)) := - mul_le_mul_of_nonneg_left (mul_le_mul (hcube_cap m hN y.1) (hcube_cap m hN y.2) - (hz _) ((hz _).trans (hcube_cap m hN y.1))) hc - _ = _ := by unfold freeH pairW; ring - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ChannelFrameLaws +import OAI.Combinatorics.HadwigerCounterexample.PrimalChannelTests +import OAI.Combinatorics.HadwigerCounterexample.MatrixRankCounting + +namespace OAI + +/-! # Independent Phase Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {J K : Type} [Fintype J] [Fintype K] + +abbrev PhasePair (p : Shape) (N : ℕ) := HCube p N × HCube p N +abbrev Party := Vec Bool + +def uPhase (p : Shape) {N} (v : HCube p N) : Ambient p N →ₗ[F] F := + ∑ e : Comp p.g, mpair ((v e).2*(v e).1ᵀ) ∘ₗ LinearMap.proj e + +def joinPhase (p : Shape) {N} (v : PhasePair p N) (o : Party) := + ∑ b : Bool, o b • uPhase p (onSide v b) + +/-- Read the whole channel frames of a unit. -/ +def listens (p : Shape) {n N} (x : UnitType p n N) : PhasePair p N := + Prod.map (hcube p) (hcube p) x + +def tone (p : Shape) {n N} (x : UnitType p n N) (S : Party) (T : Ambient p N) := + joinPhase p (listens p x) S T + +def pitch (p : Shape) {n N} (Δ : UnitType p n N → Ambient p N) + (w : Wgt (UnitType p n N)) (S R : Party) := + avg (pairW w w) (fun x => + wsign (tone p x.1 R (Δ x.2)+tone p x.2 S (Δ x.1))) + +theorem phase_actual (p : Shape) {n N} (x : Orient p n N) : + uPhase p (hcube p x)=ufun x := by + apply LinearMap.ext + intro v + simp only [uPhase,LinearMap.sum_apply]; rfl + +private theorem perm_pair (A B : Mat J K) (M : Mat J J) : + mpair (A*Bᵀ) M=mpair (M*B) A := by + + change (A*Bᵀ*Mᵀ).trace=(M*B*Aᵀ).trace + + rw [← Matrix.trace_transpose (M*B*Aᵀ),Matrix.transpose_mul,Matrix.transpose_mul, + Matrix.transpose_transpose,Matrix.mul_assoc] + +variable [DecidableEq J] [DecidableEq K] + +private theorem iid_prodM (M : Mat J J) : + avg (pairW (unif : Wgt (Mat J K)) unif) (fun x => wsign (mpair (x.2*x.1ᵀ) M)) = + bp (- (M.rank:ℝ) * num K) := by + classical + rw [pairW_avg] + obtain ⟨A,B,hA,hB,hM⟩ := rank_product M + have he (y : Mat J K) : + avg unif (fun a : Mat J K => wsign (mpair (a*yᵀ) M)) = ind (B*y=0) := by + have ht : mpair (M*y)=0 ↔ B*y=0 := by + rw [ show M*y=A*B*y from congrArg (·*y) hM.symm,Matrix.mul_assoc] + constructor + · intro h + have he := mpair_nondeg _ h + exact matrix_cancel_left hA (B*y) 0 (he.trans (Matrix.mul_zero A).symm) + intro h + rw [h,Matrix.mul_zero] + exact LinearMap.ext fun x => by rw [mpair_comm,map_zero,LinearMap.zero_apply] + simp_rw [perm_pair,wsign_lin] + rw [ht] + change avg unif (fun y => avg unif _) = _ + simp_rw [he] + change pr unif _ = _ + have hf : pr unif (fun y : Mat J K => B*y=0)=bp (-num (Fin M.rank)*num K) := by + have hx : Function.Injective Bᵀ.mulVec := + transpose_surj_iff.mp (by rw [transpose_transpose]; exact hB) + simpa only [Matrix.transpose_transpose] using + pr_gram_fixed hx (0:Mat (Fin M.rank) K) + rw [hf,num,Fintype.card_fin] + +omit [Fintype J] in +theorem wsign_sum (s : Finset J) (f : J → F) : + wsign (∑ i∈s,f i)=∏ i∈s,wsign (f i) := by + classical + induction s using Finset.induction with + | empty => simp + | insert a s h ih => rw [Finset.sum_insert h,Finset.prod_insert h,wsign_add,ih] + +theorem lawH_law (p : Shape) (N : ℕ) : IsLaw (lawH p N) := + prodW_law (fun _ => pairW_law unif_law unif_law) + +theorem lawH_phased (x : Ambient p N) : + avg (lawH p N) (fun y => wsign (uPhase p y x)) = bp (- (p.h:ℝ) * epoch p x) := by + classical + let w (i : Comp p.g) := (pairW unif unif : Wgt (HFrame p N)) + let f (i : Comp p.g) (x' : HFrame p N) := wsign (mpair (x'.2*x'.1ᵀ) (x i)) + have hh y : wsign (uPhase p y x)= prodW f y := by + rw [uPhase,LinearMap.sum_apply, wsign_sum]; rfl + change avg (prodW w) _ = _ + simp_rw [hh] + rw [prodW_avg] + have hg i : avg (w i) (f i)=bp (- (p.h:ℝ)*(x i).rank) := by + change avg (pairW unif unif) _ = _ + refine (iid_prodM (x i) (K:=Chan p)).trans ?_ + congr 1 + simp only [Chan,num,Fintype.card_fin] + ring + simp_rw [hg] + rw [←bp_sum,←Finset.mul_sum,←Nat.cast_sum,epoch] + +def freeH (p : Shape) (N : ℕ) := pairW (lawH p N) (lawH p N) + +theorem freeH_law (p : Shape) (N : ℕ) : IsLaw (freeH p N) := + pairW_law (lawH_law p N) (lawH_law p N) + +set_option maxHeartbeats 800000 in +theorem free_phase {S : Party} (x : Ambient p N) (h : S≠0) : + let Q := avg (freeH p N) (fun y => wsign (joinPhase p y S x)); + 0 ≤ Q ∧ Q ≤ bp (- (p.h:ℝ)* epoch p x) := by + classical + let T (b : F) := avg (lawH p N) (fun y => wsign (b*uPhase p y x)) + have he : + avg (freeH p N) (fun y => wsign (joinPhase p y S x))=T (S true)*T (S false) := by + have hh y : + wsign (joinPhase p y S x)= + wsign (S true*uPhase p y.1 x)*wsign (S false*uPhase p y.2 x) := by + rw [joinPhase, Fintype.sum_bool,LinearMap.add_apply,wsign_add] + rfl + simp_rw [hh] + exact pairW_separate (lawH p N) (fun y => wsign (S true*uPhase p y x)) + (lawH p N) (fun y => wsign (S false*uPhase p y x)) + rw [he] + let B := bp (- (p.h:ℝ) * epoch p x) + have h0 : T 0=1 := by + unfold T; simp only [zero_mul,wsign_zero, (lawH_law p N).avg_const] + have h1 : T 1=B := by unfold T; simp only [one_mul,lawH_phased,B] + have hz : 0≤ B := (bp_pos _).le + have hl : B ≤1 := by + unfold B + rw [←bp_zero] + exact bp_le (mul_nonpos_of_nonpos_of_nonneg (by simp) (Nat.cast_nonneg _)) + rcases bit_cases (S true) with hT|hT <;> + rcases bit_cases (S false) with hF|hF <;> rw [hT,hF] + · exact (h (by funext i; cases i <;> assumption)).elim + · rw [h0,h1,one_mul]; exact ⟨hz,le_rfl⟩ + · rw [h1,h0,mul_one]; exact ⟨hz,le_rfl⟩ + rw [h1]; exact ⟨mul_nonneg hz hz,(mul_le_mul_of_nonneg_left hl hz).trans_eq (mul_one B)⟩ + +/-- cap for channel cube pair from joint raw -/ +theorem phase_cap {w : Wgt (UnitType p n N)} {c : ℝ} (hc : 0≤c) + (m : Mixer p n) + (h : ∀ x,w x≤c*pairW (raw m N) (raw m N) x) + (hN : 2*num (Full p n)-N≤ -1) (y : PhasePair p N) : + mapW w (listens p) y≤c*chanPrice p^2 * freeH p N y := by + refine (mapW_cap h (listens p) _).trans ?_ + unfold listens + simp only [map_pair_law] + have hz (x) : 0≤mapW (raw m N) (hcube p) x := pr_nonneg (raw_nonneg m) + calc c*pairW _ _ y + _ ≤ c*((chanPrice p*lawH p N y.1)*(chanPrice p*lawH p N y.2)) := + mul_le_mul_of_nonneg_left (mul_le_mul (hcube_cap m hN y.1) (hcube_cap m hN y.2) + (hz _) ((hz _).trans (hcube_cap m hN y.1))) hc + _ = _ := by unfold freeH pairW; ring + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentTestWitnesses.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentTestWitnesses.lean index 7a942608f35f64280685fa91539c2a1f7895b1b2..c12d717a4a1ef81f37f4331acbfe668fc0e3249d 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentTestWitnesses.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentTestWitnesses.lean @@ -1,109 +1,109 @@ -import OAI.Combinatorics.HadwigerCounterexample.AdditionalProbeBounds - -namespace OAI - -/-! # Independent Test Witnesses -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Function Finset -open scoped BigOperators -variable {p : Shape} {n N r : ℕ} {T : Cov p N} - -namespace Bazaar -variable (s : Bazaar p n r T) - -set_option maxHeartbeats 800000 in -theorem shooting {w : Wgt (UnitType p n N)} (hw : IsLaw w) - (S : Party) (j : Bool) (k d : ℕ) (hh : k ≤ d) (l : ℝ) (hl : 0 < l) - (h : 5*l ≤ pr (pairW w w) (fun x => s.frequent w S j (s.ix x.1) (s.ix x.2) x.2)) - (hC : ∀ C : Cov p N,cdim p C≤d → pr w (fun x => offsetCov (s.ix x) ≤ C) ≤ l) - (hb : ∀ A M Z,(↑(s.bids w S j A M Z).card:ℝ) ≤ bp (0.51*N)) : - ∃ (q : Place p→ℕ) (R : DTuple (p:=p) q N) - (F : Catalog p T r q), ctot p q=k ∧ - (∀ i, Injective (R i).mulVec) ∧ - (∀ M Z,(↑(F M Z).card:ℝ) ≤ bp (0.51*k*N)) ∧ l^(k+1)≤pr w (s.atList S j R F) := by - classical - let A := UnitType p n N - let u (x y : A) := s.frequent w S j (s.ix x) (s.ix y) y - let B (y : A) := 3*l≤pr w (fun x => u x y) - suffices he : ∃ (q : Place p→ℕ) (R : DTuple (p:=p) q N) - (F : Catalog p T r q), ctot p q=k ∧ - (∀ i, Injective (R i).mulVec) ∧ (∀ M Z,(↑(F M Z).card:ℝ) ≤ bp (0.51*k*N)) ∧ - l^(k+1)≤pr w (fun x => B x ∧ s.atList S j R F x) by - obtain ⟨a,b,c,h1,h2,h3,h4⟩ := he - exact ⟨a,b,c,h1,h2,h3,h4.trans (pr_mono hw.nz fun x h => h.2)⟩ - induction k with - | zero => - let q := fun _ : Place p => 0 - let R : DTuple (p:=p) q N := 0 - let F : Catalog p T r q := fun _ _ => {R} - have heq x : s.atList S j R F x := mem_singleton.mpr (Subsingleton.elim _ _) - refine ⟨q,R,F,by simp [ctot,q],fun i x y h => Subsingleton.elim _ _,by simp [F],?_⟩ - simp only [heq,and_true,Nat.zero_add,pow_one] - have hf : 5*l ≤ avg w (fun y => pr w (fun x => u x y)) := by - change 5*l≤avg (pairW w w) _ at h - rw [pairW_avg,avg_avg] at h - exact h - have hg (y) : pr w (fun x => u x y) ≤ 3*l+ind (B y) := by - by_cases hh : B y - · rw [ind_one hh]; exact ((pr_le_tot hw.nz).trans hw.total.le).trans (by linarith) - rw [ind_zero hh,add_zero]; exact le_of_not_ge hh - have ha := hf.trans (avg_mono hw.nz hg) - rw [avg_add,hw.avg_const] at ha - unfold pr; linarith only [hl,ha] - | succ k ih => - obtain ⟨q,R,F,h1,h2,h3,h4⟩ := ih (Nat.le_of_succ_le hh) - let P := fun x => B x ∧ s.atList S j R F x - let C := Bazaar.probed p R - let Z := fun x => offsetCov (s.ix x) ≤ C - have hD : pr w Z ≤ l := by - apply hC C - refine le_trans ?_ (Nat.le_of_succ_le hh) - rw [←h1] - exact Finset.sum_le_sum fun i _ => (R i).rank_le_card_width.trans_eq (Fintype.card_fin _) - obtain ⟨x,hx,hg⟩ : - ∃ x,¬ Z x ∧ l^(k+2)≤ pr w (fun y => P y ∧ u x y) := by - have he : - avg w (fun x => ind (¬Z x)*pr w (fun y => P y ∧ u x y)) = - avg w (fun y => ind (P y)*pr w (fun x => u x y ∧ ¬Z x)) := by - unfold pr; simp_rw [← avg_mul',ind_and] - rw [avg_avg]; apply congrArg - funext y; apply congrArg; ext; ring - let f := fun x => ind (¬Z x)*pr w (fun y => P y ∧ u x y) - have hu (y : A) (hy : P y) : 2*l ≤ pr w (fun x => u x y ∧ ¬Z x) := by - have hi (x : A) (h : u x y) : Z x ∨ (u x y ∧ ¬ Z x) := - or_iff_not_imp_left.mpr fun hx => ⟨h,hx⟩ - have hf := (show 3*l ≤ pr w _ from hy.1).trans - ((pr_mono hw.nz hi).trans (pr_or_le hw.nz)) - linarith - have hp := pow_pos hl (k+2) - have hi : l^(k+2) ?_) - by_cases hv : P y - · rw [ind_one hv,mul_one,one_mul] - exact hu y hv - simp only [ind_zero hv,mul_zero,zero_mul,le_refl] - obtain ⟨x,hx⟩ : ∃ x,l^(k+2) P y ∧ u x y) from (by simp [f,hz])) ▸ hx.le⟩ - obtain ⟨q',R',F',hQ,hR,hF,hH⟩ := - s.extend_probe w S j R h1 h2 F h3 (s.ix x) hx (hb _) - refine ⟨q',R',F',hQ,hR, ?_,hg.trans (pr_mono hw.nz (fun y h => ⟨h.1.1,hH y h.1.2 h.2⟩))⟩ - simpa only [Nat.cast_add,Nat.cast_one] using hF - -end Bazaar -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.AdditionalProbeBounds + +namespace OAI + +/-! # Independent Test Witnesses -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Function Finset +open scoped BigOperators +variable {p : Shape} {n N r : ℕ} {T : Cov p N} + +namespace Bazaar +variable (s : Bazaar p n r T) + +set_option maxHeartbeats 800000 in +theorem shooting {w : Wgt (UnitType p n N)} (hw : IsLaw w) + (S : Party) (j : Bool) (k d : ℕ) (hh : k ≤ d) (l : ℝ) (hl : 0 < l) + (h : 5*l ≤ pr (pairW w w) (fun x => s.frequent w S j (s.ix x.1) (s.ix x.2) x.2)) + (hC : ∀ C : Cov p N,cdim p C≤d → pr w (fun x => offsetCov (s.ix x) ≤ C) ≤ l) + (hb : ∀ A M Z,(↑(s.bids w S j A M Z).card:ℝ) ≤ bp (0.51*N)) : + ∃ (q : Place p→ℕ) (R : DTuple (p:=p) q N) + (F : Catalog p T r q), ctot p q=k ∧ + (∀ i, Injective (R i).mulVec) ∧ + (∀ M Z,(↑(F M Z).card:ℝ) ≤ bp (0.51*k*N)) ∧ l^(k+1)≤pr w (s.atList S j R F) := by + classical + let A := UnitType p n N + let u (x y : A) := s.frequent w S j (s.ix x) (s.ix y) y + let B (y : A) := 3*l≤pr w (fun x => u x y) + suffices he : ∃ (q : Place p→ℕ) (R : DTuple (p:=p) q N) + (F : Catalog p T r q), ctot p q=k ∧ + (∀ i, Injective (R i).mulVec) ∧ (∀ M Z,(↑(F M Z).card:ℝ) ≤ bp (0.51*k*N)) ∧ + l^(k+1)≤pr w (fun x => B x ∧ s.atList S j R F x) by + obtain ⟨a,b,c,h1,h2,h3,h4⟩ := he + exact ⟨a,b,c,h1,h2,h3,h4.trans (pr_mono hw.nz fun x h => h.2)⟩ + induction k with + | zero => + let q := fun _ : Place p => 0 + let R : DTuple (p:=p) q N := 0 + let F : Catalog p T r q := fun _ _ => {R} + have heq x : s.atList S j R F x := mem_singleton.mpr (Subsingleton.elim _ _) + refine ⟨q,R,F,by simp [ctot,q],fun i x y h => Subsingleton.elim _ _,by simp [F],?_⟩ + simp only [heq,and_true,Nat.zero_add,pow_one] + have hf : 5*l ≤ avg w (fun y => pr w (fun x => u x y)) := by + change 5*l≤avg (pairW w w) _ at h + rw [pairW_avg,avg_avg] at h + exact h + have hg (y) : pr w (fun x => u x y) ≤ 3*l+ind (B y) := by + by_cases hh : B y + · rw [ind_one hh]; exact ((pr_le_tot hw.nz).trans hw.total.le).trans (by linarith) + rw [ind_zero hh,add_zero]; exact le_of_not_ge hh + have ha := hf.trans (avg_mono hw.nz hg) + rw [avg_add,hw.avg_const] at ha + unfold pr; linarith only [hl,ha] + | succ k ih => + obtain ⟨q,R,F,h1,h2,h3,h4⟩ := ih (Nat.le_of_succ_le hh) + let P := fun x => B x ∧ s.atList S j R F x + let C := Bazaar.probed p R + let Z := fun x => offsetCov (s.ix x) ≤ C + have hD : pr w Z ≤ l := by + apply hC C + refine le_trans ?_ (Nat.le_of_succ_le hh) + rw [←h1] + exact Finset.sum_le_sum fun i _ => (R i).rank_le_card_width.trans_eq (Fintype.card_fin _) + obtain ⟨x,hx,hg⟩ : + ∃ x,¬ Z x ∧ l^(k+2)≤ pr w (fun y => P y ∧ u x y) := by + have he : + avg w (fun x => ind (¬Z x)*pr w (fun y => P y ∧ u x y)) = + avg w (fun y => ind (P y)*pr w (fun x => u x y ∧ ¬Z x)) := by + unfold pr; simp_rw [← avg_mul',ind_and] + rw [avg_avg]; apply congrArg + funext y; apply congrArg; ext; ring + let f := fun x => ind (¬Z x)*pr w (fun y => P y ∧ u x y) + have hu (y : A) (hy : P y) : 2*l ≤ pr w (fun x => u x y ∧ ¬Z x) := by + have hi (x : A) (h : u x y) : Z x ∨ (u x y ∧ ¬ Z x) := + or_iff_not_imp_left.mpr fun hx => ⟨h,hx⟩ + have hf := (show 3*l ≤ pr w _ from hy.1).trans + ((pr_mono hw.nz hi).trans (pr_or_le hw.nz)) + linarith + have hp := pow_pos hl (k+2) + have hi : l^(k+2) ?_) + by_cases hv : P y + · rw [ind_one hv,mul_one,one_mul] + exact hu y hv + simp only [ind_zero hv,mul_zero,zero_mul,le_refl] + obtain ⟨x,hx⟩ : ∃ x,l^(k+2) P y ∧ u x y) from (by simp [f,hz])) ▸ hx.le⟩ + obtain ⟨q',R',F',hQ,hR,hF,hH⟩ := + s.extend_probe w S j R h1 h2 F h3 (s.ix x) hx (hb _) + refine ⟨q',R',F',hQ,hR, ?_,hg.trans (pr_mono hw.nz (fun y h => ⟨h.1.1,hH y h.1.2 h.2⟩))⟩ + simpa only [Nat.cast_add,Nat.cast_one] using hF + +end Bazaar +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentWeightCorrelation.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentWeightCorrelation.lean index f994aedb2479cb1869ca4d0641665ecc90190b6f..98fa4fb2418cac74eeac58202a222e9352448c6b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentWeightCorrelation.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/IndependentWeightCorrelation.lean @@ -1,122 +1,122 @@ -import OAI.Combinatorics.HadwigerCounterexample.RepeatedQueryBounds - -namespace OAI - -/-! # Independent Weight Correlation -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Submodule Function Finset -open scoped BigOperators -variable {I J T : Type} [Fintype I] [Fintype J] [Fintype T] -variable [DecidableEq I] [DecidableEq J] [DecidableEq T] -variable {N : ℕ} - -def brightProd (f : I→ Wgt (Rack J N)) (x : Rack (I × J) N) := - ∏ i:I,f i (led i x) - -private theorem brProd (f : I→ Wgt (Rack J N)) : - avg unif (brightProd f)=∏ i,avg unif (f i) := by - have he := (led_uniform (prodW f)) - exact he.trans (prodW_avg _ _) - -omit [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] in -theorem lane_abs (f : I → Wgt (Rack J N)) (hf : ∀ i x,|f i x|≤1) (T : Finset I) (x) : - |∏ i∈T,f i (led i x)|≤1 := by - rw [Finset.abs_prod]; exact (Finset.prod_le_prod₀ (fun i _ => abs_nonneg _) - (fun i _ => hf i _)).trans_eq (by simp) - -omit [Fintype I] [Fintype J] [DecidableEq T] in -private theorem unchanged_true (i : I) {x : Rack (I×J) N} (e : T → I×J) - (h : i ∉ heard e) (v : PlusRack T N) : led i (x+(upliftR e v,0)) = led i x := by - apply Prod.ext - · ext - simp only [led,sectionR,Prod.fst_add,Matrix.submatrix_apply,Matrix.add_apply, - heard_fresh v h,add_zero] - ext; simp [led,sectionR] -omit [Fintype I] [Fintype J] [DecidableEq T] in -private theorem unchanged_false (i : I) {x : Rack (I×J) N} - (e : T → I×J) (h : i ∉ heard e) (v : PlusRack T N) : - led i (x+(0,upliftR e v)) = led i x := by - apply Prod.ext - · ext; simp [led,sectionR] - ext - simp only [led,sectionR,Prod.snd_add,Matrix.submatrix_apply,Matrix.add_apply, - heard_fresh v h,add_zero] - -theorem speed (M : Avenue I J) - {i j : I} (hi : i ≠ j) {x y : J} (h : M (i,x) (j,y)=1) - (f : I→ Wgt (Rack J N)) (hf : ∀ i x,|f i x|≤1) : - |avg unif (fun x => phasedBy M x * brightProd f x)|≤ bp (- (N:ℝ)/2) := by - classical - let g (q : Rack (I×J) N) := f i (led i q) - let P := Finset.univ.erase i - let l (q : Rack (I×J) N) := ∏ i∈P,f i (led i q) - have he q : brightProd f q=g q*l q := (Finset.mul_prod_erase _ _ (Finset.mem_univ _)).symm - let X := fun _ : Unit => (i,x) - let Y := fun _ : Unit => (j,y) - have hr : M.submatrix X Y=1 := by ext a b; cases a; cases b; rw [Matrix.one_apply_eq]; exact h - let r := fun _ : Rack (I×J) N => (1:ℝ) - have hh q : phasedBy M q * brightProd f q=phasedBy M q*g q*l q*r q := by - unfold r; rw [he]; ring - simp_rw [hh] - have hg q w : g (q+(0,upliftR Y w))=g q := by - unfold g - rw [unchanged_false i Y (by simp [heard,Y,hi]) w] - have hl (q) w : l (q+(upliftR X w,0))=l q := Finset.prod_congr rfl (fun z hz => by - rw [unchanged_true z X (by - have hh := (Finset.mem_erase.mp hz).1 - simp [X,heard,hh]) w]) - refine (layerLeak M g l r X Y (fun q => hf i _) (lane_abs f hf P) hg hl (fun _ _ _ => rfl)).trans_eq ?_ - rw [hr,Matrix.rank_one] - simp only [r,abs_one, Fintype.card_unit, Nat.cast_one,mul_one,unif_law.avg_const] - -theorem speed_expand (f : I→ Wgt (Rack J N)) (hf : ∀ i x,|f i x|≤1) - (E : Rail (I×J)) (Z : Vec E) (hx : ∀ i∈E,i.1.1≠i.2.1) : - |avg unif (fun x => ind (traced x E Z)*brightProd f x)- bp (-(E.card:ℝ))*avg unif (brightProd f)| ≤ - bp (- (N:ℝ)/2) := by - classical - let F (v : Vec E) := - vectorPhase v Z * avg unif (fun x => phasedBy (ledgerM E v) x*brightProd f x) - have hh : avg unif (fun x => ind (traced x E Z)*brightProd f x)=avg unif F := by - simp_rw [rail_expand,←avg_mul] - rw [avg_avg]; apply avg_congr - intro x _ - unfold F - rw [← avg_mul'] - refine avg_congr (fun i _ => ?_); ring - let L := bp (- (N:ℝ)/2) - let B (x : Vec E) := ind (x=0)*avg unif (brightProd f) - have he x : |F x-B x| ≤ L := by - unfold F B - by_cases ht : x=0 - · subst x - simp only [ledger_zero,layer_zero,one_mul,vectorPhase,zero_dotProduct, - wsign_zero,ind_true,sub_self,abs_zero] - exact (bp_pos _).le - rw [ind_zero ht,zero_mul, sub_zero, abs_mul] - obtain ⟨y,hy⟩ : ∃ y,x y=1 := by - by_contra! h; exact ht (funext fun i => (bit_cases _).resolve_right (h _)) - let M := ledgerM E x - obtain ⟨⟨⟨i,j⟩,k,l⟩,hY⟩ := y - have hA : M (i,j) (k,l)=1 := by - simp only [M,ledgerM,Matrix.of_apply,dite_eq_left hY] - exact hy - rw [vectorPhase,wsign_abs,one_mul] - exact speed M (hx _ hY) hA f hf - rw [hh] - have hk : - bp (-(E.card:ℝ))*avg unif (brightProd f)=avg unif B := by - unfold B; rw [avg_mul] - congr 1 - symm - change pr unif (fun x : Vec E => x=0)=_ - rw [pr_point',unif_apply,card_space,dim_vec, Fintype.card_coe,bp_neg] - rw [hk,← avg_sub] - exact (abs_avg_le unif_law.nz).trans (unif_law.avg_le he) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RepeatedQueryBounds + +namespace OAI + +/-! # Independent Weight Correlation -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Submodule Function Finset +open scoped BigOperators +variable {I J T : Type} [Fintype I] [Fintype J] [Fintype T] +variable [DecidableEq I] [DecidableEq J] [DecidableEq T] +variable {N : ℕ} + +def brightProd (f : I→ Wgt (Rack J N)) (x : Rack (I × J) N) := + ∏ i:I,f i (led i x) + +private theorem brProd (f : I→ Wgt (Rack J N)) : + avg unif (brightProd f)=∏ i,avg unif (f i) := by + have he := (led_uniform (prodW f)) + exact he.trans (prodW_avg _ _) + +omit [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] in +theorem lane_abs (f : I → Wgt (Rack J N)) (hf : ∀ i x,|f i x|≤1) (T : Finset I) (x) : + |∏ i∈T,f i (led i x)|≤1 := by + rw [Finset.abs_prod]; exact (Finset.prod_le_prod₀ (fun i _ => abs_nonneg _) + (fun i _ => hf i _)).trans_eq (by simp) + +omit [Fintype I] [Fintype J] [DecidableEq T] in +private theorem unchanged_true (i : I) {x : Rack (I×J) N} (e : T → I×J) + (h : i ∉ heard e) (v : PlusRack T N) : led i (x+(upliftR e v,0)) = led i x := by + apply Prod.ext + · ext + simp only [led,sectionR,Prod.fst_add,Matrix.submatrix_apply,Matrix.add_apply, + heard_fresh v h,add_zero] + ext; simp [led,sectionR] +omit [Fintype I] [Fintype J] [DecidableEq T] in +private theorem unchanged_false (i : I) {x : Rack (I×J) N} + (e : T → I×J) (h : i ∉ heard e) (v : PlusRack T N) : + led i (x+(0,upliftR e v)) = led i x := by + apply Prod.ext + · ext; simp [led,sectionR] + ext + simp only [led,sectionR,Prod.snd_add,Matrix.submatrix_apply,Matrix.add_apply, + heard_fresh v h,add_zero] + +theorem speed (M : Avenue I J) + {i j : I} (hi : i ≠ j) {x y : J} (h : M (i,x) (j,y)=1) + (f : I→ Wgt (Rack J N)) (hf : ∀ i x,|f i x|≤1) : + |avg unif (fun x => phasedBy M x * brightProd f x)|≤ bp (- (N:ℝ)/2) := by + classical + let g (q : Rack (I×J) N) := f i (led i q) + let P := Finset.univ.erase i + let l (q : Rack (I×J) N) := ∏ i∈P,f i (led i q) + have he q : brightProd f q=g q*l q := (Finset.mul_prod_erase _ _ (Finset.mem_univ _)).symm + let X := fun _ : Unit => (i,x) + let Y := fun _ : Unit => (j,y) + have hr : M.submatrix X Y=1 := by ext a b; cases a; cases b; rw [Matrix.one_apply_eq]; exact h + let r := fun _ : Rack (I×J) N => (1:ℝ) + have hh q : phasedBy M q * brightProd f q=phasedBy M q*g q*l q*r q := by + unfold r; rw [he]; ring + simp_rw [hh] + have hg q w : g (q+(0,upliftR Y w))=g q := by + unfold g + rw [unchanged_false i Y (by simp [heard,Y,hi]) w] + have hl (q) w : l (q+(upliftR X w,0))=l q := Finset.prod_congr rfl (fun z hz => by + rw [unchanged_true z X (by + have hh := (Finset.mem_erase.mp hz).1 + simp [X,heard,hh]) w]) + refine (layerLeak M g l r X Y (fun q => hf i _) (lane_abs f hf P) hg hl (fun _ _ _ => rfl)).trans_eq ?_ + rw [hr,Matrix.rank_one] + simp only [r,abs_one, Fintype.card_unit, Nat.cast_one,mul_one,unif_law.avg_const] + +theorem speed_expand (f : I→ Wgt (Rack J N)) (hf : ∀ i x,|f i x|≤1) + (E : Rail (I×J)) (Z : Vec E) (hx : ∀ i∈E,i.1.1≠i.2.1) : + |avg unif (fun x => ind (traced x E Z)*brightProd f x)- bp (-(E.card:ℝ))*avg unif (brightProd f)| ≤ + bp (- (N:ℝ)/2) := by + classical + let F (v : Vec E) := + vectorPhase v Z * avg unif (fun x => phasedBy (ledgerM E v) x*brightProd f x) + have hh : avg unif (fun x => ind (traced x E Z)*brightProd f x)=avg unif F := by + simp_rw [rail_expand,←avg_mul] + rw [avg_avg]; apply avg_congr + intro x _ + unfold F + rw [← avg_mul'] + refine avg_congr (fun i _ => ?_); ring + let L := bp (- (N:ℝ)/2) + let B (x : Vec E) := ind (x=0)*avg unif (brightProd f) + have he x : |F x-B x| ≤ L := by + unfold F B + by_cases ht : x=0 + · subst x + simp only [ledger_zero,layer_zero,one_mul,vectorPhase,zero_dotProduct, + wsign_zero,ind_true,sub_self,abs_zero] + exact (bp_pos _).le + rw [ind_zero ht,zero_mul, sub_zero, abs_mul] + obtain ⟨y,hy⟩ : ∃ y,x y=1 := by + by_contra! h; exact ht (funext fun i => (bit_cases _).resolve_right (h _)) + let M := ledgerM E x + obtain ⟨⟨⟨i,j⟩,k,l⟩,hY⟩ := y + have hA : M (i,j) (k,l)=1 := by + simp only [M,ledgerM,Matrix.of_apply,dite_eq_left hY] + exact hy + rw [vectorPhase,wsign_abs,one_mul] + exact speed M (hx _ hY) hA f hf + rw [hh] + have hk : + bp (-(E.card:ℝ))*avg unif (brightProd f)=avg unif B := by + unfold B; rw [avg_mul] + congr 1 + symm + change pr unif (fun x : Vec E => x=0)=_ + rw [pr_point',unif_apply,card_space,dim_vec, Fintype.card_coe,bp_neg] + rw [hk,← avg_sub] + exact (abs_avg_le unif_law.nz).trans (unif_law.avg_le he) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/InformationSmallSetBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/InformationSmallSetBounds.lean index 82c446ef7b95c6567f4cf2fb981fdd9b72ccfdf0..44558f3bf8842833c57786ed847a5633e3c4019f 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/InformationSmallSetBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/InformationSmallSetBounds.lean @@ -1,144 +1,144 @@ -import OAI.Combinatorics.HadwigerCounterexample.UnfilteredHistogramEnergy - -namespace OAI - -/-! # Information Small Set Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Filter Matrix Real -open scoped BigOperators -variable {A B C X : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype X] - -/-- Family of orientation/flag-conditional laws (μ already -realizes joint flag law). -/ -structure Ultra (μ : Wgt A) (p : A→Wgt B) : Prop where - law : IsLaw μ - labs : ∀ i,IsLaw (p i) - -variable {μ : Wgt A} {p : A→Wgt B} - -def budget (μ : Wgt A) (p : A→Wgt B) (f : B→ C) := - avg μ (fun i => tension (mapW (p i) f) (mapW unif f)) -def tariffs (μ : Wgt A) (p : A→ Wgt B) (r : ℕ) (δ V : ℝ) := - ∀ (C : Type) [Fintype C],Fintype.card C≤ r → - ∀ (f : B→ C), stamina (mapW unif f) δ → budget μ p f ≤ V - -def catalog (μ : Wgt A) (p : A→Wgt B) (w : Wgt B) := - ∃ t : Wgt A,(∀ i,0 ≤ t i) ∧ (∀ i,t i≤ μ i) ∧ w=mixW t p -namespace Ultra - -variable [Nonempty B] (h : Ultra μ p) - -omit [Nonempty B] in -theorem maxCat (h : Ultra μ p) : IsLaw (mixW μ p) := mixW_law h.law h.labs -omit [Nonempty B] in -theorem cat_dom (h : Ultra μ p) (w : Wgt B) (hw : catalog μ p w) : - (∀ i, 0 ≤ w i) ∧ (∀ i, w i ≤ mixW μ p i) := by - obtain ⟨t,hp,hq,rfl⟩ := hw - exact ⟨fun i => avg_nonneg hp (fun j => (h.labs j).nz _),fun i => avg_mono_left - (fun j => (h.labs j).nz _) hq⟩ - -omit [Nonempty B] in -theorem cat_sub (h : Ultra μ p) (w : Wgt B) (hw : catalog μ p w) : - SubLaw w := by - obtain ⟨h1,h2⟩ := h.cat_dom w hw - exact ⟨h1,(Finset.sum_le_sum fun i _ => h2 i).trans_eq h.maxCat.total⟩ - -end Ultra - -private theorem binary_info (q w : Wgt Bool) (hq : IsLaw q) (hw : IsLaw w) - (L : ℝ) (he : 0 < q true) (h : q true ≤ exp (-L)) : - w true * L-log 2 ≤ tension w q := by - have h1 := Real.log_le_log he h - rw [Real.log_exp] at h1 - have h2 : log (q false)≤0 := log_nonpos (hq.nz _) (hq.weight_le_one _) - rw [tension_as_diff] - have hh : -log 2 ≤ negEnt w := by simpa using log_card_le_negEnt hw - simp only [avg,Fintype.sum_bool] - linarith only [hh,mul_nonpos_of_nonneg_of_nonpos (hw.nz false) h2, - mul_le_mul_of_nonneg_left h1 (hw.nz true)] - -theorem expand_event {w : Wgt B} (hw : IsLaw w) (P : B→Prop) (δ : ℝ) - (he : 2*δ < 1) (hm : ∀ x,w x ≤ δ) (hP : pr w P ≤ 2*δ) : - ∃ Q : B→Prop,(∀ x,P x → Q x) ∧ δ ≤ pr w Q ∧ pr w Q ≤2*δ := by - classical - let S := Finset.univ.filter P - let M := Finset.univ.filter (fun T : Finset B => S ⊆ T ∧ pr w (·∈T) ≤2*δ) - have hS (i : B) : i∈S ↔ P i := by simp [S] - have hh : S∈M := mem_filter.mpr ⟨mem_univ _,(by simp_rw [hS]; exact ⟨le_rfl,hP⟩)⟩ - obtain ⟨T,hT,hmax⟩ := Finset.exists_max_image M Finset.card ⟨S,hh⟩ - obtain ⟨hx,hz⟩ := (mem_filter.mp hT).2 - refine ⟨(·∈T),fun i hi => hx ((hS i).mpr hi),?_,hz⟩ - by_contra! h - obtain ⟨i,hi⟩ : ∃ i,i∉T := by - by_contra! hs - simp only [hs,pr_true,hw.total] at hz - linarith - let T' := insert i T - have hh' : pr w (·∈T') ≤ w i + pr w (·∈T) := - le_trans (le_of_eq (congrArg (pr w) (funext fun i => propext (Finset.mem_insert)))) - ((pr_or_le hw.nz).trans_eq (by simp)) - have ht : T' ∈ M := mem_filter.mpr - ⟨mem_univ _,hx.trans (subset_insert ..),by linarith only [hh',h,hm i]⟩ - specialize hmax _ ht - rw [show T'.card=T.card+1 from Finset.card_insert_of_notMem hi] at hmax - omega - -set_option maxHeartbeats 800000 in -theorem ui_threshold (V η : ℝ) (hη : 0<η) : - ∃ δ : ℝ,0<δ ∧ δ≤1 ∧ - ∀ (A B : Type) [Fintype A] [Fintype B] [Nonempty B] - (μ : Wgt A) (p : A→ Wgt B), Ultra μ p → - tariffs μ p 2 δ V → - ∀ S : B→Prop, pr unif S ≤δ → pr (mixW μ p) S ≤ η := by - classical - obtain ⟨L,hL,hL'⟩ : ∃ L : ℝ,0 ?_⟩ - have he : IsLaw (unif : Wgt B) := unif_law - by_cases hy : ∃ i,S i - · obtain ⟨i,hi⟩ := hy - have hh (j : B) : unif j ≤δ := by - rw [show unif j=unif i from by simp [unif_apply],← pr_point' unif i] - exact (pr_mono he.nz (fun j (h:j=i) => h.symm ▸ hi)).trans hS - obtain ⟨Q,hq,hQ,hQ'⟩ := expand_event he S δ (by linarith) hh (by linarith) - let f := fun x : B => decide (Q x) - let q := mapW (unif : Wgt B) f - have hqL := mapW_law he f - have hf (w : Wgt B) : mapW w f true=pr w Q := by simp [mapW,f] - have hq1 : δ≤q true := by unfold q; rw [hf]; exact hQ - have hq2 : q true ≤2*δ := by unfold q; rw [hf]; exact hQ' - have hE : budget μ p f ≤ V := ht Bool (by simp) f (by - rintro (a|a) _ - case false => - have hh : q true+q false=1 := by - have h := hqL.total; rw [tot,Fintype.sum_bool] at h; exact h - change δ≤q false; linarith only [hh,hq2,h1] - case true => exact hq1) - have hi (j : A) : - pr (p j) Q*L-log 2 ≤ tension (mapW (p j) f) q := by - rw [← hf]; exact binary_info q _ hqL (mapW_law (hw.labs j) _) L (hδ.trans_le hq1) - (by linarith only [hq2,h0]) - have hz := avg_mono hw.law.nz hi - rw [avg_sub,avg_mul,hw.law.avg_const] at hz - change avg μ (fun i => pr (p i) Q) * _-_ ≤ budget μ p f at hz - have hv : pr (mixW μ p) Q=avg μ (fun i => pr (p i) Q) := mixW_avg .. - apply (pr_mono hw.maxCat.nz hq).trans - rw [hv] - exact le_of_mul_le_mul_right (by linarith only [hz,hE,hL']) hL - have ht (i) : ¬ S i := fun h => hy ⟨i,h⟩ - simp [pr,ht,hη.le] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.UnfilteredHistogramEnergy + +namespace OAI + +/-! # Information Small Set Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Filter Matrix Real +open scoped BigOperators +variable {A B C X : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype X] + +/-- Family of orientation/flag-conditional laws (μ already +realizes joint flag law). -/ +structure Ultra (μ : Wgt A) (p : A→Wgt B) : Prop where + law : IsLaw μ + labs : ∀ i,IsLaw (p i) + +variable {μ : Wgt A} {p : A→Wgt B} + +def budget (μ : Wgt A) (p : A→Wgt B) (f : B→ C) := + avg μ (fun i => tension (mapW (p i) f) (mapW unif f)) +def tariffs (μ : Wgt A) (p : A→ Wgt B) (r : ℕ) (δ V : ℝ) := + ∀ (C : Type) [Fintype C],Fintype.card C≤ r → + ∀ (f : B→ C), stamina (mapW unif f) δ → budget μ p f ≤ V + +def catalog (μ : Wgt A) (p : A→Wgt B) (w : Wgt B) := + ∃ t : Wgt A,(∀ i,0 ≤ t i) ∧ (∀ i,t i≤ μ i) ∧ w=mixW t p +namespace Ultra + +variable [Nonempty B] (h : Ultra μ p) + +omit [Nonempty B] in +theorem maxCat (h : Ultra μ p) : IsLaw (mixW μ p) := mixW_law h.law h.labs +omit [Nonempty B] in +theorem cat_dom (h : Ultra μ p) (w : Wgt B) (hw : catalog μ p w) : + (∀ i, 0 ≤ w i) ∧ (∀ i, w i ≤ mixW μ p i) := by + obtain ⟨t,hp,hq,rfl⟩ := hw + exact ⟨fun i => avg_nonneg hp (fun j => (h.labs j).nz _),fun i => avg_mono_left + (fun j => (h.labs j).nz _) hq⟩ + +omit [Nonempty B] in +theorem cat_sub (h : Ultra μ p) (w : Wgt B) (hw : catalog μ p w) : + SubLaw w := by + obtain ⟨h1,h2⟩ := h.cat_dom w hw + exact ⟨h1,(Finset.sum_le_sum fun i _ => h2 i).trans_eq h.maxCat.total⟩ + +end Ultra + +private theorem binary_info (q w : Wgt Bool) (hq : IsLaw q) (hw : IsLaw w) + (L : ℝ) (he : 0 < q true) (h : q true ≤ exp (-L)) : + w true * L-log 2 ≤ tension w q := by + have h1 := Real.log_le_log he h + rw [Real.log_exp] at h1 + have h2 : log (q false)≤0 := log_nonpos (hq.nz _) (hq.weight_le_one _) + rw [tension_as_diff] + have hh : -log 2 ≤ negEnt w := by simpa using log_card_le_negEnt hw + simp only [avg,Fintype.sum_bool] + linarith only [hh,mul_nonpos_of_nonneg_of_nonpos (hw.nz false) h2, + mul_le_mul_of_nonneg_left h1 (hw.nz true)] + +theorem expand_event {w : Wgt B} (hw : IsLaw w) (P : B→Prop) (δ : ℝ) + (he : 2*δ < 1) (hm : ∀ x,w x ≤ δ) (hP : pr w P ≤ 2*δ) : + ∃ Q : B→Prop,(∀ x,P x → Q x) ∧ δ ≤ pr w Q ∧ pr w Q ≤2*δ := by + classical + let S := Finset.univ.filter P + let M := Finset.univ.filter (fun T : Finset B => S ⊆ T ∧ pr w (·∈T) ≤2*δ) + have hS (i : B) : i∈S ↔ P i := by simp [S] + have hh : S∈M := mem_filter.mpr ⟨mem_univ _,(by simp_rw [hS]; exact ⟨le_rfl,hP⟩)⟩ + obtain ⟨T,hT,hmax⟩ := Finset.exists_max_image M Finset.card ⟨S,hh⟩ + obtain ⟨hx,hz⟩ := (mem_filter.mp hT).2 + refine ⟨(·∈T),fun i hi => hx ((hS i).mpr hi),?_,hz⟩ + by_contra! h + obtain ⟨i,hi⟩ : ∃ i,i∉T := by + by_contra! hs + simp only [hs,pr_true,hw.total] at hz + linarith + let T' := insert i T + have hh' : pr w (·∈T') ≤ w i + pr w (·∈T) := + le_trans (le_of_eq (congrArg (pr w) (funext fun i => propext (Finset.mem_insert)))) + ((pr_or_le hw.nz).trans_eq (by simp)) + have ht : T' ∈ M := mem_filter.mpr + ⟨mem_univ _,hx.trans (subset_insert ..),by linarith only [hh',h,hm i]⟩ + specialize hmax _ ht + rw [show T'.card=T.card+1 from Finset.card_insert_of_notMem hi] at hmax + omega + +set_option maxHeartbeats 800000 in +theorem ui_threshold (V η : ℝ) (hη : 0<η) : + ∃ δ : ℝ,0<δ ∧ δ≤1 ∧ + ∀ (A B : Type) [Fintype A] [Fintype B] [Nonempty B] + (μ : Wgt A) (p : A→ Wgt B), Ultra μ p → + tariffs μ p 2 δ V → + ∀ S : B→Prop, pr unif S ≤δ → pr (mixW μ p) S ≤ η := by + classical + obtain ⟨L,hL,hL'⟩ : ∃ L : ℝ,0 ?_⟩ + have he : IsLaw (unif : Wgt B) := unif_law + by_cases hy : ∃ i,S i + · obtain ⟨i,hi⟩ := hy + have hh (j : B) : unif j ≤δ := by + rw [show unif j=unif i from by simp [unif_apply],← pr_point' unif i] + exact (pr_mono he.nz (fun j (h:j=i) => h.symm ▸ hi)).trans hS + obtain ⟨Q,hq,hQ,hQ'⟩ := expand_event he S δ (by linarith) hh (by linarith) + let f := fun x : B => decide (Q x) + let q := mapW (unif : Wgt B) f + have hqL := mapW_law he f + have hf (w : Wgt B) : mapW w f true=pr w Q := by simp [mapW,f] + have hq1 : δ≤q true := by unfold q; rw [hf]; exact hQ + have hq2 : q true ≤2*δ := by unfold q; rw [hf]; exact hQ' + have hE : budget μ p f ≤ V := ht Bool (by simp) f (by + rintro (a|a) _ + case false => + have hh : q true+q false=1 := by + have h := hqL.total; rw [tot,Fintype.sum_bool] at h; exact h + change δ≤q false; linarith only [hh,hq2,h1] + case true => exact hq1) + have hi (j : A) : + pr (p j) Q*L-log 2 ≤ tension (mapW (p j) f) q := by + rw [← hf]; exact binary_info q _ hqL (mapW_law (hw.labs j) _) L (hδ.trans_le hq1) + (by linarith only [hq2,h0]) + have hz := avg_mono hw.law.nz hi + rw [avg_sub,avg_mul,hw.law.avg_const] at hz + change avg μ (fun i => pr (p i) Q) * _-_ ≤ budget μ p f at hz + have hv : pr (mixW μ p) Q=avg μ (fun i => pr (p i) Q) := mixW_avg .. + apply (pr_mono hw.maxCat.nz hq).trans + rw [hv] + exact le_of_mul_le_mul_right (by linarith only [hz,hE,hL']) hL + have ht (i) : ¬ S i := fun h => hy ⟨i,h⟩ + simp [pr,ht,hη.le] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/InitialPartitionExistence.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/InitialPartitionExistence.lean index efcc09b8f770065ce5cd77917d9cf8694fa9ca77..de9c63cf75f77fd2883cd3bf2392b66a5fac481b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/InitialPartitionExistence.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/InitialPartitionExistence.lean @@ -1,105 +1,105 @@ -import OAI.Combinatorics.HadwigerCounterexample.PredictionDichotomy -import OAI.Combinatorics.HadwigerCounterexample.FrameIntersectionBounds -import OAI.Combinatorics.HadwigerCounterexample.TerminalCut - -namespace OAI - -/-! # Initial Partition Existence -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset -open scoped BigOperators Topology -namespace PreparationParameters - -variable {p : Shape} {n N M : ℕ} {q : PreparationParameters} - -theorem born (w : Wgt (UnitType p n N)) (hw : IsLaw w) (m : Mixer p n) - (h : pairCaps (raw m N) q.L (bp ((q.D:ℝ)*N)) w) : - nascent q p N w m := by - refine ⟨hw,fun i x=>?_, h.2.2⟩ - cases i - · exact h.2.1 _ - exact h.1 _ - -structure entry (q : PreparationParameters) (p : Shape) (M : ℕ) : Prop where - first : q.planted p M - hF : ∀ᶠ n : ℕ in atTop, let N:=M*n; - ∀ (m : Mixer p n) (w:Wgt (UnitType p n N)), q.nascent p N w m → - carried w (rawHoles m).unit → ∃ s : LeafMixture p n N,q.entered p N m w s - -/-- combines early h & M choices assuming row/selector bounds supplied. -/ -theorem stamp (g : ℕ) (q : PreparationParameters) - (hq : q.allows) (hd : 0 < q.D) (hf : (q.D:ℝ)+q.ζ ≤ (q.ζ-q.ζ/4)*q.e) - (hk : q.k≤ q.d) (hg : q.spJoint+1 ≤0.49*q.k) - (hu : 3*q.d+2*q.e+2 ≤ q.u) : - ∀ᶠ h : ℕ in atTop,∀ p:Shape,p.g=g→p.h=h → - Odd p.g → 3≤p.g → 1≤p.j → 1≤p.r → (q.B:ℝ) (hr m).2 a),?_,ht⟩ - · have hg : (3*q.d+2*q.e+2:ℝ) ≤ q.u := by exact_mod_cast hu - have hk := mul_le_mul_of_nonneg_right hg (show (0:ℝ) ≤ (M*n:ℕ) by positivity) - change _≤((M*n:ℕ):ℝ) at hN - linarith only [hN,hk] - intro m - specialize hn m - rw [hp]; exact hn - refine ⟨hh,?_⟩ - filter_upwards [hF,hh.wrap,hz.1.eventually (eventually_gt_atTop 0), - (((bp_tendsto_zero hq.pos).comp hz.2).eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1/4))), - (((bp_tendsto_zero hs).comp hz.2).eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1/4)))] - with n hn ht hN hA hB N m w hw hx - let P (x:UnitType p n N) := w x≠0 ∧ (rawHoles m).unit x ∧ joins x≤2*q.D ∧ frameSide p m x - obtain ⟨s,h1,h2,h3⟩:= LeafMixture.grove_first q.ζ q.D q.e hq.pos hq.small hN - (ht.2.2.1 m) hw.total hw.law.nz P hf - refine ⟨s,?_,h1.slide (by unfold leafOld; linarith) le_rfl le_rfl - (fun x=> mul_nonneg (raw_nonneg ..) (raw_nonneg ..)),h2⟩ - have heq x (h : w x≠0) : (rawHoles m).unit x ∧ frameSide p m x := by - have he := lt_of_lt_of_le (lt_of_le_of_ne (hw.law.nz _) h.symm) (hw.total x) - have he : usual p m N x≠0 := by intro hg; rw [hg,mul_zero] at he; exact he.false - refine ⟨by_contra fun e=>h (hx x e),fun i=>?_⟩ - have hz := raw_carried m N - cases i - · exact by_contra fun e => right_ne_zero_of_mul he (hz _ e) - exact by_contra fun e=> left_ne_zero_of_mul he (hz _ e) - let Q (x:UnitType p n N):=2*q.D¬Q x) := by - apply avg_congr - intro x hx - simp only [P,Q,(heq x hx).1,(heq x hx).2,and_true,true_and,not_lt] - exact congrArg ind (propext (and_iff_right hx)) - rw [hi,pr_not,hw.law.total] at h3 - have he : pr w Q≤bp (-((q.D:ℝ)/2)*N) := by - specialize hn _ _ hw.total - rwa [neg_div] at hn - change bp (-q.ζ*N)<1/4 at hA - change bp _ < 1/4 at hB - linarith only [he,h3,hB,hA] -end PreparationParameters -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PredictionDichotomy +import OAI.Combinatorics.HadwigerCounterexample.FrameIntersectionBounds +import OAI.Combinatorics.HadwigerCounterexample.TerminalCut + +namespace OAI + +/-! # Initial Partition Existence -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset +open scoped BigOperators Topology +namespace PreparationParameters + +variable {p : Shape} {n N M : ℕ} {q : PreparationParameters} + +theorem born (w : Wgt (UnitType p n N)) (hw : IsLaw w) (m : Mixer p n) + (h : pairCaps (raw m N) q.L (bp ((q.D:ℝ)*N)) w) : + nascent q p N w m := by + refine ⟨hw,fun i x=>?_, h.2.2⟩ + cases i + · exact h.2.1 _ + exact h.1 _ + +structure entry (q : PreparationParameters) (p : Shape) (M : ℕ) : Prop where + first : q.planted p M + hF : ∀ᶠ n : ℕ in atTop, let N:=M*n; + ∀ (m : Mixer p n) (w:Wgt (UnitType p n N)), q.nascent p N w m → + carried w (rawHoles m).unit → ∃ s : LeafMixture p n N,q.entered p N m w s + +/-- combines early h & M choices assuming row/selector bounds supplied. -/ +theorem stamp (g : ℕ) (q : PreparationParameters) + (hq : q.allows) (hd : 0 < q.D) (hf : (q.D:ℝ)+q.ζ ≤ (q.ζ-q.ζ/4)*q.e) + (hk : q.k≤ q.d) (hg : q.spJoint+1 ≤0.49*q.k) + (hu : 3*q.d+2*q.e+2 ≤ q.u) : + ∀ᶠ h : ℕ in atTop,∀ p:Shape,p.g=g→p.h=h → + Odd p.g → 3≤p.g → 1≤p.j → 1≤p.r → (q.B:ℝ) (hr m).2 a),?_,ht⟩ + · have hg : (3*q.d+2*q.e+2:ℝ) ≤ q.u := by exact_mod_cast hu + have hk := mul_le_mul_of_nonneg_right hg (show (0:ℝ) ≤ (M*n:ℕ) by positivity) + change _≤((M*n:ℕ):ℝ) at hN + linarith only [hN,hk] + intro m + specialize hn m + rw [hp]; exact hn + refine ⟨hh,?_⟩ + filter_upwards [hF,hh.wrap,hz.1.eventually (eventually_gt_atTop 0), + (((bp_tendsto_zero hq.pos).comp hz.2).eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1/4))), + (((bp_tendsto_zero hs).comp hz.2).eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1/4)))] + with n hn ht hN hA hB N m w hw hx + let P (x:UnitType p n N) := w x≠0 ∧ (rawHoles m).unit x ∧ joins x≤2*q.D ∧ frameSide p m x + obtain ⟨s,h1,h2,h3⟩:= LeafMixture.grove_first q.ζ q.D q.e hq.pos hq.small hN + (ht.2.2.1 m) hw.total hw.law.nz P hf + refine ⟨s,?_,h1.slide (by unfold leafOld; linarith) le_rfl le_rfl + (fun x=> mul_nonneg (raw_nonneg ..) (raw_nonneg ..)),h2⟩ + have heq x (h : w x≠0) : (rawHoles m).unit x ∧ frameSide p m x := by + have he := lt_of_lt_of_le (lt_of_le_of_ne (hw.law.nz _) h.symm) (hw.total x) + have he : usual p m N x≠0 := by intro hg; rw [hg,mul_zero] at he; exact he.false + refine ⟨by_contra fun e=>h (hx x e),fun i=>?_⟩ + have hz := raw_carried m N + cases i + · exact by_contra fun e => right_ne_zero_of_mul he (hz _ e) + exact by_contra fun e=> left_ne_zero_of_mul he (hz _ e) + let Q (x:UnitType p n N):=2*q.D¬Q x) := by + apply avg_congr + intro x hx + simp only [P,Q,(heq x hx).1,(heq x hx).2,and_true,true_and,not_lt] + exact congrArg ind (propext (and_iff_right hx)) + rw [hi,pr_not,hw.law.total] at h3 + have he : pr w Q≤bp (-((q.D:ℝ)/2)*N) := by + specialize hn _ _ hw.total + rwa [neg_div] at hn + change bp (-q.ζ*N)<1/4 at hA + change bp _ < 1/4 at hB + linarith only [he,h3,hB,hA] +end PreparationParameters +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/InjectionWitnesses.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/InjectionWitnesses.lean index 9db467575fc74d5046a319445a3c196cb22ecc52..5b147fe5418b65d8c4c5b54818884480bdcfd9f8 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/InjectionWitnesses.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/InjectionWitnesses.lean @@ -1,161 +1,161 @@ -import OAI.Combinatorics.HadwigerCounterexample.PinInjectionTests - -namespace OAI - -/-! # Injection Witnesses -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module Submodule Function Finset -open scoped BigOperators -variable {I J K : Type} [Fintype I] [Fintype J] [Fintype K] -private def moreMatrix {r : ℕ} (A : Mat I (Fin r)) (v : Vec I) : Mat I (Fin (r+1)) := - Matrix.of (fun i => Fin.cons (v i) (A i)) - -omit [Fintype I] in -private theorem moreMatrix_act {r : ℕ} (A : Mat I (Fin r)) (v : Vec I) - (x : Vec (Fin (r+1))) : - moreMatrix A v *ᵥ x=x 0 • v + A *ᵥ (fun i => x i.succ) := by - funext i; simp only [Matrix.mulVec,dotProduct,moreMatrix,Matrix.of_apply, - Fin.sum_univ_succ,Pi.add_apply,Pi.smul_apply,smul_eq_mul,Fin.cons_zero,Fin.cons_succ] - congr 1; exact mul_comm _ _ - -omit [Fintype I] in -private theorem moreMatrix_inj {r : ℕ} (A : Mat I (Fin r)) (v : Vec I) - (ha : Injective A.mulVec) (h : v∉colSp A) : - Injective (moreMatrix A v).mulVec := by - rw [← Matrix.coe_mulVecLin,← LinearMap.ker_eq_bot, Matrix.ker_mulVecLin_eq_bot_iff] - intro x hx - rw [moreMatrix_act] at hx - let b (i : Fin r) := x i.succ - rcases bit_cases (x 0) with he|he - · have hh : b=0 := by - apply ha - rw [he,zero_smul,zero_add] at hx - exact hx.trans (Matrix.mulVec_zero _).symm - funext i - refine Fin.cases he (fun k => ?_) i - exact congr_fun hh k - · rw [he,one_smul] at hx - have heq : v=A *ᵥ b := add_right_cancel (hx.trans (char_two _).symm) - exact (h ⟨b,heq.symm⟩).elim - -variable {p : Shape} {n N : ℕ} -def pushCost (l : ℝ) (K : ℕ) := l/bp K - -set_option maxHeartbeats 800000 in -private theorem booming (b : Fpins p n N) (K k t : ℕ) (hk : k≤t) - (hK : ∀ x,planRank (b x) ≤ K) (z : Place p) (i j : Bool) - (w v : Wgt (UnitType p n N)) (hw : IsLaw w) (hv : IsLaw v) {l : ℝ} (hl : 0 < l) - (hf : ∀ T : Space (Vec (Fin N)),dim T ≤ t → - pr w (fun x => ¬Disjoint (imageP p x i z) T) ≤ l) - (Q : UnitType p n N→Prop) (hp : 0 < pr v Q) - (hQ : ∀ y,Q y→3*l≤ pr w (fun x => fans b z i j x y)) : - ∃ Y : Mat (Fin N) (Fin k), Injective Y.mulVec ∧ - (pushCost l K)^k * pr v Q ≤ pr v (fun y => Q y ∧ ∀ m,strikeH b z j (Y.col m) y) := by - classical - have hx : 0 - refine ⟨0,fun a b _ => Subsingleton.elim a b,?_⟩ - simp - | succ k ih => - obtain ⟨Y,hY,hA⟩ := ih (Nat.le_of_succ_le hk) - let S (y) := Q y∧∀ m,strikeH b z j (Y.col m) y - have hq : 0 < pr v S := lt_of_lt_of_le (mul_pos (pow_pos hx _) hp) hA - let P (x : UnitType p n N) := Disjoint (imageP p x i z) (colSp Y) - obtain ⟨x,hx,hP⟩ : - ∃ x,P x ∧ l*pr v S S y ∧ fans b z i j x y) := by - have hg : - avg w (fun x => ind (P x)*pr v (fun y => S y∧fans b z i j x y))= - avg v (fun y => ind (S y)*pr w (fun x => fans b z i j x y∧P x)) := by - unfold pr; simp_rw [← avg_mul',ind_and] - rw [avg_avg]; apply congrArg; funext y - apply congrArg; ext; ring - have he : pr w (fun x => ¬ P x) ≤ l := hf _ ((Y.rank_le_card_width.trans_eq - (Fintype.card_fin _)).trans (Nat.le_of_succ_le hk)) - let g (x) := ind (P x)*pr v (fun y => S y∧fans b z i j x y) - have hh : 2*l*pr v S≤avg w g := by - unfold g; rw [hg] - unfold pr; rw [← avg_mul']; refine avg_mono hv.nz fun y => ?_ - by_cases ht : S y - · rw [ind_one ht,mul_one,one_mul] - refine le_trans ?_ (pr_shield hw.nz (fun x => fans b z i j x y) P) - have hh := hQ y ht.1; linarith - rw [ind_zero ht,zero_mul,mul_zero] - obtain ⟨x,hx⟩ : ∃ x,l*pr v S he i) - rw [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,card_space] at ht - have hlg : bp (dim R) ≤ bp K := bp_le (by exact_mod_cast ((rootSet_dim ..).trans (hK x))) - have he' := mul_le_mul_of_nonneg_right hlg (show 0≤pushCost l K*pr v S by - unfold pushCost; exact mul_nonneg (div_nonneg hl.le (bp_pos _).le) hq.le) - have hr : bp (K:ℝ)*(pushCost l K*pr v S)=l*pr v S := by - have hz := bp_pos (K:ℝ) - unfold pushCost - field_simp - exact (lt_irrefl _ (ht.trans_le (he'.trans_eq hr))) - have hc : a.val≠0 := by - by_contra hc - rw [show C a=(fun _ => False) by unfold C; rw [hc]; simp,pr_false] at ha - have h := div_pos hl (bp_pos (K:ℝ)) - exact (not_lt_of_ge (mul_pos h hq).le ha).elim - refine ⟨moreMatrix Y a.val,moreMatrix_inj Y _ hY ?_,?_⟩ - · intro h - exact hc (Submodule.disjoint_def.mp hx a.val ((rootSet_subset ..) a.property) h) - · have hC y (h : C a y) : Q y ∧ ∀ m,strikeH b z j ((moreMatrix Y a.val).col m) y := by - refine ⟨h.2.1.1,fun k => Fin.cases h.2.2 (fun m => ?_) k⟩ - have hh : (moreMatrix Y a.val).col m.succ=Y.col m := by - ext; simp [Matrix.col_apply,moreMatrix] - rw [hh]; exact h.2.1.2 m - rw [pow_succ,mul_comm _ (pushCost l K),mul_assoc] - exact ((mul_le_mul_of_nonneg_left hA (div_pos hl (bp_pos _)).le).trans ha.le).trans - (pr_mono hv.nz hC) - -set_option maxHeartbeats 600000 in -theorem cannon {b : Fpins p n N} (K k : ℕ) - (hK : ∀ x,planRank (b x) ≤ K) (z : Place p) (i j : Bool) - (w v : Wgt (UnitType p n N)) (hw : IsLaw w) (hv : IsLaw v) - {l : ℝ} (hl : 0 < l) - (m : Mixer p n) {A B : ℝ} (hL : 0≤ A) (hB : 0 ≤ B) - (he : bySide p w m A) (hf : bySide p v m B) - (hN : 2*num (Full p n)-N≤ -1) - (hg : A*2*bp (num (Row p n)+k-N) ≤ l) : - pr v (fun y => 3*l≤ pr w (fun x => fans b z i j x y)) ≤ - fireBill p k K B / (pushCost l K)^k := by - classical - let Q := fun y => 3*l≤pr w (fun x => fans b z i j x y) - have hx : 0 ¬Disjoint (imageP p x i z) T)≤ l := by - apply le_trans (any_frame_hit m hL he i z hN T) (le_trans ?_ hg) - have hr : (dim T:ℝ) ≤ k := by exact_mod_cast h - gcongr - obtain ⟨Y,hY,hP⟩ := booming b K k k le_rfl hK z i j w v hw hv hl het Q h (fun _ h => h) - exact (hP.trans (pr_mono hv.nz fun _ => And.right)).trans - (strikers b K hK Y hY m hB hf hv.sub j z hN) - exact (mul_nonpos_of_nonneg_of_nonpos (pow_nonneg hx.le _) (not_lt.mp h)).trans (by - unfold fireBill; exact mul_nonneg (by positivity) (bp_pos _).le) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PinInjectionTests + +namespace OAI + +/-! # Injection Witnesses -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module Submodule Function Finset +open scoped BigOperators +variable {I J K : Type} [Fintype I] [Fintype J] [Fintype K] +private def moreMatrix {r : ℕ} (A : Mat I (Fin r)) (v : Vec I) : Mat I (Fin (r+1)) := + Matrix.of (fun i => Fin.cons (v i) (A i)) + +omit [Fintype I] in +private theorem moreMatrix_act {r : ℕ} (A : Mat I (Fin r)) (v : Vec I) + (x : Vec (Fin (r+1))) : + moreMatrix A v *ᵥ x=x 0 • v + A *ᵥ (fun i => x i.succ) := by + funext i; simp only [Matrix.mulVec,dotProduct,moreMatrix,Matrix.of_apply, + Fin.sum_univ_succ,Pi.add_apply,Pi.smul_apply,smul_eq_mul,Fin.cons_zero,Fin.cons_succ] + congr 1; exact mul_comm _ _ + +omit [Fintype I] in +private theorem moreMatrix_inj {r : ℕ} (A : Mat I (Fin r)) (v : Vec I) + (ha : Injective A.mulVec) (h : v∉colSp A) : + Injective (moreMatrix A v).mulVec := by + rw [← Matrix.coe_mulVecLin,← LinearMap.ker_eq_bot, Matrix.ker_mulVecLin_eq_bot_iff] + intro x hx + rw [moreMatrix_act] at hx + let b (i : Fin r) := x i.succ + rcases bit_cases (x 0) with he|he + · have hh : b=0 := by + apply ha + rw [he,zero_smul,zero_add] at hx + exact hx.trans (Matrix.mulVec_zero _).symm + funext i + refine Fin.cases he (fun k => ?_) i + exact congr_fun hh k + · rw [he,one_smul] at hx + have heq : v=A *ᵥ b := add_right_cancel (hx.trans (char_two _).symm) + exact (h ⟨b,heq.symm⟩).elim + +variable {p : Shape} {n N : ℕ} +def pushCost (l : ℝ) (K : ℕ) := l/bp K + +set_option maxHeartbeats 800000 in +private theorem booming (b : Fpins p n N) (K k t : ℕ) (hk : k≤t) + (hK : ∀ x,planRank (b x) ≤ K) (z : Place p) (i j : Bool) + (w v : Wgt (UnitType p n N)) (hw : IsLaw w) (hv : IsLaw v) {l : ℝ} (hl : 0 < l) + (hf : ∀ T : Space (Vec (Fin N)),dim T ≤ t → + pr w (fun x => ¬Disjoint (imageP p x i z) T) ≤ l) + (Q : UnitType p n N→Prop) (hp : 0 < pr v Q) + (hQ : ∀ y,Q y→3*l≤ pr w (fun x => fans b z i j x y)) : + ∃ Y : Mat (Fin N) (Fin k), Injective Y.mulVec ∧ + (pushCost l K)^k * pr v Q ≤ pr v (fun y => Q y ∧ ∀ m,strikeH b z j (Y.col m) y) := by + classical + have hx : 0 + refine ⟨0,fun a b _ => Subsingleton.elim a b,?_⟩ + simp + | succ k ih => + obtain ⟨Y,hY,hA⟩ := ih (Nat.le_of_succ_le hk) + let S (y) := Q y∧∀ m,strikeH b z j (Y.col m) y + have hq : 0 < pr v S := lt_of_lt_of_le (mul_pos (pow_pos hx _) hp) hA + let P (x : UnitType p n N) := Disjoint (imageP p x i z) (colSp Y) + obtain ⟨x,hx,hP⟩ : + ∃ x,P x ∧ l*pr v S S y ∧ fans b z i j x y) := by + have hg : + avg w (fun x => ind (P x)*pr v (fun y => S y∧fans b z i j x y))= + avg v (fun y => ind (S y)*pr w (fun x => fans b z i j x y∧P x)) := by + unfold pr; simp_rw [← avg_mul',ind_and] + rw [avg_avg]; apply congrArg; funext y + apply congrArg; ext; ring + have he : pr w (fun x => ¬ P x) ≤ l := hf _ ((Y.rank_le_card_width.trans_eq + (Fintype.card_fin _)).trans (Nat.le_of_succ_le hk)) + let g (x) := ind (P x)*pr v (fun y => S y∧fans b z i j x y) + have hh : 2*l*pr v S≤avg w g := by + unfold g; rw [hg] + unfold pr; rw [← avg_mul']; refine avg_mono hv.nz fun y => ?_ + by_cases ht : S y + · rw [ind_one ht,mul_one,one_mul] + refine le_trans ?_ (pr_shield hw.nz (fun x => fans b z i j x y) P) + have hh := hQ y ht.1; linarith + rw [ind_zero ht,zero_mul,mul_zero] + obtain ⟨x,hx⟩ : ∃ x,l*pr v S he i) + rw [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,card_space] at ht + have hlg : bp (dim R) ≤ bp K := bp_le (by exact_mod_cast ((rootSet_dim ..).trans (hK x))) + have he' := mul_le_mul_of_nonneg_right hlg (show 0≤pushCost l K*pr v S by + unfold pushCost; exact mul_nonneg (div_nonneg hl.le (bp_pos _).le) hq.le) + have hr : bp (K:ℝ)*(pushCost l K*pr v S)=l*pr v S := by + have hz := bp_pos (K:ℝ) + unfold pushCost + field_simp + exact (lt_irrefl _ (ht.trans_le (he'.trans_eq hr))) + have hc : a.val≠0 := by + by_contra hc + rw [show C a=(fun _ => False) by unfold C; rw [hc]; simp,pr_false] at ha + have h := div_pos hl (bp_pos (K:ℝ)) + exact (not_lt_of_ge (mul_pos h hq).le ha).elim + refine ⟨moreMatrix Y a.val,moreMatrix_inj Y _ hY ?_,?_⟩ + · intro h + exact hc (Submodule.disjoint_def.mp hx a.val ((rootSet_subset ..) a.property) h) + · have hC y (h : C a y) : Q y ∧ ∀ m,strikeH b z j ((moreMatrix Y a.val).col m) y := by + refine ⟨h.2.1.1,fun k => Fin.cases h.2.2 (fun m => ?_) k⟩ + have hh : (moreMatrix Y a.val).col m.succ=Y.col m := by + ext; simp [Matrix.col_apply,moreMatrix] + rw [hh]; exact h.2.1.2 m + rw [pow_succ,mul_comm _ (pushCost l K),mul_assoc] + exact ((mul_le_mul_of_nonneg_left hA (div_pos hl (bp_pos _)).le).trans ha.le).trans + (pr_mono hv.nz hC) + +set_option maxHeartbeats 600000 in +theorem cannon {b : Fpins p n N} (K k : ℕ) + (hK : ∀ x,planRank (b x) ≤ K) (z : Place p) (i j : Bool) + (w v : Wgt (UnitType p n N)) (hw : IsLaw w) (hv : IsLaw v) + {l : ℝ} (hl : 0 < l) + (m : Mixer p n) {A B : ℝ} (hL : 0≤ A) (hB : 0 ≤ B) + (he : bySide p w m A) (hf : bySide p v m B) + (hN : 2*num (Full p n)-N≤ -1) + (hg : A*2*bp (num (Row p n)+k-N) ≤ l) : + pr v (fun y => 3*l≤ pr w (fun x => fans b z i j x y)) ≤ + fireBill p k K B / (pushCost l K)^k := by + classical + let Q := fun y => 3*l≤pr w (fun x => fans b z i j x y) + have hx : 0 ¬Disjoint (imageP p x i z) T)≤ l := by + apply le_trans (any_frame_hit m hL he i z hN T) (le_trans ?_ hg) + have hr : (dim T:ℝ) ≤ k := by exact_mod_cast h + gcongr + obtain ⟨Y,hY,hP⟩ := booming b K k k le_rfl hK z i j w v hw hv hl het Q h (fun _ h => h) + exact (hP.trans (pr_mono hv.nz fun _ => And.right)).trans + (strikers b K hK Y hY m hB hf hv.sub j z hN) + exact (mul_nonpos_of_nonneg_of_nonpos (pow_nonneg hx.le _) (not_lt.mp h)).trans (by + unfold fireBill; exact mul_nonneg (by positivity) (bp_pos _).le) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/KeyDirections.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/KeyDirections.lean index dd06bc4c3bba9a47d903b5b175e5e8c5d05b4a84..62c3d8fe61035b487c03efeb93a51d9c0edb1410 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/KeyDirections.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/KeyDirections.lean @@ -1,167 +1,167 @@ -import OAI.Combinatorics.HadwigerCounterexample.CrossForms -import OAI.Combinatorics.HadwigerCounterexample.ImagePartitions - -namespace OAI - -/-! # Key Directions -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Finset - -variable {I : Type} [Fintype I] -variable {p : Shape} {n N : ℕ} - -/-- One side of the lists, with actual point inputs, indexed by the -simultaneous (both units') list positions. Tags passed separately -because matched across the two sides. -/ -structure Volley (p : Shape) (n : ℕ) (I : Type) where - obj : I → Bool - sel : I → Label p.b - par : I → Base p.g n - -abbrev Tagging (p : Shape) (I : Type) := I → Tag p.g -abbrev AtomKey {p : Shape} (l : Tag p.g) (N : ℕ) := TagStar l → Bool → Vec (Fin N) - -def keyOne (p : Shape) (l : Tag p.g) (s : Label p.b) (z : Base p.g n) - (o : Orient p n N) : AtomKey (p:=p) l N := - fun e b => primary (takeSign (p:=p) (o e.val) b) *ᵥ point p s z - -abbrev Keys {p : Shape} {I : Type} (t : Tagging p I) (N : ℕ) := ∀ i, AtomKey (p:=p) (t i) N - -namespace Volley -variable (v : Volley p n I) -def atomAt (t : Tagging p I) (i) := atom p (t i) (v.sel i) (v.par i) -def rayAt (i) := point p (v.sel i) (v.par i) -def rayLoc (i) := IP p n (v.obj i) *ᵥ v.rayAt i - -/-- List from endpoint j to endpoint k of the other unit. -/ -def shoots (w : I → Bool) (j k : Bool) := univ.filter (fun i => v.obj i=j ∧ w i=k) -def here (j : Bool) := Finset.univ.filter (fun i => v.obj i=j) -def sumAt (t : Tagging p I) (w : I→Bool) (j k : Bool) := - ∑ i∈shoots v w j k, v.atomAt t i - -def keys (t : Tagging p I) (x : UnitType p n N) : Keys (p:=p) t N := - fun i => keyOne p (t i) (v.sel i) (v.par i) (onSide x (v.obj i)) - -abbrev visits (p : Shape) (t : Tagging p I) (e : Comp p.g) := {i:I//inc e (t i)} -instance (t : Tagging p I) (e) : Fintype (visits p t e) := inferInstance - -def keyM (t : Tagging p I) (e : Comp p.g) : Mat (JointIdx p n) (visits p t e) := - Matrix.of fun i j => v.rayLoc j.val i -def keyPlan (t : Tagging p I) : Plan p n := fun e => colSp (v.keyM t e.1) - -omit [Fintype I] in -theorem keys_loc (t : Tagging p I) (x : UnitType p n N) (i : I) (f : TagStar (t i)) (b : Bool) : - v.keys t x i f b = images x (f.val,b) *ᵥ v.rayLoc i := by - rw [rayLoc,mulVec_mulVec, images_ip]; rfl - -omit [Fintype I] in -theorem atom_share (v' : Volley p n I) (t : Tagging p I) (x y : UnitType p n N) - (h : v.keys t x=v'.keys t y) (i : I) : - Uembed (onSide x (v.obj i)) (v.atomAt t i) = Uembed (onSide y (v'.obj i)) (v'.atomAt t i) := by - classical - funext e - change liftM _ _ (atom p _ _ _ e) = liftM _ _ (atom p _ _ _ e) - by_cases hs : inc e (t i) - · simp only [atom_def,hs, ite_true,mom,liftM_outer] - exact congrArg₂ vecMulVec (congr_fun (congr_fun (congr_fun h i) (⟨e,hs⟩)) true) - (congr_fun (congr_fun (congr_fun h i) (⟨e,hs⟩)) false) - simp only [atom_def,hs,ite_false,map_zero] - -/-- At each endpoint at most q calls, with distinct labels and no -label interacting with a short vector in the pinned projections. -/ -def avoids (a : Plan p n) (q : ℕ) := - ∀ i, ∃ B : Finset (Label p.b), - (∀ z : Place p, protectedBy p (sPin a z i) q B) ∧ - (∀ j∈v.here i,v.sel j∉ B) ∧ - (v.here i).card ≤ q ∧ - Set.InjOn v.sel (v.here i : Set I) -end Volley - -/-- Any combination of points with distinct labels has a short-ray representation -on the image label set. -/ -theorem point_comb {p : Shape} {A : Type*} (J : Finset A) (s : A → Label p.b) - (z : A → Base p.g n) (a : A → F) (hs : Set.InjOn s (J : Set A)) : - ∃ u : LabVals p n, (∀ i∈J,u (s i)=a i • baseV (z i)) ∧ - ∑ i∈J,a i • point p (s i) (z i)=labcomb p n (J.image s) u := by - classical - let f := fun j : Label p.b => ∑ i∈J, if s i=j then a i • baseV (z i) else 0 - have he i (hi : i∈J) : f (s i)=a i • baseV (z i) := by - unfold f - rw [Finset.sum_eq_single i] - · simp - · intro j hj he; exact ite_eq_right (fun h => he (hs hj hi h)) - simp [hi] - refine ⟨f,he,?_⟩ - rw [labcomb_eval,Finset.sum_image hs] - exact Finset.sum_congr rfl fun i hi => by rw [he i hi,map_smul]; rfl - -namespace Volley - -variable (v : Volley p n I) - -theorem key_miss (t : Tagging p I) {a : Plan p n} {q} (h : v.avoids a q) - (e : Place p) (x : Vec (visits p t e.1)) - (hx : v.keyM t e.1 *ᵥ x ∈ tabSpace a e) : x=0 := by - classical - let M := v.keyM t e.1 - have he : M *ᵥ x = ∑ i : visits p t e.1,x i • (v.rayLoc i.val) := by - rw [mulVec_eq_sum] - simp_rw [op_smul_eq_smul] - rfl - funext j - let i := v.obj j.val - obtain ⟨B,hB,hj,hc,hsel⟩ := h i - have hT := (tab_mem a e _).mp hx i - let f (j : visits p t e.1) := v.obj j.val=i - let J := univ.filter f - have hg : ∑ j∈J,x j • v.rayAt j.val ∈ sPin a e i := by - change ((IP p n i)ᵀ.mulVecLin (M *ᵥ x))∈_ at hT - rw [he,map_sum] at hT - have hi : - (∑ j∈J,x j • v.rayAt j.val) = - ∑ j : visits p t e.1,(IP p n i)ᵀ.mulVecLin (x j • v.rayLoc j.val) := by - rw [show J = univ.filter f from rfl,Finset.sum_filter] - refine Finset.sum_congr rfl fun j _ => ?_ - rw [map_smul,mulVecLin_apply,rayLoc,Matrix.mulVec_mulVec] - by_cases hj : f j - · rw [ite_eq_left hj,show v.obj j.val=i from hj,IP_self, Matrix.one_mulVec] - rw [ite_eq_right hj,IP_cross (show i≠_ from Ne.symm hj), Matrix.zero_mulVec,smul_zero] - rwa [hi] - let s (x : visits p t e.1) := v.sel x.val - have hh {j : visits p t e.1} (h : j∈J) : j.val∈v.here i := - Finset.mem_filter.mpr ⟨Finset.mem_univ _,(mem_filter.mp h).2⟩ - have heq : Set.InjOn s (J : Set _) := fun j hj k hk h => Subtype.ext (hsel (hh hj) (hh hk) h) - obtain ⟨u,hu,hZ⟩ := point_comb J s (v.par ∘ Subtype.val) x heq - have hjj : j∈J := mem_filter.mpr ⟨mem_univ _,rfl⟩ - have hx : (J.image s).card ≤ q := by - refine (card_image_le).trans (le_trans ?_ hc) - have hsub : J.image Subtype.val ⊆ v.here i := by - rintro x hx; obtain ⟨i,hi,rfl⟩ := mem_image.mp hx; exact hh hi - rw [← card_image_of_injective J Subtype.val_injective]; exact card_le_card hsub - have hz := hB e (J.image s) u (hZ ▸ hg) hx (s j) (mem_image_of_mem s hjj) (hj _ (hh hjj)) - rw [hu j hjj] at hz - have heq := congr_fun hz none - simpa only [Pi.zero_apply,Pi.smul_apply,smul_eq_mul,baseV,Option.elim',mul_one] using heq - -theorem key_independent (t : Tagging p I) {a : Plan p n} {q} (h : v.avoids a q) - (e : Place p) : Function.Injective (v.keyM t e.1).mulVec ∧ - Disjoint (v.keyPlan t e) (tabSpace a e) := by - constructor - · rw [← Matrix.coe_mulVecLin,← LinearMap.ker_eq_bot, Matrix.ker_mulVecLin_eq_bot_iff] - intro x hx - apply key_miss v t h e - rw [hx] - exact Submodule.zero_mem _ - rw [disjoint_iff_inf_le] - rintro x ⟨⟨y,rfl⟩,hx⟩ - rw [key_miss v t h e y hx,map_zero] - exact Submodule.zero_mem _ -end Volley -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CrossForms +import OAI.Combinatorics.HadwigerCounterexample.ImagePartitions + +namespace OAI + +/-! # Key Directions -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Finset + +variable {I : Type} [Fintype I] +variable {p : Shape} {n N : ℕ} + +/-- One side of the lists, with actual point inputs, indexed by the +simultaneous (both units') list positions. Tags passed separately +because matched across the two sides. -/ +structure Volley (p : Shape) (n : ℕ) (I : Type) where + obj : I → Bool + sel : I → Label p.b + par : I → Base p.g n + +abbrev Tagging (p : Shape) (I : Type) := I → Tag p.g +abbrev AtomKey {p : Shape} (l : Tag p.g) (N : ℕ) := TagStar l → Bool → Vec (Fin N) + +def keyOne (p : Shape) (l : Tag p.g) (s : Label p.b) (z : Base p.g n) + (o : Orient p n N) : AtomKey (p:=p) l N := + fun e b => primary (takeSign (p:=p) (o e.val) b) *ᵥ point p s z + +abbrev Keys {p : Shape} {I : Type} (t : Tagging p I) (N : ℕ) := ∀ i, AtomKey (p:=p) (t i) N + +namespace Volley +variable (v : Volley p n I) +def atomAt (t : Tagging p I) (i) := atom p (t i) (v.sel i) (v.par i) +def rayAt (i) := point p (v.sel i) (v.par i) +def rayLoc (i) := IP p n (v.obj i) *ᵥ v.rayAt i + +/-- List from endpoint j to endpoint k of the other unit. -/ +def shoots (w : I → Bool) (j k : Bool) := univ.filter (fun i => v.obj i=j ∧ w i=k) +def here (j : Bool) := Finset.univ.filter (fun i => v.obj i=j) +def sumAt (t : Tagging p I) (w : I→Bool) (j k : Bool) := + ∑ i∈shoots v w j k, v.atomAt t i + +def keys (t : Tagging p I) (x : UnitType p n N) : Keys (p:=p) t N := + fun i => keyOne p (t i) (v.sel i) (v.par i) (onSide x (v.obj i)) + +abbrev visits (p : Shape) (t : Tagging p I) (e : Comp p.g) := {i:I//inc e (t i)} +instance (t : Tagging p I) (e) : Fintype (visits p t e) := inferInstance + +def keyM (t : Tagging p I) (e : Comp p.g) : Mat (JointIdx p n) (visits p t e) := + Matrix.of fun i j => v.rayLoc j.val i +def keyPlan (t : Tagging p I) : Plan p n := fun e => colSp (v.keyM t e.1) + +omit [Fintype I] in +theorem keys_loc (t : Tagging p I) (x : UnitType p n N) (i : I) (f : TagStar (t i)) (b : Bool) : + v.keys t x i f b = images x (f.val,b) *ᵥ v.rayLoc i := by + rw [rayLoc,mulVec_mulVec, images_ip]; rfl + +omit [Fintype I] in +theorem atom_share (v' : Volley p n I) (t : Tagging p I) (x y : UnitType p n N) + (h : v.keys t x=v'.keys t y) (i : I) : + Uembed (onSide x (v.obj i)) (v.atomAt t i) = Uembed (onSide y (v'.obj i)) (v'.atomAt t i) := by + classical + funext e + change liftM _ _ (atom p _ _ _ e) = liftM _ _ (atom p _ _ _ e) + by_cases hs : inc e (t i) + · simp only [atom_def,hs, ite_true,mom,liftM_outer] + exact congrArg₂ vecMulVec (congr_fun (congr_fun (congr_fun h i) (⟨e,hs⟩)) true) + (congr_fun (congr_fun (congr_fun h i) (⟨e,hs⟩)) false) + simp only [atom_def,hs,ite_false,map_zero] + +/-- At each endpoint at most q calls, with distinct labels and no +label interacting with a short vector in the pinned projections. -/ +def avoids (a : Plan p n) (q : ℕ) := + ∀ i, ∃ B : Finset (Label p.b), + (∀ z : Place p, protectedBy p (sPin a z i) q B) ∧ + (∀ j∈v.here i,v.sel j∉ B) ∧ + (v.here i).card ≤ q ∧ + Set.InjOn v.sel (v.here i : Set I) +end Volley + +/-- Any combination of points with distinct labels has a short-ray representation +on the image label set. -/ +theorem point_comb {p : Shape} {A : Type*} (J : Finset A) (s : A → Label p.b) + (z : A → Base p.g n) (a : A → F) (hs : Set.InjOn s (J : Set A)) : + ∃ u : LabVals p n, (∀ i∈J,u (s i)=a i • baseV (z i)) ∧ + ∑ i∈J,a i • point p (s i) (z i)=labcomb p n (J.image s) u := by + classical + let f := fun j : Label p.b => ∑ i∈J, if s i=j then a i • baseV (z i) else 0 + have he i (hi : i∈J) : f (s i)=a i • baseV (z i) := by + unfold f + rw [Finset.sum_eq_single i] + · simp + · intro j hj he; exact ite_eq_right (fun h => he (hs hj hi h)) + simp [hi] + refine ⟨f,he,?_⟩ + rw [labcomb_eval,Finset.sum_image hs] + exact Finset.sum_congr rfl fun i hi => by rw [he i hi,map_smul]; rfl + +namespace Volley + +variable (v : Volley p n I) + +theorem key_miss (t : Tagging p I) {a : Plan p n} {q} (h : v.avoids a q) + (e : Place p) (x : Vec (visits p t e.1)) + (hx : v.keyM t e.1 *ᵥ x ∈ tabSpace a e) : x=0 := by + classical + let M := v.keyM t e.1 + have he : M *ᵥ x = ∑ i : visits p t e.1,x i • (v.rayLoc i.val) := by + rw [mulVec_eq_sum] + simp_rw [op_smul_eq_smul] + rfl + funext j + let i := v.obj j.val + obtain ⟨B,hB,hj,hc,hsel⟩ := h i + have hT := (tab_mem a e _).mp hx i + let f (j : visits p t e.1) := v.obj j.val=i + let J := univ.filter f + have hg : ∑ j∈J,x j • v.rayAt j.val ∈ sPin a e i := by + change ((IP p n i)ᵀ.mulVecLin (M *ᵥ x))∈_ at hT + rw [he,map_sum] at hT + have hi : + (∑ j∈J,x j • v.rayAt j.val) = + ∑ j : visits p t e.1,(IP p n i)ᵀ.mulVecLin (x j • v.rayLoc j.val) := by + rw [show J = univ.filter f from rfl,Finset.sum_filter] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [map_smul,mulVecLin_apply,rayLoc,Matrix.mulVec_mulVec] + by_cases hj : f j + · rw [ite_eq_left hj,show v.obj j.val=i from hj,IP_self, Matrix.one_mulVec] + rw [ite_eq_right hj,IP_cross (show i≠_ from Ne.symm hj), Matrix.zero_mulVec,smul_zero] + rwa [hi] + let s (x : visits p t e.1) := v.sel x.val + have hh {j : visits p t e.1} (h : j∈J) : j.val∈v.here i := + Finset.mem_filter.mpr ⟨Finset.mem_univ _,(mem_filter.mp h).2⟩ + have heq : Set.InjOn s (J : Set _) := fun j hj k hk h => Subtype.ext (hsel (hh hj) (hh hk) h) + obtain ⟨u,hu,hZ⟩ := point_comb J s (v.par ∘ Subtype.val) x heq + have hjj : j∈J := mem_filter.mpr ⟨mem_univ _,rfl⟩ + have hx : (J.image s).card ≤ q := by + refine (card_image_le).trans (le_trans ?_ hc) + have hsub : J.image Subtype.val ⊆ v.here i := by + rintro x hx; obtain ⟨i,hi,rfl⟩ := mem_image.mp hx; exact hh hi + rw [← card_image_of_injective J Subtype.val_injective]; exact card_le_card hsub + have hz := hB e (J.image s) u (hZ ▸ hg) hx (s j) (mem_image_of_mem s hjj) (hj _ (hh hjj)) + rw [hu j hjj] at hz + have heq := congr_fun hz none + simpa only [Pi.zero_apply,Pi.smul_apply,smul_eq_mul,baseV,Option.elim',mul_one] using heq + +theorem key_independent (t : Tagging p I) {a : Plan p n} {q} (h : v.avoids a q) + (e : Place p) : Function.Injective (v.keyM t e.1).mulVec ∧ + Disjoint (v.keyPlan t e) (tabSpace a e) := by + constructor + · rw [← Matrix.coe_mulVecLin,← LinearMap.ker_eq_bot, Matrix.ker_mulVecLin_eq_bot_iff] + intro x hx + apply key_miss v t h e + rw [hx] + exact Submodule.zero_mem _ + rw [disjoint_iff_inf_le] + rintro x ⟨⟨y,rfl⟩,hx⟩ + rw [key_miss v t h e y hx,map_zero] + exact Submodule.zero_mem _ +end Volley +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/KeyProjectionBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/KeyProjectionBounds.lean index f7c5fc849ac53edd0c6d1072557bab93a55e8f2b..c2c459514082364aebff1da3136daec047b334c6 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/KeyProjectionBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/KeyProjectionBounds.lean @@ -1,147 +1,147 @@ -import OAI.Combinatorics.HadwigerCounterexample.UniformLeafComparisons - -namespace OAI - -/-! # Key Projection Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix LinearMap -open scoped BigOperators Topology -variable {p:Shape} {n N M K r s0 : ℕ} -namespace StatusAnalysis -open Station -namespace Station -variable {q:Format} {d e:Rates} {w : LeafMixture p n N} (t : Station p n N K w) - (x:Typus p q d e) (m:Mixer p n) (μ:Wgt (UnitType p n N)) (k:Fin (2^deckMax p K)) - (Y:Silhouette p N r) - -variable {B : Type} [Fintype B] -def taxLeft (P : Keys (p:=p) x.t N →B) (i j : w.T) := - varOne (mapW (fun a=> lawNu p N x.t x.z a * stageLeft t x m μ k Y i j a) P) - (mapW (t.leftSales x m μ i j k) P) -def taxRight (P : Keys (p:=p) x.t N →B) (i j : w.T) := - varOne (mapW (fun a=> lawNu p N x.t x.z a * stageRight t x m μ k Y i j a) P) - (mapW (t.rightSales x m μ i j k) P) -def due (P : Keys (p:=p) x.t N→B) := - avg (pairW (portionW μ w.T) (portionW μ w.T)) (fun i=> - taxLeft t x m μ k Y P i.1 i.2+taxRight t x m μ k Y P i.1 i.2) -def dueEnough {l:ℕ} (ε η:ℝ) (P : Keys (p:=p) x.t N→ Fin l) := - ∀ r:ℕ,∀ Y:Silhouette p N r, due t x m μ k Y P ≤ η → stratum t x m μ k Y ≤ ε -end Station - -open PreparationParameters -variable {l:Filter ℕ} {b:PreparationParameters} {m:cycleM p} {s : rhythms p M} {w:tale p M} - -set_option maxHeartbeats 1800000 in -theorem projectCut {q:Format} {d e:Rates} (x:Typus p q d e) - (h:x.permission) - (k:Fin (2^deckMax p b.pins)) - (hv:veil p M b s0 l m s w) (t:Stations p M b.pins s) - (ε:ℝ) (he:0<ε) : - ∃ (r:ℕ) (η:ℝ), 0<η∧∀ᶠ n in l, let N:=M*n; - ∃ P:Keys (p:=p) x.t N→Fin r, - dueEnough (t n) x (m n) (w n) k ε η P := by - classical - let H := (ε/2)^2/8 - have hH : 0(he'.1.leaf _ hi).pos) hm).1 - have hhN : 2*num (Messenger q×Toast p)-(N:ℝ)≤ -1 := by - change _≤(N:ℝ) at hN; linarith only [hN] - have hν : IsLaw ν := nuLaw x.t x.z hhN - obtain ⟨j,hj,P,hP⟩:= hk (↑I) (↑I) (Keys (p:=p) x.t N) u u ν hu hu hν A B - (fun i=>(hA' i).roll) (fun i=>(hB' i).roll) - let Q := (Fin.castLE hj) ∘ P - refine ⟨Q,fun z Y hs=>?_⟩ - let W := pairW u u - have hW:=pairW_law hu hu - let L := fun x':↑I×↑I =>t n|>.leftSales x (m n) (w n) x'.1 x'.2 k - let U' := fun x':↑I×↑I =>t n|>.rightSales x (m n) (w n) x'.1 x'.2 k - - have hχ (i:↑I×↑I) : A i.1 (L i) := x.qA.sales_custom _ _ _ _ _ _ - have hν' (i:↑I×↑I) : B i.2 (U' i) := x.qB.sales_custom _ _ _ _ _ _ - let J(i:↑I×↑I):=|rebate ν (mcut R ν (L i)) (mcut R ν (U' i)) Q| - have he1 : - avg W J≤H := by - unfold J Q; simp_rw [rebate_thick ν _ _ (Fin.castLE_injective hj)]; exact hP L U' hχ hν' - let g := fun i : ↑I×↑I=> stagePlane v x (m n) (w n) k Y i.1 i.2 - let f := fun i : ↑I×↑I=> Station.eclipse v x (m n) (w n) k Y i.1 i.2 - let C := fun i : ↑I×↑I=> matchScore v x (m n) (w n) i.1 i.2 k - let D := fun i:↑I×↑I=> taxLeft v x (m n) (w n) k Y Q i.1 i.2+taxRight v x - (m n) (w n) k Y Q i.1 i.2 - have hA1 i : IsLaw (x.qA.policies x.t x.z n i) := - Appearance.witLaw (x.qA.allure_apt _ _ h.2.1 _) ht.hR hn.age - have hB1 i : IsLaw (x.qB.policies x.t x.z n i) := - Appearance.witLaw (x.qB.allure_apt _ _ h.2.2.1 _) ht.hR hn.age - let X i:= C i+J i+D i+(2*H) - have hP : ∀ i,g i^2≤ X i := by - intro i - let A' := stageLeft v x (m n) (w n) k Y i.1 i.2 - let B' := stageRight v x (m n) (w n) k Y i.1 i.2 - have hh := hχ i; have hk:= hν' i - obtain ⟨h1,h2⟩:= (hA' _).sales _ hh - obtain ⟨h3,h4⟩:= (hB' _).sales _ hk - have h := density_mend ν hν Q R hr.le A' B' (L i) (U' i) (x.qA.bower_case _ _ _ _ _ _ _ (hF _ i.1.property) - hA1) (x.qB.bower_case _ _ _ _ _ _ _ (hF _ i.2.property) hB1) h1 h3 h2 h4 - have he1 : trayLoss R ν (L i) ≤ H := (hA' _).tailS _ hh - have he2 : trayLoss R ν (U' i)≤ H := (hB' _).tailS _ hk - let a:=taxLeft v x (m n) (w n) k Y Q i.1 i.2 - let b0:=taxRight v x (m n) (w n) k Y Q i.1 i.2 - change g i^2 ≤ C i+ J i+(a+trayLoss R ν (L i)+(b0+trayLoss R ν (U' i))) at h - change _ ≤ C i+J i+(a+b0)+2*H - linarith only [he1,he2,h] - refine skylineMean W f g X ε he.le hW ?_ hP (fun i=> (eclipse_beam v x (m n) (w n) - k Y i.1 i.2 hF hA1 hB1 hhN).trans hR) - have hc : avg W C≤ H := le_trans ((le_abs_self _).trans (hh q d e x k)) h' - unfold X; rw [avg_add,avg_add,avg_add] - have hj : avg W (fun _=> 2*H)=2*H := hW.avg_const _ - rw [hj] - change avg W D≤ H at hs - rw [show (ε/2)^2=8*H from by unfold H; ring]; linarith only [hc,he1,hs,hH] -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.UniformLeafComparisons + +namespace OAI + +/-! # Key Projection Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix LinearMap +open scoped BigOperators Topology +variable {p:Shape} {n N M K r s0 : ℕ} +namespace StatusAnalysis +open Station +namespace Station +variable {q:Format} {d e:Rates} {w : LeafMixture p n N} (t : Station p n N K w) + (x:Typus p q d e) (m:Mixer p n) (μ:Wgt (UnitType p n N)) (k:Fin (2^deckMax p K)) + (Y:Silhouette p N r) + +variable {B : Type} [Fintype B] +def taxLeft (P : Keys (p:=p) x.t N →B) (i j : w.T) := + varOne (mapW (fun a=> lawNu p N x.t x.z a * stageLeft t x m μ k Y i j a) P) + (mapW (t.leftSales x m μ i j k) P) +def taxRight (P : Keys (p:=p) x.t N →B) (i j : w.T) := + varOne (mapW (fun a=> lawNu p N x.t x.z a * stageRight t x m μ k Y i j a) P) + (mapW (t.rightSales x m μ i j k) P) +def due (P : Keys (p:=p) x.t N→B) := + avg (pairW (portionW μ w.T) (portionW μ w.T)) (fun i=> + taxLeft t x m μ k Y P i.1 i.2+taxRight t x m μ k Y P i.1 i.2) +def dueEnough {l:ℕ} (ε η:ℝ) (P : Keys (p:=p) x.t N→ Fin l) := + ∀ r:ℕ,∀ Y:Silhouette p N r, due t x m μ k Y P ≤ η → stratum t x m μ k Y ≤ ε +end Station + +open PreparationParameters +variable {l:Filter ℕ} {b:PreparationParameters} {m:cycleM p} {s : rhythms p M} {w:tale p M} + +set_option maxHeartbeats 1800000 in +theorem projectCut {q:Format} {d e:Rates} (x:Typus p q d e) + (h:x.permission) + (k:Fin (2^deckMax p b.pins)) + (hv:veil p M b s0 l m s w) (t:Stations p M b.pins s) + (ε:ℝ) (he:0<ε) : + ∃ (r:ℕ) (η:ℝ), 0<η∧∀ᶠ n in l, let N:=M*n; + ∃ P:Keys (p:=p) x.t N→Fin r, + dueEnough (t n) x (m n) (w n) k ε η P := by + classical + let H := (ε/2)^2/8 + have hH : 0(he'.1.leaf _ hi).pos) hm).1 + have hhN : 2*num (Messenger q×Toast p)-(N:ℝ)≤ -1 := by + change _≤(N:ℝ) at hN; linarith only [hN] + have hν : IsLaw ν := nuLaw x.t x.z hhN + obtain ⟨j,hj,P,hP⟩:= hk (↑I) (↑I) (Keys (p:=p) x.t N) u u ν hu hu hν A B + (fun i=>(hA' i).roll) (fun i=>(hB' i).roll) + let Q := (Fin.castLE hj) ∘ P + refine ⟨Q,fun z Y hs=>?_⟩ + let W := pairW u u + have hW:=pairW_law hu hu + let L := fun x':↑I×↑I =>t n|>.leftSales x (m n) (w n) x'.1 x'.2 k + let U' := fun x':↑I×↑I =>t n|>.rightSales x (m n) (w n) x'.1 x'.2 k + + have hχ (i:↑I×↑I) : A i.1 (L i) := x.qA.sales_custom _ _ _ _ _ _ + have hν' (i:↑I×↑I) : B i.2 (U' i) := x.qB.sales_custom _ _ _ _ _ _ + let J(i:↑I×↑I):=|rebate ν (mcut R ν (L i)) (mcut R ν (U' i)) Q| + have he1 : + avg W J≤H := by + unfold J Q; simp_rw [rebate_thick ν _ _ (Fin.castLE_injective hj)]; exact hP L U' hχ hν' + let g := fun i : ↑I×↑I=> stagePlane v x (m n) (w n) k Y i.1 i.2 + let f := fun i : ↑I×↑I=> Station.eclipse v x (m n) (w n) k Y i.1 i.2 + let C := fun i : ↑I×↑I=> matchScore v x (m n) (w n) i.1 i.2 k + let D := fun i:↑I×↑I=> taxLeft v x (m n) (w n) k Y Q i.1 i.2+taxRight v x + (m n) (w n) k Y Q i.1 i.2 + have hA1 i : IsLaw (x.qA.policies x.t x.z n i) := + Appearance.witLaw (x.qA.allure_apt _ _ h.2.1 _) ht.hR hn.age + have hB1 i : IsLaw (x.qB.policies x.t x.z n i) := + Appearance.witLaw (x.qB.allure_apt _ _ h.2.2.1 _) ht.hR hn.age + let X i:= C i+J i+D i+(2*H) + have hP : ∀ i,g i^2≤ X i := by + intro i + let A' := stageLeft v x (m n) (w n) k Y i.1 i.2 + let B' := stageRight v x (m n) (w n) k Y i.1 i.2 + have hh := hχ i; have hk:= hν' i + obtain ⟨h1,h2⟩:= (hA' _).sales _ hh + obtain ⟨h3,h4⟩:= (hB' _).sales _ hk + have h := density_mend ν hν Q R hr.le A' B' (L i) (U' i) (x.qA.bower_case _ _ _ _ _ _ _ (hF _ i.1.property) + hA1) (x.qB.bower_case _ _ _ _ _ _ _ (hF _ i.2.property) hB1) h1 h3 h2 h4 + have he1 : trayLoss R ν (L i) ≤ H := (hA' _).tailS _ hh + have he2 : trayLoss R ν (U' i)≤ H := (hB' _).tailS _ hk + let a:=taxLeft v x (m n) (w n) k Y Q i.1 i.2 + let b0:=taxRight v x (m n) (w n) k Y Q i.1 i.2 + change g i^2 ≤ C i+ J i+(a+trayLoss R ν (L i)+(b0+trayLoss R ν (U' i))) at h + change _ ≤ C i+J i+(a+b0)+2*H + linarith only [he1,he2,h] + refine skylineMean W f g X ε he.le hW ?_ hP (fun i=> (eclipse_beam v x (m n) (w n) + k Y i.1 i.2 hF hA1 hB1 hhN).trans hR) + have hc : avg W C≤ H := le_trans ((le_abs_self _).trans (hh q d e x k)) h' + unfold X; rw [avg_add,avg_add,avg_add] + have hj : avg W (fun _=> 2*H)=2*H := hW.avg_const _ + rw [hj] + change avg W D≤ H at hs + rw [show (ε/2)^2=8*H from by unfold H; ring]; linarith only [hc,he1,hs,hH] +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/KeyReferenceLaws.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/KeyReferenceLaws.lean index 704507ad7b41b50b7064c232360a9245c4bd1dd1..2f1e593ac93fbcb83fe1ec00e33fdad0c6a69451 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/KeyReferenceLaws.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/KeyReferenceLaws.lean @@ -1,119 +1,119 @@ -import OAI.Combinatorics.HadwigerCounterexample.BoundedQueryTemplates -import OAI.Combinatorics.HadwigerCounterexample.GramConditionedLaws - -namespace OAI - -/-! # Key Reference Laws -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module Function -open scoped BigOperators -variable {I : Type} [Fintype I] [DecidableEq I] {p : Shape} {n N : ℕ} - -abbrev Toast (p : Shape) := Fin (p.g-1) -def outlet (p : Shape) (l : Tag p.g) : Toast p ≃ TagStar l := - (Fintype.equivFinOfCardEq (card_star l)).symm -def channelTag (p : Shape) (l : Tag p.g) (i : Toast p) := (outlet p l i).val -theorem channelTag_inj (p : Shape) (l : Tag p.g) : Injective (channelTag p l) := - Subtype.val_injective.comp (outlet p l).injective - -def mug (p : Shape) (l : Tag p.g) (N : ℕ) : AtomKey (p:=p) l N ≃ Rack (Toast p) N where - toFun x := (Matrix.of (fun i j => x (outlet p l j) true i),Matrix.of (fun i j => - x (outlet p l j) false i)) - invFun x := fun i b j => if b then x.1 j ((outlet p l).symm i) else x.2 j ((outlet p l).symm i) - left_inv x := by - funext i b j - cases b <;> simp - right_inv x := by apply Prod.ext <;> ext <;> simp - -def tray (p : Shape) (t : Tagging p I) (N : ℕ) : Keys (p:=p) t N ≃ Rack (I×Toast p) N := - (Equiv.piCongrRight (fun i => mug p (t i) N)).trans (relay I (Toast p) N).symm - -def handles (p : Shape) (t : Tagging p I) : I×Toast p ≃ KeySlots p t where - toFun x := ⟨x.1,outlet p (t x.1) x.2⟩ - invFun x := (x.1,(outlet p (t x.1)).symm x.2) - left_inv x := by simp - right_inv x := by simp -def trayPort (p : Shape) (t : Tagging p I) : Route (I×Toast p) (Comp p.g) := - fun x => channelTag p (t x.1) x.2 -def trayJoin (p : Shape) (t : Tagging p I) (e : Comp p.g) : - Port (trayPort p t) e ≃ Port (ownPort (p:=p) t) e where - toFun x := ⟨handles p t x.val,x.property⟩ - invFun x := - ⟨(handles p t).symm x.val,by - have h : (ownPort t) ∘ (handles p t)=trayPort p t := rfl - rw [←h]; simp only [Function.comp_apply,Equiv.apply_symm_apply]; exact x.property⟩ - left_inv x := Subtype.ext (Equiv.symm_apply_apply ..) - right_inv x := Subtype.ext (Equiv.apply_symm_apply ..) - -def trayMap (p : Shape) (t : Tagging p I) (q : I → F) : GeoM (trayPort p t) := - fun e => (ownMap (p:=p) t q e).submatrix (trayJoin p t e) (trayJoin p t e) - -omit [DecidableEq I] in -theorem tray_sips (p : Shape) (t : Tagging p I) (N : ℕ) (x : Keys (p:=p) t N) (i : I) : - led i (tray p t N x)=mug p (t i) N (x i) := by apply Prod.ext <;> rfl - -theorem tray_wave (p : Shape) (t : Tagging p I) (q : I→ F) (x : Keys (p:=p) t N) : - ownPart (p:=p) t q x↔ gramPart (trayMap p t q) (tray p t N x) := by - classical - unfold ownPart - rw [part_scores,part_scores] - let y := scatter t N x - let z := tray p t N x - let A := trayMap p t q - let g := handles p t - have hi i j : scoreR z i j=scoreR y (g i) (g j) := rfl - constructor - · exact fun h i a b => h i (trayJoin p t i a) (trayJoin p t i b) - intro hh i a b - obtain ⟨a,rfl⟩ := (trayJoin p t i).surjective a - obtain ⟨b,rfl⟩ := (trayJoin p t i).surjective b - exact hh i a b -theorem lawtray (p : Shape) (t : Tagging p I) (q : I → F) : - mapW (lawNu p N t q) (tray p t N) = rackWave (trayMap p t q) N := by - unfold lawNu - have h : ownPart (p:=p) t q (N:=N)=(fun x => gramPart (trayMap p t q) (tray p t N x)) := - funext fun i => propext (tray_wave ..) - rw [h] - exact on_equiv .. - -omit [Fintype I] in -theorem mug_wave (p : Shape) (t : Tagging p I) (q : I→F) (i : I) - (x : AtomKey (p:=p) (t i) N) : - ownOne p (t i) (q i) x ↔ gramPart (laneM (trayMap p t q) i) (mug p (t i) N x) := by - classical - rw [part_scores] - let g := trayPort p t; let b := street g i - let X := mug p (t i) N x - let A := laneM (trayMap p t q) i - have hi {j} (a : Port b j) : - scoreR X a.val a.val=dotProduct (x (outlet p (t i) a.val) true) - (x (outlet p (t i) a.val) false) := rfl - have hj {j} (a : Port b j) : A j a a=q i := by - let s := trayJoin p t j (condLane (trayPort p t) i j a) - exact Matrix.diagonal_apply_eq (fun i : Port (ownPort (p:=p) t) j => q i.val.1) s - have hh (a c : Toast p) (h : b a=b c) : a=c := channelTag_inj p (t i) h - constructor - · intro he j a c - have h : c=a := Subtype.ext (hh _ _ (c.property.trans a.property.symm)); subst c - exact (hi a).trans ((he _).trans (hj a).symm) - intro h j - obtain ⟨a,rfl⟩ := (outlet p (t i)).surjective j - let e := b a - let c : Port b e := ⟨a,rfl⟩ - exact (hi c).symm.trans ((h e c c).trans (hj c)) - -omit [Fintype I] in -theorem lawmug (p : Shape) (t : Tagging p I) (q : I → F) (i : I) : - mapW (lawOmega p N (t i) (q i)) (mug p (t i) N) = rackWave (laneM (trayMap p t q) i) N := by - unfold lawOmega - rw [show ownOne p (t i) (q i) (N:=N)= - (fun x => gramPart (laneM (trayMap p t q) i) (mug p (t i) N x)) from - funext fun x => propext (mug_wave ..)] - exact on_equiv .. -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BoundedQueryTemplates +import OAI.Combinatorics.HadwigerCounterexample.GramConditionedLaws + +namespace OAI + +/-! # Key Reference Laws -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module Function +open scoped BigOperators +variable {I : Type} [Fintype I] [DecidableEq I] {p : Shape} {n N : ℕ} + +abbrev Toast (p : Shape) := Fin (p.g-1) +def outlet (p : Shape) (l : Tag p.g) : Toast p ≃ TagStar l := + (Fintype.equivFinOfCardEq (card_star l)).symm +def channelTag (p : Shape) (l : Tag p.g) (i : Toast p) := (outlet p l i).val +theorem channelTag_inj (p : Shape) (l : Tag p.g) : Injective (channelTag p l) := + Subtype.val_injective.comp (outlet p l).injective + +def mug (p : Shape) (l : Tag p.g) (N : ℕ) : AtomKey (p:=p) l N ≃ Rack (Toast p) N where + toFun x := (Matrix.of (fun i j => x (outlet p l j) true i),Matrix.of (fun i j => + x (outlet p l j) false i)) + invFun x := fun i b j => if b then x.1 j ((outlet p l).symm i) else x.2 j ((outlet p l).symm i) + left_inv x := by + funext i b j + cases b <;> simp + right_inv x := by apply Prod.ext <;> ext <;> simp + +def tray (p : Shape) (t : Tagging p I) (N : ℕ) : Keys (p:=p) t N ≃ Rack (I×Toast p) N := + (Equiv.piCongrRight (fun i => mug p (t i) N)).trans (relay I (Toast p) N).symm + +def handles (p : Shape) (t : Tagging p I) : I×Toast p ≃ KeySlots p t where + toFun x := ⟨x.1,outlet p (t x.1) x.2⟩ + invFun x := (x.1,(outlet p (t x.1)).symm x.2) + left_inv x := by simp + right_inv x := by simp +def trayPort (p : Shape) (t : Tagging p I) : Route (I×Toast p) (Comp p.g) := + fun x => channelTag p (t x.1) x.2 +def trayJoin (p : Shape) (t : Tagging p I) (e : Comp p.g) : + Port (trayPort p t) e ≃ Port (ownPort (p:=p) t) e where + toFun x := ⟨handles p t x.val,x.property⟩ + invFun x := + ⟨(handles p t).symm x.val,by + have h : (ownPort t) ∘ (handles p t)=trayPort p t := rfl + rw [←h]; simp only [Function.comp_apply,Equiv.apply_symm_apply]; exact x.property⟩ + left_inv x := Subtype.ext (Equiv.symm_apply_apply ..) + right_inv x := Subtype.ext (Equiv.apply_symm_apply ..) + +def trayMap (p : Shape) (t : Tagging p I) (q : I → F) : GeoM (trayPort p t) := + fun e => (ownMap (p:=p) t q e).submatrix (trayJoin p t e) (trayJoin p t e) + +omit [DecidableEq I] in +theorem tray_sips (p : Shape) (t : Tagging p I) (N : ℕ) (x : Keys (p:=p) t N) (i : I) : + led i (tray p t N x)=mug p (t i) N (x i) := by apply Prod.ext <;> rfl + +theorem tray_wave (p : Shape) (t : Tagging p I) (q : I→ F) (x : Keys (p:=p) t N) : + ownPart (p:=p) t q x↔ gramPart (trayMap p t q) (tray p t N x) := by + classical + unfold ownPart + rw [part_scores,part_scores] + let y := scatter t N x + let z := tray p t N x + let A := trayMap p t q + let g := handles p t + have hi i j : scoreR z i j=scoreR y (g i) (g j) := rfl + constructor + · exact fun h i a b => h i (trayJoin p t i a) (trayJoin p t i b) + intro hh i a b + obtain ⟨a,rfl⟩ := (trayJoin p t i).surjective a + obtain ⟨b,rfl⟩ := (trayJoin p t i).surjective b + exact hh i a b +theorem lawtray (p : Shape) (t : Tagging p I) (q : I → F) : + mapW (lawNu p N t q) (tray p t N) = rackWave (trayMap p t q) N := by + unfold lawNu + have h : ownPart (p:=p) t q (N:=N)=(fun x => gramPart (trayMap p t q) (tray p t N x)) := + funext fun i => propext (tray_wave ..) + rw [h] + exact on_equiv .. + +omit [Fintype I] in +theorem mug_wave (p : Shape) (t : Tagging p I) (q : I→F) (i : I) + (x : AtomKey (p:=p) (t i) N) : + ownOne p (t i) (q i) x ↔ gramPart (laneM (trayMap p t q) i) (mug p (t i) N x) := by + classical + rw [part_scores] + let g := trayPort p t; let b := street g i + let X := mug p (t i) N x + let A := laneM (trayMap p t q) i + have hi {j} (a : Port b j) : + scoreR X a.val a.val=dotProduct (x (outlet p (t i) a.val) true) + (x (outlet p (t i) a.val) false) := rfl + have hj {j} (a : Port b j) : A j a a=q i := by + let s := trayJoin p t j (condLane (trayPort p t) i j a) + exact Matrix.diagonal_apply_eq (fun i : Port (ownPort (p:=p) t) j => q i.val.1) s + have hh (a c : Toast p) (h : b a=b c) : a=c := channelTag_inj p (t i) h + constructor + · intro he j a c + have h : c=a := Subtype.ext (hh _ _ (c.property.trans a.property.symm)); subst c + exact (hi a).trans ((he _).trans (hj a).symm) + intro h j + obtain ⟨a,rfl⟩ := (outlet p (t i)).surjective j + let e := b a + let c : Port b e := ⟨a,rfl⟩ + exact (hi c).symm.trans ((h e c c).trans (hj c)) + +omit [Fintype I] in +theorem lawmug (p : Shape) (t : Tagging p I) (q : I → F) (i : I) : + mapW (lawOmega p N (t i) (q i)) (mug p (t i) N) = rackWave (laneM (trayMap p t q) i) N := by + unfold lawOmega + rw [show ownOne p (t i) (q i) (N:=N)= + (fun x => gramPart (laneM (trayMap p t q) i) (mug p (t i) N x)) from + funext fun x => propext (mug_wave ..)] + exact on_equiv .. +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/KeyTestCorrespondence.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/KeyTestCorrespondence.lean index 759988a1760da5e694648675143f68e1e64d0daa..a7a0eca834202df848b06dc513657185676e51c7 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/KeyTestCorrespondence.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/KeyTestCorrespondence.lean @@ -1,138 +1,138 @@ -import OAI.Combinatorics.HadwigerCounterexample.ScriptGramCorrespondence - -namespace OAI - -/-! # Key Test Correspondence -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix LinearMap -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] - -namespace Template -variable (v : Template p I) - -def pairedRead (s : Script p I) (m : Mixer p n) (z : Inputs p n I) (i j : I) := - ∀ a:MOne p, s i j a=evmat (orderedM m a) (v.croon i (z i)) (v.croon j (z j)) - -def knows (s : Script p I) (m : Mixer p n) (z : Inputs p n I) (i j : I) := - v.aim i=v.aim j→ v.pairedRead s m z i j∧v.pairedRead s m z j i -omit [Fintype I] [DecidableEq I] in -theorem knows_rev (v : Template p I) {s : Script p I} {m : Mixer p n} {z} {i j} - (h : v.knows s m z i j) : v.knows s m z j i := fun ht => (h ht.symm).symm - -omit [DecidableEq I] in -theorem voice_agreement (v : Template p I) (s : Script p I) (m : Mixer p n) - (x : UnitType p n N) (z : Inputs p n I) (hw : ∀ i,frameLaw m (onSide x i)) - (hg : 2≤p.g) (j : v.Chorus) : - listen v.choral (v.chime m x) z j = v.lyrics s j ↔ - v.verges ((v.draw z).keys v.t x) (v.verses j).1 (v.verses j).2 ∧ - v.knows s m z (v.verses j).1 (v.verses j).2 := by - classical - let y := (v.draw z).keys v.t x - cases j with - | inr k => - let a := k.val.1; let b := k.val.2 - have he : v.aim a≠v.aim b := by rw [k.property.1,k.property.2]; decide - have hh e ha hb q : - listen v.choral (v.chime m x) z (.inr k) (⟨(e,q),ha,hb⟩ : - Crossing p (v.t a) (v.t b))=v.voices y a b e ha hb q := by - change evmat (duel p (x.1 e) (x.2 e) q) _ _=_ - rw [voice_note,k.property.1,k.property.2]; rfl - constructor - · intro h - exact ⟨fun e ha hb q => (hh e ha hb q).symm.trans (congr_fun h _),fun ht => (he ht).elim⟩ - rintro ⟨h,_⟩ - apply funext - rintro ⟨⟨e,q⟩,ha,hb⟩ - exact (hh e ha hb q).trans (h e ha hb q) - | inl k => - let a := k.val.1; let b:= k.val.2 - have he : v.aim a=v.aim b := k.property.1 - let u := listen v.choral (v.chime m x) z (.inl k) - let d := v.lyrics s (.inl k) - have hi1 i : - u (Sum.inl (i,true))=d (Sum.inl (i,true)) ↔ - s a b i=evmat (orderedM m i) (v.croon a (z a)) (v.croon b (z b)) := Eq.comm - have hi2 i : - u (Sum.inl (i,false))=d (Sum.inl (i,false)) ↔ - s b a i=evmat (orderedM m i) (v.croon b (z b)) (v.croon a (z a)) := by - change evmat (orderedM m i)ᵀ _ _=s b a i ↔ _ - rw [evmat_transpose]; exact Eq.comm - have ht e ha hb q : - u (Sum.inr q)=d (Sum.inr q) ↔ v.voices y a b e ha hb q=0 := by - rw [voice_same _ x z m hw e a b ha hb he q]; rfl - change u=d↔v.verges y a b ∧ v.knows s m z a b - constructor - · intro h - exact ⟨fun e ha hb q => (ht e ha hb q).mp (congr_fun h _), - fun _ => ⟨fun i => (hi1 i).mp (congr_fun h _),fun i => (hi2 i).mp (congr_fun h _)⟩⟩ - have hk : ∃ e : Comp p.g,inc e (v.t a) ∧ inc e (v.t b) := by - by_cases hx : v.t a=v.t b - · rw [hx] - have h : 0 h _ _ (v.choral.diff _) - rw [h1]; unfold g neigh - constructor - · intro h; exact ⟨fun i j e he => ((h i j e).2 he).1,fun i j e => (h i j e).1⟩ - rintro ⟨h,h'⟩ i j he - exact ⟨h' i j he,fun e => ⟨h i j he e,h j i (Ne.symm he) (Eq.symm e)⟩⟩ - -theorem performs_own (v : Template p I) (s : Script p I) (m : Mixer p n) - (x : UnitType p n N) (z : Inputs p n I) (hw : ∀ i,frameLaw m (onSide x i)) - (hg : 2 ≤ p.g) (hj : 1 ≤ p.j) - (q : I→F) (hq : ∀ i,dialed p (v.t i) (v.f i) (z i)=q i) : - v.performs s m x z ↔ (v.draw z).reads s m ∧ - ownPart (p:=p) v.t q ((v.draw z).keys v.t x) := by - rw [neigh_voice _ _ _ _ _ hw hg,ownPart_def] - unfold neigh - apply and_congr Iff.rfl - have ht (i : I) := v.voices_diag m x z hw hj i - simp_rw [hq] at ht - let y := (v.draw z).keys v.t x - constructor - · intro h; exact ⟨ht,fun i j e hi hj hh => h i j hh e hi hj true⟩ - rintro ⟨_,h⟩ i j hh e hi hj (b|b) - · unfold voices; rw [dotProduct_comm]; exact h j i e hj hi (Ne.symm hh) - exact h i j e hi hj hh - -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ScriptGramCorrespondence + +namespace OAI + +/-! # Key Test Correspondence -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix LinearMap +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] + +namespace Template +variable (v : Template p I) + +def pairedRead (s : Script p I) (m : Mixer p n) (z : Inputs p n I) (i j : I) := + ∀ a:MOne p, s i j a=evmat (orderedM m a) (v.croon i (z i)) (v.croon j (z j)) + +def knows (s : Script p I) (m : Mixer p n) (z : Inputs p n I) (i j : I) := + v.aim i=v.aim j→ v.pairedRead s m z i j∧v.pairedRead s m z j i +omit [Fintype I] [DecidableEq I] in +theorem knows_rev (v : Template p I) {s : Script p I} {m : Mixer p n} {z} {i j} + (h : v.knows s m z i j) : v.knows s m z j i := fun ht => (h ht.symm).symm + +omit [DecidableEq I] in +theorem voice_agreement (v : Template p I) (s : Script p I) (m : Mixer p n) + (x : UnitType p n N) (z : Inputs p n I) (hw : ∀ i,frameLaw m (onSide x i)) + (hg : 2≤p.g) (j : v.Chorus) : + listen v.choral (v.chime m x) z j = v.lyrics s j ↔ + v.verges ((v.draw z).keys v.t x) (v.verses j).1 (v.verses j).2 ∧ + v.knows s m z (v.verses j).1 (v.verses j).2 := by + classical + let y := (v.draw z).keys v.t x + cases j with + | inr k => + let a := k.val.1; let b := k.val.2 + have he : v.aim a≠v.aim b := by rw [k.property.1,k.property.2]; decide + have hh e ha hb q : + listen v.choral (v.chime m x) z (.inr k) (⟨(e,q),ha,hb⟩ : + Crossing p (v.t a) (v.t b))=v.voices y a b e ha hb q := by + change evmat (duel p (x.1 e) (x.2 e) q) _ _=_ + rw [voice_note,k.property.1,k.property.2]; rfl + constructor + · intro h + exact ⟨fun e ha hb q => (hh e ha hb q).symm.trans (congr_fun h _),fun ht => (he ht).elim⟩ + rintro ⟨h,_⟩ + apply funext + rintro ⟨⟨e,q⟩,ha,hb⟩ + exact (hh e ha hb q).trans (h e ha hb q) + | inl k => + let a := k.val.1; let b:= k.val.2 + have he : v.aim a=v.aim b := k.property.1 + let u := listen v.choral (v.chime m x) z (.inl k) + let d := v.lyrics s (.inl k) + have hi1 i : + u (Sum.inl (i,true))=d (Sum.inl (i,true)) ↔ + s a b i=evmat (orderedM m i) (v.croon a (z a)) (v.croon b (z b)) := Eq.comm + have hi2 i : + u (Sum.inl (i,false))=d (Sum.inl (i,false)) ↔ + s b a i=evmat (orderedM m i) (v.croon b (z b)) (v.croon a (z a)) := by + change evmat (orderedM m i)ᵀ _ _=s b a i ↔ _ + rw [evmat_transpose]; exact Eq.comm + have ht e ha hb q : + u (Sum.inr q)=d (Sum.inr q) ↔ v.voices y a b e ha hb q=0 := by + rw [voice_same _ x z m hw e a b ha hb he q]; rfl + change u=d↔v.verges y a b ∧ v.knows s m z a b + constructor + · intro h + exact ⟨fun e ha hb q => (ht e ha hb q).mp (congr_fun h _), + fun _ => ⟨fun i => (hi1 i).mp (congr_fun h _),fun i => (hi2 i).mp (congr_fun h _)⟩⟩ + have hk : ∃ e : Comp p.g,inc e (v.t a) ∧ inc e (v.t b) := by + by_cases hx : v.t a=v.t b + · rw [hx] + have h : 0 h _ _ (v.choral.diff _) + rw [h1]; unfold g neigh + constructor + · intro h; exact ⟨fun i j e he => ((h i j e).2 he).1,fun i j e => (h i j e).1⟩ + rintro ⟨h,h'⟩ i j he + exact ⟨h' i j he,fun e => ⟨h i j he e,h j i (Ne.symm he) (Eq.symm e)⟩⟩ + +theorem performs_own (v : Template p I) (s : Script p I) (m : Mixer p n) + (x : UnitType p n N) (z : Inputs p n I) (hw : ∀ i,frameLaw m (onSide x i)) + (hg : 2 ≤ p.g) (hj : 1 ≤ p.j) + (q : I→F) (hq : ∀ i,dialed p (v.t i) (v.f i) (z i)=q i) : + v.performs s m x z ↔ (v.draw z).reads s m ∧ + ownPart (p:=p) v.t q ((v.draw z).keys v.t x) := by + rw [neigh_voice _ _ _ _ _ hw hg,ownPart_def] + unfold neigh + apply and_congr Iff.rfl + have ht (i : I) := v.voices_diag m x z hw hj i + simp_rw [hq] at ht + let y := (v.draw z).keys v.t x + constructor + · intro h; exact ⟨ht,fun i j e hi hj hh => h i j hh e hi hj true⟩ + rintro ⟨_,h⟩ i j hh e hi hj (b|b) + · unfold voices; rw [dotProduct_comm]; exact h j i e hj hi (Ne.symm hh) + exact h i j e hi hj hh + +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/LabeledGenerators.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/LabeledGenerators.lean index fe38ab6ff2b8d24b6b763d5a55fe08b63b876ac5..d841a2a1574172b6cbaaf720d8e19871565c0d09 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/LabeledGenerators.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/LabeledGenerators.lean @@ -1,166 +1,166 @@ -import OAI.Combinatorics.HadwigerCounterexample.CoordinateDuality - -namespace OAI - -/-! # Labeled Generators -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Function LinearMap Submodule Module -open scoped BigOperators -namespace StatusAnalysis -variable {L I X Y : Type} [DecidableEq L] [DecidableEq I] [AddCommGroup X] - [Module F X] [AddCommGroup Y] [Module F Y] - -structure Club (I X L : Type) where - valid : I→Prop - writes : I→ X - addr : I→ Bool→L - -abbrev Straps (L : Type) := Bool→Finset L -variable (C : Club I X L) -namespace Club -def zone (s : Straps L) (i) := C.valid i ∧ ∀ b,C.addr i b∉s b -def band (s : Straps L) : Space X := Submodule.span F {x|∃ i, C.zone s i∧C.writes i=x} -def bundle (p : Finset I) (s : Straps L) := - (∀ i∈p,zone C s i) ∧ ∀ b : Bool, Set.InjOn (fun i=> C.addr i b) (p : Set I) -def contents (p : Finset I) := ∑ i∈p,C.writes i - -def length3 (s : Straps L) (π : X→ₗ[F] Y) (x : X) := - ∃ p : Finset I,C.bundle p s ∧ p.card≤3 ∧ C.contents p=x ∧ π x=0 -def ration (s : Straps L) (π : X→ₗ[F] Y) : Space X := Submodule.span F (C.length3 s π) - -def yield3 (s : Straps L) (π : X→ₗ[F] Y) := - ∀ u:Straps L,(∀ b,(u b).card≤2) → ∀ y,∃ i,zone C (s⊔u) i ∧ π (C.writes i)=y - -omit [DecidableEq L] [DecidableEq I] in -theorem band_write (s : Straps L) {i : I} (hi : C.zone s i) : - C.writes i∈ C.band s := subset_span ⟨i,hi,rfl⟩ -omit [DecidableEq L] [DecidableEq I] in -theorem band_contents (s : Straps L) {p : Finset I} (hp : C.bundle p s) : - C.contents p∈ C.band s := Submodule.sum_mem _ fun i hi=> band_write C s (hp.1 i hi) -omit [DecidableEq L] [DecidableEq I] in -theorem length3_zero (s : Straps L) (π : X→ₗ[F] Y) : - C.length3 s π 0 := by refine ⟨∅,⟨?_,?_⟩,?_,?_,?_⟩ <;> simp [contents] - -omit [DecidableEq L] [DecidableEq I] [AddCommGroup X] [Module F X] in -theorem zone_smaller {s t : Straps L} (h : s≤t) (i:I) (hi : zone C t i) : zone C s i := - ⟨hi.1,fun b hx=> hi.2 b (h b hx)⟩ -omit [DecidableEq L] [DecidableEq I] in -theorem ration_le (s : Straps L) (π : X→ₗ[F] Y) : ration C s π ≤ C.band s⊓LinearMap.ker π := by - refine Submodule.span_le.mpr ?_ - rintro i ⟨x,ha,hb,rfl,hg⟩ - exact ⟨band_contents C s ha,hg⟩ - -def addrs (p : Finset I) : Straps L := fun b=>p.image (fun i=> C.addr i b) -omit [DecidableEq I] in -theorem yield_after (s : Straps L) (π : X→ₗ[F] Y) (h : yield3 C s π) - (p : Finset I) (hp : p.card≤ 2) (y : Y) : - ∃ i,zone C s i ∧ π (C.writes i)=y ∧ - ∀ j∈p,∀ b,C.addr i b≠C.addr j b := by - obtain ⟨i,hi,ht⟩ := h (addrs C p) (fun i=>card_image_le.trans hp) y - refine ⟨i,C.zone_smaller le_sup_left i hi,ht,fun j hj b h=>?_⟩ - exact hi.2 b (mem_union_right _ (Finset.mem_image.mpr ⟨j,hj,h.symm⟩)) - -def different (i j : I) := ∀ b,C.addr i b≠ C.addr j b -omit [DecidableEq L] [DecidableEq I] [AddCommGroup X] [Module F X] in -theorem different_ne {i j : I} (h : C.different i j) : i≠j := fun hx=> h true (hx ▸ rfl) -omit [DecidableEq L] [DecidableEq I] [AddCommGroup X] [Module F X] in -theorem bundle_one (s : Straps L) {i} (h : zone C s i) : bundle C {i} s := by - constructor - · intro j hj; rwa [mem_singleton.mp hj] - simp - -omit [DecidableEq L] [AddCommGroup X] [Module F X] in -theorem bundle_insert (s : Straps L) {i} (h : zone C s i) (p : Finset I) (hp : bundle C p s) - (he : ∀ j∈p,C.different i j) : bundle C (insert i p) s := by - refine ⟨fun j hj=>?_,fun b y hy z hz hh=>?_⟩ - · rcases mem_insert.mp hj with h'|h' - · exact h' ▸ h - exact hp.1 j h' - rcases mem_insert.mp hy with h'|h' - · subst y; rcases mem_insert.mp hz with hz|hz - · exact hz.symm - exact (he _ hz b hh).elim - rcases mem_insert.mp hz with hz|hz - · subst z; exact (he _ h' b hh.symm).elim - exact hp.2 b h' hz hh - -set_option maxHeartbeats 900000 in -theorem ration_eq (s : Straps L) (π : X→ₗ[F] Y) (h : yield3 C s π) : - ration C s π=C.band s⊓LinearMap.ker π := by - classical - let R:=ration C s π; let q:=R.mkQ - - have hr (i j:I) (hi:C.zone s i) (hj:C.zone s j) (ht : π (C.writes i)=π (C.writes j)) - (hh : C.different i j) : q (C.writes i)=q (C.writes j) := by - have hg:=C.different_ne hh - let W := C.writes - apply add_right_cancel (b:=q (W j)) - rw [char_two,←map_add] - apply (Submodule.Quotient.mk_eq_zero R).mpr - refine subset_span ⟨{i,j},C.bundle_insert s hi _ (C.bundle_one s hj) - (fun z hz=> (mem_singleton.mp hz).symm ▸ hh),by simp [hg], - by simp [contents,W,hg],?_⟩ - rw [map_add,ht,char_two] - let f:=C.writes - have hg (i j:I) (hi:C.zone s i) (hj:C.zone s j) (ht : π (f i)=π (f j)) : - q (f i)=q (f j) := by - obtain ⟨t,ht',hy,hb⟩:=C.yield_after s π h {i,j} (by - by_cases hi : i=j <;> simp [hi]) (π (f j)) - exact (hr t i ht' hi (hy.trans ht.symm) (hb i (by simp))).symm.trans - (hr t j ht' hj hy (hb j (by simp))) - choose g he hG hP using fun y=>C.yield_after s π h ∅ (by simp) y - let F (x : Y) := q (f (g x)) - have hq i (hi:C.zone s i) : F (π (f i))=q (f i) := hg _ i (he _) hi (hG _) - have h0 : F 0=0 := by - have hh:=he 0 - refine (Submodule.Quotient.mk_eq_zero R).mpr (subset_span ?_) - exact ⟨{g 0},C.bundle_one s hh, by simp, by simp [f,contents], hG 0⟩ - have hh (x y) : F (x+y)=F x+F y := by - let i:=g x - obtain ⟨j,hj,hJ,hA⟩:=C.yield_after s π h {i} (by simp) y - have hai:=hA i (by simp) - have hg' : j≠i:=C.different_ne hai - let t : Finset I := {j,i} - have ht : t.card=2 := by simp [t,hg'] - obtain ⟨k,hk,hK,hB⟩:=C.yield_after s π h t (by omega) (x+y) - have hkt : k∉t := fun hx=> C.different_ne (hB k hx) rfl - have hQ : - q (f k)+(q (f j)+q (f i))=0 := by - have hR : C.length3 s π (f k+(f j+f i)) := by - refine ⟨insert k t,C.bundle_insert s hk _ (C.bundle_insert s hj _ (C.bundle_one s - (he x)) (fun i hi => hA i hi)) hB,?_,?_,?_⟩ - · rw [card_insert_of_notMem hkt,ht] - · rw [contents, Finset.sum_insert hkt] - simp [t,f,hg'] - rw [map_add,map_add,hK,hJ,hG] - rw [add_comm y,char_two] - rw [← map_add,←map_add] - exact (Submodule.Quotient.mk_eq_zero R).mpr (subset_span hR) - change q _+ _=0 at hQ - have hq' (z a) (hz:zone C s a) (h : π (C.writes a)=z) : q (f a)=F z := by rw [←h]; exact (hq a hz).symm - rw [hq' _ k hk hK,hq' _ j hj hJ,hq' x i (he x) (hG x),add_comm (F y)] at hQ - exact add_right_cancel (hQ.trans (char_two _).symm) - apply le_antisymm (ration_le ..) - rintro x ⟨hy,hx⟩ - apply (Submodule.Quotient.mk_eq_zero R).mp - have hz {x} (h : x∈C.band s) : q x=F (π x) := by - unfold band at h; induction h using Submodule.span_induction with - | zero => rw [map_zero,map_zero,h0] - | mem x hx => - obtain ⟨i,hi,rfl⟩ := hx; exact (hq i hi).symm - | add a b _ _ ha hb => rw [map_add,map_add,hh,ha,hb] - | smul a b _ hb => - rcases bit_cases a with ha|ha - · rw [ha,zero_smul,map_zero,map_zero,h0] - rw [ha,one_smul,hb] - change q x=0; change π x=0 at hx - rw [hz hy,hx,h0] -end Club -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CoordinateDuality + +namespace OAI + +/-! # Labeled Generators -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Function LinearMap Submodule Module +open scoped BigOperators +namespace StatusAnalysis +variable {L I X Y : Type} [DecidableEq L] [DecidableEq I] [AddCommGroup X] + [Module F X] [AddCommGroup Y] [Module F Y] + +structure Club (I X L : Type) where + valid : I→Prop + writes : I→ X + addr : I→ Bool→L + +abbrev Straps (L : Type) := Bool→Finset L +variable (C : Club I X L) +namespace Club +def zone (s : Straps L) (i) := C.valid i ∧ ∀ b,C.addr i b∉s b +def band (s : Straps L) : Space X := Submodule.span F {x|∃ i, C.zone s i∧C.writes i=x} +def bundle (p : Finset I) (s : Straps L) := + (∀ i∈p,zone C s i) ∧ ∀ b : Bool, Set.InjOn (fun i=> C.addr i b) (p : Set I) +def contents (p : Finset I) := ∑ i∈p,C.writes i + +def length3 (s : Straps L) (π : X→ₗ[F] Y) (x : X) := + ∃ p : Finset I,C.bundle p s ∧ p.card≤3 ∧ C.contents p=x ∧ π x=0 +def ration (s : Straps L) (π : X→ₗ[F] Y) : Space X := Submodule.span F (C.length3 s π) + +def yield3 (s : Straps L) (π : X→ₗ[F] Y) := + ∀ u:Straps L,(∀ b,(u b).card≤2) → ∀ y,∃ i,zone C (s⊔u) i ∧ π (C.writes i)=y + +omit [DecidableEq L] [DecidableEq I] in +theorem band_write (s : Straps L) {i : I} (hi : C.zone s i) : + C.writes i∈ C.band s := subset_span ⟨i,hi,rfl⟩ +omit [DecidableEq L] [DecidableEq I] in +theorem band_contents (s : Straps L) {p : Finset I} (hp : C.bundle p s) : + C.contents p∈ C.band s := Submodule.sum_mem _ fun i hi=> band_write C s (hp.1 i hi) +omit [DecidableEq L] [DecidableEq I] in +theorem length3_zero (s : Straps L) (π : X→ₗ[F] Y) : + C.length3 s π 0 := by refine ⟨∅,⟨?_,?_⟩,?_,?_,?_⟩ <;> simp [contents] + +omit [DecidableEq L] [DecidableEq I] [AddCommGroup X] [Module F X] in +theorem zone_smaller {s t : Straps L} (h : s≤t) (i:I) (hi : zone C t i) : zone C s i := + ⟨hi.1,fun b hx=> hi.2 b (h b hx)⟩ +omit [DecidableEq L] [DecidableEq I] in +theorem ration_le (s : Straps L) (π : X→ₗ[F] Y) : ration C s π ≤ C.band s⊓LinearMap.ker π := by + refine Submodule.span_le.mpr ?_ + rintro i ⟨x,ha,hb,rfl,hg⟩ + exact ⟨band_contents C s ha,hg⟩ + +def addrs (p : Finset I) : Straps L := fun b=>p.image (fun i=> C.addr i b) +omit [DecidableEq I] in +theorem yield_after (s : Straps L) (π : X→ₗ[F] Y) (h : yield3 C s π) + (p : Finset I) (hp : p.card≤ 2) (y : Y) : + ∃ i,zone C s i ∧ π (C.writes i)=y ∧ + ∀ j∈p,∀ b,C.addr i b≠C.addr j b := by + obtain ⟨i,hi,ht⟩ := h (addrs C p) (fun i=>card_image_le.trans hp) y + refine ⟨i,C.zone_smaller le_sup_left i hi,ht,fun j hj b h=>?_⟩ + exact hi.2 b (mem_union_right _ (Finset.mem_image.mpr ⟨j,hj,h.symm⟩)) + +def different (i j : I) := ∀ b,C.addr i b≠ C.addr j b +omit [DecidableEq L] [DecidableEq I] [AddCommGroup X] [Module F X] in +theorem different_ne {i j : I} (h : C.different i j) : i≠j := fun hx=> h true (hx ▸ rfl) +omit [DecidableEq L] [DecidableEq I] [AddCommGroup X] [Module F X] in +theorem bundle_one (s : Straps L) {i} (h : zone C s i) : bundle C {i} s := by + constructor + · intro j hj; rwa [mem_singleton.mp hj] + simp + +omit [DecidableEq L] [AddCommGroup X] [Module F X] in +theorem bundle_insert (s : Straps L) {i} (h : zone C s i) (p : Finset I) (hp : bundle C p s) + (he : ∀ j∈p,C.different i j) : bundle C (insert i p) s := by + refine ⟨fun j hj=>?_,fun b y hy z hz hh=>?_⟩ + · rcases mem_insert.mp hj with h'|h' + · exact h' ▸ h + exact hp.1 j h' + rcases mem_insert.mp hy with h'|h' + · subst y; rcases mem_insert.mp hz with hz|hz + · exact hz.symm + exact (he _ hz b hh).elim + rcases mem_insert.mp hz with hz|hz + · subst z; exact (he _ h' b hh.symm).elim + exact hp.2 b h' hz hh + +set_option maxHeartbeats 900000 in +theorem ration_eq (s : Straps L) (π : X→ₗ[F] Y) (h : yield3 C s π) : + ration C s π=C.band s⊓LinearMap.ker π := by + classical + let R:=ration C s π; let q:=R.mkQ + + have hr (i j:I) (hi:C.zone s i) (hj:C.zone s j) (ht : π (C.writes i)=π (C.writes j)) + (hh : C.different i j) : q (C.writes i)=q (C.writes j) := by + have hg:=C.different_ne hh + let W := C.writes + apply add_right_cancel (b:=q (W j)) + rw [char_two,←map_add] + apply (Submodule.Quotient.mk_eq_zero R).mpr + refine subset_span ⟨{i,j},C.bundle_insert s hi _ (C.bundle_one s hj) + (fun z hz=> (mem_singleton.mp hz).symm ▸ hh),by simp [hg], + by simp [contents,W,hg],?_⟩ + rw [map_add,ht,char_two] + let f:=C.writes + have hg (i j:I) (hi:C.zone s i) (hj:C.zone s j) (ht : π (f i)=π (f j)) : + q (f i)=q (f j) := by + obtain ⟨t,ht',hy,hb⟩:=C.yield_after s π h {i,j} (by + by_cases hi : i=j <;> simp [hi]) (π (f j)) + exact (hr t i ht' hi (hy.trans ht.symm) (hb i (by simp))).symm.trans + (hr t j ht' hj hy (hb j (by simp))) + choose g he hG hP using fun y=>C.yield_after s π h ∅ (by simp) y + let F (x : Y) := q (f (g x)) + have hq i (hi:C.zone s i) : F (π (f i))=q (f i) := hg _ i (he _) hi (hG _) + have h0 : F 0=0 := by + have hh:=he 0 + refine (Submodule.Quotient.mk_eq_zero R).mpr (subset_span ?_) + exact ⟨{g 0},C.bundle_one s hh, by simp, by simp [f,contents], hG 0⟩ + have hh (x y) : F (x+y)=F x+F y := by + let i:=g x + obtain ⟨j,hj,hJ,hA⟩:=C.yield_after s π h {i} (by simp) y + have hai:=hA i (by simp) + have hg' : j≠i:=C.different_ne hai + let t : Finset I := {j,i} + have ht : t.card=2 := by simp [t,hg'] + obtain ⟨k,hk,hK,hB⟩:=C.yield_after s π h t (by omega) (x+y) + have hkt : k∉t := fun hx=> C.different_ne (hB k hx) rfl + have hQ : + q (f k)+(q (f j)+q (f i))=0 := by + have hR : C.length3 s π (f k+(f j+f i)) := by + refine ⟨insert k t,C.bundle_insert s hk _ (C.bundle_insert s hj _ (C.bundle_one s + (he x)) (fun i hi => hA i hi)) hB,?_,?_,?_⟩ + · rw [card_insert_of_notMem hkt,ht] + · rw [contents, Finset.sum_insert hkt] + simp [t,f,hg'] + rw [map_add,map_add,hK,hJ,hG] + rw [add_comm y,char_two] + rw [← map_add,←map_add] + exact (Submodule.Quotient.mk_eq_zero R).mpr (subset_span hR) + change q _+ _=0 at hQ + have hq' (z a) (hz:zone C s a) (h : π (C.writes a)=z) : q (f a)=F z := by rw [←h]; exact (hq a hz).symm + rw [hq' _ k hk hK,hq' _ j hj hJ,hq' x i (he x) (hG x),add_comm (F y)] at hQ + exact add_right_cancel (hQ.trans (char_two _).symm) + apply le_antisymm (ration_le ..) + rintro x ⟨hy,hx⟩ + apply (Submodule.Quotient.mk_eq_zero R).mp + have hz {x} (h : x∈C.band s) : q x=F (π x) := by + unfold band at h; induction h using Submodule.span_induction with + | zero => rw [map_zero,map_zero,h0] + | mem x hx => + obtain ⟨i,hi,rfl⟩ := hx; exact (hq i hi).symm + | add a b _ _ ha hb => rw [map_add,map_add,hh,ha,hb] + | smul a b _ hb => + rcases bit_cases a with ha|ha + · rw [ha,zero_smul,map_zero,map_zero,h0] + rw [ha,one_smul,hb] + change q x=0; change π x=0 at hx + rw [hz hy,hx,h0] +end Club +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/LargeSetHits.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/LargeSetHits.lean index 6264a89ae6906db159d345add3480e5618e84958..98ad1c1721176d050b816438ce1e9a95e9157ed9 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/LargeSetHits.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/LargeSetHits.lean @@ -1,144 +1,144 @@ -import OAI.Combinatorics.HadwigerCounterexample.ConditionalLargeSetHits - -namespace OAI - -/-! # Large Set Hits -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix Function -open scoped BigOperators Topology -open Template -variable {p:Shape} {M n N K r s0:ℕ} -namespace StatusAnalysis -namespace Quill -variable {q:Format} {d:Rates} {b:Bool} (w:Quill p q d b) - (t:Tagging p (Messenger q)) (z:Messenger q→F) -def dilate (K:ℕ) := (w.pen t).kappa*((basebeta p K)/2)^Fintype.card (Messenger q) -theorem dilate_pos (K:ℕ) : 0 ind (H x)) := by - classical - let ν:=lawNu p N t z - have hu i:IsLaw (w.policies t z n i) := Appearance.witLaw (w.allure_apt t z hw _) ht hn - have hν := nuLaw t z hN - let I:=Messenger q - let f i:=w.allure t z i - let P (i:I) (x:Keys (p:=p) t N) := δ≤ (f i).reference Y (Y (t i) (z i) (x i)) - let Q (x:Keys (p:=p) t N):=∀ i,P i x - have hm i : pr ν (fun x=>¬P i x)≤ - r*δ+2*netFact (trayPort p t)*bp (-(N:ℝ)/2) := by - unfold P; simp_rw [not_le] - exact w.tinyCell_loss t z Y hp.le _ hN hh - have h1 : pr ν (fun x=>¬Q x) ≤ ε/2 := by - have hx (x) (h:¬Q x) : ∃ i,¬ P i x := Classical.not_forall.mp h - refine ((pr_mono hν.nz hx).trans (pr_exists_le hν.nz _)).trans - ((Finset.sum_le_sum (fun i _=>hm i)).trans ?_) - rw [Finset.sum_const] - simpa only [Finset.card_univ,nsmul_eq_mul] using hK - have h2 : ε/2 ≤ pr ν (fun x=> H x∧Q x) := - le_trans (by linarith only [he,h1]) (pr_shield hν.nz H Q) - let L:=w.dilate t K; let Z:=basebeta p K/2 - have hh x (hx:Q x) : L ≤ w.mirror t z o m s Y x := by - have hg' i : Z ≤ w.seraph t z o m s Y i (x i):= w.thinGlaze t z m Y o i s (x i) hp hw hg hq ht hn (hx i) - apply mul_le_mul_of_nonneg_left _ (kappa_pos _).le - change Z^Fintype.card I≤prodW _ _ - rw [show Z^Fintype.card I=∏ i:Messenger q,Z from by simp [I]] - exact Finset.prod_le_prod₀ (fun i _=> (half_pos (basebeta_pos _ _)).le) fun i _=>hg' i - apply (mul_le_mul_of_nonneg_left h2 (w.dilate_pos _ _).le).trans - unfold pr sheen; rw [←avg_mul']; refine avg_mono hν.nz fun i => ?_ - dsimp only - by_cases h:H i - · rw [show (H i ∧ Q i)=Q i from propext (and_iff_right h),ind_one h,mul_one] - by_cases hp : Q i - · rw [ind_one hp,mul_one]; exact hh i hp - rw [ind_zero hp,mul_zero] - exact (w.mirror_floor t z o m s Y hu i).1 - rw [ind_zero h,ind_zero (show ¬ (H i∧ Q i) from fun hv=>h hv.1),mul_zero,mul_zero] - -variable {b':PreparationParameters} -def sober (K:ℕ) (H:Keys (p:=p) t N→Prop) (m:Mixer p n) (α:ℝ) (o:UnitType p n N) := - ∀ s:Charts p n d,w.steady t z m K s o → α≤w.prowl s t z m o (fun x=>ind (H x)) - -set_option maxHeartbeats 1400000 in -theorem soberCalendar (h:AnalyticParameters p M b' s0) (hw : w.moral t z) (ε:ℝ) (he:0<ε) : - ∃ (α c:ℝ),0<α∧0¬w.sober t z K H m α i) ≤ bp (-c*n) := by - classical - let K:=b'.pins - let α:=w.dilate t K*(ε/4) - have hα :0<α:=mul_pos (dilate_pos ..) (by positivity) - obtain ⟨r,u,c,hu,hc,hR⟩:= w.sideRelease t z M h hw α hα - let I:=Messenger q; let D:=num I; have hD : 0 ≤ D:=Nat.cast_nonneg _ - let β:= ε/(4*(D+1)*(r+1:ℝ)); let δ:=min u β - have hd : 0<δ:= lt_min hu (show 0<β from by unfold β; positivity) - have hδ : D*(r:ℝ)*δ ≤ ε/4 := by - have hi : δ* (4*(D+1)*(r+1:ℝ)) ≤ ε := (le_div_iff₀ (by positivity)).mp (min_le_right ..) - have hh : D*(r:ℝ) ≤ (D+1)*(r+1:ℝ) := mul_le_mul (by linarith) (by linarith) - (by positivity) (by positivity) - linarith only [hi,mul_le_mul_of_nonneg_right hh hd.le] - have hq:=h.enter.first - let k:ℝ:=min c (1/100) - have hk:0 ind (H x) - obtain ⟨Y,hY⟩:=hn W (fun i=>(abs_of_nonneg (ind_nonneg (H i))).trans_le (ind_le_one _)) - let F:= w.flunk t z Y W m u α - let Q i:= ¬gauze p δ δ Y m K i - have h1 :pr U F≤bp (-c*n) := hY r Y (self_refine Y) _ _ hm - have h2 :pr U Q ≤bp (-(1/100:ℝ)*n) := hv _ _ hm Y - have hhN : 2*num (Messenger q×Toast p)-(N:ℝ)≤ -1 := by - change 2*num (Messenger q×Toast p)+1 ≤ (N:ℝ) at hI; linarith only [hI] - have ht : 2*num (Toast p)-(N:ℝ) ≤ -1 := by - change _≤(N:ℝ) at hG; linarith only [hG] - have h3 o (h :¬w.sober t z K H m α o) : F o ∨ Q o := by - by_contra! hh - obtain ⟨s,hg,hl⟩:= show ∃ s,w.steady t z m K s o∧ w.prowl s t z m o W<α from by - unfold sober at h; push Not at h; exact h - have hσ : gauze p δ δ Y m K o := not_not.mp hh.2 - have ht := w.sheen_hit t z m Y o s H hd hH hw hq.hR hm.age hg hhN ht - (show D*(r*δ+L*bp (-(N:ℝ)/2))≤ε/2 by - change _*(L*bp (-(N:ℝ)/2)) ≤_ at hx; linarith only [hx,hδ]) hσ - refine hh.1 ⟨hg.frame,Station.gauzed_area _ _ _ _ hw δ (min_le_left ..) - _ hσ,s,?_⟩ - rw [abs_sub_comm] - refine lt_of_lt_of_le ?_ (le_abs_self _); unfold α W at * - linarith only [ht,hl] - have ht (x:ℝ) (hx : k≤x): bp (-x*n) ≤ bp (-k*n) := bp_le - (mul_le_mul_of_nonneg_right (neg_le_neg hx) (Nat.cast_nonneg _)) - rw [two_mul] at he' - have hg:=hm.drain.1 - exact ((pr_mono hg.nz h3).trans (pr_or_le hg.nz)).trans - ((add_le_add (h1.trans (ht _ (min_le_left ..))) (h2.trans (ht _ (min_le_right ..)))).trans he') - -end Quill -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ConditionalLargeSetHits + +namespace OAI + +/-! # Large Set Hits -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix Function +open scoped BigOperators Topology +open Template +variable {p:Shape} {M n N K r s0:ℕ} +namespace StatusAnalysis +namespace Quill +variable {q:Format} {d:Rates} {b:Bool} (w:Quill p q d b) + (t:Tagging p (Messenger q)) (z:Messenger q→F) +def dilate (K:ℕ) := (w.pen t).kappa*((basebeta p K)/2)^Fintype.card (Messenger q) +theorem dilate_pos (K:ℕ) : 0 ind (H x)) := by + classical + let ν:=lawNu p N t z + have hu i:IsLaw (w.policies t z n i) := Appearance.witLaw (w.allure_apt t z hw _) ht hn + have hν := nuLaw t z hN + let I:=Messenger q + let f i:=w.allure t z i + let P (i:I) (x:Keys (p:=p) t N) := δ≤ (f i).reference Y (Y (t i) (z i) (x i)) + let Q (x:Keys (p:=p) t N):=∀ i,P i x + have hm i : pr ν (fun x=>¬P i x)≤ + r*δ+2*netFact (trayPort p t)*bp (-(N:ℝ)/2) := by + unfold P; simp_rw [not_le] + exact w.tinyCell_loss t z Y hp.le _ hN hh + have h1 : pr ν (fun x=>¬Q x) ≤ ε/2 := by + have hx (x) (h:¬Q x) : ∃ i,¬ P i x := Classical.not_forall.mp h + refine ((pr_mono hν.nz hx).trans (pr_exists_le hν.nz _)).trans + ((Finset.sum_le_sum (fun i _=>hm i)).trans ?_) + rw [Finset.sum_const] + simpa only [Finset.card_univ,nsmul_eq_mul] using hK + have h2 : ε/2 ≤ pr ν (fun x=> H x∧Q x) := + le_trans (by linarith only [he,h1]) (pr_shield hν.nz H Q) + let L:=w.dilate t K; let Z:=basebeta p K/2 + have hh x (hx:Q x) : L ≤ w.mirror t z o m s Y x := by + have hg' i : Z ≤ w.seraph t z o m s Y i (x i):= w.thinGlaze t z m Y o i s (x i) hp hw hg hq ht hn (hx i) + apply mul_le_mul_of_nonneg_left _ (kappa_pos _).le + change Z^Fintype.card I≤prodW _ _ + rw [show Z^Fintype.card I=∏ i:Messenger q,Z from by simp [I]] + exact Finset.prod_le_prod₀ (fun i _=> (half_pos (basebeta_pos _ _)).le) fun i _=>hg' i + apply (mul_le_mul_of_nonneg_left h2 (w.dilate_pos _ _).le).trans + unfold pr sheen; rw [←avg_mul']; refine avg_mono hν.nz fun i => ?_ + dsimp only + by_cases h:H i + · rw [show (H i ∧ Q i)=Q i from propext (and_iff_right h),ind_one h,mul_one] + by_cases hp : Q i + · rw [ind_one hp,mul_one]; exact hh i hp + rw [ind_zero hp,mul_zero] + exact (w.mirror_floor t z o m s Y hu i).1 + rw [ind_zero h,ind_zero (show ¬ (H i∧ Q i) from fun hv=>h hv.1),mul_zero,mul_zero] + +variable {b':PreparationParameters} +def sober (K:ℕ) (H:Keys (p:=p) t N→Prop) (m:Mixer p n) (α:ℝ) (o:UnitType p n N) := + ∀ s:Charts p n d,w.steady t z m K s o → α≤w.prowl s t z m o (fun x=>ind (H x)) + +set_option maxHeartbeats 1400000 in +theorem soberCalendar (h:AnalyticParameters p M b' s0) (hw : w.moral t z) (ε:ℝ) (he:0<ε) : + ∃ (α c:ℝ),0<α∧0¬w.sober t z K H m α i) ≤ bp (-c*n) := by + classical + let K:=b'.pins + let α:=w.dilate t K*(ε/4) + have hα :0<α:=mul_pos (dilate_pos ..) (by positivity) + obtain ⟨r,u,c,hu,hc,hR⟩:= w.sideRelease t z M h hw α hα + let I:=Messenger q; let D:=num I; have hD : 0 ≤ D:=Nat.cast_nonneg _ + let β:= ε/(4*(D+1)*(r+1:ℝ)); let δ:=min u β + have hd : 0<δ:= lt_min hu (show 0<β from by unfold β; positivity) + have hδ : D*(r:ℝ)*δ ≤ ε/4 := by + have hi : δ* (4*(D+1)*(r+1:ℝ)) ≤ ε := (le_div_iff₀ (by positivity)).mp (min_le_right ..) + have hh : D*(r:ℝ) ≤ (D+1)*(r+1:ℝ) := mul_le_mul (by linarith) (by linarith) + (by positivity) (by positivity) + linarith only [hi,mul_le_mul_of_nonneg_right hh hd.le] + have hq:=h.enter.first + let k:ℝ:=min c (1/100) + have hk:0 ind (H x) + obtain ⟨Y,hY⟩:=hn W (fun i=>(abs_of_nonneg (ind_nonneg (H i))).trans_le (ind_le_one _)) + let F:= w.flunk t z Y W m u α + let Q i:= ¬gauze p δ δ Y m K i + have h1 :pr U F≤bp (-c*n) := hY r Y (self_refine Y) _ _ hm + have h2 :pr U Q ≤bp (-(1/100:ℝ)*n) := hv _ _ hm Y + have hhN : 2*num (Messenger q×Toast p)-(N:ℝ)≤ -1 := by + change 2*num (Messenger q×Toast p)+1 ≤ (N:ℝ) at hI; linarith only [hI] + have ht : 2*num (Toast p)-(N:ℝ) ≤ -1 := by + change _≤(N:ℝ) at hG; linarith only [hG] + have h3 o (h :¬w.sober t z K H m α o) : F o ∨ Q o := by + by_contra! hh + obtain ⟨s,hg,hl⟩:= show ∃ s,w.steady t z m K s o∧ w.prowl s t z m o W<α from by + unfold sober at h; push Not at h; exact h + have hσ : gauze p δ δ Y m K o := not_not.mp hh.2 + have ht := w.sheen_hit t z m Y o s H hd hH hw hq.hR hm.age hg hhN ht + (show D*(r*δ+L*bp (-(N:ℝ)/2))≤ε/2 by + change _*(L*bp (-(N:ℝ)/2)) ≤_ at hx; linarith only [hx,hδ]) hσ + refine hh.1 ⟨hg.frame,Station.gauzed_area _ _ _ _ hw δ (min_le_left ..) + _ hσ,s,?_⟩ + rw [abs_sub_comm] + refine lt_of_lt_of_le ?_ (le_abs_self _); unfold α W at * + linarith only [ht,hl] + have ht (x:ℝ) (hx : k≤x): bp (-x*n) ≤ bp (-k*n) := bp_le + (mul_le_mul_of_nonneg_right (neg_le_neg hx) (Nat.cast_nonneg _)) + rw [two_mul] at he' + have hg:=hm.drain.1 + exact ((pr_mono hg.nz h3).trans (pr_or_le hg.nz)).trans + ((add_le_add (h1.trans (ht _ (min_le_left ..))) (h2.trans (ht _ (min_le_right ..)))).trans he') + +end Quill +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/LeafMixtures.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/LeafMixtures.lean index 4d64fe6f2072d08eeba9cd8eb311b012e1f30f85..fcebc58ffd8cec02908f9d51ac1490991a8bae05 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/LeafMixtures.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/LeafMixtures.lean @@ -1,167 +1,167 @@ -import OAI.Combinatorics.HadwigerCounterexample.PartitionDeletionBounds -import OAI.Combinatorics.HadwigerCounterexample.RefinedPinImages - -namespace OAI - -/-! # Leaf Mixtures -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Finset LinearMap Filter -open scoped BigOperators -variable {p : Shape} {n N M : ℕ} -structure LeafMixture (p : Shape) (n N : ℕ) where - T : Canopy p n N - pin : CTile p n N → Pin p n N - -namespace LeafMixture -abbrev X (p : Shape) (n N : ℕ) := UnitType p n N - -instance : Inhabited (LeafMixture p n N) := ⟨⟨∅,fun _=>dustPin ..⟩⟩ - -def poller (s : LeafMixture p n N) (x : X p n N) : Pin p n N := - open scoped Classical in - if h : inTiles s.T x then s.pin h.choose else dustPin p n N - -theorem poller_eq (s : LeafMixture p n N) (h : apart s.T) {x i} (hi : i∈s.T) (hx : x∈i) : - s.poller x=s.pin i := by - classical - have hc : inTiles s.T x := ⟨_,hi,hx⟩ - unfold poller; rw [dite_eq_left hc,h _ _ hc.choose_spec.1 _ hi hc.choose_spec.2 hx] - -def rooting (s : LeafMixture p n N) (x : X p n N) := (s.poller x).sp -def amount (s : LeafMixture p n N) (w : Wgt (X p n N)) := allMass w s.T -def sap (s : LeafMixture p n N) (w : Wgt (X p n N)) := allW w s.T - -variable {s : LeafMixture p n N} {w μ : Wgt (X p n N)} -structure strength (s : LeafMixture p n N) (w μ : Wgt (X p n N)) (D ζ : ℝ) (K : ℕ) : Prop where - part : apart s.T - leaf : ∀ i∈s.T,Ripe p w μ i (s.pin i) D ζ K -variable {D E ζ η : ℝ} {K L : ℕ} - -theorem root_bound (hh : strength s w μ D ζ K) (x : X p n N) : planRank (s.rooting x) ≤ K := by - classical - by_cases hs : inTiles s.T x - · rw [rooting,poller,dite_eq_left hs] - exact (hh.leaf _ hs.choose_spec.1).bound - unfold rooting poller; rw [dite_eq_right hs] - exact le_of_eq_of_le (Finset.sum_eq_zero (fun i _=>finrank_bot ..)) K.zero_le - -theorem strength.slide (h : strength s w μ D ζ K) (hD : D≤E) (hζ : ζ≤η) - (hk : K≤L) (hμ : ∀ x,0≤μ x) : strength s w μ E η L := by - classical - refine ⟨h.part,fun i hi=>?_⟩ - have hh:=h.leaf _ hi - refine ⟨hh.pos,hh.fixpin,hh.bound.trans hk,fun b=>?_,fun x=>?_⟩ - · refine (hh.clear b).trans (bp_le ?_) - gcongr - exact (hh.density x).trans (mul_le_mul_of_nonneg_right (bp_le (by gcongr)) (hμ _)) - -theorem sapLaw (h : 0by - by_cases hs : S∈T - · obtain ⟨x,h⟩:=(hg S hs).2; exact ⟨x,fun _=>h⟩ - exact ⟨dustPin ..,fun hh=>(hs hh).elim⟩) - let s : LeafMixture p n N := ⟨T,a⟩ - refine ⟨s, ⟨ht,fun x hx=>ha x hx⟩,fun i hi x hx=>(hr x).mp ((hg _ hi).1 hx),?_⟩ - simp_rw [hr] at h - let Q (x : X p n N) := P x ∧ ¬inTiles T x - have hv (x : X p n N) : P x → inTiles T x ∨ Q x := by unfold Q; tauto - have hh : pr w P≤s.amount w+bp (-ζ*N) := - ((pr_mono hw hv).trans (pr_or_le hw)).trans (add_le_add_right h _) - linarith - -def elder (s t : LeafMixture p n N) (P : X p n N→Prop) - (S : CTile p n N → CTile p n N → Prop) := - ∀ i ∈ t.T, ∃ i'∈ s.T,i⊆i' ∧ (∀ x∈i,P x) ∧ S i i' -theorem ancestral {s t : LeafMixture p n N} {P Q} - (he : elder s t P Q) {x} (h : inTiles t.T x) : inTiles s.T x∧P x := by - obtain ⟨j,hj,hx⟩ := h - obtain ⟨i,hi,hs,hp,_⟩ := he j hj - exact ⟨⟨_,hi,hs hx⟩,hp x hx⟩ -theorem elder_trim {s : LeafMixture p n N} (h : strength s w μ D ζ K) (hz : 0≤ζ) - (hw : IsLaw w) (P : X p n N→Prop) : - ∃ t : LeafMixture p n N, t.strength w μ (D+ζ) (2*ζ) K ∧ - elder s t P (fun i j=>t.pin i=s.pin j) ∧ - pr w (fun x=>inTiles s.T x∧P x∧¬inTiles t.T x)≤ bp (-ζ*N) := by - classical - obtain ⟨T,ht,hg,hf⟩:= trim P hw.nz hz h.part s.pin h.leaf - let f (i : CTile p n N) := if hi:i∈T then (hg i hi).choose else ∅ - let t : LeafMixture p n N := ⟨T,fun i=>s.pin (f i)⟩ - have he (i : CTile p n N) (hi : i∈T) : - f i∈s.T ∧ i⊆ f i ∧ Ripe p w μ i (s.pin (f i)) (D+ζ) (2*ζ) K ∧ ∀ x∈i,P x := by - unfold f; rw [dite_eq_left hi]; exact (hg i hi).choose_spec - exact ⟨t,⟨ht,fun i hi=>(he i hi).2.2.1⟩,fun i hi=>by - obtain ⟨h,h1,h2,h3⟩:= he i hi; exact ⟨_,h,h1,h3,rfl⟩, - hf.trans (by - have hi : allMass w s.T ≤1 := (pr_le_tot hw.nz).trans hw.total.le - exact (mul_le_mul_of_nonneg_right hi (bp_pos _).le).trans_eq (one_mul _))⟩ - -set_option maxHeartbeats 800000 in -theorem elder_weave {s : LeafMixture p n N} (h : strength s w μ D ζ K) (hz : 0<ζ) - (hw : IsLaw w) (P : X p n N→Prop) - {u : ℝ} {K' d : ℕ} - (m : BMark p n N) (T : Cov p N) - (hz' : ζ<1) (hn : 0 specialLeaf T m (s.pin j) i (t.pin i)) ∧ - pr w (fun x=>inTiles s.T x∧P x∧¬inTiles t.T x)≤ bp (-(N:ℝ))+bp (-ζ*N) := by - classical - obtain ⟨V,hV,hX,hF⟩:= weave P m T hw.nz hz hz' hn hμ hd h.part _ h.leaf hg hk hu - let R (i j : CTile p n N) b := j∈s.T ∧ i⊆j ∧ (∀ x∈i,P x) ∧ - Ripe p w μ i b (D+u+K'+1) ζ (3*K+K') ∧ specialLeaf T m (s.pin j) i b - choose f h1 using (show ∀ i: CTile p n N,∃ b,i∈V → ∃ j,R i j b from - fun i=>by - by_cases hi : i∈ V - · obtain ⟨j,hj,hp,hc,b,h⟩:= hX i hi - exact ⟨b,fun _ => ⟨_,hj,hp,hc,h⟩⟩ - exact ⟨dustPin ..,fun hh=> (hi hh).elim⟩) - refine ⟨⟨V,f⟩,⟨hV,fun i hi=>?_⟩,fun i hi=>?_,hF.trans (by - have hh : allMass w s.T ≤1 := (pr_le_tot hw.nz).trans hw.total.le - exact (mul_le_mul_of_nonneg_right hh (add_nonneg (bp_pos _).le (bp_pos _).le)).trans_eq - (one_mul _))⟩ - · obtain ⟨_,_,_,_,hh,_⟩:= h1 i hi; exact hh - obtain ⟨_,h',hx,hy,_,hh⟩:= h1 i hi; exact ⟨_,h',hx,hy,hh⟩ - -end LeafMixture -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PartitionDeletionBounds +import OAI.Combinatorics.HadwigerCounterexample.RefinedPinImages + +namespace OAI + +/-! # Leaf Mixtures -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Finset LinearMap Filter +open scoped BigOperators +variable {p : Shape} {n N M : ℕ} +structure LeafMixture (p : Shape) (n N : ℕ) where + T : Canopy p n N + pin : CTile p n N → Pin p n N + +namespace LeafMixture +abbrev X (p : Shape) (n N : ℕ) := UnitType p n N + +instance : Inhabited (LeafMixture p n N) := ⟨⟨∅,fun _=>dustPin ..⟩⟩ + +def poller (s : LeafMixture p n N) (x : X p n N) : Pin p n N := + open scoped Classical in + if h : inTiles s.T x then s.pin h.choose else dustPin p n N + +theorem poller_eq (s : LeafMixture p n N) (h : apart s.T) {x i} (hi : i∈s.T) (hx : x∈i) : + s.poller x=s.pin i := by + classical + have hc : inTiles s.T x := ⟨_,hi,hx⟩ + unfold poller; rw [dite_eq_left hc,h _ _ hc.choose_spec.1 _ hi hc.choose_spec.2 hx] + +def rooting (s : LeafMixture p n N) (x : X p n N) := (s.poller x).sp +def amount (s : LeafMixture p n N) (w : Wgt (X p n N)) := allMass w s.T +def sap (s : LeafMixture p n N) (w : Wgt (X p n N)) := allW w s.T + +variable {s : LeafMixture p n N} {w μ : Wgt (X p n N)} +structure strength (s : LeafMixture p n N) (w μ : Wgt (X p n N)) (D ζ : ℝ) (K : ℕ) : Prop where + part : apart s.T + leaf : ∀ i∈s.T,Ripe p w μ i (s.pin i) D ζ K +variable {D E ζ η : ℝ} {K L : ℕ} + +theorem root_bound (hh : strength s w μ D ζ K) (x : X p n N) : planRank (s.rooting x) ≤ K := by + classical + by_cases hs : inTiles s.T x + · rw [rooting,poller,dite_eq_left hs] + exact (hh.leaf _ hs.choose_spec.1).bound + unfold rooting poller; rw [dite_eq_right hs] + exact le_of_eq_of_le (Finset.sum_eq_zero (fun i _=>finrank_bot ..)) K.zero_le + +theorem strength.slide (h : strength s w μ D ζ K) (hD : D≤E) (hζ : ζ≤η) + (hk : K≤L) (hμ : ∀ x,0≤μ x) : strength s w μ E η L := by + classical + refine ⟨h.part,fun i hi=>?_⟩ + have hh:=h.leaf _ hi + refine ⟨hh.pos,hh.fixpin,hh.bound.trans hk,fun b=>?_,fun x=>?_⟩ + · refine (hh.clear b).trans (bp_le ?_) + gcongr + exact (hh.density x).trans (mul_le_mul_of_nonneg_right (bp_le (by gcongr)) (hμ _)) + +theorem sapLaw (h : 0by + by_cases hs : S∈T + · obtain ⟨x,h⟩:=(hg S hs).2; exact ⟨x,fun _=>h⟩ + exact ⟨dustPin ..,fun hh=>(hs hh).elim⟩) + let s : LeafMixture p n N := ⟨T,a⟩ + refine ⟨s, ⟨ht,fun x hx=>ha x hx⟩,fun i hi x hx=>(hr x).mp ((hg _ hi).1 hx),?_⟩ + simp_rw [hr] at h + let Q (x : X p n N) := P x ∧ ¬inTiles T x + have hv (x : X p n N) : P x → inTiles T x ∨ Q x := by unfold Q; tauto + have hh : pr w P≤s.amount w+bp (-ζ*N) := + ((pr_mono hw hv).trans (pr_or_le hw)).trans (add_le_add_right h _) + linarith + +def elder (s t : LeafMixture p n N) (P : X p n N→Prop) + (S : CTile p n N → CTile p n N → Prop) := + ∀ i ∈ t.T, ∃ i'∈ s.T,i⊆i' ∧ (∀ x∈i,P x) ∧ S i i' +theorem ancestral {s t : LeafMixture p n N} {P Q} + (he : elder s t P Q) {x} (h : inTiles t.T x) : inTiles s.T x∧P x := by + obtain ⟨j,hj,hx⟩ := h + obtain ⟨i,hi,hs,hp,_⟩ := he j hj + exact ⟨⟨_,hi,hs hx⟩,hp x hx⟩ +theorem elder_trim {s : LeafMixture p n N} (h : strength s w μ D ζ K) (hz : 0≤ζ) + (hw : IsLaw w) (P : X p n N→Prop) : + ∃ t : LeafMixture p n N, t.strength w μ (D+ζ) (2*ζ) K ∧ + elder s t P (fun i j=>t.pin i=s.pin j) ∧ + pr w (fun x=>inTiles s.T x∧P x∧¬inTiles t.T x)≤ bp (-ζ*N) := by + classical + obtain ⟨T,ht,hg,hf⟩:= trim P hw.nz hz h.part s.pin h.leaf + let f (i : CTile p n N) := if hi:i∈T then (hg i hi).choose else ∅ + let t : LeafMixture p n N := ⟨T,fun i=>s.pin (f i)⟩ + have he (i : CTile p n N) (hi : i∈T) : + f i∈s.T ∧ i⊆ f i ∧ Ripe p w μ i (s.pin (f i)) (D+ζ) (2*ζ) K ∧ ∀ x∈i,P x := by + unfold f; rw [dite_eq_left hi]; exact (hg i hi).choose_spec + exact ⟨t,⟨ht,fun i hi=>(he i hi).2.2.1⟩,fun i hi=>by + obtain ⟨h,h1,h2,h3⟩:= he i hi; exact ⟨_,h,h1,h3,rfl⟩, + hf.trans (by + have hi : allMass w s.T ≤1 := (pr_le_tot hw.nz).trans hw.total.le + exact (mul_le_mul_of_nonneg_right hi (bp_pos _).le).trans_eq (one_mul _))⟩ + +set_option maxHeartbeats 800000 in +theorem elder_weave {s : LeafMixture p n N} (h : strength s w μ D ζ K) (hz : 0<ζ) + (hw : IsLaw w) (P : X p n N→Prop) + {u : ℝ} {K' d : ℕ} + (m : BMark p n N) (T : Cov p N) + (hz' : ζ<1) (hn : 0 specialLeaf T m (s.pin j) i (t.pin i)) ∧ + pr w (fun x=>inTiles s.T x∧P x∧¬inTiles t.T x)≤ bp (-(N:ℝ))+bp (-ζ*N) := by + classical + obtain ⟨V,hV,hX,hF⟩:= weave P m T hw.nz hz hz' hn hμ hd h.part _ h.leaf hg hk hu + let R (i j : CTile p n N) b := j∈s.T ∧ i⊆j ∧ (∀ x∈i,P x) ∧ + Ripe p w μ i b (D+u+K'+1) ζ (3*K+K') ∧ specialLeaf T m (s.pin j) i b + choose f h1 using (show ∀ i: CTile p n N,∃ b,i∈V → ∃ j,R i j b from + fun i=>by + by_cases hi : i∈ V + · obtain ⟨j,hj,hp,hc,b,h⟩:= hX i hi + exact ⟨b,fun _ => ⟨_,hj,hp,hc,h⟩⟩ + exact ⟨dustPin ..,fun hh=> (hi hh).elim⟩) + refine ⟨⟨V,f⟩,⟨hV,fun i hi=>?_⟩,fun i hi=>?_,hF.trans (by + have hh : allMass w s.T ≤1 := (pr_le_tot hw.nz).trans hw.total.le + exact (mul_le_mul_of_nonneg_right hh (add_nonneg (bp_pos _).le (bp_pos _).le)).trans_eq + (one_mul _))⟩ + · obtain ⟨_,_,_,_,hh,_⟩:= h1 i hi; exact hh + obtain ⟨_,h',hx,hy,_,hh⟩:= h1 i hi; exact ⟨_,h',hx,hy,hh⟩ + +end LeafMixture +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/LeafSurrogateExperiments.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/LeafSurrogateExperiments.lean index 5cd70e98e7402613afa9c6af393a1633648985a6..fb15b44b0ec5f365a2632be377422b0417827089 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/LeafSurrogateExperiments.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/LeafSurrogateExperiments.lean @@ -1,93 +1,93 @@ -import OAI.Combinatorics.HadwigerCounterexample.SurrogateAggregation - -namespace OAI - -/-! # Leaf Surrogate Experiments -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Function Finset Filter -open scoped BigOperators Topology -namespace StatusAnalysis -variable {p : Shape} {n N K s M : ℕ} - {w : LeafMixture p n N} {q : Format} {d e : Rates} - -namespace Station -variable (t : Station p n N K w) (x : Typus p q d e) - (m : Mixer p n) (μ : Wgt (UnitType p n N)) (k : Fin (2^deckMax p K)) -variable (Y : Silhouette p N s) (i j : w.T) - -def stageLeft := - x.qA.showcase x.t x.z (partW μ i.val) (t.frontPage x m i j k) m (t.cAxes i d) Y -def stageRight := - x.qB.showcase x.t x.z (partW μ j.val) (t.backPage x m i j k) m (t.cAxes j e) Y -def stagePlane := - dip (lawNu p N x.t x.z) (t.stageLeft x m μ k Y i j) (t.stageRight x m μ k Y i j) - -def twilight (o : UnitType p n N × UnitType p n N) := - ind (t.frontPage x m i j k o.1 ∧ t.backPage x m i j k o.2)* - x.constellation o.1 o.2 (t.cAxes i d) (t.cAxes j e) m Y - -def eclipse := - avg (pairW (partW μ i.val) (partW μ j.val)) (t.twilight x m k Y i j) - -def stratum := - let v:=portionW μ w.T - avg (pairW v v) (fun i=>t.eclipse x m μ k Y i.1 i.2) - -set_option maxHeartbeats 900000 in -theorem eclipse_beam - (hv : ∀ i∈w.T,IsLaw (partW μ i)) - (ha : ∀ i,IsLaw (x.qA.policies x.t x.z n i)) (hb : ∀ i,IsLaw (x.qB.policies x.t x.z n i)) - (hN : 2*num (Messenger q × Toast p)-(N:ℝ)≤ -1) : - t.eclipse x m μ k Y i j - t.stagePlane x m μ k Y i j ≤ - 2*netFact (trayPort p x.t)*bp (-(N:ℝ)/2) := by - classical - let X:=UnitType p n N - let u:=partW μ i.val; let v:= partW μ j.val; let hK:=pairW u v - have h := show IsLaw hK from pairW_law (hv _ i.property) (hv _ j.property) - let U := t.frontPage x m i j k; let V := t.backPage x m i j k - let Q o:=ind (U o) - let R o:=ind (V o) - let F o:= x.qA.mirror x.t x.z o m (t.cAxes i d) Y - let G o:= x.qB.mirror x.t x.z o m (t.cAxes j e) Y - let A:= lawNu p N x.t x.z - have he : t.stagePlane x m μ k Y i j= - avg hK (fun o=> Q o.1*R o.2*dip A (F o.1) (G o.2)) := by - unfold stagePlane stageLeft stageRight Quill.showcase dip - change avg A (fun i=>avg u (fun x=>Q x*F x i)*avg v (fun x=>R x*G x i))=_ - have hx (i:Keys (p:=p) x.t N) : avg u (fun x=>Q x*F x i)*avg v (fun x=>R x*G x i)= - avg hK (fun o=> Q o.1*F o.1 i*(R o.2*G o.2 i)) := (pairW_separate ..).symm - simp_rw [hx]; rw [avg_avg] - apply avg_congr; intro o _ - rw [←avg_mul']; exact avg_congr fun i _=> by ring - let C:= 2*netFact (trayPort p x.t)*bp (-(N:ℝ)/2) - rw [he]; unfold eclipse; rw [← avg_sub] - refine h.avg_le fun o=> ?_ - have ht := x.shine_match o.1 o.2 (t.cAxes i d) (t.cAxes j e) m Y ha hb hN - unfold twilight; rw [ind_and] - have hU := Q o.1; have hV:= R o.2 - let Z:= x.constellation o.1 o.2 (t.cAxes i d) (t.cAxes j e) m Y - let L:= Z-dip A (F o.1) (G o.2) - change Q o.1*R o.2* Z-Q o.1*R o.2*_≤ C - by_cases hh : U o.1∧V o.2 - · have hf : Q o.1*R o.2=1 := by unfold Q R; rw [←ind_and,ind_one hh] - rw [hf,one_mul,one_mul]; exact (abs_le.mp ht).2 - have hf : Q o.1*R o.2=0 := by unfold Q R; rw [←ind_and,ind_zero hh] - rw [hf,zero_mul,zero_mul,sub_zero]; exact (abs_nonneg L).trans ht - -end Station - -variable {I : Type} [Fintype I] -theorem skylineMean (w : Wgt I) (f g c : Wgt I) (ε : ℝ) (he:0≤ε) (hw:IsLaw w) - (h : avg w c≤ (ε/2)^2) (hc : ∀ i,g i^2≤c i) - (hg:∀ i,f i - g i ≤ ε/2) : avg w f ≤ ε := by - have h1 := (mean_sq _ hw g).trans ((avg_mono hw.nz hc).trans h) - have h2 : avg w f-avg w g≤ ε/2 := by rw [←avg_sub]; exact hw.avg_le hg - nlinarith only [he,h1,h2] -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SurrogateAggregation + +namespace OAI + +/-! # Leaf Surrogate Experiments -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Function Finset Filter +open scoped BigOperators Topology +namespace StatusAnalysis +variable {p : Shape} {n N K s M : ℕ} + {w : LeafMixture p n N} {q : Format} {d e : Rates} + +namespace Station +variable (t : Station p n N K w) (x : Typus p q d e) + (m : Mixer p n) (μ : Wgt (UnitType p n N)) (k : Fin (2^deckMax p K)) +variable (Y : Silhouette p N s) (i j : w.T) + +def stageLeft := + x.qA.showcase x.t x.z (partW μ i.val) (t.frontPage x m i j k) m (t.cAxes i d) Y +def stageRight := + x.qB.showcase x.t x.z (partW μ j.val) (t.backPage x m i j k) m (t.cAxes j e) Y +def stagePlane := + dip (lawNu p N x.t x.z) (t.stageLeft x m μ k Y i j) (t.stageRight x m μ k Y i j) + +def twilight (o : UnitType p n N × UnitType p n N) := + ind (t.frontPage x m i j k o.1 ∧ t.backPage x m i j k o.2)* + x.constellation o.1 o.2 (t.cAxes i d) (t.cAxes j e) m Y + +def eclipse := + avg (pairW (partW μ i.val) (partW μ j.val)) (t.twilight x m k Y i j) + +def stratum := + let v:=portionW μ w.T + avg (pairW v v) (fun i=>t.eclipse x m μ k Y i.1 i.2) + +set_option maxHeartbeats 900000 in +theorem eclipse_beam + (hv : ∀ i∈w.T,IsLaw (partW μ i)) + (ha : ∀ i,IsLaw (x.qA.policies x.t x.z n i)) (hb : ∀ i,IsLaw (x.qB.policies x.t x.z n i)) + (hN : 2*num (Messenger q × Toast p)-(N:ℝ)≤ -1) : + t.eclipse x m μ k Y i j - t.stagePlane x m μ k Y i j ≤ + 2*netFact (trayPort p x.t)*bp (-(N:ℝ)/2) := by + classical + let X:=UnitType p n N + let u:=partW μ i.val; let v:= partW μ j.val; let hK:=pairW u v + have h := show IsLaw hK from pairW_law (hv _ i.property) (hv _ j.property) + let U := t.frontPage x m i j k; let V := t.backPage x m i j k + let Q o:=ind (U o) + let R o:=ind (V o) + let F o:= x.qA.mirror x.t x.z o m (t.cAxes i d) Y + let G o:= x.qB.mirror x.t x.z o m (t.cAxes j e) Y + let A:= lawNu p N x.t x.z + have he : t.stagePlane x m μ k Y i j= + avg hK (fun o=> Q o.1*R o.2*dip A (F o.1) (G o.2)) := by + unfold stagePlane stageLeft stageRight Quill.showcase dip + change avg A (fun i=>avg u (fun x=>Q x*F x i)*avg v (fun x=>R x*G x i))=_ + have hx (i:Keys (p:=p) x.t N) : avg u (fun x=>Q x*F x i)*avg v (fun x=>R x*G x i)= + avg hK (fun o=> Q o.1*F o.1 i*(R o.2*G o.2 i)) := (pairW_separate ..).symm + simp_rw [hx]; rw [avg_avg] + apply avg_congr; intro o _ + rw [←avg_mul']; exact avg_congr fun i _=> by ring + let C:= 2*netFact (trayPort p x.t)*bp (-(N:ℝ)/2) + rw [he]; unfold eclipse; rw [← avg_sub] + refine h.avg_le fun o=> ?_ + have ht := x.shine_match o.1 o.2 (t.cAxes i d) (t.cAxes j e) m Y ha hb hN + unfold twilight; rw [ind_and] + have hU := Q o.1; have hV:= R o.2 + let Z:= x.constellation o.1 o.2 (t.cAxes i d) (t.cAxes j e) m Y + let L:= Z-dip A (F o.1) (G o.2) + change Q o.1*R o.2* Z-Q o.1*R o.2*_≤ C + by_cases hh : U o.1∧V o.2 + · have hf : Q o.1*R o.2=1 := by unfold Q R; rw [←ind_and,ind_one hh] + rw [hf,one_mul,one_mul]; exact (abs_le.mp ht).2 + have hf : Q o.1*R o.2=0 := by unfold Q R; rw [←ind_and,ind_zero hh] + rw [hf,zero_mul,zero_mul,sub_zero]; exact (abs_nonneg L).trans ht + +end Station + +variable {I : Type} [Fintype I] +theorem skylineMean (w : Wgt I) (f g c : Wgt I) (ε : ℝ) (he:0≤ε) (hw:IsLaw w) + (h : avg w c≤ (ε/2)^2) (hc : ∀ i,g i^2≤c i) + (hg:∀ i,f i - g i ≤ ε/2) : avg w f ≤ ε := by + have h1 := (mean_sq _ hw g).trans ((avg_mono hw.nz hc).trans h) + have h2 : avg w f-avg w g≤ ε/2 := by rw [←avg_sub]; exact hw.avg_le hg + nlinarith only [he,h1,h2] +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/LinearExtension.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/LinearExtension.lean index f8cc1c14a00f72336363179907f64d202258e8aa..3ae9a198a6bca91917b4a8d52b5f213e0a26fffc 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/LinearExtension.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/LinearExtension.lean @@ -1,138 +1,138 @@ -import OAI.Combinatorics.HadwigerCounterexample.BinaryMatrices -import Mathlib.LinearAlgebra.Projection - -namespace OAI - -/-! # Linear Extension -/ - -noncomputable section -namespace HadwigerCounterexample - -open Matrix Module Submodule LinearMap Function - -abbrev dim (V : Type) [AddCommGroup V] [Module F V] := finrank F V -abbrev rk {V W : Type} [AddCommGroup V] [Module F V] - [AddCommGroup W] [Module F W] (f : V →ₗ[F] W) := dim (LinearMap.range f) - -variable {V W U V' : Type} -variable [AddCommGroup V] [Module F V] [AddCommGroup W] [Module F W] -variable [AddCommGroup U] [Module F U] [AddCommGroup V'] [Module F V'] - -theorem mem_range_comp {f : V →ₗ[F] W} {g : V →ₗ[F] U} (h : ker f ≤ ker g) : - ∃ L : W →ₗ[F] U, L ∘ₗ f = g := by - obtain ⟨i,hi⟩ := f.rangeRestrict.exists_rightInverse_of_surjective f.range_rangeRestrict - obtain ⟨L,hL⟩ := (g ∘ₗ i).exists_extend - refine ⟨L,LinearMap.ext fun x => ?_⟩ - have hm := LinearMap.congr_fun hL (f.rangeRestrict x) - change L (f x) = g _ at hm - change L (f x) = _ - rw [hm] - have heq : f (i (f.rangeRestrict x)) = f x := - congrArg Subtype.val (LinearMap.congr_fun hi (f.rangeRestrict x)) - have ha : i (f.rangeRestrict x) - x ∈ ker f := by rw [mem_ker,map_sub,heq,sub_self] - simpa only [mem_ker,map_sub,sub_eq_zero] using h ha - -/-- Transport equal-sized domain embeddings in equal-dimensional spaces. -/ -theorem equate {f : U →ₗ[F] V} {g : U →ₗ[F] V'} [FiniteDimensional F V] - [FiniteDimensional F V'] (hf : Injective f) (hg : Injective g) - (h : dim V = dim V') : - ∃ A : V ≃ₗ[F] V', ∀ x, A (f x) = g x := by - let p := LinearMap.range f - let p' := LinearMap.range g - let e := LinearEquiv.ofInjective f hf - let e' := LinearEquiv.ofInjective g hg - obtain ⟨q,hq⟩ := p.exists_isCompl - obtain ⟨q',hq'⟩ := p'.exists_isCompl - let B := Submodule.prodEquivOfIsCompl p q hq - let B' := Submodule.prodEquivOfIsCompl p' q' hq' - have hk : dim q = dim q' := by - have h₁ := B.finrank_eq - have h₂ := B'.finrank_eq - rw [finrank_prod] at h₁ h₂ - have h₃ : dim p = dim p' := (e.symm.trans e').finrank_eq - dsimp only [dim] at * - omega - let C : q ≃ₗ[F] q' := LinearEquiv.ofFinrankEq _ _ hk - refine ⟨B.symm.trans ((LinearEquiv.prodCongr (e.symm.trans e') C).trans B'), fun x => ?_⟩ - have hb : B.symm (f x) = (e x,0) := - Submodule.prodEquivOfIsCompl_symm_apply_left p q hq (e x) - change B' ((e.symm.trans e') (B.symm (f x)).1, C (B.symm (f x)).2) = _ - rw [hb] - simp only [LinearEquiv.trans_apply, LinearEquiv.symm_apply_apply,map_zero] - change (e' x).val + (0:q').val = g x - simp only [Submodule.coe_zero,add_zero] - rfl - -/-- Split projection into kernel plus section. -/ -theorem lin_split (f : V →ₗ[F] W) (h : Surjective f) : - ∃ (B : W →ₗ[F] V) (k : V →ₗ[F] ker f), (∀ x, f (B x) = x) ∧ - ∀ x, B (f x) + (k x).val = x := by - obtain ⟨B,hB⟩ := f.exists_rightInverse_of_surjective (range_eq_top.mpr h) - have hb x : f (B x) = x := LinearMap.congr_fun hB x - let K := LinearMap.id - B ∘ₗ f - have hk x : K x ∈ ker f := by - change f (x - B (f x)) = 0 - rw [map_sub,hb,sub_self] - exact ⟨B,K.codRestrict _ hk,hb,fun x => by change B _ + (x-B _) = x; abel⟩ - -/-- Extend simultaneous diagram A' = L A, G = G' L to some change of basis L. -Here the two maps A, A' are injective, G, G' are onto, and G A = G' A'. -/ -theorem equate_pair {A A' : U →ₗ[F] V} {G G' : V →ₗ[F] W} - [FiniteDimensional F V] (hA : Injective A) (hA' : Injective A') - (hG : Surjective G) (hG' : Surjective G') (h : G ∘ₗ A = G' ∘ₗ A') : - ∃ L : V ≃ₗ[F] V, (∀ x, L (A x) = A' x) ∧ (∀ y, G y = G' (L y)) := by - let f := G ∘ₗ A - obtain ⟨B,k,hB,hk⟩ := lin_split G hG - obtain ⟨B',k',hB',hk'⟩ := lin_split G' hG' - have eqn x : G (A x) = G' (A' x) := LinearMap.congr_fun h x - have hh {A : U →ₗ[F] V} {G : V →ₗ[F] W} (hA : Injective A) - (hg : ∀ x, G (A x)=f x) (B : W →ₗ[F] V) {k : V →ₗ[F] ker G} - (hk : ∀ x, B (G x)+(k x).val=x) : - Injective (k ∘ₗ A ∘ₗ (ker f).subtype) := by - intro x y hxy - have hxx (x : ker f) : ↑(k (A x.val)) = A x.val := by - simpa only [hg, show f x.val = 0 from x.property, map_zero,zero_add] using hk (A x.val) - apply Subtype.ext - apply hA - rw [←hxx x,←hxx y] - exact congrArg Subtype.val hxy - have hd : dim (ker G) = dim (ker G') := by - have hr := G.finrank_range_add_finrank_ker - have hr' := G'.finrank_range_add_finrank_ker - rw [range_eq_top.mpr hG] at hr - rw [range_eq_top.mpr hG'] at hr' - exact Nat.add_left_cancel (hr.trans hr'.symm) - obtain ⟨C,hC⟩ := equate (hh hA (fun _ => rfl) B hk) - (hh hA' (fun x => (eqn x).symm) B' hk') hd - let E := k' ∘ₗ A' - C.toLinearMap ∘ₗ k ∘ₗ A - obtain ⟨D,hD⟩ := mem_range_comp (show ker f ≤ ker E by - intro x hx - change k' (A' x) - C (k (A x)) = 0 - have heq : C (k (A x)) = k' (A' x) := hC ⟨x,hx⟩ - rw [heq,sub_self]) - let L := B' ∘ₗ G + (ker G').subtype ∘ₗ (C.toLinearMap ∘ₗ k + D ∘ₗ G) - have hl (x : V) : G x = G' (L x) := by - change G x = G' (B' (G x) + ((C (k x)+D (G x)) : ker G').val) - rw [map_add,hB', show G' ((C (k x)+D (G x)) : ker G').val = 0 from - (C (k x)+D (G x)).property,add_zero] - have hli : Injective L := by - rw [← LinearMap.ker_eq_bot,eq_bot_iff] - intro x hx - have hy : G x=0 := by rw [hl,show L x=0 from hx,map_zero] - change B' _ + ((C (k x)+ D (G x)) : ker G').val = 0 at hx - simp only [hy,map_zero,zero_add,add_zero] at hx - have h00 : C (k x) = 0 := Subtype.ext hx - have h0 : k x = 0 := C.injective (by rw [map_zero, h00]) - have hw := hk x - rw [h0,hy,map_zero,Submodule.coe_zero,zero_add] at hw - rw [←hw]; exact Submodule.zero_mem _ - refine ⟨LinearEquiv.ofInjectiveEndo L hli, fun x => ?_, hl⟩ - change B' (G (A x)) + ((C (k (A x))+D (G (A x))) : ker G').val = _ - have heq : D (G (A x)) = k' (A' x) - C (k (A x)) := LinearMap.congr_fun hD x - rw [heq,add_sub_cancel,eqn,hk'] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BinaryMatrices +import Mathlib.LinearAlgebra.Projection + +namespace OAI + +/-! # Linear Extension -/ + +noncomputable section +namespace HadwigerCounterexample + +open Matrix Module Submodule LinearMap Function + +abbrev dim (V : Type) [AddCommGroup V] [Module F V] := finrank F V +abbrev rk {V W : Type} [AddCommGroup V] [Module F V] + [AddCommGroup W] [Module F W] (f : V →ₗ[F] W) := dim (LinearMap.range f) + +variable {V W U V' : Type} +variable [AddCommGroup V] [Module F V] [AddCommGroup W] [Module F W] +variable [AddCommGroup U] [Module F U] [AddCommGroup V'] [Module F V'] + +theorem mem_range_comp {f : V →ₗ[F] W} {g : V →ₗ[F] U} (h : ker f ≤ ker g) : + ∃ L : W →ₗ[F] U, L ∘ₗ f = g := by + obtain ⟨i,hi⟩ := f.rangeRestrict.exists_rightInverse_of_surjective f.range_rangeRestrict + obtain ⟨L,hL⟩ := (g ∘ₗ i).exists_extend + refine ⟨L,LinearMap.ext fun x => ?_⟩ + have hm := LinearMap.congr_fun hL (f.rangeRestrict x) + change L (f x) = g _ at hm + change L (f x) = _ + rw [hm] + have heq : f (i (f.rangeRestrict x)) = f x := + congrArg Subtype.val (LinearMap.congr_fun hi (f.rangeRestrict x)) + have ha : i (f.rangeRestrict x) - x ∈ ker f := by rw [mem_ker,map_sub,heq,sub_self] + simpa only [mem_ker,map_sub,sub_eq_zero] using h ha + +/-- Transport equal-sized domain embeddings in equal-dimensional spaces. -/ +theorem equate {f : U →ₗ[F] V} {g : U →ₗ[F] V'} [FiniteDimensional F V] + [FiniteDimensional F V'] (hf : Injective f) (hg : Injective g) + (h : dim V = dim V') : + ∃ A : V ≃ₗ[F] V', ∀ x, A (f x) = g x := by + let p := LinearMap.range f + let p' := LinearMap.range g + let e := LinearEquiv.ofInjective f hf + let e' := LinearEquiv.ofInjective g hg + obtain ⟨q,hq⟩ := p.exists_isCompl + obtain ⟨q',hq'⟩ := p'.exists_isCompl + let B := Submodule.prodEquivOfIsCompl p q hq + let B' := Submodule.prodEquivOfIsCompl p' q' hq' + have hk : dim q = dim q' := by + have h₁ := B.finrank_eq + have h₂ := B'.finrank_eq + rw [finrank_prod] at h₁ h₂ + have h₃ : dim p = dim p' := (e.symm.trans e').finrank_eq + dsimp only [dim] at * + omega + let C : q ≃ₗ[F] q' := LinearEquiv.ofFinrankEq _ _ hk + refine ⟨B.symm.trans ((LinearEquiv.prodCongr (e.symm.trans e') C).trans B'), fun x => ?_⟩ + have hb : B.symm (f x) = (e x,0) := + Submodule.prodEquivOfIsCompl_symm_apply_left p q hq (e x) + change B' ((e.symm.trans e') (B.symm (f x)).1, C (B.symm (f x)).2) = _ + rw [hb] + simp only [LinearEquiv.trans_apply, LinearEquiv.symm_apply_apply,map_zero] + change (e' x).val + (0:q').val = g x + simp only [Submodule.coe_zero,add_zero] + rfl + +/-- Split projection into kernel plus section. -/ +theorem lin_split (f : V →ₗ[F] W) (h : Surjective f) : + ∃ (B : W →ₗ[F] V) (k : V →ₗ[F] ker f), (∀ x, f (B x) = x) ∧ + ∀ x, B (f x) + (k x).val = x := by + obtain ⟨B,hB⟩ := f.exists_rightInverse_of_surjective (range_eq_top.mpr h) + have hb x : f (B x) = x := LinearMap.congr_fun hB x + let K := LinearMap.id - B ∘ₗ f + have hk x : K x ∈ ker f := by + change f (x - B (f x)) = 0 + rw [map_sub,hb,sub_self] + exact ⟨B,K.codRestrict _ hk,hb,fun x => by change B _ + (x-B _) = x; abel⟩ + +/-- Extend simultaneous diagram A' = L A, G = G' L to some change of basis L. +Here the two maps A, A' are injective, G, G' are onto, and G A = G' A'. -/ +theorem equate_pair {A A' : U →ₗ[F] V} {G G' : V →ₗ[F] W} + [FiniteDimensional F V] (hA : Injective A) (hA' : Injective A') + (hG : Surjective G) (hG' : Surjective G') (h : G ∘ₗ A = G' ∘ₗ A') : + ∃ L : V ≃ₗ[F] V, (∀ x, L (A x) = A' x) ∧ (∀ y, G y = G' (L y)) := by + let f := G ∘ₗ A + obtain ⟨B,k,hB,hk⟩ := lin_split G hG + obtain ⟨B',k',hB',hk'⟩ := lin_split G' hG' + have eqn x : G (A x) = G' (A' x) := LinearMap.congr_fun h x + have hh {A : U →ₗ[F] V} {G : V →ₗ[F] W} (hA : Injective A) + (hg : ∀ x, G (A x)=f x) (B : W →ₗ[F] V) {k : V →ₗ[F] ker G} + (hk : ∀ x, B (G x)+(k x).val=x) : + Injective (k ∘ₗ A ∘ₗ (ker f).subtype) := by + intro x y hxy + have hxx (x : ker f) : ↑(k (A x.val)) = A x.val := by + simpa only [hg, show f x.val = 0 from x.property, map_zero,zero_add] using hk (A x.val) + apply Subtype.ext + apply hA + rw [←hxx x,←hxx y] + exact congrArg Subtype.val hxy + have hd : dim (ker G) = dim (ker G') := by + have hr := G.finrank_range_add_finrank_ker + have hr' := G'.finrank_range_add_finrank_ker + rw [range_eq_top.mpr hG] at hr + rw [range_eq_top.mpr hG'] at hr' + exact Nat.add_left_cancel (hr.trans hr'.symm) + obtain ⟨C,hC⟩ := equate (hh hA (fun _ => rfl) B hk) + (hh hA' (fun x => (eqn x).symm) B' hk') hd + let E := k' ∘ₗ A' - C.toLinearMap ∘ₗ k ∘ₗ A + obtain ⟨D,hD⟩ := mem_range_comp (show ker f ≤ ker E by + intro x hx + change k' (A' x) - C (k (A x)) = 0 + have heq : C (k (A x)) = k' (A' x) := hC ⟨x,hx⟩ + rw [heq,sub_self]) + let L := B' ∘ₗ G + (ker G').subtype ∘ₗ (C.toLinearMap ∘ₗ k + D ∘ₗ G) + have hl (x : V) : G x = G' (L x) := by + change G x = G' (B' (G x) + ((C (k x)+D (G x)) : ker G').val) + rw [map_add,hB', show G' ((C (k x)+D (G x)) : ker G').val = 0 from + (C (k x)+D (G x)).property,add_zero] + have hli : Injective L := by + rw [← LinearMap.ker_eq_bot,eq_bot_iff] + intro x hx + have hy : G x=0 := by rw [hl,show L x=0 from hx,map_zero] + change B' _ + ((C (k x)+ D (G x)) : ker G').val = 0 at hx + simp only [hy,map_zero,zero_add,add_zero] at hx + have h00 : C (k x) = 0 := Subtype.ext hx + have h0 : k x = 0 := C.injective (by rw [map_zero, h00]) + have hw := hk x + rw [h0,hy,map_zero,Submodule.coe_zero,zero_add] at hw + rw [←hw]; exact Submodule.zero_mem _ + refine ⟨LinearEquiv.ofInjectiveEndo L hli, fun x => ?_, hl⟩ + change B' (G (A x)) + ((C (k (A x))+D (G (A x))) : ker G').val = _ + have heq : D (G (A x)) = k' (A' x) - C (k (A x)) := LinearMap.congr_fun hD x + rw [heq,add_sub_cancel,eqn,hk'] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/LinearResponse.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/LinearResponse.lean index 7992cc0e1aa5788d44c6a8e50109466c48303fa5..f29db2dc8384c48b409ce686079bc12a1fc8bdbb 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/LinearResponse.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/LinearResponse.lean @@ -1,117 +1,117 @@ -import OAI.Combinatorics.HadwigerCounterexample.BaselineForms - -namespace OAI - -/-! # Linear Response -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Submodule Module -open scoped BigOperators -variable {p : Shape} {n : ℕ} - -abbrev PureForms (p : Shape) (n : ℕ) := Comp p.g → Mat (JointIdx p n) (JointIdx p n) -abbrev ChanOut (p : Shape) (n : ℕ) := Place p → Mat (Chan p) (JointIdx p n) -abbrev Xpair (p : Shape) (n : ℕ) := Bool → Xspace p n - -def pureSpace (p : Shape) {n} (f : Plan p n) : Space (PureForms p n) := - Submodule.pi Set.univ (fun e => box (annih (f (e,true))) (annih (f (e,false)))) -def deltaSpace (p : Shape) {n} (f b : Plan p n) (j : Bool) : Space (ChanOut p n) := - Submodule.pi Set.univ (fun e => box (annih (hPin b (flipZ p e) j)) (annih (f e))) - -theorem pureSpace_mem {f : Plan p n} (P : PureForms p n) : - P∈pureSpace p f ↔ ∀ e : Comp p.g, - P e∈box (annih (f (e,true))) (annih (f (e,false))) := by simp [pureSpace,Submodule.mem_pi] -theorem deltaSpace_mem {b f : Plan p n} {j} (C : ChanOut p n) : - C∈deltaSpace p f b j ↔ ∀ e : Place p, - C e∈box (annih (hPin b (flipZ p e) j)) (annih (f e)) := by simp [deltaSpace,Submodule.mem_pi] - -def chanInner (p : Shape) {n} (C D : ChanOut p n) : PureForms p n := - fun e => (C (e,true))ᵀ * D (e,false) -def chanDeriv (p : Shape) {n} (C D : ChanOut p n) : PureForms p n := - chanInner p C D+chanInner p D C - -def purePair (p : Shape) (n) (x : Xpair p n) : PureForms p n := - ∑ i : Bool,(fun e => liftM (IP p n i) (IP p n i) ((x i).val e)) - -def react (p : Shape) {n : ℕ} (C : ChanOut p n) : - ChanOut p n × PureForms p n →ₗ[F] Module.Dual F (Xpair p n) where - toFun A := { - toFun x := ∑ e : Comp p.g, - mpair ((chanDeriv p C A.1+A.2) e) (purePair p n x e) - map_add' x y := by - have hh (e) : purePair p n (x+y) e=purePair p n x e+purePair p n y e := by - simp only [purePair,Finset.sum_apply,Pi.add_apply,Submodule.coe_add,map_add, - Finset.sum_add_distrib] - simp only [hh,map_add,Finset.sum_add_distrib] - map_smul' b x := by - have hh (e) : purePair p n (b•x) e=b • purePair p n x e := by - simp only [purePair,Finset.sum_apply,Pi.smul_apply,Submodule.coe_smul,map_smul, - Finset.smul_sum] - simp only [hh,map_smul,RingHom.id_apply,Finset.smul_sum] } - map_add' A B := LinearMap.ext fun x => by - have h (e) : (chanDeriv p C (A+B).1 + (A+B).2) e = - (chanDeriv p C A.1 + A.2) e + (chanDeriv p C B.1 + B.2) e := by - simp only [chanDeriv,chanInner,Pi.add_apply,Prod.fst_add,Prod.snd_add, - transpose_add,Matrix.add_mul,Matrix.mul_add]; abel - simp only [LinearMap.coe_mk,AddHom.coe_mk,h,mpair_add,LinearMap.add_apply, - Finset.sum_add_distrib] - map_smul' b A := LinearMap.ext fun x => by - have h (e) : (chanDeriv p C (b•A).1 + (b•A).2) e = - b • (chanDeriv p C A.1 + A.2) e := by - simp only [chanDeriv,chanInner,Pi.add_apply,Pi.smul_apply,Prod.smul_fst,Prod.smul_snd, - transpose_smul, Matrix.smul_mul, Matrix.mul_smul,smul_add] - simp only [LinearMap.coe_mk,AddHom.coe_mk,h,mpair_smul,LinearMap.smul_apply,RingHom.id_apply, - smul_eq_mul,Finset.mul_sum] - -def orth (p : Shape) {n : ℕ} (C : ChanOut p n) (f b : Plan p n) (j) (x : Xpair p n) := - ∀ D∈deltaSpace p f b j,∀ A∈pureSpace p f, react p C (D,A) x=0 - -theorem solve_by_dual {f b : Plan p n} {C : ChanOut p n} {j : Bool} - (G : Module.Dual F (Xpair p n)) - (h : ∀ x, orth p C f b j x → G x = 0) : - ∃ D∈deltaSpace p f b j,∃ A∈ pureSpace p f,react p C (D,A) = G := by - classical - let S := ((deltaSpace p f b j).prod (pureSpace p f)).map (react p C) - by_cases he : G∈S - · obtain ⟨⟨D,A⟩,⟨h1,h2⟩,hh⟩ := he - exact ⟨D,h1,A,h2,hh⟩ - obtain ⟨g,hg,hk⟩ := S.exists_le_ker_of_notMem he - let x := (Module.evalEquiv F (Xpair p n)).symm g - have ht (f : Module.Dual F (Xpair p n)) : f x=g f := - apply_evalEquiv_symm_apply .. - have h1 : orth p C f b j x := by - intro D hd A ha - rw [ht]; exact hk (show react p C (D,A)∈S from ⟨_,⟨hd,ha⟩,rfl⟩) - exact (hg ((ht G).symm.trans (h x h1))).elim - -/-- Pure test annihilation vanishes in the factor quotients. -/ -theorem orth_pure {f b : Plan p n} {x : Xpair p n} {C : ChanOut p n} {j} - (h : orth p C f b j x) (e : Comp p.g) : - vanish (f (e,true)) (f (e,false)) (purePair p n x e) := by - classical - intro y hy z hz - let m : Mat (JointIdx p n) (JointIdx p n) := vecMulVec y z - let a : PureForms p n := Pi.single e m - have he : a∈pureSpace p f := by - refine (pureSpace_mem _).mpr (fun i => ?_) - by_cases h : i = e - · subst i; rw [show a e=m from Pi.single_eq_same _ _]; exact outer_in_box _ _ hy hz - simp [a,h] - have hx := h 0 (Submodule.zero_mem _) a he - change ∑ i, mpair ((chanDeriv p C 0+a) i) (purePair p n x i) = _ at hx - have ha : chanDeriv p C 0=0 := by - unfold chanDeriv chanInner; ext; simp - rw [ha,zero_add,Finset.sum_eq_single e] at hx - · rw [←mpair_outer,mpair_comm] - rw [show a e=m from Pi.single_eq_same _ _] at hx - exact hx - · intro i _ h - rw [show a i=0 from Pi.single_eq_of_ne h _,mpair_comm,map_zero] - simp - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BaselineForms + +namespace OAI + +/-! # Linear Response -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Submodule Module +open scoped BigOperators +variable {p : Shape} {n : ℕ} + +abbrev PureForms (p : Shape) (n : ℕ) := Comp p.g → Mat (JointIdx p n) (JointIdx p n) +abbrev ChanOut (p : Shape) (n : ℕ) := Place p → Mat (Chan p) (JointIdx p n) +abbrev Xpair (p : Shape) (n : ℕ) := Bool → Xspace p n + +def pureSpace (p : Shape) {n} (f : Plan p n) : Space (PureForms p n) := + Submodule.pi Set.univ (fun e => box (annih (f (e,true))) (annih (f (e,false)))) +def deltaSpace (p : Shape) {n} (f b : Plan p n) (j : Bool) : Space (ChanOut p n) := + Submodule.pi Set.univ (fun e => box (annih (hPin b (flipZ p e) j)) (annih (f e))) + +theorem pureSpace_mem {f : Plan p n} (P : PureForms p n) : + P∈pureSpace p f ↔ ∀ e : Comp p.g, + P e∈box (annih (f (e,true))) (annih (f (e,false))) := by simp [pureSpace,Submodule.mem_pi] +theorem deltaSpace_mem {b f : Plan p n} {j} (C : ChanOut p n) : + C∈deltaSpace p f b j ↔ ∀ e : Place p, + C e∈box (annih (hPin b (flipZ p e) j)) (annih (f e)) := by simp [deltaSpace,Submodule.mem_pi] + +def chanInner (p : Shape) {n} (C D : ChanOut p n) : PureForms p n := + fun e => (C (e,true))ᵀ * D (e,false) +def chanDeriv (p : Shape) {n} (C D : ChanOut p n) : PureForms p n := + chanInner p C D+chanInner p D C + +def purePair (p : Shape) (n) (x : Xpair p n) : PureForms p n := + ∑ i : Bool,(fun e => liftM (IP p n i) (IP p n i) ((x i).val e)) + +def react (p : Shape) {n : ℕ} (C : ChanOut p n) : + ChanOut p n × PureForms p n →ₗ[F] Module.Dual F (Xpair p n) where + toFun A := { + toFun x := ∑ e : Comp p.g, + mpair ((chanDeriv p C A.1+A.2) e) (purePair p n x e) + map_add' x y := by + have hh (e) : purePair p n (x+y) e=purePair p n x e+purePair p n y e := by + simp only [purePair,Finset.sum_apply,Pi.add_apply,Submodule.coe_add,map_add, + Finset.sum_add_distrib] + simp only [hh,map_add,Finset.sum_add_distrib] + map_smul' b x := by + have hh (e) : purePair p n (b•x) e=b • purePair p n x e := by + simp only [purePair,Finset.sum_apply,Pi.smul_apply,Submodule.coe_smul,map_smul, + Finset.smul_sum] + simp only [hh,map_smul,RingHom.id_apply,Finset.smul_sum] } + map_add' A B := LinearMap.ext fun x => by + have h (e) : (chanDeriv p C (A+B).1 + (A+B).2) e = + (chanDeriv p C A.1 + A.2) e + (chanDeriv p C B.1 + B.2) e := by + simp only [chanDeriv,chanInner,Pi.add_apply,Prod.fst_add,Prod.snd_add, + transpose_add,Matrix.add_mul,Matrix.mul_add]; abel + simp only [LinearMap.coe_mk,AddHom.coe_mk,h,mpair_add,LinearMap.add_apply, + Finset.sum_add_distrib] + map_smul' b A := LinearMap.ext fun x => by + have h (e) : (chanDeriv p C (b•A).1 + (b•A).2) e = + b • (chanDeriv p C A.1 + A.2) e := by + simp only [chanDeriv,chanInner,Pi.add_apply,Pi.smul_apply,Prod.smul_fst,Prod.smul_snd, + transpose_smul, Matrix.smul_mul, Matrix.mul_smul,smul_add] + simp only [LinearMap.coe_mk,AddHom.coe_mk,h,mpair_smul,LinearMap.smul_apply,RingHom.id_apply, + smul_eq_mul,Finset.mul_sum] + +def orth (p : Shape) {n : ℕ} (C : ChanOut p n) (f b : Plan p n) (j) (x : Xpair p n) := + ∀ D∈deltaSpace p f b j,∀ A∈pureSpace p f, react p C (D,A) x=0 + +theorem solve_by_dual {f b : Plan p n} {C : ChanOut p n} {j : Bool} + (G : Module.Dual F (Xpair p n)) + (h : ∀ x, orth p C f b j x → G x = 0) : + ∃ D∈deltaSpace p f b j,∃ A∈ pureSpace p f,react p C (D,A) = G := by + classical + let S := ((deltaSpace p f b j).prod (pureSpace p f)).map (react p C) + by_cases he : G∈S + · obtain ⟨⟨D,A⟩,⟨h1,h2⟩,hh⟩ := he + exact ⟨D,h1,A,h2,hh⟩ + obtain ⟨g,hg,hk⟩ := S.exists_le_ker_of_notMem he + let x := (Module.evalEquiv F (Xpair p n)).symm g + have ht (f : Module.Dual F (Xpair p n)) : f x=g f := + apply_evalEquiv_symm_apply .. + have h1 : orth p C f b j x := by + intro D hd A ha + rw [ht]; exact hk (show react p C (D,A)∈S from ⟨_,⟨hd,ha⟩,rfl⟩) + exact (hg ((ht G).symm.trans (h x h1))).elim + +/-- Pure test annihilation vanishes in the factor quotients. -/ +theorem orth_pure {f b : Plan p n} {x : Xpair p n} {C : ChanOut p n} {j} + (h : orth p C f b j x) (e : Comp p.g) : + vanish (f (e,true)) (f (e,false)) (purePair p n x e) := by + classical + intro y hy z hz + let m : Mat (JointIdx p n) (JointIdx p n) := vecMulVec y z + let a : PureForms p n := Pi.single e m + have he : a∈pureSpace p f := by + refine (pureSpace_mem _).mpr (fun i => ?_) + by_cases h : i = e + · subst i; rw [show a e=m from Pi.single_eq_same _ _]; exact outer_in_box _ _ hy hz + simp [a,h] + have hx := h 0 (Submodule.zero_mem _) a he + change ∑ i, mpair ((chanDeriv p C 0+a) i) (purePair p n x i) = _ at hx + have ha : chanDeriv p C 0=0 := by + unfold chanDeriv chanInner; ext; simp + rw [ha,zero_add,Finset.sum_eq_single e] at hx + · rw [←mpair_outer,mpair_comm] + rw [show a e=m from Pi.single_eq_same _ _] at hx + exact hx + · intro i _ h + rw [show a i=0 from Pi.single_eq_of_ne h _,mpair_comm,map_zero] + simp + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/LowRankKernelAlternative.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/LowRankKernelAlternative.lean index 1886b444c336b31ef9a5133da60b05ca0772526f..7ee1e18dfaebe0bdb603ec4586cc1b0bf0b33da6 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/LowRankKernelAlternative.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/LowRankKernelAlternative.lean @@ -1,200 +1,200 @@ -import OAI.Combinatorics.HadwigerCounterexample.SmallCoverBounds - -namespace OAI - -/-! # Low Rank Kernel Alternative -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Finset Filter -open scoped BigOperators Topology -variable {A J B : Type} [Fintype A] [Fintype J] [Fintype B] - -private def rbase (a : A → Vec B) (S : Finset A) := - Submodule.span F (Set.image a (S : Set A)) -omit [Fintype A] in -private theorem row_extract (a : A → Vec B) (S : Finset A) : - ∃ T⊆ S,rbase a T=rbase a S ∧ T.card=dim (rbase a T) := by - classical - induction S using Finset.induction with - | empty => - have hh : Set.image a ((∅:Finset A):Set _) = ∅ := by ext; simp - have he : rbase a ∅=⊥ := by unfold rbase; rw [hh,Submodule.span_empty] - refine ⟨∅,by simp, rfl,?_⟩; rw [he]; exact (finrank_bot ..).symm - | insert x S hx ih => - obtain ⟨T,hT,hR,hD⟩ := ih - have he (S : Finset A) : - rbase a (insert x S)= rbase a S⊔Submodule.span F ({a x} : Set _) := by - unfold rbase - rw [← span_union] - congr 1 - ext; simp - rw [he] - by_cases h : a x∈rbase a T - · refine ⟨T,hT.trans (Finset.subset_insert ..),?_,hD⟩ - rw [←hR,sup_eq_left.mpr (by rwa [Submodule.span_singleton_le_iff_mem])] - refine ⟨insert x T,Finset.insert_subset_insert x hT,by rw [he,hR],?_⟩ - rw [he] - have hh (h' : a x∉rbase a T) := - Submodule.finrank_sup_span_singleton h' - rw [Finset.card_insert_of_notMem (fun e => hx (hT e)),hD] - exact (hh h).symm - -private def tilt (m u : ℝ) : Wgt F := - fun x => if x=0 then bp (-m) else bp (-u) - -private theorem tilt_sub (m u : ℝ) (h : bp (-m)+bp (-u) ≤1) : SubLaw (tilt m u) := by - classical - refine ⟨fun x => ?_,?_⟩ - · unfold tilt; split <;> exact (bp_pos _).le - unfold tot - rw [show (Finset.univ : Finset F)={0,1} from (by ext x; simp [bit_cases])] - simpa only [Finset.sum_insert (show (0:F)∉({1}:Finset _) by simp), tilt,ite_true, - Finset.sum_singleton, ite_eq_right (show (1:F) ≠ 0 from one_ne_zero)] using h - -theorem draws_sub {K : Type} [Fintype K] [DecidableEq K] (w : Wgt A) (h : SubLaw w) : - SubLaw (draws K w) := by - refine ⟨prodW_nonneg (fun _ => h.nz),?_⟩ - rw [draws,prodW_tot] - refine (Finset.prod_le_prod₀ (g:=fun _ => 1) (fun _ _ => tot_nonneg h.nz) (fun _ _ => h.total)).trans_eq - (by simp) - -private theorem tilted_fiber [DecidableEq J] (w : Wgt A) (f : A → Vec J) - (v m u η : ℝ) (hh : 0 f x i=0)≤η) : - ∃ z : Vec J,bp (-v)/4 ≤ pr w (fun x => f x=z) := by - classical - let d (i : F) := u+m*ind (i=0) - let c (v : Vec J) := ∑ i,d (v i) - have hd i : 0 ≤ d i := add_nonneg hu.le (mul_nonneg hm.le (ind_nonneg _)) - have hc : - avg w (fun x => c (f x)) ≤ v/2 := by - unfold c; rw [avg_sum] - refine (Finset.sum_le_sum (g:=fun _ => u+m*η) fun i _ => ?_).trans ?_ - · simp only [d,avg_add,avg_mul',hw.avg_const] - exact add_le_add_right (mul_le_mul_of_nonneg_left (h _) hm.le) _ - simpa [mul_add] using he - let H (x : Vec J) := ¬ v≤ c x - let W := mapW w f - have h1 : (1/2:ℝ) ≤ pr W H := by - rw [mapW_pr,show (fun x => H (f x))=(fun x => ¬ v≤c (f x)) from rfl, - pr_not,hw.total] - have heq := (le_avg_markov hw.nz (f:=fun x => c (f x)) - (fun x => Finset.sum_nonneg (fun i _ => hd _)) v).trans hc - apply le_of_mul_le_mul_right _ hh; linarith only [heq] - let t : Wgt (Vec J) := draws J (tilt m u) - have hk (x : Vec J) : H x → bp (-v) ≤ t x := by - intro h' - apply le_trans (bp_le (show -v ≤ -c x from neg_le_neg (le_of_not_ge h'))) - unfold c t draws prodW - rw [← Finset.sum_neg_distrib,bp_sum] - refine Finset.prod_le_prod₀ (fun i _ => (bp_pos _).le) fun i _ => ?_ - by_cases he : x i=0 - · simp only [tilt,d,he,ite_true,ind_true,mul_one] - exact bp_le (by linarith) - simp only [d,tilt,ite_eq_right he,ind_zero he,mul_zero,add_zero,le_refl] - by_contra! hz - have hi x : W x*ind (H x)≤t x * (1/4) := by - by_cases h : H x - · rw [ind_one h,mul_one] - apply le_trans (hz x).le - simpa only [div_eq_mul_inv,one_mul] using div_le_div_of_nonneg_right (hk x h) - (show 0 ≤ (4:ℝ) by norm_num) - · rw [ind_zero h,mul_zero] - exact mul_nonneg ((draws_sub _ (tilt_sub m u hp)).nz _) (by norm_num) - have ht : SubLaw t := draws_sub _ (tilt_sub m u hp) - have h2 := h1.trans ((Finset.sum_le_sum (s:=Finset.univ) fun i _ => hi i).trans - (ht.avg_le (show (0:ℝ) ≤ 1/4 by norm_num) (fun _ => le_rfl))) - norm_num at h2 - -set_option maxHeartbeats 800000 in -theorem fiber_growth (d : ℝ) (c : ℝ) (hc : 0 P x.1 x.2=0)≤ θ → - ∃ S : A→Prop, bp (-c*N) ≤ pr w S ∧ ∀ x,S x → ∀ y,S y → P x y=0 := by - classical - let u := c /(16*(d+1)) - have hu : 0 < u := div_pos hc (by linarith) - obtain ⟨m,hm,hp⟩ : ∃ m : ℝ,0 P x y=0) - let Q : Finset A := Finset.univ.filter (fun x => ¬ 2*θ ≤ f x) - have hq : (1/2:ℝ) ≤ pr w (fun x => x∈Q) := by - have hg : avg w f ≤ θ := by rw [pr,pairW_avg] at hp'; exact hp' - have hi := (le_avg_markov hw.nz (f:=f) (fun x => pr_nonneg hw.nz) (2*θ)).trans hg - simp only [Q,Finset.mem_filter,Finset.mem_univ,true_and,pr_not,hw.total] - apply le_of_mul_le_mul_right _ ht; linarith only [hi] - let v := onW w (fun x => x∈Q) - obtain ⟨T,hT,hR,hM⟩ := row_extract (P.row) Q - have hM' : ↑T.card ≤ d*N := by - rw [hM] - have hg : rbase P.row T≤colSp Pᵀ := by - apply Submodule.span_le.mpr - rintro y ⟨x,hx,rfl⟩; exact colSp_mem (P:=Pᵀ) x - have hi := Submodule.finrank_mono hg - change dim _ ≤ Pᵀ.rank at hi; rw [Matrix.rank_transpose] at hi - exact le_trans (Nat.cast_le.mpr hi) hP - let g (x : A) : Vec T := fun j => P j.val x - let E (x : A) := x∈Q - have hpc : 0 g x i=0)≤4*θ := by - have h : f i.val ≤ 2*θ := le_of_not_ge (Finset.mem_filter.mp (hT i.property)).2 - unfold v - rw [pr_on]; refine (div_le_iff₀ hpc).mpr ?_ - apply le_trans _ (le_trans h ?_) - · exact pr_mono hw.nz fun x => And.right - nlinarith only [mul_le_mul_of_nonneg_left hq ht.le] - let x := c*N/2 - have hn : 0<(N:ℝ) := Nat.cast_pos.mpr hN - have hx : 0 E x∧g x=z,?_,fun x hx y hy => ?_⟩ - · rw [pr_of_on hw.nz E] - calc bp (-c*N) ≤ (1/2)*(bp (-x)/4) := by - have hq : bp (-c*N) ≤ bp (-3+ -x) := bp_le (by - change (8/c) ≤ (N:ℝ) at h - have he := (div_le_iff₀ hc).mp h - unfold x; linarith only [he]) - rw [bp_add,bp_neg,show (3:ℝ)=↑(3:ℕ) from by norm_num,bp_nat] at hq - linarith only [hq] - _ ≤ _ := mul_le_mul hq hZ (div_nonneg (bp_pos _).le (by norm_num)) hpc.le - · have hv (x y : A) (h : g x=g y) : - ∀ i∈Q,P i x=P i y := by - let f := LinearMap.proj (R:=HadwigerCounterexample.F) (φ:=fun _ : A => HadwigerCounterexample.F) x - let f' := LinearMap.proj (R:=HadwigerCounterexample.F) (φ:=fun _ : A => HadwigerCounterexample.F) y - have hh : rbase P.row T ≤ LinearMap.ker (f-f') := by - refine Submodule.span_le.mpr ?_ - rintro v ⟨i,hi,rfl⟩ - exact sub_eq_zero.mpr (congr_fun h (⟨i,hi⟩ : T)) - intro i hi - rw [hR] at hh - exact sub_eq_zero.mp (hh (Submodule.subset_span ⟨i,hi,rfl⟩)) - rw [← hv x y (hx.2.trans hy.2.symm) x hx.1,hz] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SmallCoverBounds + +namespace OAI + +/-! # Low Rank Kernel Alternative -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Finset Filter +open scoped BigOperators Topology +variable {A J B : Type} [Fintype A] [Fintype J] [Fintype B] + +private def rbase (a : A → Vec B) (S : Finset A) := + Submodule.span F (Set.image a (S : Set A)) +omit [Fintype A] in +private theorem row_extract (a : A → Vec B) (S : Finset A) : + ∃ T⊆ S,rbase a T=rbase a S ∧ T.card=dim (rbase a T) := by + classical + induction S using Finset.induction with + | empty => + have hh : Set.image a ((∅:Finset A):Set _) = ∅ := by ext; simp + have he : rbase a ∅=⊥ := by unfold rbase; rw [hh,Submodule.span_empty] + refine ⟨∅,by simp, rfl,?_⟩; rw [he]; exact (finrank_bot ..).symm + | insert x S hx ih => + obtain ⟨T,hT,hR,hD⟩ := ih + have he (S : Finset A) : + rbase a (insert x S)= rbase a S⊔Submodule.span F ({a x} : Set _) := by + unfold rbase + rw [← span_union] + congr 1 + ext; simp + rw [he] + by_cases h : a x∈rbase a T + · refine ⟨T,hT.trans (Finset.subset_insert ..),?_,hD⟩ + rw [←hR,sup_eq_left.mpr (by rwa [Submodule.span_singleton_le_iff_mem])] + refine ⟨insert x T,Finset.insert_subset_insert x hT,by rw [he,hR],?_⟩ + rw [he] + have hh (h' : a x∉rbase a T) := + Submodule.finrank_sup_span_singleton h' + rw [Finset.card_insert_of_notMem (fun e => hx (hT e)),hD] + exact (hh h).symm + +private def tilt (m u : ℝ) : Wgt F := + fun x => if x=0 then bp (-m) else bp (-u) + +private theorem tilt_sub (m u : ℝ) (h : bp (-m)+bp (-u) ≤1) : SubLaw (tilt m u) := by + classical + refine ⟨fun x => ?_,?_⟩ + · unfold tilt; split <;> exact (bp_pos _).le + unfold tot + rw [show (Finset.univ : Finset F)={0,1} from (by ext x; simp [bit_cases])] + simpa only [Finset.sum_insert (show (0:F)∉({1}:Finset _) by simp), tilt,ite_true, + Finset.sum_singleton, ite_eq_right (show (1:F) ≠ 0 from one_ne_zero)] using h + +theorem draws_sub {K : Type} [Fintype K] [DecidableEq K] (w : Wgt A) (h : SubLaw w) : + SubLaw (draws K w) := by + refine ⟨prodW_nonneg (fun _ => h.nz),?_⟩ + rw [draws,prodW_tot] + refine (Finset.prod_le_prod₀ (g:=fun _ => 1) (fun _ _ => tot_nonneg h.nz) (fun _ _ => h.total)).trans_eq + (by simp) + +private theorem tilted_fiber [DecidableEq J] (w : Wgt A) (f : A → Vec J) + (v m u η : ℝ) (hh : 0 f x i=0)≤η) : + ∃ z : Vec J,bp (-v)/4 ≤ pr w (fun x => f x=z) := by + classical + let d (i : F) := u+m*ind (i=0) + let c (v : Vec J) := ∑ i,d (v i) + have hd i : 0 ≤ d i := add_nonneg hu.le (mul_nonneg hm.le (ind_nonneg _)) + have hc : + avg w (fun x => c (f x)) ≤ v/2 := by + unfold c; rw [avg_sum] + refine (Finset.sum_le_sum (g:=fun _ => u+m*η) fun i _ => ?_).trans ?_ + · simp only [d,avg_add,avg_mul',hw.avg_const] + exact add_le_add_right (mul_le_mul_of_nonneg_left (h _) hm.le) _ + simpa [mul_add] using he + let H (x : Vec J) := ¬ v≤ c x + let W := mapW w f + have h1 : (1/2:ℝ) ≤ pr W H := by + rw [mapW_pr,show (fun x => H (f x))=(fun x => ¬ v≤c (f x)) from rfl, + pr_not,hw.total] + have heq := (le_avg_markov hw.nz (f:=fun x => c (f x)) + (fun x => Finset.sum_nonneg (fun i _ => hd _)) v).trans hc + apply le_of_mul_le_mul_right _ hh; linarith only [heq] + let t : Wgt (Vec J) := draws J (tilt m u) + have hk (x : Vec J) : H x → bp (-v) ≤ t x := by + intro h' + apply le_trans (bp_le (show -v ≤ -c x from neg_le_neg (le_of_not_ge h'))) + unfold c t draws prodW + rw [← Finset.sum_neg_distrib,bp_sum] + refine Finset.prod_le_prod₀ (fun i _ => (bp_pos _).le) fun i _ => ?_ + by_cases he : x i=0 + · simp only [tilt,d,he,ite_true,ind_true,mul_one] + exact bp_le (by linarith) + simp only [d,tilt,ite_eq_right he,ind_zero he,mul_zero,add_zero,le_refl] + by_contra! hz + have hi x : W x*ind (H x)≤t x * (1/4) := by + by_cases h : H x + · rw [ind_one h,mul_one] + apply le_trans (hz x).le + simpa only [div_eq_mul_inv,one_mul] using div_le_div_of_nonneg_right (hk x h) + (show 0 ≤ (4:ℝ) by norm_num) + · rw [ind_zero h,mul_zero] + exact mul_nonneg ((draws_sub _ (tilt_sub m u hp)).nz _) (by norm_num) + have ht : SubLaw t := draws_sub _ (tilt_sub m u hp) + have h2 := h1.trans ((Finset.sum_le_sum (s:=Finset.univ) fun i _ => hi i).trans + (ht.avg_le (show (0:ℝ) ≤ 1/4 by norm_num) (fun _ => le_rfl))) + norm_num at h2 + +set_option maxHeartbeats 800000 in +theorem fiber_growth (d : ℝ) (c : ℝ) (hc : 0 P x.1 x.2=0)≤ θ → + ∃ S : A→Prop, bp (-c*N) ≤ pr w S ∧ ∀ x,S x → ∀ y,S y → P x y=0 := by + classical + let u := c /(16*(d+1)) + have hu : 0 < u := div_pos hc (by linarith) + obtain ⟨m,hm,hp⟩ : ∃ m : ℝ,0 P x y=0) + let Q : Finset A := Finset.univ.filter (fun x => ¬ 2*θ ≤ f x) + have hq : (1/2:ℝ) ≤ pr w (fun x => x∈Q) := by + have hg : avg w f ≤ θ := by rw [pr,pairW_avg] at hp'; exact hp' + have hi := (le_avg_markov hw.nz (f:=f) (fun x => pr_nonneg hw.nz) (2*θ)).trans hg + simp only [Q,Finset.mem_filter,Finset.mem_univ,true_and,pr_not,hw.total] + apply le_of_mul_le_mul_right _ ht; linarith only [hi] + let v := onW w (fun x => x∈Q) + obtain ⟨T,hT,hR,hM⟩ := row_extract (P.row) Q + have hM' : ↑T.card ≤ d*N := by + rw [hM] + have hg : rbase P.row T≤colSp Pᵀ := by + apply Submodule.span_le.mpr + rintro y ⟨x,hx,rfl⟩; exact colSp_mem (P:=Pᵀ) x + have hi := Submodule.finrank_mono hg + change dim _ ≤ Pᵀ.rank at hi; rw [Matrix.rank_transpose] at hi + exact le_trans (Nat.cast_le.mpr hi) hP + let g (x : A) : Vec T := fun j => P j.val x + let E (x : A) := x∈Q + have hpc : 0 g x i=0)≤4*θ := by + have h : f i.val ≤ 2*θ := le_of_not_ge (Finset.mem_filter.mp (hT i.property)).2 + unfold v + rw [pr_on]; refine (div_le_iff₀ hpc).mpr ?_ + apply le_trans _ (le_trans h ?_) + · exact pr_mono hw.nz fun x => And.right + nlinarith only [mul_le_mul_of_nonneg_left hq ht.le] + let x := c*N/2 + have hn : 0<(N:ℝ) := Nat.cast_pos.mpr hN + have hx : 0 E x∧g x=z,?_,fun x hx y hy => ?_⟩ + · rw [pr_of_on hw.nz E] + calc bp (-c*N) ≤ (1/2)*(bp (-x)/4) := by + have hq : bp (-c*N) ≤ bp (-3+ -x) := bp_le (by + change (8/c) ≤ (N:ℝ) at h + have he := (div_le_iff₀ hc).mp h + unfold x; linarith only [he]) + rw [bp_add,bp_neg,show (3:ℝ)=↑(3:ℕ) from by norm_num,bp_nat] at hq + linarith only [hq] + _ ≤ _ := mul_le_mul hq hZ (div_nonneg (bp_pos _).le (by norm_num)) hpc.le + · have hv (x y : A) (h : g x=g y) : + ∀ i∈Q,P i x=P i y := by + let f := LinearMap.proj (R:=HadwigerCounterexample.F) (φ:=fun _ : A => HadwigerCounterexample.F) x + let f' := LinearMap.proj (R:=HadwigerCounterexample.F) (φ:=fun _ : A => HadwigerCounterexample.F) y + have hh : rbase P.row T ≤ LinearMap.ker (f-f') := by + refine Submodule.span_le.mpr ?_ + rintro v ⟨i,hi,rfl⟩ + exact sub_eq_zero.mpr (congr_fun h (⟨i,hi⟩ : T)) + intro i hi + rw [hR] at hh + exact sub_eq_zero.mp (hh (Submodule.subset_span ⟨i,hi,rfl⟩)) + rw [← hv x y (hx.2.trans hy.2.symm) x hx.1,hz] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/Main.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/Main.lean index 1a333f54dd31055adb26c9ce9ac22922fe42b815..0b8b8d46203e289c68f117b10916c28cc0573e23 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/Main.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/Main.lean @@ -1,128 +1,128 @@ -import OAI.Combinatorics.HadwigerCounterexample.ParameterExistence -import OAI.Combinatorics.HadwigerCounterexample.FinalContradiction -import OAI.Combinatorics.HadwigerCounterexample.ExponentialGraphTransfer -import OAI.Combinatorics.HadwigerMatching.Main - -namespace OAI - -/-! -# Counterexamples to Hadwiger's conjecture - -The binary frame construction yields arbitrarily large graphs with independence -number at most two and small touching matchings. The matching–minor inequality -then separates their complete-minor order from their ordinary chromatic number. - -This formalizes the construction theorem and the ordinary chromatic consequence -in OpenAI, *A counterexample to Hadwiger's conjecture* (September 23, 2026). --/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Filter Finset -open scoped BigOperators Topology - -variable {p:Shape} {n N M s0 :ℕ} {b: PreparationParameters} -open PreparationParameters - -def conflictLowerBound (p: Shape) (m:Mixer p n) (N:ℕ) (b:PreparationParameters) := - ∀ w:Wgt (UnitType p n N), b.nascent p N w m → carried w (rawHoles m).unit → - bp (-100*p.g*(N:ℝ))≤ pr (pairW w w) (fun i=>(rawHoles m).conflict i.1 i.2) - -set_option maxHeartbeats 1600000 in -theorem eventual_conflict_lower_bound (h:AnalyticParameters p M b s0) : - ∀ᶠ n : ℕ in atTop,∀ m:Mixer p n,unaryGood m b.pins s0→binaryGood m→conflictLowerBound p m (M*n) b := by - classical - let P:= fun n:ℕ=> ∃ (m:Mixer p n),unaryGood m b.pins s0∧binaryGood m∧ - ∃ w:Wgt (UnitType p n (M*n)), b.nascent p (M*n) w m ∧ carried w (rawHoles m).unit ∧ - conflicted p m (M*n) w - suffices hf : ¬∃ᶠ n:ℕ in atTop,P n by - have hx := not_frequently.mp hf - refine hx.mono (fun n hn m hm hv w hw hx=>?_); by_contra! hT - exact hn ⟨m,hm,hv,w,hw,hx,hT⟩ - intro hc - have hn := frequently_iff_neBot.mp hc - obtain ⟨U,hU⟩:= Filter.exists_ultrafilter_le (atTop⊓principal {n|P n}) - - let l:Filter ℕ:= U - have hl : l≤atTop := hU.trans inf_le_left - have hr : ∀ᶠ n in l,P n := - (show ∀ᶠ n in principal {i|P i},P n from Filter.eventually_principal.mpr fun x hx=>hx).filter_mono - (hU.trans inf_le_right) - let (n:ℕ) : Nonempty (Mixer p n) := ⟨⟨0,0,0⟩⟩ - obtain ⟨m,hm⟩ := taking hr - obtain ⟨w,hw⟩ := taking (hm.mono fun i h=> h.2.2) - have hF : ∀ᶠ n in l, ∃ s : LeafMixture p n (M*n),b.entered p (M*n) (m n) (w n) s := by - filter_upwards [hw,h.enter.hF.filter_mono hl] with n hn ht - exact ht _ _ hn.1 hn.2.1 - obtain ⟨s,hS⟩:= taking hF - obtain ⟨v,hv,hV⟩:= prepare U hl h.enter.first (hw.mono fun i hi=>hi.1) hS - refine StatusAnalysis.refuteVeil ⟨h,hl,hv,(hm.and hw).mono fun n ⟨h1,h2⟩=> - ⟨h2.1,h1.1,h1.2.1,h2.2.2⟩⟩ (show NeBot (U:Filter ℕ) from inferInstance) hV - -open HadwigerMatching LinearListHadwiger - -/-- Arbitrarily large finite graphs of independence number at most two and -touching-matching number less than one hundredth of the number of vertices. -/ -theorem exists_graphs (M : ℕ) : ∃ m:ℕ, max M 5 ≤ m ∧ - ∃ G : SimpleGraph (Fin m), G.indepNum ≤ 2 ∧ - (connectedMatchingNumber G:ℚ) < (m:ℚ)/100 := by - classical - obtain ⟨p,b,k,r,h,hg,hd,he⟩:= exists_parameters - have ht:=h.enter.first - let B:=4*num (Comp p.g) - let Y (n:ℕ):=k*n - have hy := (trend_sizes atTop le_rfl ht.hM).1 - have hp : 0 < p.g := lt_of_lt_of_le (by norm_num) ht.hG - have hs : ∀ᶠ n:ℕ in atTop, ∃ m:ℕ, max M 5 ≤ m ∧ - ∃ G : SimpleGraph (Fin m), G.indepNum ≤ 2 ∧ (connectedMatchingNumber G:ℚ)<(m:ℚ)/100 := by - filter_upwards [eventual_conflict_lower_bound h,ht.wrap,goodMixers p b.pins r (by linarith only [ht.hG]) - ht.hJ (by have hi:=h.profiles; omega) h.bigJ,hy.eventually - (transfer_scales hp (show 0≤B from mul_nonneg (by norm_num) (Nat.cast_nonneg _))), - ((tendsto_ord hp).comp hy).eventually (eventually_ge_atTop (max M 5))] with n hn ht hl hq hN - let N:=Y n - obtain ⟨m,hm,he'⟩:=hl - have hT:= hn m hm he'; have hV:2*num (Full p n)<(N:ℝ):=ht.1 - have hC : num (UnitType p n N)≤bp (B*N^ (2:ℕ)) := by - rw [unit_size]; apply bp_le - have hf : num (Full p n) ≤ N := by linarith only [hV,(Nat.cast_nonneg N : 0≤(N:ℝ))] - unfold B - calc _ ≤ num (Comp p.g)*4*(N:ℝ)*N := mul_le_mul_of_nonneg_left hf (by unfold num; positivity) - _ = _ := by ring - obtain ⟨x,hx,hX⟩:=hq (Orient p n N) (rawHoles m) (raw m N) (raw_law m hV) hC (by - intro w hw hC hU - apply hT w _ hU - apply born w hw m - rw [hd,he]; simpa only [N,Y,Nat.cast_mul,Nat.cast_ofNat] using hC) - exact ⟨ord p.g N,hN,(rawHoles m).graph x,hx,hX⟩ - obtain ⟨n,hn⟩:=hs.exists; exact hn - -/-- Arbitrarily large counterexamples to Hadwiger's conjecture, with the full -rational bounds and finiteness of the ordinary chromatic number. -/ -theorem exists_counterexamples (M : ℕ) : ∃ m : ℕ, max M 5 ≤ m ∧ - ∃ G : SimpleGraph (Fin m), G.indepNum ≤ 2 ∧ (connectedMatchingNumber G : ℚ) < (m : ℚ) / 100 ∧ - (hadwigerNumber G : ℚ) < 26 * (m : ℚ) / 75 + 2 / 3 ∧ - 26 * (m : ℚ) / 75 + 2 / 3 < (m : ℚ) / 2 ∧ (m : ℚ) / 2 ≤ (G.chromaticNumber.toNat : ℚ) ∧ - hadwigerNumber G < G.chromaticNumber.toNat ∧ - G.chromaticNumber ≠ ⊤ ∧ G.chromaticNumber = ↑(G.chromaticNumber.toNat) := by - obtain ⟨m,hm,G,ha,hc⟩:= exists_graphs M - have he : 5≤ m:=(le_max_right ..).trans hm - have : NeZero m:= ⟨by omega⟩ - have hx:=full_matching_minor_proposition (Fin m) G - dsimp only at hx - rw [Fintype.card_fin] at hx - obtain ⟨h1,h2,h3⟩:= hx.2 ha hc he - have hk:G.chromaticNumber ≠ ⊤:= by - intro h; have hs := G.chromaticNumber_le_card; simp [h] at hs - refine ⟨m,hm,G,ha,hc,h1,h2,h3,?_,hk,?_⟩ - · exact_mod_cast ((h1.trans h2).trans_le h3) - exact (ENat.natCast_toNat_eq_self.mpr hk).symm - -theorem not_hadwiger_conjecture : ¬ (∀ (m:ℕ)(G:SimpleGraph (Fin m)), G.chromaticNumber ≤ ↑(hadwigerNumber G)) := by - intro h; obtain ⟨m,hM,G,h1,h2,h3,h4,h5,h6,he,hC⟩:=exists_counterexamples 0 - have ht:=h m G; rw [hC] at ht - exact h6.not_ge (by exact_mod_cast ht) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ParameterExistence +import OAI.Combinatorics.HadwigerCounterexample.FinalContradiction +import OAI.Combinatorics.HadwigerCounterexample.ExponentialGraphTransfer +import OAI.Combinatorics.HadwigerMatching.Main + +namespace OAI + +/-! +# Counterexamples to Hadwiger's conjecture + +The binary frame construction yields arbitrarily large graphs with independence +number at most two and small touching matchings. The matching–minor inequality +then separates their complete-minor order from their ordinary chromatic number. + +This formalizes the construction theorem and the ordinary chromatic consequence +in OpenAI, *A counterexample to Hadwiger's conjecture* (September 23, 2026). +-/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Filter Finset +open scoped BigOperators Topology + +variable {p:Shape} {n N M s0 :ℕ} {b: PreparationParameters} +open PreparationParameters + +def conflictLowerBound (p: Shape) (m:Mixer p n) (N:ℕ) (b:PreparationParameters) := + ∀ w:Wgt (UnitType p n N), b.nascent p N w m → carried w (rawHoles m).unit → + bp (-100*p.g*(N:ℝ))≤ pr (pairW w w) (fun i=>(rawHoles m).conflict i.1 i.2) + +set_option maxHeartbeats 1600000 in +theorem eventual_conflict_lower_bound (h:AnalyticParameters p M b s0) : + ∀ᶠ n : ℕ in atTop,∀ m:Mixer p n,unaryGood m b.pins s0→binaryGood m→conflictLowerBound p m (M*n) b := by + classical + let P:= fun n:ℕ=> ∃ (m:Mixer p n),unaryGood m b.pins s0∧binaryGood m∧ + ∃ w:Wgt (UnitType p n (M*n)), b.nascent p (M*n) w m ∧ carried w (rawHoles m).unit ∧ + conflicted p m (M*n) w + suffices hf : ¬∃ᶠ n:ℕ in atTop,P n by + have hx := not_frequently.mp hf + refine hx.mono (fun n hn m hm hv w hw hx=>?_); by_contra! hT + exact hn ⟨m,hm,hv,w,hw,hx,hT⟩ + intro hc + have hn := frequently_iff_neBot.mp hc + obtain ⟨U,hU⟩:= Filter.exists_ultrafilter_le (atTop⊓principal {n|P n}) + + let l:Filter ℕ:= U + have hl : l≤atTop := hU.trans inf_le_left + have hr : ∀ᶠ n in l,P n := + (show ∀ᶠ n in principal {i|P i},P n from Filter.eventually_principal.mpr fun x hx=>hx).filter_mono + (hU.trans inf_le_right) + let (n:ℕ) : Nonempty (Mixer p n) := ⟨⟨0,0,0⟩⟩ + obtain ⟨m,hm⟩ := taking hr + obtain ⟨w,hw⟩ := taking (hm.mono fun i h=> h.2.2) + have hF : ∀ᶠ n in l, ∃ s : LeafMixture p n (M*n),b.entered p (M*n) (m n) (w n) s := by + filter_upwards [hw,h.enter.hF.filter_mono hl] with n hn ht + exact ht _ _ hn.1 hn.2.1 + obtain ⟨s,hS⟩:= taking hF + obtain ⟨v,hv,hV⟩:= prepare U hl h.enter.first (hw.mono fun i hi=>hi.1) hS + refine StatusAnalysis.refuteVeil ⟨h,hl,hv,(hm.and hw).mono fun n ⟨h1,h2⟩=> + ⟨h2.1,h1.1,h1.2.1,h2.2.2⟩⟩ (show NeBot (U:Filter ℕ) from inferInstance) hV + +open HadwigerMatching LinearListHadwiger + +/-- Arbitrarily large finite graphs of independence number at most two and +touching-matching number less than one hundredth of the number of vertices. -/ +theorem exists_graphs (M : ℕ) : ∃ m:ℕ, max M 5 ≤ m ∧ + ∃ G : SimpleGraph (Fin m), G.indepNum ≤ 2 ∧ + (connectedMatchingNumber G:ℚ) < (m:ℚ)/100 := by + classical + obtain ⟨p,b,k,r,h,hg,hd,he⟩:= exists_parameters + have ht:=h.enter.first + let B:=4*num (Comp p.g) + let Y (n:ℕ):=k*n + have hy := (trend_sizes atTop le_rfl ht.hM).1 + have hp : 0 < p.g := lt_of_lt_of_le (by norm_num) ht.hG + have hs : ∀ᶠ n:ℕ in atTop, ∃ m:ℕ, max M 5 ≤ m ∧ + ∃ G : SimpleGraph (Fin m), G.indepNum ≤ 2 ∧ (connectedMatchingNumber G:ℚ)<(m:ℚ)/100 := by + filter_upwards [eventual_conflict_lower_bound h,ht.wrap,goodMixers p b.pins r (by linarith only [ht.hG]) + ht.hJ (by have hi:=h.profiles; omega) h.bigJ,hy.eventually + (transfer_scales hp (show 0≤B from mul_nonneg (by norm_num) (Nat.cast_nonneg _))), + ((tendsto_ord hp).comp hy).eventually (eventually_ge_atTop (max M 5))] with n hn ht hl hq hN + let N:=Y n + obtain ⟨m,hm,he'⟩:=hl + have hT:= hn m hm he'; have hV:2*num (Full p n)<(N:ℝ):=ht.1 + have hC : num (UnitType p n N)≤bp (B*N^ (2:ℕ)) := by + rw [unit_size]; apply bp_le + have hf : num (Full p n) ≤ N := by linarith only [hV,(Nat.cast_nonneg N : 0≤(N:ℝ))] + unfold B + calc _ ≤ num (Comp p.g)*4*(N:ℝ)*N := mul_le_mul_of_nonneg_left hf (by unfold num; positivity) + _ = _ := by ring + obtain ⟨x,hx,hX⟩:=hq (Orient p n N) (rawHoles m) (raw m N) (raw_law m hV) hC (by + intro w hw hC hU + apply hT w _ hU + apply born w hw m + rw [hd,he]; simpa only [N,Y,Nat.cast_mul,Nat.cast_ofNat] using hC) + exact ⟨ord p.g N,hN,(rawHoles m).graph x,hx,hX⟩ + obtain ⟨n,hn⟩:=hs.exists; exact hn + +/-- Arbitrarily large counterexamples to Hadwiger's conjecture, with the full +rational bounds and finiteness of the ordinary chromatic number. -/ +theorem exists_counterexamples (M : ℕ) : ∃ m : ℕ, max M 5 ≤ m ∧ + ∃ G : SimpleGraph (Fin m), G.indepNum ≤ 2 ∧ (connectedMatchingNumber G : ℚ) < (m : ℚ) / 100 ∧ + (hadwigerNumber G : ℚ) < 26 * (m : ℚ) / 75 + 2 / 3 ∧ + 26 * (m : ℚ) / 75 + 2 / 3 < (m : ℚ) / 2 ∧ (m : ℚ) / 2 ≤ (G.chromaticNumber.toNat : ℚ) ∧ + hadwigerNumber G < G.chromaticNumber.toNat ∧ + G.chromaticNumber ≠ ⊤ ∧ G.chromaticNumber = ↑(G.chromaticNumber.toNat) := by + obtain ⟨m,hm,G,ha,hc⟩:= exists_graphs M + have he : 5≤ m:=(le_max_right ..).trans hm + have : NeZero m:= ⟨by omega⟩ + have hx:=full_matching_minor_proposition (Fin m) G + dsimp only at hx + rw [Fintype.card_fin] at hx + obtain ⟨h1,h2,h3⟩:= hx.2 ha hc he + have hk:G.chromaticNumber ≠ ⊤:= by + intro h; have hs := G.chromaticNumber_le_card; simp [h] at hs + refine ⟨m,hm,G,ha,hc,h1,h2,h3,?_,hk,?_⟩ + · exact_mod_cast ((h1.trans h2).trans_le h3) + exact (ENat.natCast_toNat_eq_self.mpr hk).symm + +theorem not_hadwiger_conjecture : ¬ (∀ (m:ℕ)(G:SimpleGraph (Fin m)), G.chromaticNumber ≤ ↑(hadwigerNumber G)) := by + intro h; obtain ⟨m,hM,G,h1,h2,h3,h4,h5,h6,he,hC⟩:=exists_counterexamples 0 + have ht:=h m G; rw [hC] at ht + exact h6.not_ge (by exact_mod_cast ht) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixFactorization.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixFactorization.lean index 0b65821bfa37ce831db43b06d857c614804d83e7..963c53e6495b805f935c69cfa201e4d491b8c091 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixFactorization.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixFactorization.lean @@ -1,140 +1,140 @@ -import OAI.Combinatorics.HadwigerCounterexample.MatrixRanks -import Mathlib.Data.Fintype.EquivFin - -namespace OAI - -/-! # Matrix Factorization -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module -open scoped BigOperators -variable {I J Q : Type} [Fintype I] [Fintype J] [Fintype Q] - -/-- Projecting the columns onto their literal column space keeps the matrix. -/ -theorem invariant_cols (M : Mat I J) (Z R) (e : colSp Z = colSp M) - [DecidableEq Q] (hr : R*Z=(1:Mat Q Q)) : - Z * (R*M) = M := by - apply coe_mv_inj - apply LinearMap.ext - intro v - change _ *ᵥ v = M *ᵥ v - simp only [← Matrix.mulVec_mulVec] - have h : M*ᵥv ∈ colSp Z := e.symm ▸ (show M*ᵥv ∈ colSp M from ⟨v,rfl⟩) - obtain ⟨x,hx⟩ := h - change Z*ᵥx=M*ᵥv at hx - rw [← hx, Matrix.mulVec_mulVec x R Z,hr, Matrix.one_mulVec] - -theorem rank_product (M : Mat I J) : - ∃ (A : Mat I (Fin M.rank)) (B : Mat (Fin M.rank) J), - Function.Injective A.mulVec ∧ Function.Surjective B.mulVec ∧ A*B=M := by - let t := M.rank - let A := pack (colSp M) - have ha := pack_inj (colSp M) - obtain ⟨L,hL⟩ := mat_left_inv ha - have hh := invariant_cols M A L (colSp_pack _) hL - refine ⟨A,L*M,ha, mrk_surj.mpr ?_, hh⟩ - refine le_antisymm (Matrix.rank_le_card_height _) ?_ - have hx := Matrix.rank_mul_le_right A (L*M) - rw [hh] at hx - rw [Fintype.card_fin]; exact hx - -/-- Symmetric nonsingular factor on the rank space. -/ -theorem rank_symmetric (M : Mat I I) (hm : Mᵀ=M) : - ∃ (P : Mat I (Fin M.rank)) (G : Mat (Fin M.rank) (Fin M.rank)), - Function.Injective P.mulVec ∧ Gᵀ=G ∧ Function.Injective G.mulVec ∧ P*G*Pᵀ=M := by - let A := pack (colSp M) - have ha := pack_inj (colSp M) - obtain ⟨L,hL⟩ := mat_left_inv ha - let H := L*M*Lᵀ - have hs := invariant_cols M A L (colSp_pack _) hL - have hx : A*H*Aᵀ=M := by - rw [show A*H=A*(L*M)*Lᵀ from (Matrix.mul_assoc ..).symm, hs] - simpa only [transpose_mul,hm] using congrArg Matrix.transpose hs - refine ⟨A,H,ha,?_,mrk_inj.mpr ?_,hx⟩ - · change (L*M*Lᵀ)ᵀ = L*M*Lᵀ - rw [transpose_mul,transpose_mul,transpose_transpose,hm, Matrix.mul_assoc] - · refine le_antisymm (Matrix.rank_le_card_width _) ?_ - rw [Fintype.card_fin] - have h := (Matrix.rank_mul_le_left (A*H) Aᵀ).trans (Matrix.rank_mul_le_right _ _) - rwa [hx] at h - -omit [Fintype Q] in -theorem matrix_cancel_left {A : Mat I J} (hA : Function.Injective A.mulVec) - (C D : Mat J Q) (h : A*C=A*D) : C=D := by - classical - obtain ⟨R,hR⟩ := mat_left_inv hA - have hh := congrArg ((R * ·) : Mat I Q → _) h - simpa only [← Matrix.mul_assoc,hR,Matrix.one_mul] using hh - -theorem eigenbasis_idem {A : Type} [AddCommGroup A] [Module F A] [Fintype A] - [FiniteDimensional F A] (E : J → A →ₗ[F] A) (h : ∀ i j x, E i (E j x)=E j (E i x)) - (hg : ∀ i x, E i (E i x)=E i x) : - ∃ B : Basis (Fin (dim A)) F A, ∀ i t, ∃ c : F, E t (B i)=c • B i := by - classical - let s (I : Finset J) := {x : A | ∀ i ∈ I, ∃ c : F, E i x=c • x} - have he (I : Finset J) : Submodule.span F (s I) = ⊤ := by - induction I using Finset.induction with - | empty => simp [s] - | insert t I _ ih => - rw [← ih] - refine le_antisymm (Submodule.span_mono ?_) (Submodule.span_le.mpr ?_) - · exact fun x hx i hi => hx i (Finset.mem_insert_of_mem hi) - intro x hx - have hi (i) (hi : i ∈ I) : - ∃ c : F, E i x = c • x ∧ E i (E t x) = c • E t x := by - obtain ⟨c,hc⟩ := hx i hi - exact ⟨c,hc,by rw [h,hc,map_smul]⟩ - have ht : E t x ∈ s (insert t I) := by - intro j hj; rcases Finset.mem_insert.mp hj with rfl|hj - · exact ⟨1, by rw [hg,one_smul]⟩ - obtain ⟨c,_,he⟩ := hi j hj - exact ⟨c,he⟩ - have hu : x-E t x ∈ s (insert t I) := by - intro j hj; rcases Finset.mem_insert.mp hj with rfl|hj - · exact ⟨0,by rw [map_sub,hg,sub_self,zero_smul]⟩ - obtain ⟨c,hc,hc'⟩ := hi j hj - exact ⟨c,by rw [map_sub,hc,hc',smul_sub]⟩ - have hw := Submodule.add_mem (Submodule.span F (s (insert t I))) (Submodule.subset_span hu) - (Submodule.subset_span ht) - rwa [sub_add_cancel] at hw - let B := Basis.ofSpan (he Finset.univ).ge - let e := Fintype.equivFinOfCardEq (finrank_eq_card_basis B).symm - refine ⟨B.reindex e,fun i t => ?_⟩ - have hb : Set.range B ⊆ s Finset.univ := Basis.extendLe_subset .. - rw [Basis.reindex_apply] - exact hb (show B (e.symm i) ∈ Set.range B from ⟨_,rfl⟩) t (Finset.mem_univ _) - -theorem diagonalize [DecidableEq I] (M : J → Mat I I) - (hm : ∀ i j, M i * M j=M j*M i) (hg : ∀ i,M i*M i=M i) : - ∃ (C D : Mat I I) (f : J → I → F), D*C=1 ∧ C*D=1 ∧ ∀ i, M i*C=C*diagonal (f i) := by - classical - let E i := (M i).mulVecLin - have hh i j x : E i (E j x)=E j (E i x) := by - simp only [E, Matrix.mulVecLin_apply, Matrix.mulVec_mulVec] - rw [hm] - have hb i x : E i (E i x)=E i x := by - simp only [E, Matrix.mulVecLin_apply, Matrix.mulVec_mulVec,hg] - obtain ⟨B,hB⟩ := eigenbasis_idem E hh hb - let A : Basis I F (Vec I) := - B.reindex (Fintype.equivOfCardEq (by rw [Fintype.card_fin,dim_vec])) - have h (i j) : ∃ c : F, E i (A j) = c • A j := by - unfold A; rw [Basis.reindex_apply]; exact hB _ _ - choose f hf using h - let C : Mat I I := Matrix.of (fun i j => A j i) - have hi : Function.Injective C.mulVec := Matrix.mulVec_injective_iff.mpr A.linearIndependent - obtain ⟨D,hD⟩ := mat_left_inv hi - have he : C*D=1 := mul_eq_one_comm.mp hD - refine ⟨C,D,f,hD,he,fun i => ?_⟩ - ext j k - rw [Matrix.mul_diagonal] - have hk := congr_fun (hf i k) j - change ∑ l, M i j l * A k l = f i k*A k j at hk - change ∑ l, M i j l * A k l = A k j * _ - rw [hk,mul_comm] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.MatrixRanks +import Mathlib.Data.Fintype.EquivFin + +namespace OAI + +/-! # Matrix Factorization -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module +open scoped BigOperators +variable {I J Q : Type} [Fintype I] [Fintype J] [Fintype Q] + +/-- Projecting the columns onto their literal column space keeps the matrix. -/ +theorem invariant_cols (M : Mat I J) (Z R) (e : colSp Z = colSp M) + [DecidableEq Q] (hr : R*Z=(1:Mat Q Q)) : + Z * (R*M) = M := by + apply coe_mv_inj + apply LinearMap.ext + intro v + change _ *ᵥ v = M *ᵥ v + simp only [← Matrix.mulVec_mulVec] + have h : M*ᵥv ∈ colSp Z := e.symm ▸ (show M*ᵥv ∈ colSp M from ⟨v,rfl⟩) + obtain ⟨x,hx⟩ := h + change Z*ᵥx=M*ᵥv at hx + rw [← hx, Matrix.mulVec_mulVec x R Z,hr, Matrix.one_mulVec] + +theorem rank_product (M : Mat I J) : + ∃ (A : Mat I (Fin M.rank)) (B : Mat (Fin M.rank) J), + Function.Injective A.mulVec ∧ Function.Surjective B.mulVec ∧ A*B=M := by + let t := M.rank + let A := pack (colSp M) + have ha := pack_inj (colSp M) + obtain ⟨L,hL⟩ := mat_left_inv ha + have hh := invariant_cols M A L (colSp_pack _) hL + refine ⟨A,L*M,ha, mrk_surj.mpr ?_, hh⟩ + refine le_antisymm (Matrix.rank_le_card_height _) ?_ + have hx := Matrix.rank_mul_le_right A (L*M) + rw [hh] at hx + rw [Fintype.card_fin]; exact hx + +/-- Symmetric nonsingular factor on the rank space. -/ +theorem rank_symmetric (M : Mat I I) (hm : Mᵀ=M) : + ∃ (P : Mat I (Fin M.rank)) (G : Mat (Fin M.rank) (Fin M.rank)), + Function.Injective P.mulVec ∧ Gᵀ=G ∧ Function.Injective G.mulVec ∧ P*G*Pᵀ=M := by + let A := pack (colSp M) + have ha := pack_inj (colSp M) + obtain ⟨L,hL⟩ := mat_left_inv ha + let H := L*M*Lᵀ + have hs := invariant_cols M A L (colSp_pack _) hL + have hx : A*H*Aᵀ=M := by + rw [show A*H=A*(L*M)*Lᵀ from (Matrix.mul_assoc ..).symm, hs] + simpa only [transpose_mul,hm] using congrArg Matrix.transpose hs + refine ⟨A,H,ha,?_,mrk_inj.mpr ?_,hx⟩ + · change (L*M*Lᵀ)ᵀ = L*M*Lᵀ + rw [transpose_mul,transpose_mul,transpose_transpose,hm, Matrix.mul_assoc] + · refine le_antisymm (Matrix.rank_le_card_width _) ?_ + rw [Fintype.card_fin] + have h := (Matrix.rank_mul_le_left (A*H) Aᵀ).trans (Matrix.rank_mul_le_right _ _) + rwa [hx] at h + +omit [Fintype Q] in +theorem matrix_cancel_left {A : Mat I J} (hA : Function.Injective A.mulVec) + (C D : Mat J Q) (h : A*C=A*D) : C=D := by + classical + obtain ⟨R,hR⟩ := mat_left_inv hA + have hh := congrArg ((R * ·) : Mat I Q → _) h + simpa only [← Matrix.mul_assoc,hR,Matrix.one_mul] using hh + +theorem eigenbasis_idem {A : Type} [AddCommGroup A] [Module F A] [Fintype A] + [FiniteDimensional F A] (E : J → A →ₗ[F] A) (h : ∀ i j x, E i (E j x)=E j (E i x)) + (hg : ∀ i x, E i (E i x)=E i x) : + ∃ B : Basis (Fin (dim A)) F A, ∀ i t, ∃ c : F, E t (B i)=c • B i := by + classical + let s (I : Finset J) := {x : A | ∀ i ∈ I, ∃ c : F, E i x=c • x} + have he (I : Finset J) : Submodule.span F (s I) = ⊤ := by + induction I using Finset.induction with + | empty => simp [s] + | insert t I _ ih => + rw [← ih] + refine le_antisymm (Submodule.span_mono ?_) (Submodule.span_le.mpr ?_) + · exact fun x hx i hi => hx i (Finset.mem_insert_of_mem hi) + intro x hx + have hi (i) (hi : i ∈ I) : + ∃ c : F, E i x = c • x ∧ E i (E t x) = c • E t x := by + obtain ⟨c,hc⟩ := hx i hi + exact ⟨c,hc,by rw [h,hc,map_smul]⟩ + have ht : E t x ∈ s (insert t I) := by + intro j hj; rcases Finset.mem_insert.mp hj with rfl|hj + · exact ⟨1, by rw [hg,one_smul]⟩ + obtain ⟨c,_,he⟩ := hi j hj + exact ⟨c,he⟩ + have hu : x-E t x ∈ s (insert t I) := by + intro j hj; rcases Finset.mem_insert.mp hj with rfl|hj + · exact ⟨0,by rw [map_sub,hg,sub_self,zero_smul]⟩ + obtain ⟨c,hc,hc'⟩ := hi j hj + exact ⟨c,by rw [map_sub,hc,hc',smul_sub]⟩ + have hw := Submodule.add_mem (Submodule.span F (s (insert t I))) (Submodule.subset_span hu) + (Submodule.subset_span ht) + rwa [sub_add_cancel] at hw + let B := Basis.ofSpan (he Finset.univ).ge + let e := Fintype.equivFinOfCardEq (finrank_eq_card_basis B).symm + refine ⟨B.reindex e,fun i t => ?_⟩ + have hb : Set.range B ⊆ s Finset.univ := Basis.extendLe_subset .. + rw [Basis.reindex_apply] + exact hb (show B (e.symm i) ∈ Set.range B from ⟨_,rfl⟩) t (Finset.mem_univ _) + +theorem diagonalize [DecidableEq I] (M : J → Mat I I) + (hm : ∀ i j, M i * M j=M j*M i) (hg : ∀ i,M i*M i=M i) : + ∃ (C D : Mat I I) (f : J → I → F), D*C=1 ∧ C*D=1 ∧ ∀ i, M i*C=C*diagonal (f i) := by + classical + let E i := (M i).mulVecLin + have hh i j x : E i (E j x)=E j (E i x) := by + simp only [E, Matrix.mulVecLin_apply, Matrix.mulVec_mulVec] + rw [hm] + have hb i x : E i (E i x)=E i x := by + simp only [E, Matrix.mulVecLin_apply, Matrix.mulVec_mulVec,hg] + obtain ⟨B,hB⟩ := eigenbasis_idem E hh hb + let A : Basis I F (Vec I) := + B.reindex (Fintype.equivOfCardEq (by rw [Fintype.card_fin,dim_vec])) + have h (i j) : ∃ c : F, E i (A j) = c • A j := by + unfold A; rw [Basis.reindex_apply]; exact hB _ _ + choose f hf using h + let C : Mat I I := Matrix.of (fun i j => A j i) + have hi : Function.Injective C.mulVec := Matrix.mulVec_injective_iff.mpr A.linearIndependent + obtain ⟨D,hD⟩ := mat_left_inv hi + have he : C*D=1 := mul_eq_one_comm.mp hD + refine ⟨C,D,f,hD,he,fun i => ?_⟩ + ext j k + rw [Matrix.mul_diagonal] + have hk := congr_fun (hf i k) j + change ∑ l, M i j l * A k l = f i k*A k j at hk + change ∑ l, M i j l * A k l = A k j * _ + rw [hk,mul_comm] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixQuotients.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixQuotients.lean index 061c678a310d2325b27034b01ed0f817b77bab12..6d0e04442520a89fd7759c1426381a54dc78afeb 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixQuotients.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixQuotients.lean @@ -1,176 +1,176 @@ -import OAI.Combinatorics.HadwigerCounterexample.CoordinateBlocks -import OAI.Combinatorics.HadwigerCounterexample.TensorIntersections - -namespace OAI - -/-! # Matrix Quotients -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Submodule Module -open scoped BigOperators -variable {I J K L : Type} [Fintype I] [Fintype J] [Fintype K] [Fintype L] - -def box (S : Space (Vec I)) (T : Space (Vec J)) := - LinearMap.range (liftM (pack S) (pack T)) - -theorem box_dim (S : Space (Vec I)) (T : Space (Vec J)) : - dim (box S T) = dim S*dim T := by - have h := rk_inj.mp (liftM_inj (pack_inj S) (pack_inj T)) - change dim (box S T)=dim (Mat _ _) at h - rw [dim_mat, Fintype.card_fin,Fintype.card_fin] at h - exact h - -omit [Fintype K] [Fintype L] in -theorem liftM_transpose (A : Mat I J) (P : Mat K I) (Q : Mat L J) : - (liftM P Q A)ᵀ = liftM Q P Aᵀ := by - simp only [liftM_def,transpose_mul,transpose_transpose,Matrix.mul_assoc] - -theorem box_mem (M : Mat I J) (S : Space (Vec I)) (T : Space (Vec J)) : - M∈box S T ↔ colSp M ≤ S ∧ colSp Mᵀ ≤ T := by - classical - constructor - · rintro ⟨A,rfl⟩ - rw [liftM_transpose] - exact ⟨(colSp_lift_le ..).trans_eq (colSp_pack _), - (colSp_lift_le ..).trans_eq (colSp_pack _)⟩ - · rintro ⟨h,g⟩ - obtain ⟨X,hX⟩ := mat_left_inv (pack_inj S) - obtain ⟨Y,hY⟩ := mat_left_inv (pack_inj T) - have h1 {I J : Type} [Fintype I] [Fintype J] {A : Mat I J} {S : Space (Vec I)} - (h : colSp A ≤ S) {X : Mat (Fin (dim S)) I} (hx : X*pack S=1) : pack S*(X*A)=A := by - apply coe_mv_inj - refine LinearMap.ext fun x => ?_ - have he : A*ᵥx ∈ colSp (pack S) := (colSp_pack S).symm ▸ - h (show A*ᵥx∈colSp A from ⟨x,rfl⟩) - obtain ⟨y,hy⟩ := he - change pack S *ᵥ y=A *ᵥ x at hy - change _ *ᵥ _ = _ - rw [← Matrix.mulVec_mulVec, ← Matrix.mulVec_mulVec, ← hy, Matrix.mulVec_mulVec y X, hx, - Matrix.one_mulVec] - exact hy - refine ⟨liftM X Y M,?_⟩ - have h2 := congrArg Matrix.transpose (h1 g hY) - rw [transpose_mul,transpose_mul,transpose_transpose] at h2 - change pack S * (X*M*Yᵀ)*(pack T)ᵀ=M - rw [← Matrix.mul_assoc (pack S) (X*M),h1 h hX,h2] - -theorem box_le {M M' : Space (Vec I)} {N N' : Space (Vec J)} (hm : M ≤ M') (hn : N ≤ N') : - box M N ≤ box M' N' := fun _ h => - have he := (box_mem ..).mp h - (box_mem ..).mpr ⟨he.1.trans hm,he.2.trans hn⟩ - -theorem pack_mem_iff (v : Vec I) (S : Space (Vec I)) : - v∈S ↔ ∃ x, pack S *ᵥ x=v := by - change _ ↔ v∈colSp (pack S) - rw [colSp_pack] - -theorem outer_in_box (x : Vec I) (y : Vec J) {S : Space (Vec I)} {T : Space (Vec J)} - (hx : x∈S) (hy : y∈T) : vecMulVec x y ∈ box S T := by - obtain ⟨a,rfl⟩ := (pack_mem_iff ..).mp hx - obtain ⟨b,rfl⟩ := (pack_mem_iff ..).mp hy - exact ⟨vecMulVec a b,liftM_outer ..⟩ - -theorem lift_mem_box {M : Mat I J} {S : Space (Vec I)} {T : Space (Vec J)} - (P : Mat K I) (Q : Mat L J) (h : M ∈ box S T) : - liftM P Q M ∈ box (S.map P.mulVecLin) (T.map Q.mulVecLin) := by - obtain ⟨A,rfl⟩ := h - rw [liftM_comp,box_mem,liftM_transpose] - constructor <;> apply le_trans (colSp_lift_le ..) <;> - rw [colSp,mulVecLin_mul,LinearMap.range_comp] - · rw [show LinearMap.range (pack S).mulVecLin=S from colSp_pack _] - rw [show LinearMap.range (pack T).mulVecLin=T from colSp_pack _] - -theorem evmat_transpose (M : Mat I J) (x : Vec I) (y : Vec J) : - evmat Mᵀ y x=evmat M x y := dotProduct_transpose_mulVec _ _ _ -theorem evmat_pull (P : Mat K I) (Q : Mat L J) (A : Mat K L) (x : Vec I) (y : Vec J) : - evmat (pullM P Q A) x y=evmat A (P *ᵥ x) (Q *ᵥ y) := by - rw [←mpair_outer,←mpair_outer,← liftM_outer,mpair_liftM]; rfl - -theorem evmat_ext {M N : Mat I J} (h : ∀ x y, evmat M x y=evmat N x y) : M=N := by - classical - ext i j - simpa [evmat] using h (Pi.single i 1) (Pi.single j 1) - -theorem box_eval_iff (S : Space (Vec I)) (T : Space (Vec J)) (M N : Mat I J) : - (∀ x∈S,∀ y∈T,evmat M x y=evmat N x y) ↔ (∀ x∈box S T,mpair M x=mpair N x) := by - constructor - · intro h x hx - have hE : pullM (pack S) (pack T) M=pullM (pack S) (pack T) N := by - refine evmat_ext (fun x y => ?_) - rw [evmat_pull,evmat_pull] - exact h _ ((pack_mem_iff ..).mpr ⟨x,rfl⟩) _ ((pack_mem_iff ..).mpr ⟨y,rfl⟩) - obtain ⟨A,rfl⟩ := hx - rw [mpair_liftM,mpair_liftM] - exact congrArg (fun x => mpair x A) hE - intro h x hx y hy - rw [← mpair_outer,← mpair_outer] - exact h _ (outer_in_box _ _ hx hy) - -def annih (S : Space (Vec I)) := ker ((pack S)ᵀ.mulVecLin) - -theorem annih_dim (S : Space (Vec I)) : - dim S + dim (annih S) = Fintype.card I := by - have h := (pack S)ᵀ.mulVecLin.finrank_range_add_finrank_ker - change ((pack S)ᵀ).rank + dim (annih S)=dim (Vec I) at h - rwa [Matrix.rank_transpose,mrk_inj.mp (pack_inj _),dim_vec,Fintype.card_fin] at h - -theorem dot_ext_zero {x : Vec I} (h : ∀ y, dotProduct y x=0) : x=0 := by - classical funext i - simpa using h (Pi.single i 1) - -theorem annih_mem (x : Vec I) (S : Space (Vec I)) : - x ∈ annih S ↔ ∀ y ∈ S,dotProduct x y = 0 := by - change (pack S)ᵀ *ᵥ x=0 ↔ _ - constructor - · intro h y hy - obtain ⟨z,rfl⟩ := (pack_mem_iff ..).mp hy - rw [← dotProduct_transpose_mulVec,h,dotProduct_zero] - intro h - refine dot_ext_zero fun y => ?_ - rw [dotProduct_transpose_mulVec]; exact h _ ((pack_mem_iff ..).mpr ⟨y,rfl⟩) - -theorem annih_annih (S : Space (Vec I)) : annih (annih S)=S := by - symm - have hh : S ≤ annih (annih S) := by - intro x hx; rw [annih_mem] - intro y hy; rw [dotProduct_comm] - exact (annih_mem ..).mp hy _ hx - refine Submodule.eq_of_le_of_finrank_eq hh ?_ - have he := annih_dim S - have hg := annih_dim (annih S) - change dim S=_ - - exact Nat.add_right_cancel ((he.trans hg.symm).trans (Nat.add_comm ..)) - -def vanish (S : Space (Vec I)) (T : Space (Vec J)) (M : Mat I J) := - ∀ x ∈ annih S, ∀ y∈ annih T, evmat M x y=0 - -/-- A tensor killed by the product of the two factor quotients has bounded rank. -/ -theorem rank_vanish {S : Space (Vec I)} {T : Space (Vec J)} {M : Mat I J} - (h : vanish S T M) : M.rank≤dim S+dim T := by - let P := pack (annih S) - let Q := pack (annih T) - have hh : Pᵀ*M*Q=0 := by - refine evmat_ext fun x y => ?_ - have he := h _ ((pack_mem_iff ..).mpr ⟨x,rfl⟩) _ ((pack_mem_iff ..).mpr ⟨y,rfl⟩) - rw [← evmat_pull] at he - exact he.trans (by simp [evmat]) - have h1 := rank_ge_mul Pᵀ M - have h2 := rank_ge_mul (Pᵀ*M) Q - have hi := (mrk_inj.mp (pack_inj (annih S))).trans (Fintype.card_fin _) - have hj := (mrk_inj.mp (pack_inj (annih T))).trans (Fintype.card_fin _) - rw [Matrix.rank_transpose] at h1 - change P.rank = _ at hi; change Q.rank = _ at hj - rw [hi] at h1; rw [hj,hh,Matrix.rank_zero] at h2 - have hx := annih_dim S - have hy := annih_dim T - have hv (x y z u v a b r : ℕ) (h : u+x≤r+a) (g : r+v≤0+b) (hx : y+u=a) (hy : z+v=b) : - x≤y+z := by omega - exact hv _ _ _ _ _ _ _ _ h1 h2 hx hy - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CoordinateBlocks +import OAI.Combinatorics.HadwigerCounterexample.TensorIntersections + +namespace OAI + +/-! # Matrix Quotients -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Submodule Module +open scoped BigOperators +variable {I J K L : Type} [Fintype I] [Fintype J] [Fintype K] [Fintype L] + +def box (S : Space (Vec I)) (T : Space (Vec J)) := + LinearMap.range (liftM (pack S) (pack T)) + +theorem box_dim (S : Space (Vec I)) (T : Space (Vec J)) : + dim (box S T) = dim S*dim T := by + have h := rk_inj.mp (liftM_inj (pack_inj S) (pack_inj T)) + change dim (box S T)=dim (Mat _ _) at h + rw [dim_mat, Fintype.card_fin,Fintype.card_fin] at h + exact h + +omit [Fintype K] [Fintype L] in +theorem liftM_transpose (A : Mat I J) (P : Mat K I) (Q : Mat L J) : + (liftM P Q A)ᵀ = liftM Q P Aᵀ := by + simp only [liftM_def,transpose_mul,transpose_transpose,Matrix.mul_assoc] + +theorem box_mem (M : Mat I J) (S : Space (Vec I)) (T : Space (Vec J)) : + M∈box S T ↔ colSp M ≤ S ∧ colSp Mᵀ ≤ T := by + classical + constructor + · rintro ⟨A,rfl⟩ + rw [liftM_transpose] + exact ⟨(colSp_lift_le ..).trans_eq (colSp_pack _), + (colSp_lift_le ..).trans_eq (colSp_pack _)⟩ + · rintro ⟨h,g⟩ + obtain ⟨X,hX⟩ := mat_left_inv (pack_inj S) + obtain ⟨Y,hY⟩ := mat_left_inv (pack_inj T) + have h1 {I J : Type} [Fintype I] [Fintype J] {A : Mat I J} {S : Space (Vec I)} + (h : colSp A ≤ S) {X : Mat (Fin (dim S)) I} (hx : X*pack S=1) : pack S*(X*A)=A := by + apply coe_mv_inj + refine LinearMap.ext fun x => ?_ + have he : A*ᵥx ∈ colSp (pack S) := (colSp_pack S).symm ▸ + h (show A*ᵥx∈colSp A from ⟨x,rfl⟩) + obtain ⟨y,hy⟩ := he + change pack S *ᵥ y=A *ᵥ x at hy + change _ *ᵥ _ = _ + rw [← Matrix.mulVec_mulVec, ← Matrix.mulVec_mulVec, ← hy, Matrix.mulVec_mulVec y X, hx, + Matrix.one_mulVec] + exact hy + refine ⟨liftM X Y M,?_⟩ + have h2 := congrArg Matrix.transpose (h1 g hY) + rw [transpose_mul,transpose_mul,transpose_transpose] at h2 + change pack S * (X*M*Yᵀ)*(pack T)ᵀ=M + rw [← Matrix.mul_assoc (pack S) (X*M),h1 h hX,h2] + +theorem box_le {M M' : Space (Vec I)} {N N' : Space (Vec J)} (hm : M ≤ M') (hn : N ≤ N') : + box M N ≤ box M' N' := fun _ h => + have he := (box_mem ..).mp h + (box_mem ..).mpr ⟨he.1.trans hm,he.2.trans hn⟩ + +theorem pack_mem_iff (v : Vec I) (S : Space (Vec I)) : + v∈S ↔ ∃ x, pack S *ᵥ x=v := by + change _ ↔ v∈colSp (pack S) + rw [colSp_pack] + +theorem outer_in_box (x : Vec I) (y : Vec J) {S : Space (Vec I)} {T : Space (Vec J)} + (hx : x∈S) (hy : y∈T) : vecMulVec x y ∈ box S T := by + obtain ⟨a,rfl⟩ := (pack_mem_iff ..).mp hx + obtain ⟨b,rfl⟩ := (pack_mem_iff ..).mp hy + exact ⟨vecMulVec a b,liftM_outer ..⟩ + +theorem lift_mem_box {M : Mat I J} {S : Space (Vec I)} {T : Space (Vec J)} + (P : Mat K I) (Q : Mat L J) (h : M ∈ box S T) : + liftM P Q M ∈ box (S.map P.mulVecLin) (T.map Q.mulVecLin) := by + obtain ⟨A,rfl⟩ := h + rw [liftM_comp,box_mem,liftM_transpose] + constructor <;> apply le_trans (colSp_lift_le ..) <;> + rw [colSp,mulVecLin_mul,LinearMap.range_comp] + · rw [show LinearMap.range (pack S).mulVecLin=S from colSp_pack _] + rw [show LinearMap.range (pack T).mulVecLin=T from colSp_pack _] + +theorem evmat_transpose (M : Mat I J) (x : Vec I) (y : Vec J) : + evmat Mᵀ y x=evmat M x y := dotProduct_transpose_mulVec _ _ _ +theorem evmat_pull (P : Mat K I) (Q : Mat L J) (A : Mat K L) (x : Vec I) (y : Vec J) : + evmat (pullM P Q A) x y=evmat A (P *ᵥ x) (Q *ᵥ y) := by + rw [←mpair_outer,←mpair_outer,← liftM_outer,mpair_liftM]; rfl + +theorem evmat_ext {M N : Mat I J} (h : ∀ x y, evmat M x y=evmat N x y) : M=N := by + classical + ext i j + simpa [evmat] using h (Pi.single i 1) (Pi.single j 1) + +theorem box_eval_iff (S : Space (Vec I)) (T : Space (Vec J)) (M N : Mat I J) : + (∀ x∈S,∀ y∈T,evmat M x y=evmat N x y) ↔ (∀ x∈box S T,mpair M x=mpair N x) := by + constructor + · intro h x hx + have hE : pullM (pack S) (pack T) M=pullM (pack S) (pack T) N := by + refine evmat_ext (fun x y => ?_) + rw [evmat_pull,evmat_pull] + exact h _ ((pack_mem_iff ..).mpr ⟨x,rfl⟩) _ ((pack_mem_iff ..).mpr ⟨y,rfl⟩) + obtain ⟨A,rfl⟩ := hx + rw [mpair_liftM,mpair_liftM] + exact congrArg (fun x => mpair x A) hE + intro h x hx y hy + rw [← mpair_outer,← mpair_outer] + exact h _ (outer_in_box _ _ hx hy) + +def annih (S : Space (Vec I)) := ker ((pack S)ᵀ.mulVecLin) + +theorem annih_dim (S : Space (Vec I)) : + dim S + dim (annih S) = Fintype.card I := by + have h := (pack S)ᵀ.mulVecLin.finrank_range_add_finrank_ker + change ((pack S)ᵀ).rank + dim (annih S)=dim (Vec I) at h + rwa [Matrix.rank_transpose,mrk_inj.mp (pack_inj _),dim_vec,Fintype.card_fin] at h + +theorem dot_ext_zero {x : Vec I} (h : ∀ y, dotProduct y x=0) : x=0 := by + classical funext i + simpa using h (Pi.single i 1) + +theorem annih_mem (x : Vec I) (S : Space (Vec I)) : + x ∈ annih S ↔ ∀ y ∈ S,dotProduct x y = 0 := by + change (pack S)ᵀ *ᵥ x=0 ↔ _ + constructor + · intro h y hy + obtain ⟨z,rfl⟩ := (pack_mem_iff ..).mp hy + rw [← dotProduct_transpose_mulVec,h,dotProduct_zero] + intro h + refine dot_ext_zero fun y => ?_ + rw [dotProduct_transpose_mulVec]; exact h _ ((pack_mem_iff ..).mpr ⟨y,rfl⟩) + +theorem annih_annih (S : Space (Vec I)) : annih (annih S)=S := by + symm + have hh : S ≤ annih (annih S) := by + intro x hx; rw [annih_mem] + intro y hy; rw [dotProduct_comm] + exact (annih_mem ..).mp hy _ hx + refine Submodule.eq_of_le_of_finrank_eq hh ?_ + have he := annih_dim S + have hg := annih_dim (annih S) + change dim S=_ + + exact Nat.add_right_cancel ((he.trans hg.symm).trans (Nat.add_comm ..)) + +def vanish (S : Space (Vec I)) (T : Space (Vec J)) (M : Mat I J) := + ∀ x ∈ annih S, ∀ y∈ annih T, evmat M x y=0 + +/-- A tensor killed by the product of the two factor quotients has bounded rank. -/ +theorem rank_vanish {S : Space (Vec I)} {T : Space (Vec J)} {M : Mat I J} + (h : vanish S T M) : M.rank≤dim S+dim T := by + let P := pack (annih S) + let Q := pack (annih T) + have hh : Pᵀ*M*Q=0 := by + refine evmat_ext fun x y => ?_ + have he := h _ ((pack_mem_iff ..).mpr ⟨x,rfl⟩) _ ((pack_mem_iff ..).mpr ⟨y,rfl⟩) + rw [← evmat_pull] at he + exact he.trans (by simp [evmat]) + have h1 := rank_ge_mul Pᵀ M + have h2 := rank_ge_mul (Pᵀ*M) Q + have hi := (mrk_inj.mp (pack_inj (annih S))).trans (Fintype.card_fin _) + have hj := (mrk_inj.mp (pack_inj (annih T))).trans (Fintype.card_fin _) + rw [Matrix.rank_transpose] at h1 + change P.rank = _ at hi; change Q.rank = _ at hj + rw [hi] at h1; rw [hj,hh,Matrix.rank_zero] at h2 + have hx := annih_dim S + have hy := annih_dim T + have hv (x y z u v a b r : ℕ) (h : u+x≤r+a) (g : r+v≤0+b) (hx : y+u=a) (hy : z+v=b) : + x≤y+z := by omega + exact hv _ _ _ _ _ _ _ _ h1 h2 hx hy + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixRankCounting.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixRankCounting.lean index b238cadfa7d49b9b0d6d173e3a44c47314f0401b..7a4e90c9dd501f222615659b9da2289e9b0eb8a4 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixRankCounting.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixRankCounting.lean @@ -1,187 +1,187 @@ -import OAI.Combinatorics.HadwigerCounterexample.MatrixFactorization -import OAI.Combinatorics.HadwigerCounterexample.FrameIntersectionBounds - -namespace OAI - -/-! # Matrix Rank Counting -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap -open scoped BigOperators - -theorem cast_mat (I J : Type) [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] : - num (Mat I J)=bp (num I*num J) := by - unfold num - rw [card_space,dim_mat] - push_cast; rfl - -theorem nbr_nonneg {A : Type} [Fintype A] (p : A → Prop) : 0 ≤ nbr p := - tot_nonneg fun _ => ind_nonneg _ - -theorem nbr_le_sum {A B : Type} [Fintype A] [Fintype B] (p : A → Prop) - (q : B → A → Prop) (h : ∀ i, p i → ∃ j,q j i) : - nbr p ≤ ∑ j, nbr (q j) := by - have hp (p : A → Prop) : nbr p = pr (fun _ => 1) p := by simp [nbr,pr,avg,tot] - rw [hp] - simp_rw [hp] - exact (pr_mono (fun _ => zero_le_one) h).trans (pr_exists_le (fun _ => zero_le_one) q) - -variable {I J K : Type} [Fintype I] [Fintype J] [Fintype K] - [DecidableEq I] [DecidableEq J] [DecidableEq K] - -omit [DecidableEq I] [DecidableEq J] in -theorem mul_factor (M : Mat I J) (r : ℕ) (h : M.rank ≤ r) : - ∃ A : Mat I (Fin r),∃ B : Mat (Fin r) J,A*B=M := by - obtain ⟨A,B,_,_,hg⟩ := rank_product M - obtain ⟨a,ha⟩ := pad_matrix_inj M.rank r h - obtain ⟨b,hb⟩ := mat_left_inv ha - refine ⟨A*b,a*B,?_⟩ - rw [←Matrix.mul_assoc,Matrix.mul_assoc A b,hb,Matrix.mul_one,hg] - -theorem nbr_matrix_rank (k : ℕ) : - nbr (fun M : Mat I J => M.rank ≤ k) ≤ bp ((num I+num J)*k) := by - classical - let v := Mat I (Fin k) × Mat (Fin k) J - let q (x : Mat I (Fin k) × Mat (Fin k) J) (M : Mat I J) := x.1*x.2=M - refine (nbr_le_sum _ q fun M h => ?_).trans_eq ?_ - · obtain ⟨A,B,hB⟩ := mul_factor M k h - exact ⟨(A,B),hB⟩ - have h (x : Mat I (Fin k) × Mat (Fin k) J) : nbr (q x) = 1 := by - unfold nbr tot - rw [Finset.sum_eq_single (x.1*x.2)] - · simp [q,ind] - · intro j _ h; simp [q,ind,h.symm] - · simp - simp_rw [h] - simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul,mul_one] - change num (Mat I (Fin k) × Mat (Fin k) J)=_ - rw [num,Fintype.card_prod,Nat.cast_mul] - change num (Mat I (Fin k))*num (Mat (Fin k) J)=_ - rw [cast_mat,cast_mat,← bp_add] - simp [num] - ring_nf - -theorem pr_matrix_rank (k : ℕ) : - pr unif (fun M : Mat I J => M.rank≤ k) ≤ - bp ((num I+num J)*k-num I*num J) := by - rw [pr_unif,bp_sub, ← cast_mat] - exact div_le_div_of_nonneg_right (nbr_matrix_rank k) (Nat.cast_nonneg _) - -def rmult (I : Type) (A : Mat J K) : Mat I J →ₗ[F] Mat I K where - toFun M := M*A - map_add' _ _ := Matrix.add_mul _ _ _ - map_smul' _ _ := Matrix.smul_mul _ _ _ - -theorem pr_mult_mat {A : Mat J K} (h : Function.Injective A.mulVec) (B : Mat I K) : - pr unif (fun M => M*A=B) = bp (-num I*num K) := by - obtain ⟨P,hP⟩ := mat_left_inv h - have hh : Function.Surjective (rmult I A) := - fun C => ⟨C*P,by change C*P*A=C; rw [Matrix.mul_assoc,hP,Matrix.mul_one]⟩ - change mapW unif (rmult I A) B = _ - rw [map_unif_surjective _ hh, unif_apply, neg_mul,bp_neg,←cast_mat] - -theorem pr_deficient (k : ℕ) : - pr unif (fun M : Mat I J => M.rank + k ≤ Fintype.card J) ≤ - bp ((num J-num I)*k) := by - classical - let p (A : Mat J (Fin k)) (M : Mat I J) := - Function.Injective A.mulVec ∧ M*A=0 - refine ((pr_mono unif_law.nz fun M hm => ?_).trans - (pr_exists_le unif_law.nz p)).trans ?_ - · let S := LinearMap.ker M.mulVecLin - have hx := M.mulVecLin.finrank_range_add_finrank_ker - change M.rank+dim S=dim (Vec J) at hx - rw [dim_vec] at hx - have hle : k ≤ dim S := Nat.le_of_add_le_add_left (hm.trans_eq hx.symm) - obtain ⟨A,hA,h'⟩ := bounded_pack S k - refine ⟨A,Matrix.mulVec_injective_iff.mpr ?_,?_⟩ - · apply Matrix.mulVec_injective_iff.mp - apply mrk_inj.mpr - rw [← colSp_dim,h',min_eq_right hle,Fintype.card_fin] - apply coe_mv_inj - change (M*A).mulVecLin = Matrix.mulVecLin 0 - rw [Matrix.mulVecLin_mul,Matrix.mulVecLin_zero] - exact LinearMap.ext fun x => hA (show A.mulVecLin x ∈ colSp A from ⟨x,rfl⟩) - have h (A : Mat J (Fin k)) : pr unif (p A) ≤ bp (-num I*k) := by - by_cases hh : Function.Injective A.mulVec - · simp only [p,hh,true_and] - rw [pr_mult_mat hh] - simp [num] - simp only [p,hh,false_and,pr_false] - exact (bp_pos _).le - apply (Finset.sum_le_sum fun i _ => h i).trans_eq - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - change num (Mat J (Fin k))*_ = _ - rw [cast_mat,←bp_add] - congr 1 - unfold num; rw [Fintype.card_fin]; ring - -variable (p : Shape) -def profileA (K : ℕ) := 10*(K+1)*psize p*(p.g*p.g+5) - -theorem nbr_profile_rank (K n : ℕ) : - let d := Fintype.card (Row p n) - nbr (fun M : Profile p n => totalRank M ≤ K) ≤ - (K+1:ℝ)^Fintype.card (Comp p.g) * bp (2*d*K) := by - classical - intro d - let q (r : Comp p.g → Fin (K+1)) (M : Profile p n) := - (∑ i,(r i).val) ≤ K ∧ ∀ i, (M i).rank=(r i).val - refine le_trans (nbr_le_sum _ q ?_) ?_ - · intro M h - have hh i : (M i).rank≤K := - (Finset.single_le_sum (s:=Finset.univ) (fun i _ => Nat.zero_le ((M i).rank)) - (Finset.mem_univ i)).trans h - exact ⟨fun i => ⟨_,Nat.lt_succ_of_le (hh i)⟩,h,fun _ => rfl⟩ - have he r : nbr (q r) ≤ bp (2*d*K) := by - by_cases h : (∑ i:Comp p.g, (r i).val) ≤ K - · unfold nbr - let c (i : Comp p.g) (M : Moment p n) := (M.rank=(r i).val) - simp_rw [q,h,true_and,ind_all] - change tot (prodW (β:=fun _ => Moment p n) (fun i M => ind (c i M))) ≤ _ - rw [prodW_tot] - have hx i : nbr (c i) ≤ bp (2*d*(r i).val) := by - let w := (r i).val - have h1 := nbr_matrix_rank (I:=Row p n) (J:=Row p n) w - rw [← two_mul] at h1 - exact le_trans (tot_mono (fun x => ind_mono (p:=x.rank=w) (q:=x.rank≤w) (fun e => e.le))) h1 - refine (Finset.prod_le_prod₀ (fun i _ => nbr_nonneg (c i)) (fun i _ => hx i)).trans ?_ - rw [←bp_sum,← Finset.mul_sum, ← Nat.cast_sum] - apply bp_le - gcongr - · simp only [q,h,false_and,nbr,tot,ind_false,Finset.sum_const_zero] - exact (bp_pos _).le - refine (Finset.sum_le_sum fun i _ => he i).trans_eq ?_ - simp - -open Filter -theorem profile_count (K : ℕ) : - ∀ᶠ n : ℕ in atTop, nbr (fun M : Profile p n => totalRank M≤K) ≤ bp ((profileA p K:ℝ)*n) := by - let B := (K+1:ℝ)^Fintype.card (Comp p.g) - have h := bp_poly_dom_nat (a:=1) zero_lt_one B 0 - have h1 : 0 < psize p := Fintype.card_pos_iff.mpr ⟨emptySel⟩ - filter_upwards [h,eventually_ge_atTop 1] with n hn hN - simp only [pow_zero,mul_one,one_mul] at hn - refine le_trans (nbr_profile_rank p K n) (le_trans - (mul_le_mul_of_nonneg_right hn.le (bp_pos _).le) ?_) - rw [← bp_add] - apply bp_le - simp only [card_row, profileA] - push_cast - let s := psize p - have he : 1 ≤ s := h1 - have h' : - n+2*(s*(1+(p.g*p.g+3)*n))*K ≤ 10*(K+1)*s*(p.g*p.g+5)*n := by - have hi : 1+(p.g*p.g+3)*n ≤ (p.g*p.g+4)*n := by nlinarith - have hl : s*(1+(p.g*p.g+3)*n) ≤ s*((p.g*p.g+4)*n) := by gcongr - have hh : n ≤ s*n := by nlinarith - nlinarith only [Nat.mul_le_mul_right K hl,hh, Nat.zero_le (s*p.g*p.g*n), - Nat.zero_le (s*n),Nat.zero_le (s*K*p.g*p.g*n),Nat.zero_le (s*K*n)] - exact_mod_cast h' - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.MatrixFactorization +import OAI.Combinatorics.HadwigerCounterexample.FrameIntersectionBounds + +namespace OAI + +/-! # Matrix Rank Counting -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap +open scoped BigOperators + +theorem cast_mat (I J : Type) [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] : + num (Mat I J)=bp (num I*num J) := by + unfold num + rw [card_space,dim_mat] + push_cast; rfl + +theorem nbr_nonneg {A : Type} [Fintype A] (p : A → Prop) : 0 ≤ nbr p := + tot_nonneg fun _ => ind_nonneg _ + +theorem nbr_le_sum {A B : Type} [Fintype A] [Fintype B] (p : A → Prop) + (q : B → A → Prop) (h : ∀ i, p i → ∃ j,q j i) : + nbr p ≤ ∑ j, nbr (q j) := by + have hp (p : A → Prop) : nbr p = pr (fun _ => 1) p := by simp [nbr,pr,avg,tot] + rw [hp] + simp_rw [hp] + exact (pr_mono (fun _ => zero_le_one) h).trans (pr_exists_le (fun _ => zero_le_one) q) + +variable {I J K : Type} [Fintype I] [Fintype J] [Fintype K] + [DecidableEq I] [DecidableEq J] [DecidableEq K] + +omit [DecidableEq I] [DecidableEq J] in +theorem mul_factor (M : Mat I J) (r : ℕ) (h : M.rank ≤ r) : + ∃ A : Mat I (Fin r),∃ B : Mat (Fin r) J,A*B=M := by + obtain ⟨A,B,_,_,hg⟩ := rank_product M + obtain ⟨a,ha⟩ := pad_matrix_inj M.rank r h + obtain ⟨b,hb⟩ := mat_left_inv ha + refine ⟨A*b,a*B,?_⟩ + rw [←Matrix.mul_assoc,Matrix.mul_assoc A b,hb,Matrix.mul_one,hg] + +theorem nbr_matrix_rank (k : ℕ) : + nbr (fun M : Mat I J => M.rank ≤ k) ≤ bp ((num I+num J)*k) := by + classical + let v := Mat I (Fin k) × Mat (Fin k) J + let q (x : Mat I (Fin k) × Mat (Fin k) J) (M : Mat I J) := x.1*x.2=M + refine (nbr_le_sum _ q fun M h => ?_).trans_eq ?_ + · obtain ⟨A,B,hB⟩ := mul_factor M k h + exact ⟨(A,B),hB⟩ + have h (x : Mat I (Fin k) × Mat (Fin k) J) : nbr (q x) = 1 := by + unfold nbr tot + rw [Finset.sum_eq_single (x.1*x.2)] + · simp [q,ind] + · intro j _ h; simp [q,ind,h.symm] + · simp + simp_rw [h] + simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul,mul_one] + change num (Mat I (Fin k) × Mat (Fin k) J)=_ + rw [num,Fintype.card_prod,Nat.cast_mul] + change num (Mat I (Fin k))*num (Mat (Fin k) J)=_ + rw [cast_mat,cast_mat,← bp_add] + simp [num] + ring_nf + +theorem pr_matrix_rank (k : ℕ) : + pr unif (fun M : Mat I J => M.rank≤ k) ≤ + bp ((num I+num J)*k-num I*num J) := by + rw [pr_unif,bp_sub, ← cast_mat] + exact div_le_div_of_nonneg_right (nbr_matrix_rank k) (Nat.cast_nonneg _) + +def rmult (I : Type) (A : Mat J K) : Mat I J →ₗ[F] Mat I K where + toFun M := M*A + map_add' _ _ := Matrix.add_mul _ _ _ + map_smul' _ _ := Matrix.smul_mul _ _ _ + +theorem pr_mult_mat {A : Mat J K} (h : Function.Injective A.mulVec) (B : Mat I K) : + pr unif (fun M => M*A=B) = bp (-num I*num K) := by + obtain ⟨P,hP⟩ := mat_left_inv h + have hh : Function.Surjective (rmult I A) := + fun C => ⟨C*P,by change C*P*A=C; rw [Matrix.mul_assoc,hP,Matrix.mul_one]⟩ + change mapW unif (rmult I A) B = _ + rw [map_unif_surjective _ hh, unif_apply, neg_mul,bp_neg,←cast_mat] + +theorem pr_deficient (k : ℕ) : + pr unif (fun M : Mat I J => M.rank + k ≤ Fintype.card J) ≤ + bp ((num J-num I)*k) := by + classical + let p (A : Mat J (Fin k)) (M : Mat I J) := + Function.Injective A.mulVec ∧ M*A=0 + refine ((pr_mono unif_law.nz fun M hm => ?_).trans + (pr_exists_le unif_law.nz p)).trans ?_ + · let S := LinearMap.ker M.mulVecLin + have hx := M.mulVecLin.finrank_range_add_finrank_ker + change M.rank+dim S=dim (Vec J) at hx + rw [dim_vec] at hx + have hle : k ≤ dim S := Nat.le_of_add_le_add_left (hm.trans_eq hx.symm) + obtain ⟨A,hA,h'⟩ := bounded_pack S k + refine ⟨A,Matrix.mulVec_injective_iff.mpr ?_,?_⟩ + · apply Matrix.mulVec_injective_iff.mp + apply mrk_inj.mpr + rw [← colSp_dim,h',min_eq_right hle,Fintype.card_fin] + apply coe_mv_inj + change (M*A).mulVecLin = Matrix.mulVecLin 0 + rw [Matrix.mulVecLin_mul,Matrix.mulVecLin_zero] + exact LinearMap.ext fun x => hA (show A.mulVecLin x ∈ colSp A from ⟨x,rfl⟩) + have h (A : Mat J (Fin k)) : pr unif (p A) ≤ bp (-num I*k) := by + by_cases hh : Function.Injective A.mulVec + · simp only [p,hh,true_and] + rw [pr_mult_mat hh] + simp [num] + simp only [p,hh,false_and,pr_false] + exact (bp_pos _).le + apply (Finset.sum_le_sum fun i _ => h i).trans_eq + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + change num (Mat J (Fin k))*_ = _ + rw [cast_mat,←bp_add] + congr 1 + unfold num; rw [Fintype.card_fin]; ring + +variable (p : Shape) +def profileA (K : ℕ) := 10*(K+1)*psize p*(p.g*p.g+5) + +theorem nbr_profile_rank (K n : ℕ) : + let d := Fintype.card (Row p n) + nbr (fun M : Profile p n => totalRank M ≤ K) ≤ + (K+1:ℝ)^Fintype.card (Comp p.g) * bp (2*d*K) := by + classical + intro d + let q (r : Comp p.g → Fin (K+1)) (M : Profile p n) := + (∑ i,(r i).val) ≤ K ∧ ∀ i, (M i).rank=(r i).val + refine le_trans (nbr_le_sum _ q ?_) ?_ + · intro M h + have hh i : (M i).rank≤K := + (Finset.single_le_sum (s:=Finset.univ) (fun i _ => Nat.zero_le ((M i).rank)) + (Finset.mem_univ i)).trans h + exact ⟨fun i => ⟨_,Nat.lt_succ_of_le (hh i)⟩,h,fun _ => rfl⟩ + have he r : nbr (q r) ≤ bp (2*d*K) := by + by_cases h : (∑ i:Comp p.g, (r i).val) ≤ K + · unfold nbr + let c (i : Comp p.g) (M : Moment p n) := (M.rank=(r i).val) + simp_rw [q,h,true_and,ind_all] + change tot (prodW (β:=fun _ => Moment p n) (fun i M => ind (c i M))) ≤ _ + rw [prodW_tot] + have hx i : nbr (c i) ≤ bp (2*d*(r i).val) := by + let w := (r i).val + have h1 := nbr_matrix_rank (I:=Row p n) (J:=Row p n) w + rw [← two_mul] at h1 + exact le_trans (tot_mono (fun x => ind_mono (p:=x.rank=w) (q:=x.rank≤w) (fun e => e.le))) h1 + refine (Finset.prod_le_prod₀ (fun i _ => nbr_nonneg (c i)) (fun i _ => hx i)).trans ?_ + rw [←bp_sum,← Finset.mul_sum, ← Nat.cast_sum] + apply bp_le + gcongr + · simp only [q,h,false_and,nbr,tot,ind_false,Finset.sum_const_zero] + exact (bp_pos _).le + refine (Finset.sum_le_sum fun i _ => he i).trans_eq ?_ + simp + +open Filter +theorem profile_count (K : ℕ) : + ∀ᶠ n : ℕ in atTop, nbr (fun M : Profile p n => totalRank M≤K) ≤ bp ((profileA p K:ℝ)*n) := by + let B := (K+1:ℝ)^Fintype.card (Comp p.g) + have h := bp_poly_dom_nat (a:=1) zero_lt_one B 0 + have h1 : 0 < psize p := Fintype.card_pos_iff.mpr ⟨emptySel⟩ + filter_upwards [h,eventually_ge_atTop 1] with n hn hN + simp only [pow_zero,mul_one,one_mul] at hn + refine le_trans (nbr_profile_rank p K n) (le_trans + (mul_le_mul_of_nonneg_right hn.le (bp_pos _).le) ?_) + rw [← bp_add] + apply bp_le + simp only [card_row, profileA] + push_cast + let s := psize p + have he : 1 ≤ s := h1 + have h' : + n+2*(s*(1+(p.g*p.g+3)*n))*K ≤ 10*(K+1)*s*(p.g*p.g+5)*n := by + have hi : 1+(p.g*p.g+3)*n ≤ (p.g*p.g+4)*n := by nlinarith + have hl : s*(1+(p.g*p.g+3)*n) ≤ s*((p.g*p.g+4)*n) := by gcongr + have hh : n ≤ s*n := by nlinarith + nlinarith only [Nat.mul_le_mul_right K hl,hh, Nat.zero_le (s*p.g*p.g*n), + Nat.zero_le (s*n),Nat.zero_le (s*K*p.g*p.g*n),Nat.zero_le (s*K*n)] + exact_mod_cast h' + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixRanks.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixRanks.lean index b6898a8da0fcb56f9bf951210fdaf465587d1c72..be244fe6702d24f4775160aa7ea2698b6b6bf7ea 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixRanks.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/MatrixRanks.lean @@ -1,166 +1,166 @@ -import OAI.Combinatorics.HadwigerCounterexample.LinearExtension - -namespace OAI - - -/-! # Matrix Ranks -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Function - -section Generic -variable {V W U : Type} - [AddCommGroup V] [Module F V] [AddCommGroup W] [Module F W] - [AddCommGroup U] [Module F U] - -theorem rk_surj {f : V →ₗ[F] W} [FiniteDimensional F W] : Surjective f ↔ rk f = dim W := by - rw [← range_eq_top] - constructor - · intro h; unfold rk dim; rw [h]; exact finrank_top _ _ - exact Submodule.eq_top_of_finrank_eq - -theorem rk_inj {f : V →ₗ[F] W} [FiniteDimensional F V] : Injective f ↔ rk f = dim V := by - constructor - · exact LinearMap.finrank_range_of_inj - intro h - rw [← ker_eq_bot, ← Submodule.finrank_eq_zero (R:=F)] - have hj := f.finrank_range_add_finrank_ker - dsimp only [rk,dim] at h - omega - -theorem rk_comp_le_right [FiniteDimensional F W] (f : V →ₗ[F] W) (g : W →ₗ[F] U) : - rk (g ∘ₗ f) ≤ rk f := by - dsimp only [rk]; rw [LinearMap.range_comp] - exact Submodule.finrank_map_le _ _ - -theorem rk_comp_le_left [FiniteDimensional F U] (f : V →ₗ[F] W) (g : W →ₗ[F] U) : - rk (g ∘ₗ f) ≤ rk g := - Submodule.finrank_mono (LinearMap.range_comp_le_range _ _) - -theorem rk_add_le [FiniteDimensional F W] (f g : V →ₗ[F] W) : - rk (f+g) ≤ rk f+rk g := - (Submodule.finrank_mono (show LinearMap.range (f+g) ≤ range f ⊔ range g by - rintro x ⟨y,rfl⟩ - exact Submodule.add_mem_sup (show f y ∈ range f from ⟨y,rfl⟩) - (show g y ∈ range g from ⟨y,rfl⟩))).trans - (Submodule.finrank_add_le_finrank_add_finrank _ _) - -end Generic - -variable {I J K : Type} -variable [Fintype I] [Fintype J] - -omit [Fintype I] in -theorem rank_cast (P : Mat I J) : P.rank = rk P.mulVecLin := rfl -theorem dim_vec (K : Type) [Fintype K] : dim (Vec K) = Fintype.card K := - Module.finrank_pi F - -omit [Fintype I] in -theorem mrk_inj {P : Mat I J} : Function.Injective P.mulVec ↔ P.rank = Fintype.card J := by - rw [rank_cast,← dim_vec,rk_inj.symm]; rfl -theorem mrk_surj {P : Mat I J} : Function.Surjective P.mulVec ↔ P.rank = Fintype.card I := by - rw [rank_cast,← dim_vec,rk_surj.symm]; rfl - -theorem transpose_surj_iff {P : Mat I J} : Surjective Pᵀ.mulVec ↔ Injective P.mulVec := by - rw [mrk_surj,mrk_inj,rank_transpose] - -theorem mrk_add_le (A B : Mat I J) : (A+B).rank ≤ A.rank + B.rank := by - rw [rank_cast,rank_cast,rank_cast,mulVecLin_add]; exact rk_add_le _ _ - -abbrev colSp (P : Mat I J) := range P.mulVecLin -omit [Fintype I] in -theorem colSp_dim (P : Mat I J) : dim (colSp P) = P.rank := rfl - -omit [Fintype I] in -theorem colSp_mem {P : Mat I J} (j : J) : P.col j ∈ colSp P := by - rw [colSp,range_mulVecLin] - exact Submodule.subset_span ⟨j,rfl⟩ - -/-- A coordinate set of basis vectors of a subspace arranged as columns. -/ -def pack (S : Space (Vec I)) : Mat I (Fin (dim S)) := - let E : Vec (Fin (dim S)) ≃ₗ[F] S := LinearEquiv.ofFinrankEq (Vec (Fin (dim S))) S (by - rw [finrank_pi]; simp) - LinearMap.toMatrix' (S.subtype ∘ₗ E.toLinearMap) - -theorem pack_eq {S : Space (Vec I)} : - ∃ E : Vec (Fin (dim S)) ≃ₗ[F] S, (pack S).mulVecLin = S.subtype ∘ₗ E.toLinearMap := by - unfold pack - refine ⟨LinearEquiv.ofFinrankEq _ _ (by rw [finrank_pi]; simp),?_⟩ - rw [← toLin'_apply'] - exact LinearEquiv.symm_apply_apply _ _ - -theorem pack_inj (S : Space (Vec I)) : Function.Injective (pack S).mulVec := by - rw [← Matrix.coe_mulVecLin] - obtain ⟨E,he⟩ := pack_eq (S:=S) - rw [he] - exact Subtype.val_injective.comp E.injective - -theorem colSp_pack (S : Space (Vec I)) : colSp (pack S) = S := by - obtain ⟨E,he⟩ := pack_eq (S:=S) - rw [colSp,he,LinearMap.range_comp] - simp - -omit [Fintype I] in -/-- Matrix multiplication cancels when a left factor is injective. -/ -theorem inj_comp_mat [Fintype K] (A : Mat I J) (B : Mat J K) - (hA : Injective A.mulVec) (hB : Injective B.mulVec) : - Injective (A*B).mulVec := by - rw [← coe_mulVecLin,mulVecLin_mul] - exact hA.comp hB - -omit [Fintype I] in -theorem coe_mv_inj : Function.Injective (fun P : Mat I J => P.mulVecLin) := by - classical - rw [show (fun P : Mat I J => P.mulVecLin) = toLin' by rfl] - exact LinearEquiv.injective _ - -omit [Fintype I] in -theorem toMat_map [DecidableEq J] (f : Vec J →ₗ[F] Vec I) : - (LinearMap.toMatrix' f).mulVecLin = f := by - rw [← toLin'_apply']; exact LinearEquiv.symm_apply_apply _ _ - -/-- Paired-frame transitivity of §3 in matrix form. -/ -theorem frame_move [Fintype K] [DecidableEq K] {A A' : Mat K I} {B B' : Mat K J} - (ha : Injective A.mulVec) (ha' : Injective A'.mulVec) (hb : Injective B.mulVec) - (hb' : Injective B'.mulVec) (h : Aᵀ * B = A'ᵀ * B') : - ∃ L R : Mat K K, L*R = 1 ∧ R*L = 1 ∧ L*A=A' ∧ Rᵀ*B = B' := by - classical - have he : (Bᵀ*A) = (B'ᵀ*A') := by - simpa only [transpose_mul,transpose_transpose] using congrArg Matrix.transpose h - obtain ⟨C,hC,hD⟩ := equate_pair (A:=A.mulVecLin) (A':=A'.mulVecLin) (G:=Bᵀ.mulVecLin) - (G':=B'ᵀ.mulVecLin) ha ha' (transpose_surj_iff.mpr hb) - (transpose_surj_iff.mpr hb') (by rw [← mulVecLin_mul,← mulVecLin_mul,he]) - let L := LinearMap.toMatrix' C.toLinearMap - let R := LinearMap.toMatrix' C.symm.toLinearMap - have hl : L * R = 1 := by - apply coe_mv_inj - change (L*R).mulVecLin = Matrix.mulVecLin 1 - dsimp only [L,R] - rw [mulVecLin_mul,toMat_map,toMat_map,mulVecLin_one] - exact LinearMap.ext fun x => C.apply_symm_apply x - have hr : R * L = 1 := by - apply coe_mv_inj - change (R*L).mulVecLin = Matrix.mulVecLin 1 - dsimp only [L,R] - rw [mulVecLin_mul,toMat_map,toMat_map,mulVecLin_one] - exact LinearMap.ext fun x => C.symm_apply_apply x - refine ⟨L,R,hl,hr,?_,?_⟩ - · apply coe_mv_inj - change (L*A).mulVecLin = _ - dsimp only [L]; rw [mulVecLin_mul,toMat_map] - exact LinearMap.ext hC - · have hB : Bᵀ = B'ᵀ * L := by - apply coe_mv_inj - change _ = (B'ᵀ*L).mulVecLin - dsimp only [L]; rw [mulVecLin_mul,toMat_map] - exact LinearMap.ext hD - apply_fun Matrix.transpose - · rw [transpose_mul,transpose_transpose,hB,Matrix.mul_assoc,hl,Matrix.mul_one] - · exact Matrix.transpose_injective - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.LinearExtension + +namespace OAI + + +/-! # Matrix Ranks -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Function + +section Generic +variable {V W U : Type} + [AddCommGroup V] [Module F V] [AddCommGroup W] [Module F W] + [AddCommGroup U] [Module F U] + +theorem rk_surj {f : V →ₗ[F] W} [FiniteDimensional F W] : Surjective f ↔ rk f = dim W := by + rw [← range_eq_top] + constructor + · intro h; unfold rk dim; rw [h]; exact finrank_top _ _ + exact Submodule.eq_top_of_finrank_eq + +theorem rk_inj {f : V →ₗ[F] W} [FiniteDimensional F V] : Injective f ↔ rk f = dim V := by + constructor + · exact LinearMap.finrank_range_of_inj + intro h + rw [← ker_eq_bot, ← Submodule.finrank_eq_zero (R:=F)] + have hj := f.finrank_range_add_finrank_ker + dsimp only [rk,dim] at h + omega + +theorem rk_comp_le_right [FiniteDimensional F W] (f : V →ₗ[F] W) (g : W →ₗ[F] U) : + rk (g ∘ₗ f) ≤ rk f := by + dsimp only [rk]; rw [LinearMap.range_comp] + exact Submodule.finrank_map_le _ _ + +theorem rk_comp_le_left [FiniteDimensional F U] (f : V →ₗ[F] W) (g : W →ₗ[F] U) : + rk (g ∘ₗ f) ≤ rk g := + Submodule.finrank_mono (LinearMap.range_comp_le_range _ _) + +theorem rk_add_le [FiniteDimensional F W] (f g : V →ₗ[F] W) : + rk (f+g) ≤ rk f+rk g := + (Submodule.finrank_mono (show LinearMap.range (f+g) ≤ range f ⊔ range g by + rintro x ⟨y,rfl⟩ + exact Submodule.add_mem_sup (show f y ∈ range f from ⟨y,rfl⟩) + (show g y ∈ range g from ⟨y,rfl⟩))).trans + (Submodule.finrank_add_le_finrank_add_finrank _ _) + +end Generic + +variable {I J K : Type} +variable [Fintype I] [Fintype J] + +omit [Fintype I] in +theorem rank_cast (P : Mat I J) : P.rank = rk P.mulVecLin := rfl +theorem dim_vec (K : Type) [Fintype K] : dim (Vec K) = Fintype.card K := + Module.finrank_pi F + +omit [Fintype I] in +theorem mrk_inj {P : Mat I J} : Function.Injective P.mulVec ↔ P.rank = Fintype.card J := by + rw [rank_cast,← dim_vec,rk_inj.symm]; rfl +theorem mrk_surj {P : Mat I J} : Function.Surjective P.mulVec ↔ P.rank = Fintype.card I := by + rw [rank_cast,← dim_vec,rk_surj.symm]; rfl + +theorem transpose_surj_iff {P : Mat I J} : Surjective Pᵀ.mulVec ↔ Injective P.mulVec := by + rw [mrk_surj,mrk_inj,rank_transpose] + +theorem mrk_add_le (A B : Mat I J) : (A+B).rank ≤ A.rank + B.rank := by + rw [rank_cast,rank_cast,rank_cast,mulVecLin_add]; exact rk_add_le _ _ + +abbrev colSp (P : Mat I J) := range P.mulVecLin +omit [Fintype I] in +theorem colSp_dim (P : Mat I J) : dim (colSp P) = P.rank := rfl + +omit [Fintype I] in +theorem colSp_mem {P : Mat I J} (j : J) : P.col j ∈ colSp P := by + rw [colSp,range_mulVecLin] + exact Submodule.subset_span ⟨j,rfl⟩ + +/-- A coordinate set of basis vectors of a subspace arranged as columns. -/ +def pack (S : Space (Vec I)) : Mat I (Fin (dim S)) := + let E : Vec (Fin (dim S)) ≃ₗ[F] S := LinearEquiv.ofFinrankEq (Vec (Fin (dim S))) S (by + rw [finrank_pi]; simp) + LinearMap.toMatrix' (S.subtype ∘ₗ E.toLinearMap) + +theorem pack_eq {S : Space (Vec I)} : + ∃ E : Vec (Fin (dim S)) ≃ₗ[F] S, (pack S).mulVecLin = S.subtype ∘ₗ E.toLinearMap := by + unfold pack + refine ⟨LinearEquiv.ofFinrankEq _ _ (by rw [finrank_pi]; simp),?_⟩ + rw [← toLin'_apply'] + exact LinearEquiv.symm_apply_apply _ _ + +theorem pack_inj (S : Space (Vec I)) : Function.Injective (pack S).mulVec := by + rw [← Matrix.coe_mulVecLin] + obtain ⟨E,he⟩ := pack_eq (S:=S) + rw [he] + exact Subtype.val_injective.comp E.injective + +theorem colSp_pack (S : Space (Vec I)) : colSp (pack S) = S := by + obtain ⟨E,he⟩ := pack_eq (S:=S) + rw [colSp,he,LinearMap.range_comp] + simp + +omit [Fintype I] in +/-- Matrix multiplication cancels when a left factor is injective. -/ +theorem inj_comp_mat [Fintype K] (A : Mat I J) (B : Mat J K) + (hA : Injective A.mulVec) (hB : Injective B.mulVec) : + Injective (A*B).mulVec := by + rw [← coe_mulVecLin,mulVecLin_mul] + exact hA.comp hB + +omit [Fintype I] in +theorem coe_mv_inj : Function.Injective (fun P : Mat I J => P.mulVecLin) := by + classical + rw [show (fun P : Mat I J => P.mulVecLin) = toLin' by rfl] + exact LinearEquiv.injective _ + +omit [Fintype I] in +theorem toMat_map [DecidableEq J] (f : Vec J →ₗ[F] Vec I) : + (LinearMap.toMatrix' f).mulVecLin = f := by + rw [← toLin'_apply']; exact LinearEquiv.symm_apply_apply _ _ + +/-- Paired-frame transitivity of §3 in matrix form. -/ +theorem frame_move [Fintype K] [DecidableEq K] {A A' : Mat K I} {B B' : Mat K J} + (ha : Injective A.mulVec) (ha' : Injective A'.mulVec) (hb : Injective B.mulVec) + (hb' : Injective B'.mulVec) (h : Aᵀ * B = A'ᵀ * B') : + ∃ L R : Mat K K, L*R = 1 ∧ R*L = 1 ∧ L*A=A' ∧ Rᵀ*B = B' := by + classical + have he : (Bᵀ*A) = (B'ᵀ*A') := by + simpa only [transpose_mul,transpose_transpose] using congrArg Matrix.transpose h + obtain ⟨C,hC,hD⟩ := equate_pair (A:=A.mulVecLin) (A':=A'.mulVecLin) (G:=Bᵀ.mulVecLin) + (G':=B'ᵀ.mulVecLin) ha ha' (transpose_surj_iff.mpr hb) + (transpose_surj_iff.mpr hb') (by rw [← mulVecLin_mul,← mulVecLin_mul,he]) + let L := LinearMap.toMatrix' C.toLinearMap + let R := LinearMap.toMatrix' C.symm.toLinearMap + have hl : L * R = 1 := by + apply coe_mv_inj + change (L*R).mulVecLin = Matrix.mulVecLin 1 + dsimp only [L,R] + rw [mulVecLin_mul,toMat_map,toMat_map,mulVecLin_one] + exact LinearMap.ext fun x => C.apply_symm_apply x + have hr : R * L = 1 := by + apply coe_mv_inj + change (R*L).mulVecLin = Matrix.mulVecLin 1 + dsimp only [L,R] + rw [mulVecLin_mul,toMat_map,toMat_map,mulVecLin_one] + exact LinearMap.ext fun x => C.symm_apply_apply x + refine ⟨L,R,hl,hr,?_,?_⟩ + · apply coe_mv_inj + change (L*A).mulVecLin = _ + dsimp only [L]; rw [mulVecLin_mul,toMat_map] + exact LinearMap.ext hC + · have hB : Bᵀ = B'ᵀ * L := by + apply coe_mv_inj + change _ = (B'ᵀ*L).mulVecLin + dsimp only [L]; rw [mulVecLin_mul,toMat_map] + exact LinearMap.ext hD + apply_fun Matrix.transpose + · rw [transpose_mul,transpose_transpose,hB,Matrix.mul_assoc,hl,Matrix.mul_one] + · exact Matrix.transpose_injective + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/MixedImageBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/MixedImageBounds.lean index e01d7fd0d1e0a7c41685d85e87e349fcbeaec7b0..47a2898a09282352d4460f73569f6dc16db3e44e 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/MixedImageBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/MixedImageBounds.lean @@ -1,222 +1,222 @@ -import OAI.Combinatorics.HadwigerCounterexample.FrameOrbitLaws -import OAI.Combinatorics.HadwigerCounterexample.ConditionalProductLaws -import Mathlib.Data.Matrix.ColumnRowPartitioned - -namespace OAI - -/-! # Mixed Image Bounds -/ - -noncomputable section - -namespace HadwigerCounterexample -open Matrix Function LinearMap -open scoped BigOperators - -variable {I J U S : Type} [Fintype I] [Fintype J] [Fintype U] [Fintype S] - [DecidableEq I] [DecidableEq J] [DecidableEq U] [DecidableEq S] - -def mixImage (D : Mat (I ⊕ I) J) (x : Mat U I × Mat U I) := fromCols x.1 x.2 * D - -def mixImageLin (D : Mat (I ⊕ I) J) : - (Mat U I × Mat U I) →ₗ[F] Mat U J where - toFun := mixImage D - map_add' a b := by - have e : fromCols (a+b).1 (a+b).2 = fromCols a.1 a.2 + fromCols b.1 b.2 := by - ext i j; cases j <;> rfl - unfold mixImage - rw [e,Matrix.add_mul] - map_smul' b x := by - have e : fromCols (b•x).1 (b•x).2 = b • fromCols x.1 x.2 := by - ext i j; cases j <;> rfl - unfold mixImage - rw [e,Matrix.smul_mul]; rfl - -/-- Exact image tests under a translate-stable minus (or plus) pair law cost -dim T bits per vector. Directions mix both endpoints in one direct sum. -/ -theorem mixed_cap {w w' : Wgt (Mat U I)} (hw : SubLaw w) (hw' : SubLaw w') - (T : Space (Vec U)) (hT : columnInv (w:=w) T) (hT' : columnInv (w:=w') T) - (D : Mat (I ⊕ I) J) (hD : Injective D.mulVec) (M : Mat U J) : - pr (pairW w w') (fun x => mixImage D x = M) ≤ bp (- (dim T:ℝ)*num J) := by - let n := dim T - obtain ⟨F,hF⟩ := mat_left_inv hD - obtain ⟨R,hR⟩ := mat_left_inv (pack_inj T) - have hi : Injective (fun A : Mat (Fin n) J => pack T * A) := by - intro A B h - have he := congrArg (R * ·) h - simpa only [← Matrix.mul_assoc,hR,Matrix.one_mul] using he - let e : Mat (Fin n) J ↪ Mat U J := ⟨(pack T * ·),hi⟩ - let f : (Mat U I × Mat U I) →ₗ[HadwigerCounterexample.F] Mat U J := mixImageLin D - have he (t : Mat (Fin n) J) : - ∃ x, f x = e t ∧ ∀ y, pairW w w' (y+x) = pairW w w' y := by - let A := t*F - let B := pack T * A.toCols₁ - let C := pack T * A.toCols₂ - have hu (G : Mat (Fin n) I) : colSp (pack T * G) ≤ T := by - rintro x ⟨y,rfl⟩ - change (pack T * G) *ᵥ y ∈ T - rw [← Matrix.mulVec_mulVec] - have hg : pack T *ᵥ (G *ᵥ y) ∈ colSp (pack T) := ⟨G *ᵥ y,rfl⟩ - rwa [colSp_pack] at hg - refine ⟨(B,C),?_,fun y => ?_⟩ - · have hx : fromCols A.toCols₁ A.toCols₂ = A := by ext i j; cases j <;> rfl - change fromCols (pack T * A.toCols₁) _ * D = _ - rw [show C = pack T * A.toCols₂ from rfl,← Matrix.mul_fromCols,hx] - change _ * _ = pack T * t - unfold A - rw [Matrix.mul_assoc,Matrix.mul_assoc,hF,Matrix.mul_one] - · change w (y.1+B) * w' (y.2+C) = _ - rw [hT _ _ (hu _),hT' _ _ (hu _)] - rfl - have h := translate_cap (subLaw_pair hw hw') f e he M - rw [card_space,dim_mat] at h - refine le_trans h (le_of_eq ?_) - have ht : (↑(Fintype.card (Fin n) * Fintype.card J) : ℝ) = (dim T:ℝ) * num J := by - simp [num,n] - rw [ht,neg_mul,bp_neg] - -omit [DecidableEq I] [DecidableEq U] in -theorem kerTr_dim {P : Mat U I} (h : Injective P.mulVec) : - (dim (ker Pᵀ.mulVecLin) : ℝ) = num U - num I := by - have hx := Pᵀ.mulVecLin.finrank_range_add_finrank_ker - change rk Pᵀ.mulVecLin + dim (ker Pᵀ.mulVecLin) = dim (Vec U) at hx - rw [rk_surj.mp (show Surjective Pᵀ.mulVecLin from transpose_surj_iff.mpr h), dim_vec, - dim_vec] at hx - have hj : num I + dim (ker Pᵀ.mulVecLin) = num U := by exact_mod_cast hx - linarith only [hj] - -omit [DecidableEq I] [DecidableEq U] in -theorem two_kerTr {P Q : Mat U I} (h : Injective P.mulVec) (g : Injective Q.mulVec) : - num U - 2*num I ≤ (dim (ker Pᵀ.mulVecLin ⊓ ker Qᵀ.mulVecLin : Submodule _ _) : ℝ) := by - let A := ker Pᵀ.mulVecLin - let B := ker Qᵀ.mulVecLin - have he : (dim (A⊔B : Submodule _ _) : ℝ)+dim (A⊓B : Submodule _ _) = dim A + (dim B:ℝ) := by - exact_mod_cast Submodule.finrank_sup_add_finrank_inf_eq A B - have hf : (dim (A⊔B : Submodule _ _) : ℝ) ≤ num U := by - have hh := Submodule.finrank_le (A ⊔ B) - change dim _ ≤ dim _ at hh - rw [dim_vec] at hh; exact_mod_cast hh - change _ ≤ (dim (A⊓B : Submodule _ _) : ℝ) - rw [show (dim A:ℝ) = _ from kerTr_dim h,show (dim B:ℝ) = _ from kerTr_dim g] at he - linarith only [he,hf] - -def weakMinus (C : Mat I I → Prop) (P : Mat U I) := unifOn (fun Q : Mat U I => C (Pᵀ*Q)) - -theorem weak_shift {C : Mat I I → Prop} (P : Mat U I) : - columnInv (w:=weakMinus C P) (ker Pᵀ.mulVecLin) := by - intro M A hA - have h : Pᵀ * A = 0 := by - apply coe_mv_inj - change (Pᵀ * A).mulVecLin = _ - rw [mulVecLin_mul] - exact LinearMap.ext fun x => by - have hh : Pᵀ.mulVecLin (A.mulVecLin x)=0 := hA (show A.mulVecLin x ∈ colSp A from ⟨x,rfl⟩) - simp only [LinearMap.comp_apply,hh,Matrix.mulVecLin_zero,LinearMap.zero_apply] - simp only [weakMinus,unifOn_val,Matrix.mul_add,h,add_zero] - -theorem minus_le_weak {C : Mat I I → Prop} (hc : ∃ M, C M) (P : Mat U I) - (hP : Injective P.mulVec) (hu : 2*num I - num U ≤ -1) (x : Mat U I) : - unifOn (fun Q => FramesAt C (P,Q)) x ≤ 2 * weakMinus C P x := by - let w := weakMinus C P - have hh : IsLaw w := by - refine unifOn_law ?_ - obtain ⟨M,hM⟩ := hc - obtain ⟨B,hB⟩ := gramL_surj I hP M - change Pᵀ*B=M at hB - exact ⟨B,hB.symm ▸ hM⟩ - have hg : pr w (fun M => ¬Injective M.mulVec) ≤ (2:ℝ)⁻¹ := by - apply le_trans (shift_fail hh.sub _ (weak_shift P)) - rw [kerTr_dim hP,show (2:ℝ)⁻¹=bp (-1) by rw [bp_neg,bp_one]] - exact bp_le (by linarith only [hu]) - rw [pr_not w (p:=fun M => Injective M.mulVec),hh.total] at hg - have h1 := on_mon hh.nz (p:=fun M => Injective M.mulVec) (a:= (2:ℝ)⁻¹) - (by norm_num) (by linarith only [hg]) x - simp only [w,weakMinus,unifOn_and,inv_inv] at h1 - simpa only [FramesAt,hP,true_and,weakMinus] using h1 - -theorem plus_le_unif (hu : num I-num U ≤ -1) (P : Mat U I) : - unifOn (fun P : Mat U I => Injective P.mulVec) P ≤ 2 * unif P := by - have h : pr unif (fun P : Mat U I => ¬ Injective P.mulVec) ≤ (2:ℝ)⁻¹ := by - apply le_trans unif_fail - rw [show (2:ℝ)⁻¹=bp (-1) by rw [bp_neg,bp_one]]; exact bp_le hu - rw [pr_not (unif:Wgt (Mat U I)) (p:=fun P => Injective P.mulVec),unif_law.total] at h - have h1 := on_mon unif_law.nz (a:=(2:ℝ)⁻¹) - (p:=fun P : Mat U I => Injective P.mulVec) (by norm_num) (by linarith only [h]) P - rwa [on_unif,inv_inv] at h1 - -private theorem pair_cap_aux {A : Type} {w v w' v' : Wgt A} - (hu : ∀ x, 0 ≤ w' x) (hg : ∀ x, 0 ≤ v x) (hc : ∀ x, w x ≤ 2*v x) - (hd : ∀ x, w' x ≤ 2*v' x) (p) : pairW w w' p ≤ 4 * pairW v v' p := by - refine (mul_le_mul (hc p.1) (hd p.2) (hu _) (mul_nonneg (by norm_num) (hg _))).trans_eq ?_ - rw [pairW]; ring - -theorem comp_image_cap {C : Mat I I → Prop} (hc : ∃ M, C M) - (hu : 2*num I-num U ≤ -1) - (D : Mat (I⊕I) J) (D' : Mat (I⊕I) S) - (hD : Injective D.mulVec) (hD' : Injective D'.mulVec) - (M : Mat U J) (M' : Mat U S) : - let w := unifOn (FramesAt (U:=U) C) - pr (pairW w w) (fun x => - mixImage D (x.1.1,x.2.1) = M ∧ mixImage D' (x.1.2,x.2.2)=M') ≤ - 16*bp (-num U * num J - (num U-2*num I)*num S) := by - let Y (x : Mat U I) := Injective x.mulVec - let w := unifOn (FramesAt (U:=U) C) - let v := unifOn Y - let k (x : Mat U I) := unifOn (fun Q => FramesAt C (x,Q)) - have h₀ : num I - num U ≤ -1 := by - have hi : 0 ≤ num I := Nat.cast_nonneg _ - linarith - have hh := framesAt_exists (U:=U) hc (show num I+num I mixImage D x=M - let q := fun x => mixImage D' x=M' - let b1 := bp (-num U * num J) - let b2 := bp (- (num U-2*num I)*num S) - change pr (pairW w w) _ ≤ _ - rw [hw,pair_semi_pr v v k k p q] - have he1 : pr (pairW v v) p ≤ 4*b1 := by - have hi := pr_cap (w:=pairW v v) - (pair_cap_aux (unifOn_sub Y).nz unif_subLaw.nz (plus_le_unif h₀) (plus_le_unif h₀)) p - refine hi.trans (mul_le_mul_of_nonneg_left ?_ (by norm_num)) - refine (mixed_cap unif_subLaw unif_subLaw ⊤ (fun _ _ _ => rfl) (fun _ _ _ => rfl) - _ hD _).trans ?_ - dsimp only [b1] - rw [dim,finrank_top,show Module.finrank F (Vec U)=_ from dim_vec _] - have he2 (P P' : Mat U I) : - pr (pairW (k P) (k P')) q ≤ 4*b2 := by - by_cases h : Y P - · by_cases g : Y P' - · let T := ker Pᵀ.mulVecLin ⊓ ker P'ᵀ.mulVecLin - have hh : columnInv (w:=weakMinus C P) T := - fun M A hA => weak_shift P _ _ (hA.trans inf_le_left) - have hh' : columnInv (w:=weakMinus C P') T := - fun M A hA => weak_shift P' _ _ (hA.trans inf_le_right) - have hi := pr_cap (w:=pairW (k P) (k P')) - (pair_cap_aux (unifOn_sub _).nz (v:=weakMinus C P) (unifOn_sub _).nz - (minus_le_weak hc P h hu) (minus_le_weak hc P' g hu)) q - refine hi.trans (mul_le_mul_of_nonneg_left ?_ (by norm_num)) - refine (mixed_cap (unifOn_sub _) (unifOn_sub _) T hh hh' _ hD' M').trans (bp_le ?_) - apply mul_le_mul_of_nonneg_right ?_ (Nat.cast_nonneg _) - exact neg_le_neg (two_kerTr h g) - · have hi := bp_pos (- (num U-2*num I)*num S) - change ¬ Injective _ at g - simp [pr,avg,pairW,k,FramesAt,g,unifOn_val,b2]; exact (bp_pos _).le - · have hi := bp_pos (- (num U-2*num I)*num S) - change ¬ Injective _ at h - simp [pr,avg,pairW,k,FramesAt,h,unifOn_val,b2]; exact (bp_pos _).le - let r := pairW v v - calc avg r (fun x => ind (p x)*pr (pairW (k x.1) (k x.2)) q) - _ ≤ avg r (fun x => ind (p x)*(4*b2)) := - avg_mono (subLaw_pair (unifOn_sub _) (unifOn_sub Y)).nz - (fun x => mul_le_mul_of_nonneg_left (he2 _ _) (ind_nonneg _)) - _ = pr r p * (4*b2) := avg_mul _ _ _ - _ ≤ (4*b1)*(4*b2) := mul_le_mul_of_nonneg_right he1 (mul_nonneg (by norm_num) (bp_pos _).le) - _ = _ := by simp only [sub_eq_add_neg,← neg_mul, bp_add,b1,b2]; ring - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FrameOrbitLaws +import OAI.Combinatorics.HadwigerCounterexample.ConditionalProductLaws +import Mathlib.Data.Matrix.ColumnRowPartitioned + +namespace OAI + +/-! # Mixed Image Bounds -/ + +noncomputable section + +namespace HadwigerCounterexample +open Matrix Function LinearMap +open scoped BigOperators + +variable {I J U S : Type} [Fintype I] [Fintype J] [Fintype U] [Fintype S] + [DecidableEq I] [DecidableEq J] [DecidableEq U] [DecidableEq S] + +def mixImage (D : Mat (I ⊕ I) J) (x : Mat U I × Mat U I) := fromCols x.1 x.2 * D + +def mixImageLin (D : Mat (I ⊕ I) J) : + (Mat U I × Mat U I) →ₗ[F] Mat U J where + toFun := mixImage D + map_add' a b := by + have e : fromCols (a+b).1 (a+b).2 = fromCols a.1 a.2 + fromCols b.1 b.2 := by + ext i j; cases j <;> rfl + unfold mixImage + rw [e,Matrix.add_mul] + map_smul' b x := by + have e : fromCols (b•x).1 (b•x).2 = b • fromCols x.1 x.2 := by + ext i j; cases j <;> rfl + unfold mixImage + rw [e,Matrix.smul_mul]; rfl + +/-- Exact image tests under a translate-stable minus (or plus) pair law cost +dim T bits per vector. Directions mix both endpoints in one direct sum. -/ +theorem mixed_cap {w w' : Wgt (Mat U I)} (hw : SubLaw w) (hw' : SubLaw w') + (T : Space (Vec U)) (hT : columnInv (w:=w) T) (hT' : columnInv (w:=w') T) + (D : Mat (I ⊕ I) J) (hD : Injective D.mulVec) (M : Mat U J) : + pr (pairW w w') (fun x => mixImage D x = M) ≤ bp (- (dim T:ℝ)*num J) := by + let n := dim T + obtain ⟨F,hF⟩ := mat_left_inv hD + obtain ⟨R,hR⟩ := mat_left_inv (pack_inj T) + have hi : Injective (fun A : Mat (Fin n) J => pack T * A) := by + intro A B h + have he := congrArg (R * ·) h + simpa only [← Matrix.mul_assoc,hR,Matrix.one_mul] using he + let e : Mat (Fin n) J ↪ Mat U J := ⟨(pack T * ·),hi⟩ + let f : (Mat U I × Mat U I) →ₗ[HadwigerCounterexample.F] Mat U J := mixImageLin D + have he (t : Mat (Fin n) J) : + ∃ x, f x = e t ∧ ∀ y, pairW w w' (y+x) = pairW w w' y := by + let A := t*F + let B := pack T * A.toCols₁ + let C := pack T * A.toCols₂ + have hu (G : Mat (Fin n) I) : colSp (pack T * G) ≤ T := by + rintro x ⟨y,rfl⟩ + change (pack T * G) *ᵥ y ∈ T + rw [← Matrix.mulVec_mulVec] + have hg : pack T *ᵥ (G *ᵥ y) ∈ colSp (pack T) := ⟨G *ᵥ y,rfl⟩ + rwa [colSp_pack] at hg + refine ⟨(B,C),?_,fun y => ?_⟩ + · have hx : fromCols A.toCols₁ A.toCols₂ = A := by ext i j; cases j <;> rfl + change fromCols (pack T * A.toCols₁) _ * D = _ + rw [show C = pack T * A.toCols₂ from rfl,← Matrix.mul_fromCols,hx] + change _ * _ = pack T * t + unfold A + rw [Matrix.mul_assoc,Matrix.mul_assoc,hF,Matrix.mul_one] + · change w (y.1+B) * w' (y.2+C) = _ + rw [hT _ _ (hu _),hT' _ _ (hu _)] + rfl + have h := translate_cap (subLaw_pair hw hw') f e he M + rw [card_space,dim_mat] at h + refine le_trans h (le_of_eq ?_) + have ht : (↑(Fintype.card (Fin n) * Fintype.card J) : ℝ) = (dim T:ℝ) * num J := by + simp [num,n] + rw [ht,neg_mul,bp_neg] + +omit [DecidableEq I] [DecidableEq U] in +theorem kerTr_dim {P : Mat U I} (h : Injective P.mulVec) : + (dim (ker Pᵀ.mulVecLin) : ℝ) = num U - num I := by + have hx := Pᵀ.mulVecLin.finrank_range_add_finrank_ker + change rk Pᵀ.mulVecLin + dim (ker Pᵀ.mulVecLin) = dim (Vec U) at hx + rw [rk_surj.mp (show Surjective Pᵀ.mulVecLin from transpose_surj_iff.mpr h), dim_vec, + dim_vec] at hx + have hj : num I + dim (ker Pᵀ.mulVecLin) = num U := by exact_mod_cast hx + linarith only [hj] + +omit [DecidableEq I] [DecidableEq U] in +theorem two_kerTr {P Q : Mat U I} (h : Injective P.mulVec) (g : Injective Q.mulVec) : + num U - 2*num I ≤ (dim (ker Pᵀ.mulVecLin ⊓ ker Qᵀ.mulVecLin : Submodule _ _) : ℝ) := by + let A := ker Pᵀ.mulVecLin + let B := ker Qᵀ.mulVecLin + have he : (dim (A⊔B : Submodule _ _) : ℝ)+dim (A⊓B : Submodule _ _) = dim A + (dim B:ℝ) := by + exact_mod_cast Submodule.finrank_sup_add_finrank_inf_eq A B + have hf : (dim (A⊔B : Submodule _ _) : ℝ) ≤ num U := by + have hh := Submodule.finrank_le (A ⊔ B) + change dim _ ≤ dim _ at hh + rw [dim_vec] at hh; exact_mod_cast hh + change _ ≤ (dim (A⊓B : Submodule _ _) : ℝ) + rw [show (dim A:ℝ) = _ from kerTr_dim h,show (dim B:ℝ) = _ from kerTr_dim g] at he + linarith only [he,hf] + +def weakMinus (C : Mat I I → Prop) (P : Mat U I) := unifOn (fun Q : Mat U I => C (Pᵀ*Q)) + +theorem weak_shift {C : Mat I I → Prop} (P : Mat U I) : + columnInv (w:=weakMinus C P) (ker Pᵀ.mulVecLin) := by + intro M A hA + have h : Pᵀ * A = 0 := by + apply coe_mv_inj + change (Pᵀ * A).mulVecLin = _ + rw [mulVecLin_mul] + exact LinearMap.ext fun x => by + have hh : Pᵀ.mulVecLin (A.mulVecLin x)=0 := hA (show A.mulVecLin x ∈ colSp A from ⟨x,rfl⟩) + simp only [LinearMap.comp_apply,hh,Matrix.mulVecLin_zero,LinearMap.zero_apply] + simp only [weakMinus,unifOn_val,Matrix.mul_add,h,add_zero] + +theorem minus_le_weak {C : Mat I I → Prop} (hc : ∃ M, C M) (P : Mat U I) + (hP : Injective P.mulVec) (hu : 2*num I - num U ≤ -1) (x : Mat U I) : + unifOn (fun Q => FramesAt C (P,Q)) x ≤ 2 * weakMinus C P x := by + let w := weakMinus C P + have hh : IsLaw w := by + refine unifOn_law ?_ + obtain ⟨M,hM⟩ := hc + obtain ⟨B,hB⟩ := gramL_surj I hP M + change Pᵀ*B=M at hB + exact ⟨B,hB.symm ▸ hM⟩ + have hg : pr w (fun M => ¬Injective M.mulVec) ≤ (2:ℝ)⁻¹ := by + apply le_trans (shift_fail hh.sub _ (weak_shift P)) + rw [kerTr_dim hP,show (2:ℝ)⁻¹=bp (-1) by rw [bp_neg,bp_one]] + exact bp_le (by linarith only [hu]) + rw [pr_not w (p:=fun M => Injective M.mulVec),hh.total] at hg + have h1 := on_mon hh.nz (p:=fun M => Injective M.mulVec) (a:= (2:ℝ)⁻¹) + (by norm_num) (by linarith only [hg]) x + simp only [w,weakMinus,unifOn_and,inv_inv] at h1 + simpa only [FramesAt,hP,true_and,weakMinus] using h1 + +theorem plus_le_unif (hu : num I-num U ≤ -1) (P : Mat U I) : + unifOn (fun P : Mat U I => Injective P.mulVec) P ≤ 2 * unif P := by + have h : pr unif (fun P : Mat U I => ¬ Injective P.mulVec) ≤ (2:ℝ)⁻¹ := by + apply le_trans unif_fail + rw [show (2:ℝ)⁻¹=bp (-1) by rw [bp_neg,bp_one]]; exact bp_le hu + rw [pr_not (unif:Wgt (Mat U I)) (p:=fun P => Injective P.mulVec),unif_law.total] at h + have h1 := on_mon unif_law.nz (a:=(2:ℝ)⁻¹) + (p:=fun P : Mat U I => Injective P.mulVec) (by norm_num) (by linarith only [h]) P + rwa [on_unif,inv_inv] at h1 + +private theorem pair_cap_aux {A : Type} {w v w' v' : Wgt A} + (hu : ∀ x, 0 ≤ w' x) (hg : ∀ x, 0 ≤ v x) (hc : ∀ x, w x ≤ 2*v x) + (hd : ∀ x, w' x ≤ 2*v' x) (p) : pairW w w' p ≤ 4 * pairW v v' p := by + refine (mul_le_mul (hc p.1) (hd p.2) (hu _) (mul_nonneg (by norm_num) (hg _))).trans_eq ?_ + rw [pairW]; ring + +theorem comp_image_cap {C : Mat I I → Prop} (hc : ∃ M, C M) + (hu : 2*num I-num U ≤ -1) + (D : Mat (I⊕I) J) (D' : Mat (I⊕I) S) + (hD : Injective D.mulVec) (hD' : Injective D'.mulVec) + (M : Mat U J) (M' : Mat U S) : + let w := unifOn (FramesAt (U:=U) C) + pr (pairW w w) (fun x => + mixImage D (x.1.1,x.2.1) = M ∧ mixImage D' (x.1.2,x.2.2)=M') ≤ + 16*bp (-num U * num J - (num U-2*num I)*num S) := by + let Y (x : Mat U I) := Injective x.mulVec + let w := unifOn (FramesAt (U:=U) C) + let v := unifOn Y + let k (x : Mat U I) := unifOn (fun Q => FramesAt C (x,Q)) + have h₀ : num I - num U ≤ -1 := by + have hi : 0 ≤ num I := Nat.cast_nonneg _ + linarith + have hh := framesAt_exists (U:=U) hc (show num I+num I mixImage D x=M + let q := fun x => mixImage D' x=M' + let b1 := bp (-num U * num J) + let b2 := bp (- (num U-2*num I)*num S) + change pr (pairW w w) _ ≤ _ + rw [hw,pair_semi_pr v v k k p q] + have he1 : pr (pairW v v) p ≤ 4*b1 := by + have hi := pr_cap (w:=pairW v v) + (pair_cap_aux (unifOn_sub Y).nz unif_subLaw.nz (plus_le_unif h₀) (plus_le_unif h₀)) p + refine hi.trans (mul_le_mul_of_nonneg_left ?_ (by norm_num)) + refine (mixed_cap unif_subLaw unif_subLaw ⊤ (fun _ _ _ => rfl) (fun _ _ _ => rfl) + _ hD _).trans ?_ + dsimp only [b1] + rw [dim,finrank_top,show Module.finrank F (Vec U)=_ from dim_vec _] + have he2 (P P' : Mat U I) : + pr (pairW (k P) (k P')) q ≤ 4*b2 := by + by_cases h : Y P + · by_cases g : Y P' + · let T := ker Pᵀ.mulVecLin ⊓ ker P'ᵀ.mulVecLin + have hh : columnInv (w:=weakMinus C P) T := + fun M A hA => weak_shift P _ _ (hA.trans inf_le_left) + have hh' : columnInv (w:=weakMinus C P') T := + fun M A hA => weak_shift P' _ _ (hA.trans inf_le_right) + have hi := pr_cap (w:=pairW (k P) (k P')) + (pair_cap_aux (unifOn_sub _).nz (v:=weakMinus C P) (unifOn_sub _).nz + (minus_le_weak hc P h hu) (minus_le_weak hc P' g hu)) q + refine hi.trans (mul_le_mul_of_nonneg_left ?_ (by norm_num)) + refine (mixed_cap (unifOn_sub _) (unifOn_sub _) T hh hh' _ hD' M').trans (bp_le ?_) + apply mul_le_mul_of_nonneg_right ?_ (Nat.cast_nonneg _) + exact neg_le_neg (two_kerTr h g) + · have hi := bp_pos (- (num U-2*num I)*num S) + change ¬ Injective _ at g + simp [pr,avg,pairW,k,FramesAt,g,unifOn_val,b2]; exact (bp_pos _).le + · have hi := bp_pos (- (num U-2*num I)*num S) + change ¬ Injective _ at h + simp [pr,avg,pairW,k,FramesAt,h,unifOn_val,b2]; exact (bp_pos _).le + let r := pairW v v + calc avg r (fun x => ind (p x)*pr (pairW (k x.1) (k x.2)) q) + _ ≤ avg r (fun x => ind (p x)*(4*b2)) := + avg_mono (subLaw_pair (unifOn_sub _) (unifOn_sub Y)).nz + (fun x => mul_le_mul_of_nonneg_left (he2 _ _) (ind_nonneg _)) + _ = pr r p * (4*b2) := avg_mul _ _ _ + _ ≤ (4*b1)*(4*b2) := mul_le_mul_of_nonneg_right he1 (mul_nonneg (by norm_num) (bp_pos _).le) + _ = _ := by simp only [sub_eq_add_neg,← neg_mul, bp_add,b1,b2]; ring + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/MixerConditions.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/MixerConditions.lean index fc3e907f1d434072ead96541fde7978a96f428cb..d929110e818d472ea0a148227348e10e2100cd43 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/MixerConditions.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/MixerConditions.lean @@ -1,122 +1,122 @@ -import OAI.Combinatorics.HadwigerCounterexample.MatrixRankCounting -import OAI.Combinatorics.HadwigerCounterexample.CoordinateBlocks -import OAI.Combinatorics.HadwigerCounterexample.MomentLabelSupport - -namespace OAI - -/-! # Mixer Conditions -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix -open scoped BigOperators -variable {p : Shape} {n : ℕ} - -abbrev MIdx (p : Shape) := Fin p.J × Comp p.g × Comp p.g -abbrev MArr (p : Shape) (n : ℕ) := MIdx p → Moment p n -abbrev Draw (p : Shape) (n : ℕ) := - MArr p n × MArr p n × (Fin p.b → Mat (Fin n) (Fin n)) - -def drawn (d : Draw p n) : Mixer p n where - mixL i j k := d.1 (i,j,k) - mixR i j k := d.2.1 (i,j,k) - mixM := d.2.2 - -abbrev MOne (p : Shape) := (MIdx p × Bool) -abbrev MBits (p : Shape) := MOne p × Bool -def orderedM (m : Mixer p n) (i : MOne p) : Moment p n := - if i.2 then m.mixL i.1.1 i.1.2.1 i.1.2.2 else m.mixR i.1.1 i.1.2.1 i.1.2.2 -def eitherM (b : Bool) {I : Type} (A : Mat I I) := if b then A else Aᵀ - -def indexedSum (m : Mixer p n) (c : Vec (MBits p)) := - ∑ i : MBits p,c i • eitherM i.2 (orderedM m i.1) -def selfSum (m : Mixer p n) (f : Vec Bool) := - ∑ i : Bool,f i • eitherM i (selfM p n m.mixM) - -def blockRank (d : Block p.g) (s t : Label p.b) (A : Moment p n) := - (pullM (blockRay p n s d) (blockRay p n t d) A).rank - -def binaryGood (m : Mixer p n) := - ∀ s t : Label p.b,s≠t → - (∀ (c : Vec (MBits p)) (b : Vec Bool),c ≠ 0 → - n ≤ 5*blockRank Block.Z s t (indexedSum m c + selfSum m b)) ∧ - (∀ b : Vec Bool, b≠0 → n ≤ 5*blockRank Block.sharp s t (selfSum m b)) - -/-- Matrix on a point's v coordinates for Tmix(x,atom_l). -/ -def qmix (m : Mixer p n) (x : Profile p n) (l : Tag p.g) : Moment p n := - ∑ j : Fin p.J, ∑ f : TagStar l, ∑ e : Comp p.g, - (liftM (m.mixL j e f.val)ᵀ (m.mixR j e f.val)ᵀ (x e) + - liftM (m.mixL j f.val e) (m.mixR j f.val e) (x e)) - -theorem Tmix_atom (m : Mixer p n) (x : Profile p n) (s : Label p.b) - (z : Base p.g n) (l : Tag p.g) : - Tmix m x (atom p l s z)=mpair (qmix m x l) (mom p s z) := by - classical - let v (i) := atom p l s z i - let q := mom p s z - have h (f : Comp p.g → Moment p n →ₗ[F] F) : - ∑ e, f e (v e) = ∑ e : TagStar l, f e.val q := by - let g e := f e q - have he : - ∑ e, f e (v e) = ∑ e ∈ Finset.univ.filter (fun e => inc e l),g e := by - rw [Finset.sum_filter] - refine Finset.sum_congr rfl fun i _ => ?_ - unfold v - by_cases h : inc i l <;> simp [atom_def,h,q,g] - rw [he] - exact Finset.sum_subtype _ (by simp) g - let L j a b := liftM (m.mixL j a b) (m.mixR j a b) - let R j a b := liftM (m.mixL j a b)ᵀ (m.mixR j a b)ᵀ - have hh (j : Fin p.J) : - ∑ e, ∑ f, mpair (x e) (L j e f (v f)) = - ∑ f : TagStar l, ∑ e, mpair (R j e f.val (x e)) q := by - have he (e : Comp p.g) (f) : mpair (x e) (L j e f (v f)) = - mpair (R j e f (x e)) (v f) := mpair_liftM _ _ _ _ - simp_rw [he] - rw [Finset.sum_comm] - let F f := ∑ e, mpair (R j e f (x e)) - specialize h F - simpa only [F,LinearMap.sum_apply] using h - have hh' (j : Fin p.J) : - ∑ f, ∑ e, mpair (v f) (L j f e (x e)) = - ∑ f : TagStar l, ∑ e, mpair (L j f.val e (x e)) q := by - have he (e f : Comp p.g) : mpair (v f) (L j f e (x e))=mpair (L j f e (x e)) (v f) := - mpair_comm _ _ - simp_rw [he] - let F f := ∑ e, mpair (L j f e (x e)) - specialize h F - simpa only [F,LinearMap.sum_apply] using h - change (∑ j, ∑ e, ∑ f, mpair (x e) (L j e f (v f)))+ - (∑ j, ∑ f, ∑ e,mpair (v f) (L j f e (x e))) = _ - simp_rw [hh,hh'] - simp only [qmix,mpair_sum,mpair_add,Finset.sum_add_distrib] - rfl - -theorem qmix_rank (m : Mixer p n) (x : Profile p n) (l) : - (qmix m x l).rank ≤ p.J*(p.g-1)*(2*totalRank x) := by - let W := 2*totalRank x - let F (j : Fin p.J) (f : TagStar l) (e : Comp p.g) := - liftM (m.mixL j e f.val)ᵀ (m.mixR j e f.val)ᵀ (x e)+ - liftM (m.mixL j f.val e) (m.mixR j f.val e) (x e) - have hh (j : Fin p.J) (f : TagStar l) : (∑ e, F j f e).rank ≤ W := by - have hi (e : Comp p.g) : (F j f e).rank ≤ 2*(x e).rank := by - unfold F; rw [two_mul] - exact (mrk_add_le ..).trans (Nat.add_le_add (rank_lift_le ..) (rank_lift_le ..)) - refine (mrk_sum_le Finset.univ _).trans ((Finset.sum_le_sum fun i _ => hi i).trans_eq ?_) - rw [←Finset.mul_sum]; rfl - have hj j : - (∑ f : TagStar l,∑ e,F j f e).rank ≤ (p.g-1)*W := by - refine (mrk_sum_le Finset.univ _).trans ((Finset.sum_le_sum fun i _ => hh j i).trans_eq ?_) - simp only [Finset.sum_const,Finset.card_univ,card_star,nsmul_eq_mul]; simp - refine (mrk_sum_le Finset.univ _).trans ((Finset.sum_le_sum fun i _ => hj i).trans_eq ?_) - simp [W,mul_assoc] - -def unaryGood (m : Mixer p n) (K s0 : ℕ) := - ∀ (x : Profile p n) (l : Tag p.g) (s : Label p.b), totalRank x ≤ K → totalRank x > 0 → - 2*(p.J-s0) ≤ blockRank Block.Z s s (qmix m x l + (qmix m x l)ᵀ) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.MatrixRankCounting +import OAI.Combinatorics.HadwigerCounterexample.CoordinateBlocks +import OAI.Combinatorics.HadwigerCounterexample.MomentLabelSupport + +namespace OAI + +/-! # Mixer Conditions -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix +open scoped BigOperators +variable {p : Shape} {n : ℕ} + +abbrev MIdx (p : Shape) := Fin p.J × Comp p.g × Comp p.g +abbrev MArr (p : Shape) (n : ℕ) := MIdx p → Moment p n +abbrev Draw (p : Shape) (n : ℕ) := + MArr p n × MArr p n × (Fin p.b → Mat (Fin n) (Fin n)) + +def drawn (d : Draw p n) : Mixer p n where + mixL i j k := d.1 (i,j,k) + mixR i j k := d.2.1 (i,j,k) + mixM := d.2.2 + +abbrev MOne (p : Shape) := (MIdx p × Bool) +abbrev MBits (p : Shape) := MOne p × Bool +def orderedM (m : Mixer p n) (i : MOne p) : Moment p n := + if i.2 then m.mixL i.1.1 i.1.2.1 i.1.2.2 else m.mixR i.1.1 i.1.2.1 i.1.2.2 +def eitherM (b : Bool) {I : Type} (A : Mat I I) := if b then A else Aᵀ + +def indexedSum (m : Mixer p n) (c : Vec (MBits p)) := + ∑ i : MBits p,c i • eitherM i.2 (orderedM m i.1) +def selfSum (m : Mixer p n) (f : Vec Bool) := + ∑ i : Bool,f i • eitherM i (selfM p n m.mixM) + +def blockRank (d : Block p.g) (s t : Label p.b) (A : Moment p n) := + (pullM (blockRay p n s d) (blockRay p n t d) A).rank + +def binaryGood (m : Mixer p n) := + ∀ s t : Label p.b,s≠t → + (∀ (c : Vec (MBits p)) (b : Vec Bool),c ≠ 0 → + n ≤ 5*blockRank Block.Z s t (indexedSum m c + selfSum m b)) ∧ + (∀ b : Vec Bool, b≠0 → n ≤ 5*blockRank Block.sharp s t (selfSum m b)) + +/-- Matrix on a point's v coordinates for Tmix(x,atom_l). -/ +def qmix (m : Mixer p n) (x : Profile p n) (l : Tag p.g) : Moment p n := + ∑ j : Fin p.J, ∑ f : TagStar l, ∑ e : Comp p.g, + (liftM (m.mixL j e f.val)ᵀ (m.mixR j e f.val)ᵀ (x e) + + liftM (m.mixL j f.val e) (m.mixR j f.val e) (x e)) + +theorem Tmix_atom (m : Mixer p n) (x : Profile p n) (s : Label p.b) + (z : Base p.g n) (l : Tag p.g) : + Tmix m x (atom p l s z)=mpair (qmix m x l) (mom p s z) := by + classical + let v (i) := atom p l s z i + let q := mom p s z + have h (f : Comp p.g → Moment p n →ₗ[F] F) : + ∑ e, f e (v e) = ∑ e : TagStar l, f e.val q := by + let g e := f e q + have he : + ∑ e, f e (v e) = ∑ e ∈ Finset.univ.filter (fun e => inc e l),g e := by + rw [Finset.sum_filter] + refine Finset.sum_congr rfl fun i _ => ?_ + unfold v + by_cases h : inc i l <;> simp [atom_def,h,q,g] + rw [he] + exact Finset.sum_subtype _ (by simp) g + let L j a b := liftM (m.mixL j a b) (m.mixR j a b) + let R j a b := liftM (m.mixL j a b)ᵀ (m.mixR j a b)ᵀ + have hh (j : Fin p.J) : + ∑ e, ∑ f, mpair (x e) (L j e f (v f)) = + ∑ f : TagStar l, ∑ e, mpair (R j e f.val (x e)) q := by + have he (e : Comp p.g) (f) : mpair (x e) (L j e f (v f)) = + mpair (R j e f (x e)) (v f) := mpair_liftM _ _ _ _ + simp_rw [he] + rw [Finset.sum_comm] + let F f := ∑ e, mpair (R j e f (x e)) + specialize h F + simpa only [F,LinearMap.sum_apply] using h + have hh' (j : Fin p.J) : + ∑ f, ∑ e, mpair (v f) (L j f e (x e)) = + ∑ f : TagStar l, ∑ e, mpair (L j f.val e (x e)) q := by + have he (e f : Comp p.g) : mpair (v f) (L j f e (x e))=mpair (L j f e (x e)) (v f) := + mpair_comm _ _ + simp_rw [he] + let F f := ∑ e, mpair (L j f e (x e)) + specialize h F + simpa only [F,LinearMap.sum_apply] using h + change (∑ j, ∑ e, ∑ f, mpair (x e) (L j e f (v f)))+ + (∑ j, ∑ f, ∑ e,mpair (v f) (L j f e (x e))) = _ + simp_rw [hh,hh'] + simp only [qmix,mpair_sum,mpair_add,Finset.sum_add_distrib] + rfl + +theorem qmix_rank (m : Mixer p n) (x : Profile p n) (l) : + (qmix m x l).rank ≤ p.J*(p.g-1)*(2*totalRank x) := by + let W := 2*totalRank x + let F (j : Fin p.J) (f : TagStar l) (e : Comp p.g) := + liftM (m.mixL j e f.val)ᵀ (m.mixR j e f.val)ᵀ (x e)+ + liftM (m.mixL j f.val e) (m.mixR j f.val e) (x e) + have hh (j : Fin p.J) (f : TagStar l) : (∑ e, F j f e).rank ≤ W := by + have hi (e : Comp p.g) : (F j f e).rank ≤ 2*(x e).rank := by + unfold F; rw [two_mul] + exact (mrk_add_le ..).trans (Nat.add_le_add (rank_lift_le ..) (rank_lift_le ..)) + refine (mrk_sum_le Finset.univ _).trans ((Finset.sum_le_sum fun i _ => hi i).trans_eq ?_) + rw [←Finset.mul_sum]; rfl + have hj j : + (∑ f : TagStar l,∑ e,F j f e).rank ≤ (p.g-1)*W := by + refine (mrk_sum_le Finset.univ _).trans ((Finset.sum_le_sum fun i _ => hh j i).trans_eq ?_) + simp only [Finset.sum_const,Finset.card_univ,card_star,nsmul_eq_mul]; simp + refine (mrk_sum_le Finset.univ _).trans ((Finset.sum_le_sum fun i _ => hj i).trans_eq ?_) + simp [W,mul_assoc] + +def unaryGood (m : Mixer p n) (K s0 : ℕ) := + ∀ (x : Profile p n) (l : Tag p.g) (s : Label p.b), totalRank x ≤ K → totalRank x > 0 → + 2*(p.J-s0) ≤ blockRank Block.Z s s (qmix m x l + (qmix m x l)ᵀ) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/MixerExistence.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/MixerExistence.lean index 737f2f27e75d675a1297dd97a7e1f8737aa96bf4..a6089ed9e67bb811b5cdfc977ff47cc286b37f44 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/MixerExistence.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/MixerExistence.lean @@ -1,80 +1,80 @@ -import OAI.Combinatorics.HadwigerCounterexample.PolarRankBounds - -namespace OAI - -/-! # Mixer Existence -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Filter -open scoped BigOperators Topology - -theorem polar_likely (p : Shape) (K s0 : ℕ) (hA : profileA p K≤s0) - (hg : 2≤p.g) (hj : s0≤p.J) : - ∀ᶠ n : ℕ in atTop, - pr unif (fun x : Draw p n => ¬unaryGood (drawn x) K s0)<1/4 := by - classical - let A := profileA p K - let U := Tag p.g × Label p.b - let c : ℝ := (prodBound p K+2*K:ℕ) - let b := num U * bp (c*(s0+1)) - have h : Tendsto (fun n:ℕ => b*bp (-(n:ℝ))) atTop (𝓝 0) := by - have h : Tendsto (fun n:ℕ=>bp (-(1:ℝ)*(n:ℝ))) atTop (𝓝 0) := - (bp_tendsto_zero zero_lt_one).comp tendsto_natCast_atTop_atTop - simpa using h.const_mul b - filter_upwards [h.eventually (gt_mem_nhds (show (0:ℝ)<1/4 by norm_num)),profile_count p K] - with n hn hP - let T := {x : Profile p n // totalRank x≤K} - let bad (i : T × U) (d : Draw p n) := urBad K s0 i.1.val i.2.1 i.2.2 d - apply lt_of_le_of_lt (le_trans (pr_mono unif_law.nz ?_) (pr_exists_le _ bad)) - show (∑ i,pr unif (bad i)) < 1/4 - · have hi i : pr unif (bad i) ≤ bp ((c-n)*(s0+1)) := by - have hi := urBad_cap K s0 hg hj (i: T × U).1.val i.2.1 i.2.2 - unfold c; push_cast; exact hi - apply lt_of_le_of_lt (Finset.sum_le_sum (s:=Finset.univ) fun i _ => hi i) - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - apply lt_of_le_of_lt _ hn - change _ ≤ b * bp _ - have hpc : num T ≤ bp (A*n) := by rw [nbr_eq_card] at hP; exact hP - rw [Fintype.card_prod,Nat.cast_mul] - change num T * num U * _ ≤ _ - have hh : (A:ℝ)*n - (s0+1:ℝ)*n ≤ -(n:ℝ) := by - have hx : (A:ℝ) ≤ s0 := by exact_mod_cast hA - have hd := mul_le_mul_of_nonneg_right hx (Nat.cast_nonneg n : (0:ℝ) ≤ n) - linarith only [hd] - have hnum : (0:ℝ) ≤ num U := Nat.cast_nonneg _ - calc num T * num U * bp ((c-n)*(s0+1)) - _ ≤ bp (A*n) * num U * bp ((c-n)*(s0+1)) := - mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hpc hnum) (bp_pos _).le - _ = b * bp ((A:ℝ)*n - (s0+1:ℝ)*n) := by - dsimp only [b] - rw [mul_comm _ (num U),mul_assoc, ← bp_add, mul_assoc, ← bp_add]; ring_nf - _ ≤ _ := mul_le_mul_of_nonneg_left (bp_le hh) (mul_nonneg hnum (bp_pos _).le) - · intro x hx - unfold unaryGood at hx - push Not at hx - obtain ⟨i,l,s,h1,h2,h3⟩ := hx - exact ⟨(⟨i,h1⟩,l,s),h1,h2,h3⟩ - · exact unif_law.nz; - -theorem goodMixers (p : Shape) (K s0 : ℕ) (hg : 2≤p.g) - (hj : 1≤p.j) (h0 : profileA p K≤s0) (hJ : s0≤p.J) : - ∀ᶠ n : ℕ in atTop, - ∃ m : Mixer p n, unaryGood m K s0 ∧ binaryGood m := by - classical - filter_upwards [polar_likely p _ _ h0 hg hJ, binary_likely p hj] with n hn hm - let q (x : Draw p n) := ¬ unaryGood (drawn x) K s0 - let r (x : Draw p n) := ¬ binaryGood (drawn x) - have hh : 0 ¬ (q x ∨ r x)) := by - rw [pr_not,unif_law.total] - have h := pr_or_le (w:=unif) (p:=q) (q:=r) unif_law.nz - change pr unif q<_ at hn; change pr unif r<_ at hm - linarith only [hn,hm,h] - obtain ⟨x,hx,_⟩ := exists_of_pr_pos unif_law.nz hh - unfold q r at hx - exact ⟨drawn (p:=p) x, Classical.not_not.mp (fun h => hx (Or.inl h)), Classical.not_not.mp (fun h => hx (Or.inr h))⟩ -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PolarRankBounds + +namespace OAI + +/-! # Mixer Existence -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Filter +open scoped BigOperators Topology + +theorem polar_likely (p : Shape) (K s0 : ℕ) (hA : profileA p K≤s0) + (hg : 2≤p.g) (hj : s0≤p.J) : + ∀ᶠ n : ℕ in atTop, + pr unif (fun x : Draw p n => ¬unaryGood (drawn x) K s0)<1/4 := by + classical + let A := profileA p K + let U := Tag p.g × Label p.b + let c : ℝ := (prodBound p K+2*K:ℕ) + let b := num U * bp (c*(s0+1)) + have h : Tendsto (fun n:ℕ => b*bp (-(n:ℝ))) atTop (𝓝 0) := by + have h : Tendsto (fun n:ℕ=>bp (-(1:ℝ)*(n:ℝ))) atTop (𝓝 0) := + (bp_tendsto_zero zero_lt_one).comp tendsto_natCast_atTop_atTop + simpa using h.const_mul b + filter_upwards [h.eventually (gt_mem_nhds (show (0:ℝ)<1/4 by norm_num)),profile_count p K] + with n hn hP + let T := {x : Profile p n // totalRank x≤K} + let bad (i : T × U) (d : Draw p n) := urBad K s0 i.1.val i.2.1 i.2.2 d + apply lt_of_le_of_lt (le_trans (pr_mono unif_law.nz ?_) (pr_exists_le _ bad)) + show (∑ i,pr unif (bad i)) < 1/4 + · have hi i : pr unif (bad i) ≤ bp ((c-n)*(s0+1)) := by + have hi := urBad_cap K s0 hg hj (i: T × U).1.val i.2.1 i.2.2 + unfold c; push_cast; exact hi + apply lt_of_le_of_lt (Finset.sum_le_sum (s:=Finset.univ) fun i _ => hi i) + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + apply lt_of_le_of_lt _ hn + change _ ≤ b * bp _ + have hpc : num T ≤ bp (A*n) := by rw [nbr_eq_card] at hP; exact hP + rw [Fintype.card_prod,Nat.cast_mul] + change num T * num U * _ ≤ _ + have hh : (A:ℝ)*n - (s0+1:ℝ)*n ≤ -(n:ℝ) := by + have hx : (A:ℝ) ≤ s0 := by exact_mod_cast hA + have hd := mul_le_mul_of_nonneg_right hx (Nat.cast_nonneg n : (0:ℝ) ≤ n) + linarith only [hd] + have hnum : (0:ℝ) ≤ num U := Nat.cast_nonneg _ + calc num T * num U * bp ((c-n)*(s0+1)) + _ ≤ bp (A*n) * num U * bp ((c-n)*(s0+1)) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hpc hnum) (bp_pos _).le + _ = b * bp ((A:ℝ)*n - (s0+1:ℝ)*n) := by + dsimp only [b] + rw [mul_comm _ (num U),mul_assoc, ← bp_add, mul_assoc, ← bp_add]; ring_nf + _ ≤ _ := mul_le_mul_of_nonneg_left (bp_le hh) (mul_nonneg hnum (bp_pos _).le) + · intro x hx + unfold unaryGood at hx + push Not at hx + obtain ⟨i,l,s,h1,h2,h3⟩ := hx + exact ⟨(⟨i,h1⟩,l,s),h1,h2,h3⟩ + · exact unif_law.nz; + +theorem goodMixers (p : Shape) (K s0 : ℕ) (hg : 2≤p.g) + (hj : 1≤p.j) (h0 : profileA p K≤s0) (hJ : s0≤p.J) : + ∀ᶠ n : ℕ in atTop, + ∃ m : Mixer p n, unaryGood m K s0 ∧ binaryGood m := by + classical + filter_upwards [polar_likely p _ _ h0 hg hJ, binary_likely p hj] with n hn hm + let q (x : Draw p n) := ¬ unaryGood (drawn x) K s0 + let r (x : Draw p n) := ¬ binaryGood (drawn x) + have hh : 0 ¬ (q x ∨ r x)) := by + rw [pr_not,unif_law.total] + have h := pr_or_le (w:=unif) (p:=q) (q:=r) unif_law.nz + change pr unif q<_ at hn; change pr unif r<_ at hm + linarith only [hn,hm,h] + obtain ⟨x,hx,_⟩ := exists_of_pr_pos unif_law.nz hh + unfold q r at hx + exact ⟨drawn (p:=p) x, Classical.not_not.mp (fun h => hx (Or.inl h)), Classical.not_not.mp (fun h => hx (Or.inr h))⟩ +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/MixerProductVariables.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/MixerProductVariables.lean index 2d9245bed547520383c71dd13c5853d3c9c3c354..b1b86c7917a9880c910291adc90d243a755880fa 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/MixerProductVariables.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/MixerProductVariables.lean @@ -1,136 +1,136 @@ -import OAI.Combinatorics.HadwigerCounterexample.RandomBinaryMixing - -namespace OAI - -/-! # Mixer Product Variables -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix -variable {p : Shape} {n : ℕ} {r : Comp p.g → ℕ} - -abbrev Terms (p : Shape) (l : Tag p.g) (r : Comp p.g → ℕ) := - Fin p.J × TagStar l × ((Σ e, Fin (r e)) × Bool) -abbrev Parts (p : Shape) (n : ℕ) (r : Comp p.g → ℕ) := - ∀ e, Mat (Row p n) (Fin (r e)) - -def formCol (P : Parts p n r) (l : Tag p.g) (d : MArr p n) : - Mat (Row p n) (Terms p l r) := - Matrix.of (fun i => - fun ⟨j,f,⟨e,k⟩,b⟩ => - (if b then (d (j,e,f.val))ᵀ * P e else d (j,f.val,e) * P e) i k) - -theorem formCol_true (P : Parts p n r) (l : Tag p.g) (d : MArr p n) - (i j f e k) : - formCol P l d i (j,f,⟨e,k⟩,true)=((d (j,e,f.val))ᵀ * P e) i k := by simp [formCol] -theorem formCol_false (P : Parts p n r) (l : Tag p.g) (d : MArr p n) - (i j f e k) : - formCol P l d i (j,f,⟨e,k⟩,false)=(d (j,f.val,e) * P e) i k := by simp [formCol] - -theorem qmix_eq (P Q : Parts p n r) (l : Tag p.g) (d : Draw p n) {x : Profile p n} - (hx : ∀ e, x e=P e*(Q e)ᵀ) : - qmix (drawn d) x l=formCol P l d.1 * (formCol Q l d.2.1)ᵀ := by - classical - have h (j : Fin p.J) (f : TagStar l) (e) (L R : Moment p n) : - liftM L R (x e) = L*P e * (R*Q e)ᵀ := by - rw [liftM_def,hx] - simp only [Matrix.mul_assoc,transpose_mul] - ext i k - let A := formCol P l d.1 - let B := formCol Q l d.2.1 - change _ = ∑ t : Terms p l r, A i t*B k t - unfold qmix - simp_rw [Matrix.sum_apply, Fintype.sum_prod_type, Fintype.sum_sigma] - refine Finset.sum_congr rfl fun j _ => Finset.sum_congr rfl fun f _ => Finset.sum_congr rfl - fun e _ => ?_ - simp_rw [Matrix.add_apply,h j f] - let a := (drawn d).mixL j e f.val - let b := (drawn d).mixR j e f.val - let a' := (drawn d).mixL j f.val e - let b' := (drawn d).mixR j f.val e - change (∑ t, (aᵀ * P e) i t * (bᵀ * Q e) k t)+ - (∑ t, (a' * P e) i t * (b' * Q e) k t) = _ - rw [←Finset.sum_add_distrib]; refine Finset.sum_congr rfl fun t _ => ?_ - rw [Fintype.sum_bool]; rfl - -theorem formCol_add (P : Parts p n r) (l : Tag p.g) (d d' : MArr p n) : - formCol P l (d+d') = formCol P l d + formCol P l d' := by - ext i j; rcases j with ⟨j,f,⟨e,k⟩,_|_⟩ - · simp only [Matrix.add_apply, formCol_false,Pi.add_apply,Matrix.add_mul] - · simp only [Matrix.add_apply, formCol_true,Pi.add_apply,Matrix.add_mul, Matrix.transpose_add] -theorem formCol_smul (P : Parts p n r) (l : Tag p.g) (a : F) (d : MArr p n) : - formCol P l (a•d) = a • formCol P l d := by - ext i j; rcases j with ⟨j,f,⟨e,k⟩,_|_⟩ - · simp only [Matrix.smul_apply, formCol_false,Pi.smul_apply,Matrix.smul_mul] - · simp only [Matrix.smul_apply, formCol_true,Pi.smul_apply,Matrix.smul_mul, - Matrix.transpose_smul] - -variable {U : Type} - -/-- Stacked evaluation of all columns on a batch of free directions. -/ -def stackL (P Q : Parts p n r) (l : Tag p.g) (W : Mat (Row p n) U) : - Draw p n →ₗ[F] Mat U (Terms p l r ⊕ Terms p l r) where - toFun d := Wᵀ * fromCols (formCol P l d.1) (formCol Q l d.2.1) - map_add' d d' := by - simp only [Prod.fst_add,Prod.snd_add,formCol_add,mul_fromCols, Matrix.mul_add] - ext i j; cases j <;> rfl - map_smul' v d := by - simp only [Prod.smul_fst,Prod.smul_snd,formCol_smul,mul_fromCols,RingHom.id_apply, - Matrix.mul_smul] - ext i j; cases j <;> rfl - -variable [Fintype U] - -/-- Well away from the profile factors all the formal variables from a given -side can be specified independently. -/ -theorem formCol_onto (P : Parts p n r) (l : Tag p.g) (W : Mat (Row p n) U) - (hw : Function.Injective W.mulVec) - (hP : ∀ i, Function.Injective (P i).mulVec) - (h : ∀ i, Disjoint (colSp (P i)) (colSp W)) - (A : Mat U (Terms p l r)) : - ∃ d : MArr p n, Wᵀ * formCol P l d=A := by - classical - let tgt (b : Bool) (j : Fin p.J) (e f : Comp p.g) : - Mat (Fin (r e)) U := - if h : inc f l then Matrix.of (fun k i => A i (j,⟨f,h⟩,⟨e,k⟩,b)) else 0 - have ho (j : Fin p.J) (e f : Comp p.g) : - ∃ L : Moment p n, (P e)ᵀ * L * W=tgt true j e f ∧ - (P f)ᵀ * Lᵀ * W=tgt false j f e := - prescribe_opposite (inj_fromCols (hP _) hw (h e)) (inj_fromCols hw (hP _) (h f).symm) _ _ - choose D hD hd using ho - let d : MArr p n := fun ⟨j,e,f⟩ => D j e f - refine ⟨d,?_⟩ - ext i j - rcases j with ⟨j,f,⟨e,k⟩,_|_⟩ - · have he : Wᵀ * (D j f e * P e)=(tgt false j e f.val)ᵀ := by - rw [← hd]; simp only [transpose_mul,transpose_transpose] - change ∑ q, Wᵀ i q * formCol P l d q (j,f,⟨e,k⟩,false) = _ - simp only [formCol_false] - change (Wᵀ*(D j f e * P e)) i k=_ - rw [he]; simp [tgt,f.property] - · have he : Wᵀ*((D j e f)ᵀ*P e)=(tgt true j e f.val)ᵀ := by - rw [← hD]; simp only [transpose_mul,transpose_transpose] - change ∑ q, Wᵀ i q * formCol P l d q (j,f,⟨e,k⟩,true) = _ - simp only [formCol_true] - change (Wᵀ*((D j e f)ᵀ*P e)) i k=_ - rw [he]; simp [tgt,f.property] - -theorem stack_surj (P Q : Parts p n r) (l : Tag p.g) (W : Mat (Row p n) U) - (hw : Function.Injective W.mulVec) - (hP : ∀ i, Function.Injective (P i).mulVec) (hQ : ∀ i, Function.Injective (Q i).mulVec) - (h1 : ∀ i, Disjoint (colSp (P i)) (colSp W)) - (h2 : ∀ i, Disjoint (colSp (Q i)) (colSp W)) : - Function.Surjective (stackL P Q l W) := by - intro A - obtain ⟨d,hd⟩ := formCol_onto P l W hw hP h1 A.toCols₁ - obtain ⟨f,hf⟩ := formCol_onto Q l W hw hQ h2 A.toCols₂ - refine ⟨(d,f,0),?_⟩ - change Wᵀ * fromCols (formCol P l d) (formCol Q l f)=_ - rw [mul_fromCols,hd,hf,fromCols_toCols] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RandomBinaryMixing + +namespace OAI + +/-! # Mixer Product Variables -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix +variable {p : Shape} {n : ℕ} {r : Comp p.g → ℕ} + +abbrev Terms (p : Shape) (l : Tag p.g) (r : Comp p.g → ℕ) := + Fin p.J × TagStar l × ((Σ e, Fin (r e)) × Bool) +abbrev Parts (p : Shape) (n : ℕ) (r : Comp p.g → ℕ) := + ∀ e, Mat (Row p n) (Fin (r e)) + +def formCol (P : Parts p n r) (l : Tag p.g) (d : MArr p n) : + Mat (Row p n) (Terms p l r) := + Matrix.of (fun i => + fun ⟨j,f,⟨e,k⟩,b⟩ => + (if b then (d (j,e,f.val))ᵀ * P e else d (j,f.val,e) * P e) i k) + +theorem formCol_true (P : Parts p n r) (l : Tag p.g) (d : MArr p n) + (i j f e k) : + formCol P l d i (j,f,⟨e,k⟩,true)=((d (j,e,f.val))ᵀ * P e) i k := by simp [formCol] +theorem formCol_false (P : Parts p n r) (l : Tag p.g) (d : MArr p n) + (i j f e k) : + formCol P l d i (j,f,⟨e,k⟩,false)=(d (j,f.val,e) * P e) i k := by simp [formCol] + +theorem qmix_eq (P Q : Parts p n r) (l : Tag p.g) (d : Draw p n) {x : Profile p n} + (hx : ∀ e, x e=P e*(Q e)ᵀ) : + qmix (drawn d) x l=formCol P l d.1 * (formCol Q l d.2.1)ᵀ := by + classical + have h (j : Fin p.J) (f : TagStar l) (e) (L R : Moment p n) : + liftM L R (x e) = L*P e * (R*Q e)ᵀ := by + rw [liftM_def,hx] + simp only [Matrix.mul_assoc,transpose_mul] + ext i k + let A := formCol P l d.1 + let B := formCol Q l d.2.1 + change _ = ∑ t : Terms p l r, A i t*B k t + unfold qmix + simp_rw [Matrix.sum_apply, Fintype.sum_prod_type, Fintype.sum_sigma] + refine Finset.sum_congr rfl fun j _ => Finset.sum_congr rfl fun f _ => Finset.sum_congr rfl + fun e _ => ?_ + simp_rw [Matrix.add_apply,h j f] + let a := (drawn d).mixL j e f.val + let b := (drawn d).mixR j e f.val + let a' := (drawn d).mixL j f.val e + let b' := (drawn d).mixR j f.val e + change (∑ t, (aᵀ * P e) i t * (bᵀ * Q e) k t)+ + (∑ t, (a' * P e) i t * (b' * Q e) k t) = _ + rw [←Finset.sum_add_distrib]; refine Finset.sum_congr rfl fun t _ => ?_ + rw [Fintype.sum_bool]; rfl + +theorem formCol_add (P : Parts p n r) (l : Tag p.g) (d d' : MArr p n) : + formCol P l (d+d') = formCol P l d + formCol P l d' := by + ext i j; rcases j with ⟨j,f,⟨e,k⟩,_|_⟩ + · simp only [Matrix.add_apply, formCol_false,Pi.add_apply,Matrix.add_mul] + · simp only [Matrix.add_apply, formCol_true,Pi.add_apply,Matrix.add_mul, Matrix.transpose_add] +theorem formCol_smul (P : Parts p n r) (l : Tag p.g) (a : F) (d : MArr p n) : + formCol P l (a•d) = a • formCol P l d := by + ext i j; rcases j with ⟨j,f,⟨e,k⟩,_|_⟩ + · simp only [Matrix.smul_apply, formCol_false,Pi.smul_apply,Matrix.smul_mul] + · simp only [Matrix.smul_apply, formCol_true,Pi.smul_apply,Matrix.smul_mul, + Matrix.transpose_smul] + +variable {U : Type} + +/-- Stacked evaluation of all columns on a batch of free directions. -/ +def stackL (P Q : Parts p n r) (l : Tag p.g) (W : Mat (Row p n) U) : + Draw p n →ₗ[F] Mat U (Terms p l r ⊕ Terms p l r) where + toFun d := Wᵀ * fromCols (formCol P l d.1) (formCol Q l d.2.1) + map_add' d d' := by + simp only [Prod.fst_add,Prod.snd_add,formCol_add,mul_fromCols, Matrix.mul_add] + ext i j; cases j <;> rfl + map_smul' v d := by + simp only [Prod.smul_fst,Prod.smul_snd,formCol_smul,mul_fromCols,RingHom.id_apply, + Matrix.mul_smul] + ext i j; cases j <;> rfl + +variable [Fintype U] + +/-- Well away from the profile factors all the formal variables from a given +side can be specified independently. -/ +theorem formCol_onto (P : Parts p n r) (l : Tag p.g) (W : Mat (Row p n) U) + (hw : Function.Injective W.mulVec) + (hP : ∀ i, Function.Injective (P i).mulVec) + (h : ∀ i, Disjoint (colSp (P i)) (colSp W)) + (A : Mat U (Terms p l r)) : + ∃ d : MArr p n, Wᵀ * formCol P l d=A := by + classical + let tgt (b : Bool) (j : Fin p.J) (e f : Comp p.g) : + Mat (Fin (r e)) U := + if h : inc f l then Matrix.of (fun k i => A i (j,⟨f,h⟩,⟨e,k⟩,b)) else 0 + have ho (j : Fin p.J) (e f : Comp p.g) : + ∃ L : Moment p n, (P e)ᵀ * L * W=tgt true j e f ∧ + (P f)ᵀ * Lᵀ * W=tgt false j f e := + prescribe_opposite (inj_fromCols (hP _) hw (h e)) (inj_fromCols hw (hP _) (h f).symm) _ _ + choose D hD hd using ho + let d : MArr p n := fun ⟨j,e,f⟩ => D j e f + refine ⟨d,?_⟩ + ext i j + rcases j with ⟨j,f,⟨e,k⟩,_|_⟩ + · have he : Wᵀ * (D j f e * P e)=(tgt false j e f.val)ᵀ := by + rw [← hd]; simp only [transpose_mul,transpose_transpose] + change ∑ q, Wᵀ i q * formCol P l d q (j,f,⟨e,k⟩,false) = _ + simp only [formCol_false] + change (Wᵀ*(D j f e * P e)) i k=_ + rw [he]; simp [tgt,f.property] + · have he : Wᵀ*((D j e f)ᵀ*P e)=(tgt true j e f.val)ᵀ := by + rw [← hD]; simp only [transpose_mul,transpose_transpose] + change ∑ q, Wᵀ i q * formCol P l d q (j,f,⟨e,k⟩,true) = _ + simp only [formCol_true] + change (Wᵀ*((D j e f)ᵀ*P e)) i k=_ + rw [he]; simp [tgt,f.property] + +theorem stack_surj (P Q : Parts p n r) (l : Tag p.g) (W : Mat (Row p n) U) + (hw : Function.Injective W.mulVec) + (hP : ∀ i, Function.Injective (P i).mulVec) (hQ : ∀ i, Function.Injective (Q i).mulVec) + (h1 : ∀ i, Disjoint (colSp (P i)) (colSp W)) + (h2 : ∀ i, Disjoint (colSp (Q i)) (colSp W)) : + Function.Surjective (stackL P Q l W) := by + intro A + obtain ⟨d,hd⟩ := formCol_onto P l W hw hP h1 A.toCols₁ + obtain ⟨f,hf⟩ := formCol_onto Q l W hw hQ h2 A.toCols₂ + refine ⟨(d,f,0),?_⟩ + change Wᵀ * fromCols (formCol P l d) (formCol Q l f)=_ + rw [mul_fromCols,hd,hf,fromCols_toCols] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/MomentCoordinates.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/MomentCoordinates.lean index 30dfc857745a392635e7af09893ee5f888081d4e..9f07a0dd96602d2cf2f85ff30dd0a37ced667d8e 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/MomentCoordinates.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/MomentCoordinates.lean @@ -1,171 +1,171 @@ -import OAI.Combinatorics.HadwigerCounterexample.ComponentIndices -import OAI.Combinatorics.HadwigerCounterexample.BinaryMatrices -import Mathlib.Data.Fintype.Powerset -import Mathlib.Data.Fintype.Option - -namespace OAI - -/-! # Moment Coordinates -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Finset - -/-- Construction parameters that affect dimensions (except n,N). j = selector degree; -r = number of ordered tester pairs in a tester. J, h mix and channel indices. -/ -structure Shape where - g : ℕ - b : ℕ - j : ℕ - J : ℕ - r : ℕ - h : ℕ - -abbrev Block (g : ℕ) := (Tag g × Tag g) ⊕ Fin 3 -namespace Block -variable {g : ℕ} -abbrev O (d t : Tag g) : Block g := .inl (d,t) -abbrev S : Block g := .inr 0 -abbrev sharp : Block g := .inr 1 -abbrev Z : Block g := .inr 2 -end Block - -abbrev BaseIdx (g n : ℕ) := Block g × Fin n -abbrev Base (g n : ℕ) := Vec (BaseIdx g n) -abbrev AIdx (g n : ℕ) := Option (BaseIdx g n) -abbrev Label (b : ℕ) := Vec (Fin b) -abbrev SelIdx (b j : ℕ) := { m : Finset (Fin b) // m.card ≤ j } -abbrev Row (p : Shape) (n : ℕ) := SelIdx p.b p.j × AIdx p.g n -abbrev Ray (p : Shape) (n : ℕ) := Vec (Row p n) -abbrev Moment (p : Shape) (n : ℕ) := Mat (Row p n) (Row p n) - -theorem card_baseIdx (g n : ℕ) : Fintype.card (BaseIdx g n) = (g*g+3)*n := by - simp [BaseIdx,Block,Tag] - -def psize (p : Shape) := Fintype.card (SelIdx p.b p.j) -theorem card_row (p : Shape) (n : ℕ) : - Fintype.card (Row p n) = psize p * (1 + (p.g*p.g+3)*n) := by - simp [Row,AIdx,psize,add_comm] - -def emptySel {b j} : SelIdx b j := ⟨∅,by simp⟩ -def selV {b} (j) (s : Label b) : Vec (SelIdx b j) := fun x => ∏ i ∈ x.val, s i -def baseV {g n} (z : Base g n) : Vec (AIdx g n) := Option.elim' 1 z - -variable (p : Shape) -variable {n : ℕ} - -/-- Embedding of the affine coordinate space at a fixed label. -/ -def putLab (n : ℕ) (s : Label p.b) : Vec (AIdx p.g n) →ₗ[F] Ray p n where - toFun z r := selV p.j s r.1 * z r.2 - map_add' z w := by ext; simp only [Pi.add_apply,mul_add] - map_smul' b z := by ext; simp only [Pi.smul_apply,RingHom.id_apply,smul_eq_mul]; ring - -def point (s : Label p.b) (z : Base p.g n) : Ray p n := putLab p n s (baseV z) -def mom (s : Label p.b) (z : Base p.g n) : Moment p n := vecMulVec (point p s z) (point p s z) - -theorem point_base_eval (s : Label p.b) (z : Base p.g n) (r : AIdx p.g n) : - point p s z (emptySel,r) = baseV z r := by simp [point,putLab,selV,emptySel] - -theorem point_ne_zero (s : Label p.b) (z : Base p.g n) : point p s z ≠ 0 := by - intro h - have := point_base_eval p s z none - rw [h] at this - simp [baseV] at this - -def Wspace (n : ℕ) : Space (Moment p n) := - Submodule.span F {m | ∃ s z, m = mom p s z} - -/-- O-blocks disallowed at l are set to zero. -/ -def allows {g n} (l : Tag g) (z : Base g n) := - ∀ d t : Tag g, ¬ allowed d l → ∀ i : Fin n, z (Block.O d t,i) = 0 - -def shared {g n} (z : Base g n) := - ∀ d t : Tag g, ∀ i : Fin n, z (Block.O d t,i) = 0 - -def Wtag (n : ℕ) (l : Tag p.g) : Space (Moment p n) := - Submodule.span F {m | ∃ s z, allows l z ∧ m = mom p s z} - -def Wstar (n : ℕ) : Space (Moment p n) := - Submodule.span F {m | ∃ s z, shared z ∧ m = mom p s z} - -variable {p} - -theorem Wstar_le_tag (l : Tag p.g) : Wstar p n ≤ Wtag p n l := - Submodule.span_mono (by rintro m ⟨s,z,h,rfl⟩; exact ⟨s,z,fun d t _ => h d t,rfl⟩) -theorem Wtag_le (l : Tag p.g) : Wtag p n l ≤ Wspace p n := - Submodule.span_mono (by rintro m ⟨s,z,h,rfl⟩; exact ⟨s,z,rfl⟩) - -theorem Wspace_sym {m : Moment p n} (h : m ∈ Wspace p n) : mᵀ = m := by - unfold Wspace at h - induction h using Submodule.span_induction with - | mem m hm => obtain ⟨s,z,rfl⟩ := hm; rw [mom,transpose_vecMulVec] - | zero => simp - | add x y _ _ hx hy => rw [transpose_add,hx,hy] - | smul b x _ hx => rw [transpose_smul,hx] - -/-- Cut profiles in the direct sum over unordered components. -/ -abbrev Profile (p : Shape) (n : ℕ) := Comp p.g → Moment p n -def cut (p : Shape) (n : ℕ) : (Tag p.g → Moment p n) →ₗ[F] Profile p n where - toFun w e := w e.val.1 + w e.val.2 - map_add' w w' := by - funext e - simp only [Pi.add_apply] - ac_rfl - map_smul' b w := by funext; simp only [Pi.smul_apply, RingHom.id_apply, smul_add] - -def Xspace (p : Shape) (n : ℕ) : Space (Profile p n) := - (Submodule.pi Set.univ (fun l => Wtag p n l)).map (cut p n) - -theorem mem_X {x : Profile p n} : - x ∈ Xspace p n ↔ ∃ w : Tag p.g → Moment p n, (∀ l, w l ∈ Wtag p n l) ∧ cut p n w = x := - Submodule.mem_map.trans (by simp [Submodule.mem_pi]) - -/-- For complete generality this returns zero on pairs with equal tags. -/ -def getPair (p : Shape) (n : ℕ) (l d : Tag p.g) : Profile p n →ₗ[F] Moment p n := - if h : l ≠ d then LinearMap.proj (edge l d h) else 0 - -theorem getPair_edge (l d : Tag p.g) (h : l ≠ d) (x : Profile p n) : - getPair p n l d x = x (edge l d h) := by rw [getPair,dite_eq_left h]; rfl - -theorem getPair_cut (w : Tag p.g → Moment p n) (l d : Tag p.g) : - getPair p n l d (cut p n w) = w l + w d := by - by_cases h : l = d - · subst l; rw [getPair,dite_eq_right, LinearMap.zero_apply,char_two]; simp - · rw [getPair_edge _ _ h] - change w _ + w _ = _ - rcases lt_or_gt_of_ne h with e|e - · rw [edge_eq e] - · rw [edge_symm,edge_eq e,add_comm] - -/-- Single star atoms as profiles in ambient coordinates. -/ -def atom (p : Shape) (l : Tag p.g) (s : Label p.b) (z : Base p.g n) : Profile p n := - cut p n (Pi.single l (mom p s z)) - -theorem atom_mem {l} {z : Base p.g n} (s : Label p.b) (h : allows l z) : - atom p l s z ∈ Xspace p n := by - rw [mem_X] - refine ⟨Pi.single l (mom p s z),fun i => ?_,rfl⟩ - by_cases e : l = i - · subst i - rw [Pi.single_eq_same] - exact Submodule.subset_span ⟨s,z,h,rfl⟩ - · simp [Pi.single_eq_of_ne (Ne.symm e)] - -theorem atom_def (l : Tag p.g) (s : Label p.b) (z : Base p.g n) (e) : - atom p l s z e = if inc e l then mom p s z else 0 := by - change (Pi.single l (mom p s z) : Tag p.g → Moment p n) e.val.1 + - (Pi.single l (mom p s z) : Tag p.g → Moment p n) e.val.2 = _ - by_cases h : e.val.1 = l - · have h' : e.val.2 ≠ l := h ▸ e.property.ne.symm - rw [Pi.single_eq_of_ne h',ite_eq_left (show inc e l from Or.inl h)] - rw [h, Pi.single_eq_same,add_zero] - by_cases h' : e.val.2 = l - · rw [Pi.single_eq_of_ne h,ite_eq_left (show inc e l from Or.inr h'),h',Pi.single_eq_same,zero_add] - rw [Pi.single_eq_of_ne h,Pi.single_eq_of_ne h',add_zero,ite_eq_right (by simp [inc,h,h'])] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ComponentIndices +import OAI.Combinatorics.HadwigerCounterexample.BinaryMatrices +import Mathlib.Data.Fintype.Powerset +import Mathlib.Data.Fintype.Option + +namespace OAI + +/-! # Moment Coordinates -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Finset + +/-- Construction parameters that affect dimensions (except n,N). j = selector degree; +r = number of ordered tester pairs in a tester. J, h mix and channel indices. -/ +structure Shape where + g : ℕ + b : ℕ + j : ℕ + J : ℕ + r : ℕ + h : ℕ + +abbrev Block (g : ℕ) := (Tag g × Tag g) ⊕ Fin 3 +namespace Block +variable {g : ℕ} +abbrev O (d t : Tag g) : Block g := .inl (d,t) +abbrev S : Block g := .inr 0 +abbrev sharp : Block g := .inr 1 +abbrev Z : Block g := .inr 2 +end Block + +abbrev BaseIdx (g n : ℕ) := Block g × Fin n +abbrev Base (g n : ℕ) := Vec (BaseIdx g n) +abbrev AIdx (g n : ℕ) := Option (BaseIdx g n) +abbrev Label (b : ℕ) := Vec (Fin b) +abbrev SelIdx (b j : ℕ) := { m : Finset (Fin b) // m.card ≤ j } +abbrev Row (p : Shape) (n : ℕ) := SelIdx p.b p.j × AIdx p.g n +abbrev Ray (p : Shape) (n : ℕ) := Vec (Row p n) +abbrev Moment (p : Shape) (n : ℕ) := Mat (Row p n) (Row p n) + +theorem card_baseIdx (g n : ℕ) : Fintype.card (BaseIdx g n) = (g*g+3)*n := by + simp [BaseIdx,Block,Tag] + +def psize (p : Shape) := Fintype.card (SelIdx p.b p.j) +theorem card_row (p : Shape) (n : ℕ) : + Fintype.card (Row p n) = psize p * (1 + (p.g*p.g+3)*n) := by + simp [Row,AIdx,psize,add_comm] + +def emptySel {b j} : SelIdx b j := ⟨∅,by simp⟩ +def selV {b} (j) (s : Label b) : Vec (SelIdx b j) := fun x => ∏ i ∈ x.val, s i +def baseV {g n} (z : Base g n) : Vec (AIdx g n) := Option.elim' 1 z + +variable (p : Shape) +variable {n : ℕ} + +/-- Embedding of the affine coordinate space at a fixed label. -/ +def putLab (n : ℕ) (s : Label p.b) : Vec (AIdx p.g n) →ₗ[F] Ray p n where + toFun z r := selV p.j s r.1 * z r.2 + map_add' z w := by ext; simp only [Pi.add_apply,mul_add] + map_smul' b z := by ext; simp only [Pi.smul_apply,RingHom.id_apply,smul_eq_mul]; ring + +def point (s : Label p.b) (z : Base p.g n) : Ray p n := putLab p n s (baseV z) +def mom (s : Label p.b) (z : Base p.g n) : Moment p n := vecMulVec (point p s z) (point p s z) + +theorem point_base_eval (s : Label p.b) (z : Base p.g n) (r : AIdx p.g n) : + point p s z (emptySel,r) = baseV z r := by simp [point,putLab,selV,emptySel] + +theorem point_ne_zero (s : Label p.b) (z : Base p.g n) : point p s z ≠ 0 := by + intro h + have := point_base_eval p s z none + rw [h] at this + simp [baseV] at this + +def Wspace (n : ℕ) : Space (Moment p n) := + Submodule.span F {m | ∃ s z, m = mom p s z} + +/-- O-blocks disallowed at l are set to zero. -/ +def allows {g n} (l : Tag g) (z : Base g n) := + ∀ d t : Tag g, ¬ allowed d l → ∀ i : Fin n, z (Block.O d t,i) = 0 + +def shared {g n} (z : Base g n) := + ∀ d t : Tag g, ∀ i : Fin n, z (Block.O d t,i) = 0 + +def Wtag (n : ℕ) (l : Tag p.g) : Space (Moment p n) := + Submodule.span F {m | ∃ s z, allows l z ∧ m = mom p s z} + +def Wstar (n : ℕ) : Space (Moment p n) := + Submodule.span F {m | ∃ s z, shared z ∧ m = mom p s z} + +variable {p} + +theorem Wstar_le_tag (l : Tag p.g) : Wstar p n ≤ Wtag p n l := + Submodule.span_mono (by rintro m ⟨s,z,h,rfl⟩; exact ⟨s,z,fun d t _ => h d t,rfl⟩) +theorem Wtag_le (l : Tag p.g) : Wtag p n l ≤ Wspace p n := + Submodule.span_mono (by rintro m ⟨s,z,h,rfl⟩; exact ⟨s,z,rfl⟩) + +theorem Wspace_sym {m : Moment p n} (h : m ∈ Wspace p n) : mᵀ = m := by + unfold Wspace at h + induction h using Submodule.span_induction with + | mem m hm => obtain ⟨s,z,rfl⟩ := hm; rw [mom,transpose_vecMulVec] + | zero => simp + | add x y _ _ hx hy => rw [transpose_add,hx,hy] + | smul b x _ hx => rw [transpose_smul,hx] + +/-- Cut profiles in the direct sum over unordered components. -/ +abbrev Profile (p : Shape) (n : ℕ) := Comp p.g → Moment p n +def cut (p : Shape) (n : ℕ) : (Tag p.g → Moment p n) →ₗ[F] Profile p n where + toFun w e := w e.val.1 + w e.val.2 + map_add' w w' := by + funext e + simp only [Pi.add_apply] + ac_rfl + map_smul' b w := by funext; simp only [Pi.smul_apply, RingHom.id_apply, smul_add] + +def Xspace (p : Shape) (n : ℕ) : Space (Profile p n) := + (Submodule.pi Set.univ (fun l => Wtag p n l)).map (cut p n) + +theorem mem_X {x : Profile p n} : + x ∈ Xspace p n ↔ ∃ w : Tag p.g → Moment p n, (∀ l, w l ∈ Wtag p n l) ∧ cut p n w = x := + Submodule.mem_map.trans (by simp [Submodule.mem_pi]) + +/-- For complete generality this returns zero on pairs with equal tags. -/ +def getPair (p : Shape) (n : ℕ) (l d : Tag p.g) : Profile p n →ₗ[F] Moment p n := + if h : l ≠ d then LinearMap.proj (edge l d h) else 0 + +theorem getPair_edge (l d : Tag p.g) (h : l ≠ d) (x : Profile p n) : + getPair p n l d x = x (edge l d h) := by rw [getPair,dite_eq_left h]; rfl + +theorem getPair_cut (w : Tag p.g → Moment p n) (l d : Tag p.g) : + getPair p n l d (cut p n w) = w l + w d := by + by_cases h : l = d + · subst l; rw [getPair,dite_eq_right, LinearMap.zero_apply,char_two]; simp + · rw [getPair_edge _ _ h] + change w _ + w _ = _ + rcases lt_or_gt_of_ne h with e|e + · rw [edge_eq e] + · rw [edge_symm,edge_eq e,add_comm] + +/-- Single star atoms as profiles in ambient coordinates. -/ +def atom (p : Shape) (l : Tag p.g) (s : Label p.b) (z : Base p.g n) : Profile p n := + cut p n (Pi.single l (mom p s z)) + +theorem atom_mem {l} {z : Base p.g n} (s : Label p.b) (h : allows l z) : + atom p l s z ∈ Xspace p n := by + rw [mem_X] + refine ⟨Pi.single l (mom p s z),fun i => ?_,rfl⟩ + by_cases e : l = i + · subst i + rw [Pi.single_eq_same] + exact Submodule.subset_span ⟨s,z,h,rfl⟩ + · simp [Pi.single_eq_of_ne (Ne.symm e)] + +theorem atom_def (l : Tag p.g) (s : Label p.b) (z : Base p.g n) (e) : + atom p l s z e = if inc e l then mom p s z else 0 := by + change (Pi.single l (mom p s z) : Tag p.g → Moment p n) e.val.1 + + (Pi.single l (mom p s z) : Tag p.g → Moment p n) e.val.2 = _ + by_cases h : e.val.1 = l + · have h' : e.val.2 ≠ l := h ▸ e.property.ne.symm + rw [Pi.single_eq_of_ne h',ite_eq_left (show inc e l from Or.inl h)] + rw [h, Pi.single_eq_same,add_zero] + by_cases h' : e.val.2 = l + · rw [Pi.single_eq_of_ne h,ite_eq_left (show inc e l from Or.inr h'),h',Pi.single_eq_same,zero_add] + rw [Pi.single_eq_of_ne h,Pi.single_eq_of_ne h',add_zero,ite_eq_right (by simp [inc,h,h'])] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/MomentLabelSupport.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/MomentLabelSupport.lean index 0e912dc0908c109bae6f572aef0032001cab74d0..26f2fbf97f906cfd3214e2be8802435a8ee09242 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/MomentLabelSupport.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/MomentLabelSupport.lean @@ -1,184 +1,184 @@ -import OAI.Combinatorics.HadwigerCounterexample.FlatRankLevels - -namespace OAI - -/-! # Moment Label Support -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Finset -open scoped BigOperators -variable {p : Shape} {n k : ℕ} - -/-- Zero extension by the Boolean union rule for low rank matrices. -/ -theorem zero_extension {M : Moment p n} (hh : hankel M) (hr : M.rank≤k) - (hk : k≤p.j) (hg : atLayer M hk=0) : M=0 := by - classical - by_contra he - let D (r : ℕ) := ∃ i j : Row p n,M i j≠0 ∧ (i.1.val∪j.1.val).card=r - have hD : ∃ r,D r := by - by_contra! h - refine he (Matrix.ext fun i j => ?_) - exact Classical.byContradiction fun g => h _ ⟨i,j,g,rfl⟩ - obtain ⟨x,y,hxy,hw⟩ := Nat.find_spec hD - let U := x.1.val∪y.1.val - let d := U.card - have hd : k (⟨i.val, (hi i).2 ▸ (show t≤p.j by - unfold t; omega)⟩, x.2) - let g : T → Row p n := fun i => (⟨U\i.val, hs i⟩,y.2) - have hf : M.submatrix f g=1 := by - ext i j - by_cases e : i = j - · subst j - rw [Matrix.one_apply_eq] - change M _ _=_ - have hU : M (f i) (g i)=M x y := - hh x.2 y.2 _ _ x.1 y.1 (Finset.union_sdiff_of_subset (hi i).1) - rw [hU]; exact (bit_cases _).resolve_left hxy - rw [Matrix.one_apply_ne e] - change M (f i) (g j)=0 - by_contra H - have hl := Nat.find_min' hD (show D _ from ⟨f i,g j,H,rfl⟩) - rw [← hw] at hl - change d ≤ (i.val ∪ (U \ j.val)).card at hl - have heq : i.val∪(U \ j.val) = U := - Finset.eq_of_subset_of_card_le (union_subset (hi i).1 sdiff_subset) hl - have hsub : j.val⊆i.val := by - intro a ha - have hj := (hi j).1 ha - rw [← heq] at hj - exact (mem_union.mp hj).resolve_right (fun h => (mem_sdiff.mp h).2 ha) - exact e (Subtype.ext (Finset.eq_of_subset_of_card_le hsub - (by rw [(hi i).2,(hi j).2])).symm) - have hK := M.rank_submatrix_le f g - rw [hf, Matrix.rank_one,Fintype.card_coe] at hK - dsimp only [T] at hK; rw [card_powersetCard] at hK - have hv := Nat.choose_le_middle 1 d - rw [Nat.choose_one_right] at hv - exact Nat.not_lt_of_le ((hv.trans hK).trans hr) hd - -theorem mrk_sum_le {I J A : Type} [Fintype I] [Fintype J] (s : Finset A) (f : A → Mat I J) : - (∑ i∈s,f i).rank ≤ ∑ i∈s,(f i).rank := by - classical - induction s using Finset.induction with - | empty => simp - | insert a s h ih => - rw [Finset.sum_insert h,Finset.sum_insert h] - exact le_trans (mrk_add_le _ _) (by gcongr) - -theorem mput_rank_le (s : Label p.b) (A : BaseMat p n) : - (mput p s A).rank ≤ A.rank := - (Matrix.rank_mul_le_left _ _).trans (Matrix.rank_mul_le_right _ _) - -def labelSum (p : Shape) (L : Finset (Label p.b)) (Z : Label p.b → BaseMat p n) := - ∑ s∈L, mput p s (Z s) - -set_option maxHeartbeats 800000 in -theorem label_support {M : Moment p n} (hm : M∈Wspace p n) - (R : ℕ) (hj : 6*R+4≤p.j) (hr : M.rank ≤ R) : - ∃ (L : Finset (Label p.b)) (Z : Label p.b → BaseMat p n), - L.card ≤ R ∧ (∑ s∈L,(Z s).rank) ≤ R ∧ M=labelSum p L Z ∧ - ∀ s∈L,(Z s)ᵀ=Z s ∧ ∀ i,Z s i i=Z s none i := by - classical - obtain ⟨k,hk,hk',hh⟩ := flat_atLayer M hr hj - let t := (atLayer M hk).rank - let h := (Nat.le_succ k).trans hk - obtain ⟨s,u,v,hv⟩ := flat_entries (Wspace_sym hm) (Wspace_hank hm) hk hh - let L := Finset.univ.image s - let S (z : Label p.b) : Finset (Fin t) := Finset.univ.filter (fun i => s i=z) - let Z := fun z : Label p.b => ∑ i ∈ S z,vecMulVec (u i) (v i) - have hS (i : Fin t) : s i∈L := mem_image_of_mem _ (mem_univ _) - have ht : t≤R := (rank_atLayer_le _ _).trans hr - have hL : L.card≤R := card_image_le.trans (by simpa [t] using ht) - have hZ : (∑ i∈L,(Z i).rank) ≤ R := by - have he (i : Label p.b) : (Z i).rank ≤ (S i).card := by - refine (mrk_sum_le (S i) _).trans ((sum_le_sum (g:=fun _ => (1:ℕ)) - (fun j _ => Matrix.rank_vecMulVec_le (u j) (v j))).trans_eq ?_) - simp - refine le_trans (sum_le_sum (fun i _ => he i)) ?_ - have hx : (∑ i∈L,(S i).card) = (Finset.univ : Finset (Fin t)).card := - (Finset.card_eq_sum_card_fiberwise (fun i _ => hS i)).symm - rw [hx,Finset.card_univ,Fintype.card_fin]; exact ht - refine ⟨L,Z,hL,hZ,?_⟩ - let T := labelSum p L Z - have hrT : T.rank ≤ R := (mrk_sum_le L _).trans - ((sum_le_sum (fun i _ => mput_rank_le i (Z i))).trans hZ) - have he : atLayer M h=atLayer T h := by - ext i j - rw [hv] - let F (x : Fin t) := monoBit (s x) i.1.val * monoBit (s x) j.1.val * (u x i.2 * v x j.2) - change ∑ x : Fin t, F x = (∑ z∈L,mput p z (Z z)) (rise p h i) (rise p h j) - rw [Matrix.sum_apply, ← Finset.sum_fiberwise_of_maps_to (fun i _ => hS i) F] - refine sum_congr rfl fun x _ => ?_ - simp only [mput_apply,Z,Matrix.sum_apply,vecMulVec_apply, mul_sum,rise] - refine sum_congr rfl fun y hy => ?_ - unfold F - rw [(mem_filter.mp hy).2] - have heq : M=T := by - have hzero : M+T=0 := by - apply zero_extension (k:=k) _ _ h - · unfold atLayer - ext i j - have h1 := congr_fun (congr_fun he i) j - change M _ _ + T _ _ = _ - change M _ _=T _ _ at h1 - rw [h1,char_two]; rfl - · intro i j a b c d hg - have h1 := Wspace_hank hm i j a b c d hg - have h2 : T (a,i) (b,j)=T (c,i) (d,j) := by - simp only [T,labelSum,Matrix.sum_apply] - exact sum_congr rfl fun x _ => mput_hank x _ i j a b c d hg - simp only [Matrix.add_apply,h1,h2] - · refine (mrk_add_le _ _).trans ?_; omega - exact add_right_cancel (hzero.trans (char_two T).symm) - refine ⟨heq,?_⟩ - have heA i j (b : SelIdx p.b p.j) : - M (b,i) (emptySel,j) = ∑ s∈L,Z s i j*monoBit s b.val ∧ - M (emptySel,i) (b,j) = ∑ s∈L,Z s i j*monoBit s b.val := by - rw [heq] - simp only [T,labelSum,Matrix.sum_apply,mput_apply] - simp only [monoBit,emptySel,Finset.prod_empty,mul_one,mul_comm] - simp - have hint (i j k l : AIdx p.g n) - (h : ∀ b : SelIdx p.b p.j, - ∑ s∈L,Z s i j*monoBit s b.val=∑ s∈L,Z s k l*monoBit s b.val) : - ∀ s∈L,Z s i j = Z s k l := by - intro s hs - have he := selector_indep L (fun s => Z s i j-Z s k l) p.j (by omega) (by - intro U hU - simp only [sub_mul,Finset.sum_sub_distrib] - exact sub_eq_zero.mpr (h ⟨U,hU⟩)) s hs - exact sub_eq_zero.mp he - intro s hs - constructor - · ext i j - apply hint j i i j _ s hs - intro b - rw [← (heA j i b).1,← (heA i j b).2] - exact congr_fun (congr_fun (Wspace_sym hm) _) _ - intro i - apply hint i i none i _ s hs - intro b - rw [← (heA i i b).1,← (heA none i b).1] - exact Wspace_diag hm _ _ _ - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FlatRankLevels + +namespace OAI + +/-! # Moment Label Support -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Finset +open scoped BigOperators +variable {p : Shape} {n k : ℕ} + +/-- Zero extension by the Boolean union rule for low rank matrices. -/ +theorem zero_extension {M : Moment p n} (hh : hankel M) (hr : M.rank≤k) + (hk : k≤p.j) (hg : atLayer M hk=0) : M=0 := by + classical + by_contra he + let D (r : ℕ) := ∃ i j : Row p n,M i j≠0 ∧ (i.1.val∪j.1.val).card=r + have hD : ∃ r,D r := by + by_contra! h + refine he (Matrix.ext fun i j => ?_) + exact Classical.byContradiction fun g => h _ ⟨i,j,g,rfl⟩ + obtain ⟨x,y,hxy,hw⟩ := Nat.find_spec hD + let U := x.1.val∪y.1.val + let d := U.card + have hd : k (⟨i.val, (hi i).2 ▸ (show t≤p.j by + unfold t; omega)⟩, x.2) + let g : T → Row p n := fun i => (⟨U\i.val, hs i⟩,y.2) + have hf : M.submatrix f g=1 := by + ext i j + by_cases e : i = j + · subst j + rw [Matrix.one_apply_eq] + change M _ _=_ + have hU : M (f i) (g i)=M x y := + hh x.2 y.2 _ _ x.1 y.1 (Finset.union_sdiff_of_subset (hi i).1) + rw [hU]; exact (bit_cases _).resolve_left hxy + rw [Matrix.one_apply_ne e] + change M (f i) (g j)=0 + by_contra H + have hl := Nat.find_min' hD (show D _ from ⟨f i,g j,H,rfl⟩) + rw [← hw] at hl + change d ≤ (i.val ∪ (U \ j.val)).card at hl + have heq : i.val∪(U \ j.val) = U := + Finset.eq_of_subset_of_card_le (union_subset (hi i).1 sdiff_subset) hl + have hsub : j.val⊆i.val := by + intro a ha + have hj := (hi j).1 ha + rw [← heq] at hj + exact (mem_union.mp hj).resolve_right (fun h => (mem_sdiff.mp h).2 ha) + exact e (Subtype.ext (Finset.eq_of_subset_of_card_le hsub + (by rw [(hi i).2,(hi j).2])).symm) + have hK := M.rank_submatrix_le f g + rw [hf, Matrix.rank_one,Fintype.card_coe] at hK + dsimp only [T] at hK; rw [card_powersetCard] at hK + have hv := Nat.choose_le_middle 1 d + rw [Nat.choose_one_right] at hv + exact Nat.not_lt_of_le ((hv.trans hK).trans hr) hd + +theorem mrk_sum_le {I J A : Type} [Fintype I] [Fintype J] (s : Finset A) (f : A → Mat I J) : + (∑ i∈s,f i).rank ≤ ∑ i∈s,(f i).rank := by + classical + induction s using Finset.induction with + | empty => simp + | insert a s h ih => + rw [Finset.sum_insert h,Finset.sum_insert h] + exact le_trans (mrk_add_le _ _) (by gcongr) + +theorem mput_rank_le (s : Label p.b) (A : BaseMat p n) : + (mput p s A).rank ≤ A.rank := + (Matrix.rank_mul_le_left _ _).trans (Matrix.rank_mul_le_right _ _) + +def labelSum (p : Shape) (L : Finset (Label p.b)) (Z : Label p.b → BaseMat p n) := + ∑ s∈L, mput p s (Z s) + +set_option maxHeartbeats 800000 in +theorem label_support {M : Moment p n} (hm : M∈Wspace p n) + (R : ℕ) (hj : 6*R+4≤p.j) (hr : M.rank ≤ R) : + ∃ (L : Finset (Label p.b)) (Z : Label p.b → BaseMat p n), + L.card ≤ R ∧ (∑ s∈L,(Z s).rank) ≤ R ∧ M=labelSum p L Z ∧ + ∀ s∈L,(Z s)ᵀ=Z s ∧ ∀ i,Z s i i=Z s none i := by + classical + obtain ⟨k,hk,hk',hh⟩ := flat_atLayer M hr hj + let t := (atLayer M hk).rank + let h := (Nat.le_succ k).trans hk + obtain ⟨s,u,v,hv⟩ := flat_entries (Wspace_sym hm) (Wspace_hank hm) hk hh + let L := Finset.univ.image s + let S (z : Label p.b) : Finset (Fin t) := Finset.univ.filter (fun i => s i=z) + let Z := fun z : Label p.b => ∑ i ∈ S z,vecMulVec (u i) (v i) + have hS (i : Fin t) : s i∈L := mem_image_of_mem _ (mem_univ _) + have ht : t≤R := (rank_atLayer_le _ _).trans hr + have hL : L.card≤R := card_image_le.trans (by simpa [t] using ht) + have hZ : (∑ i∈L,(Z i).rank) ≤ R := by + have he (i : Label p.b) : (Z i).rank ≤ (S i).card := by + refine (mrk_sum_le (S i) _).trans ((sum_le_sum (g:=fun _ => (1:ℕ)) + (fun j _ => Matrix.rank_vecMulVec_le (u j) (v j))).trans_eq ?_) + simp + refine le_trans (sum_le_sum (fun i _ => he i)) ?_ + have hx : (∑ i∈L,(S i).card) = (Finset.univ : Finset (Fin t)).card := + (Finset.card_eq_sum_card_fiberwise (fun i _ => hS i)).symm + rw [hx,Finset.card_univ,Fintype.card_fin]; exact ht + refine ⟨L,Z,hL,hZ,?_⟩ + let T := labelSum p L Z + have hrT : T.rank ≤ R := (mrk_sum_le L _).trans + ((sum_le_sum (fun i _ => mput_rank_le i (Z i))).trans hZ) + have he : atLayer M h=atLayer T h := by + ext i j + rw [hv] + let F (x : Fin t) := monoBit (s x) i.1.val * monoBit (s x) j.1.val * (u x i.2 * v x j.2) + change ∑ x : Fin t, F x = (∑ z∈L,mput p z (Z z)) (rise p h i) (rise p h j) + rw [Matrix.sum_apply, ← Finset.sum_fiberwise_of_maps_to (fun i _ => hS i) F] + refine sum_congr rfl fun x _ => ?_ + simp only [mput_apply,Z,Matrix.sum_apply,vecMulVec_apply, mul_sum,rise] + refine sum_congr rfl fun y hy => ?_ + unfold F + rw [(mem_filter.mp hy).2] + have heq : M=T := by + have hzero : M+T=0 := by + apply zero_extension (k:=k) _ _ h + · unfold atLayer + ext i j + have h1 := congr_fun (congr_fun he i) j + change M _ _ + T _ _ = _ + change M _ _=T _ _ at h1 + rw [h1,char_two]; rfl + · intro i j a b c d hg + have h1 := Wspace_hank hm i j a b c d hg + have h2 : T (a,i) (b,j)=T (c,i) (d,j) := by + simp only [T,labelSum,Matrix.sum_apply] + exact sum_congr rfl fun x _ => mput_hank x _ i j a b c d hg + simp only [Matrix.add_apply,h1,h2] + · refine (mrk_add_le _ _).trans ?_; omega + exact add_right_cancel (hzero.trans (char_two T).symm) + refine ⟨heq,?_⟩ + have heA i j (b : SelIdx p.b p.j) : + M (b,i) (emptySel,j) = ∑ s∈L,Z s i j*monoBit s b.val ∧ + M (emptySel,i) (b,j) = ∑ s∈L,Z s i j*monoBit s b.val := by + rw [heq] + simp only [T,labelSum,Matrix.sum_apply,mput_apply] + simp only [monoBit,emptySel,Finset.prod_empty,mul_one,mul_comm] + simp + have hint (i j k l : AIdx p.g n) + (h : ∀ b : SelIdx p.b p.j, + ∑ s∈L,Z s i j*monoBit s b.val=∑ s∈L,Z s k l*monoBit s b.val) : + ∀ s∈L,Z s i j = Z s k l := by + intro s hs + have he := selector_indep L (fun s => Z s i j-Z s k l) p.j (by omega) (by + intro U hU + simp only [sub_mul,Finset.sum_sub_distrib] + exact sub_eq_zero.mpr (h ⟨U,hU⟩)) s hs + exact sub_eq_zero.mp he + intro s hs + constructor + · ext i j + apply hint j i i j _ s hs + intro b + rw [← (heA j i b).1,← (heA i j b).2] + exact congr_fun (congr_fun (Wspace_sym hm) _) _ + intro i + apply hint i i none i _ s hs + intro b + rw [← (heA i i b).1,← (heA none i b).1] + exact Wspace_diag hm _ _ _ + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/MutualInformation.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/MutualInformation.lean index 068dc6793d26f52836cc2570b0421b2f5abfed72..93a40989f9cca52a4a79fc5d6940a9894ee26669 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/MutualInformation.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/MutualInformation.lean @@ -1,115 +1,115 @@ -import OAI.Combinatorics.HadwigerCounterexample.ProjectionEnergy - -namespace OAI - -/-! # Mutual Information -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real -open scoped BigOperators -variable {A B C : Type} [Fintype A] [Fintype B] [Fintype C] - -omit [Fintype B] in -theorem mix_high {μ : Wgt A} {p : A→ Wgt B} (hμ : ∀ i,0 ≤ μ i) (hp : ∀ i j,0 ≤ p i j) - (i j) : μ i * p i j ≤ mixW μ p j := - weight_le_tot (fun x => mul_nonneg (hμ x) (hp x j)) i - -theorem mix_overhead [Nonempty B] {μ : Wgt A} {p : A→Wgt B} - (hμ : IsLaw μ) (hp : ∀ i,IsLaw (p i)) : - avg μ (fun x => tension (p x) (mixW μ p))≤log (Fintype.card B) := by - simp_rw [tension_as_diff,avg_sub,← mixW_avg] - change avg μ (fun x => negEnt (p x))-negEnt _ ≤ _ - linarith only [hμ.avg_le (fun i => negEnt_le_zero ((hp i).sub)), - log_card_le_negEnt (mixW_law hμ hp)] - -theorem mix_charge [Nonempty A] {μ : Wgt A} {p : A→Wgt B} - (hμ : IsLaw μ) (hp : ∀ i,IsLaw (p i)) : - avg μ (fun x => tension (p x) (mixW μ p))≤log (Fintype.card A) := by - let q := mixW μ p - have h (i : A) (hi : μ i ≠0) : - tension (p i) q≤0-log (μ i) := by - have hr := lt_of_le_of_ne (hμ.nz i) (Ne.symm hi) - have hcap (j) : p i j ≤ (μ i)⁻¹*q j := by - rw [mul_comm,←div_eq_mul_inv,le_div_iff₀ hr,mul_comm] - exact mix_high hμ.nz (fun i => (hp i).nz) i j - refine (tension_le_cap (hp i).nz (mixW_law hμ hp).nz _ (by positivity) hcap).trans_eq ?_ - rw [(hp i).total,one_mul,log_inv,zero_sub] - calc _ ≤ avg μ (fun i => (0-log (μ i))) := - Finset.sum_le_sum fun i _ => (by - by_cases hi : μ i=0 - · simp only [hi,zero_mul]; rfl - exact mul_le_mul_of_nonneg_left (h i hi) (hμ.nz i)) - _ = -negEnt μ := by rw [avg_sub,avg_zero,zero_sub]; rfl - _ ≤ _ := neg_le.mpr (log_card_le_negEnt hμ) - -omit [Fintype C] in -theorem map_banded {p : Wgt B} (f : B→C) (h : ∀ i j,f i=f j → p i=p j) - (i : B) : mapW p f (f i) = p i * nbr (fun j => f j=f i) := by - unfold mapW pr avg nbr tot - rw [Finset.mul_sum] - refine sum_congr rfl fun j _ => ?_ - by_cases hj : f j=f i - · rw [h j i hj] - simp only [ind_zero hj,mul_zero] - -theorem tension_banded {p q : Wgt B} (f : B→C) (h : lsupp p q) - (hp : ∀ i j,f i=f j→p i=p j) (hq : ∀ i j,f i=f j→q i=q j) : - tension p q=tension (mapW p f) (mapW q f) := by - unfold tension; rw [mapW_avg] - apply avg_congr - intro i hi - let P (j : B) := f j=f i - have hk : nbr P≠0 := by - have he := weight_le_tot (fun j => ind_nonneg (P j)) i - rw [ind_one (show P i from rfl)] at he - exact (lt_of_lt_of_le zero_lt_one he).ne' - change _=Real.log (mapW p f (f i))-Real.log (mapW q f (f i)) - rw [map_banded f hp,map_banded f hq,log_mul hi hk, log_mul (h i hi) hk] - ring - -theorem banded_overhead [Nonempty C] {μ : Wgt A} {p : A→Wgt B} - (hμ : IsLaw μ) (hp : ∀ i,IsLaw (p i)) (f : B→C) - (h : ∀ i j k,f j=f k→ p i j=p i k) : - avg μ (fun i => tension (p i) (mixW μ p)) ≤ log (Fintype.card C) := by - let q := mixW μ p - have he (i : A) (hi : μ i ≠0) : - tension (p i) (mixW μ p) = - tension (mapW (p i) f) (mixW μ (fun i => mapW (p i) f)) := by - have hh : lsupp (p i) q := fun x hx => - (lt_of_lt_of_le (mul_pos (lt_of_le_of_ne (hμ.nz i) (Ne.symm hi)) - (lt_of_le_of_ne ((hp i).nz x) (Ne.symm hx))) - (mix_high hμ.nz (fun i => (hp i).nz) i x)).ne' - rw [←map_mix] - exact tension_banded f hh (h i) (fun i j ht => by unfold mixW; simp_rw [h _ i j ht]) - exact (le_of_eq (avg_congr he)).trans - (mix_overhead hμ (fun i => mapW_law (hp i) f)) - -private theorem add_charge (x y : ℝ) (hx : 0 ≤ x) (hy : 0≤y) : - (x+y)*log (x+y) ≤ x*log x+y*log y+(x+y)*log 2 := by - - have hh := Real.convexOn_mul_log.2 (Set.mem_Ici.mpr hx) (Set.mem_Ici.mpr hy) - (by norm_num : 0 ≤ (2:ℝ)⁻¹) (by norm_num : 0 ≤ (2:ℝ)⁻¹) (by norm_num) - simp only [smul_eq_mul] at hh - by_cases he : x+y=0 - · obtain rfl : x=0 := by linarith - obtain rfl : y=0 := by linarith - simp - rw [←mul_add,log_mul (by norm_num) he, log_inv] at hh - linarith - -theorem tension_add_le (p q w u : Wgt A) (h : ∀ i,p i=q i+w i) - (hq : ∀ i, 0 ≤ q i) (hw : ∀ i,0 ≤ w i) : - tension p u≤ tension q u+tension w u+tot p * log 2 := by - unfold tension tot avg - rw [Finset.sum_mul,← Finset.sum_add_distrib,← Finset.sum_add_distrib] - apply sum_le_sum; intro i _ - change p i*_ ≤ _ - simp only [h] - linarith only [add_charge _ _ (hq i) (hw i)] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ProjectionEnergy + +namespace OAI + +/-! # Mutual Information -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real +open scoped BigOperators +variable {A B C : Type} [Fintype A] [Fintype B] [Fintype C] + +omit [Fintype B] in +theorem mix_high {μ : Wgt A} {p : A→ Wgt B} (hμ : ∀ i,0 ≤ μ i) (hp : ∀ i j,0 ≤ p i j) + (i j) : μ i * p i j ≤ mixW μ p j := + weight_le_tot (fun x => mul_nonneg (hμ x) (hp x j)) i + +theorem mix_overhead [Nonempty B] {μ : Wgt A} {p : A→Wgt B} + (hμ : IsLaw μ) (hp : ∀ i,IsLaw (p i)) : + avg μ (fun x => tension (p x) (mixW μ p))≤log (Fintype.card B) := by + simp_rw [tension_as_diff,avg_sub,← mixW_avg] + change avg μ (fun x => negEnt (p x))-negEnt _ ≤ _ + linarith only [hμ.avg_le (fun i => negEnt_le_zero ((hp i).sub)), + log_card_le_negEnt (mixW_law hμ hp)] + +theorem mix_charge [Nonempty A] {μ : Wgt A} {p : A→Wgt B} + (hμ : IsLaw μ) (hp : ∀ i,IsLaw (p i)) : + avg μ (fun x => tension (p x) (mixW μ p))≤log (Fintype.card A) := by + let q := mixW μ p + have h (i : A) (hi : μ i ≠0) : + tension (p i) q≤0-log (μ i) := by + have hr := lt_of_le_of_ne (hμ.nz i) (Ne.symm hi) + have hcap (j) : p i j ≤ (μ i)⁻¹*q j := by + rw [mul_comm,←div_eq_mul_inv,le_div_iff₀ hr,mul_comm] + exact mix_high hμ.nz (fun i => (hp i).nz) i j + refine (tension_le_cap (hp i).nz (mixW_law hμ hp).nz _ (by positivity) hcap).trans_eq ?_ + rw [(hp i).total,one_mul,log_inv,zero_sub] + calc _ ≤ avg μ (fun i => (0-log (μ i))) := + Finset.sum_le_sum fun i _ => (by + by_cases hi : μ i=0 + · simp only [hi,zero_mul]; rfl + exact mul_le_mul_of_nonneg_left (h i hi) (hμ.nz i)) + _ = -negEnt μ := by rw [avg_sub,avg_zero,zero_sub]; rfl + _ ≤ _ := neg_le.mpr (log_card_le_negEnt hμ) + +omit [Fintype C] in +theorem map_banded {p : Wgt B} (f : B→C) (h : ∀ i j,f i=f j → p i=p j) + (i : B) : mapW p f (f i) = p i * nbr (fun j => f j=f i) := by + unfold mapW pr avg nbr tot + rw [Finset.mul_sum] + refine sum_congr rfl fun j _ => ?_ + by_cases hj : f j=f i + · rw [h j i hj] + simp only [ind_zero hj,mul_zero] + +theorem tension_banded {p q : Wgt B} (f : B→C) (h : lsupp p q) + (hp : ∀ i j,f i=f j→p i=p j) (hq : ∀ i j,f i=f j→q i=q j) : + tension p q=tension (mapW p f) (mapW q f) := by + unfold tension; rw [mapW_avg] + apply avg_congr + intro i hi + let P (j : B) := f j=f i + have hk : nbr P≠0 := by + have he := weight_le_tot (fun j => ind_nonneg (P j)) i + rw [ind_one (show P i from rfl)] at he + exact (lt_of_lt_of_le zero_lt_one he).ne' + change _=Real.log (mapW p f (f i))-Real.log (mapW q f (f i)) + rw [map_banded f hp,map_banded f hq,log_mul hi hk, log_mul (h i hi) hk] + ring + +theorem banded_overhead [Nonempty C] {μ : Wgt A} {p : A→Wgt B} + (hμ : IsLaw μ) (hp : ∀ i,IsLaw (p i)) (f : B→C) + (h : ∀ i j k,f j=f k→ p i j=p i k) : + avg μ (fun i => tension (p i) (mixW μ p)) ≤ log (Fintype.card C) := by + let q := mixW μ p + have he (i : A) (hi : μ i ≠0) : + tension (p i) (mixW μ p) = + tension (mapW (p i) f) (mixW μ (fun i => mapW (p i) f)) := by + have hh : lsupp (p i) q := fun x hx => + (lt_of_lt_of_le (mul_pos (lt_of_le_of_ne (hμ.nz i) (Ne.symm hi)) + (lt_of_le_of_ne ((hp i).nz x) (Ne.symm hx))) + (mix_high hμ.nz (fun i => (hp i).nz) i x)).ne' + rw [←map_mix] + exact tension_banded f hh (h i) (fun i j ht => by unfold mixW; simp_rw [h _ i j ht]) + exact (le_of_eq (avg_congr he)).trans + (mix_overhead hμ (fun i => mapW_law (hp i) f)) + +private theorem add_charge (x y : ℝ) (hx : 0 ≤ x) (hy : 0≤y) : + (x+y)*log (x+y) ≤ x*log x+y*log y+(x+y)*log 2 := by + + have hh := Real.convexOn_mul_log.2 (Set.mem_Ici.mpr hx) (Set.mem_Ici.mpr hy) + (by norm_num : 0 ≤ (2:ℝ)⁻¹) (by norm_num : 0 ≤ (2:ℝ)⁻¹) (by norm_num) + simp only [smul_eq_mul] at hh + by_cases he : x+y=0 + · obtain rfl : x=0 := by linarith + obtain rfl : y=0 := by linarith + simp + rw [←mul_add,log_mul (by norm_num) he, log_inv] at hh + linarith + +theorem tension_add_le (p q w u : Wgt A) (h : ∀ i,p i=q i+w i) + (hq : ∀ i, 0 ≤ q i) (hw : ∀ i,0 ≤ w i) : + tension p u≤ tension q u+tension w u+tot p * log 2 := by + unfold tension tot avg + rw [Finset.sum_mul,← Finset.sum_add_distrib,← Finset.sum_add_distrib] + apply sum_le_sum; intro i _ + change p i*_ ≤ _ + simp only [h] + linarith only [add_charge _ _ (hq i) (hw i)] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/NominalPointArrays.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/NominalPointArrays.lean index b7fe3584d7b6012d910ca22a9c90e0e8f4518b87..f8fe83bb31c6d4b01431b310fd9808b8dcf74900 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/NominalPointArrays.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/NominalPointArrays.lean @@ -1,114 +1,114 @@ -import OAI.Combinatorics.HadwigerCounterexample.SyntheticSliceExperiments - -namespace OAI - -/-! # Nominal Point Arrays -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Function Finset -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I J U : Type} [Fintype I] [Fintype J] [Fintype U] -variable [DecidableEq I] [DecidableEq J] [DecidableEq U] - -def incision (p : Shape) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) - (x : I →Knobs p.g n) : - Mat (Row p n) I := Matrix.of (fun i j=> spring p l s f (x j) i) -def sketchLaw (p : Shape) (n : ℕ) (a : I→ Tickets p) := - prodW (fun i => rung p n (a i)) -theorem sketch_law (p : Shape) (n : ℕ) (a : I→ Tickets p) (h : 2*p.r≤n) : - IsLaw (sketchLaw p n a) := prodW_law (fun _ =>ticketLaw n _ h) - -omit [DecidableEq I] in -theorem sketch_matrix (p : Shape) (l s f) (m : Mixer p n) (a : I→ Tickets p) - (hj : 1 ≤ p.j) (x : I→Knobs p.g n) (h : sketchLaw p n a x ≠0) : - let A:= incision p l s f x - pullM A A (selfM p n m.mixM)= Matrix.of (fun i j=>tabGram p l f (a i) (a j)) := by - classical - intro A - have he i : punchField p (x i)=a i := by - by_contra! hv - refine h (Finset.prod_eq_zero (mem_univ i) (f:=fun i=>rung p n (a i) (x i)) ?_) - unfold rung; rw [onW_val,ind_zero (show ¬ issued p _ _ from hv),mul_zero,zero_div] - ext i j - let E := selfM p n m.mixM - have hi : (pullM A A E) i j=evmat E (spring p l s f (x i)) (spring p l s f (x j)) := by - rw [pullM_def,Matrix.mul_assoc]; rfl - rw [hi,tabGram_sound _ n l s f (x i) (x j) m hj,he,he]; rfl - -def weightsAff (u : Vec I) := ∑ i,u i=(1:F) -def compound (p : Shape) (x : I →Knobs p.g n) (u : Vec I) := ∑ i:I,u i • x i - -omit [DecidableEq I] in -set_option maxHeartbeats 600000 in -theorem inc_compound (p : Shape) (l s f) (x : I→ Knobs p.g n) (u : Vec I) (h : weightsAff u) : - incision p l s f x *ᵥ u=spring p l s f (compound p x u) := by - classical - funext i - rcases i with ⟨i,_|k⟩ - · unfold Matrix.mulVec dotProduct incision; simp only [Matrix.of_apply,spring,point_eval] - change ∑ j,monoBit s i.val*1*_ = monoBit s i.val *1 - rw [← Finset.mul_sum,show ∑ i,u i=1 from h,mul_one] - unfold Matrix.mulVec dotProduct incision; simp only [Matrix.of_apply,spring,point_eval] - change ∑ j,monoBit s i.val*lit f l (x j) k*_ = monoBit s i.val* lit f l (compound p x u) k - have hz : - lit f l (compound p x u) k=∑ i,u i*lit f l (x i) k := by - unfold lit compound - by_cases h : f.keeps l k.1 - · simp only [Finset.sum_apply,ite_eq_left h,Pi.smul_apply,smul_eq_mul] - simp only [ite_eq_right h,mul_zero,Finset.sum_const_zero] - rw [hz,Finset.mul_sum]; exact Finset.sum_congr rfl fun i _=> by ring - -omit [DecidableEq I] in -theorem inc_diag (p : Shape) (l s f) (m : Mixer p n) (x : I →Knobs p.g n) - (u : Vec I) (h : weightsAff u) (hj : 1 ≤ p.j) : - let A:=incision p l s f x; let y:=compound p x u - evmat (pullM A A (selfM p n m.mixM)) u u=dialed p l f y := by - intro A y - rw [evmat_pull,inc_compound p l s f x u h,←mpair_outer] - exact (selfM_pair p hj _ (show mom p _ (lit f l y)∈ Wspace p n from Submodule.subset_span - ⟨s,_,rfl⟩)).trans (etaScan p l s f y).symm - -def labFee (p : Shape) (I : Type) [Fintype I] := (ticketsFee p)^Fintype.card I -theorem labFee_pos (p : Shape) (I : Type) [Fintype I] : 0 smul_comm _ _ _) - -theorem sketch_point (p : Shape) (n : ℕ) (a:I→ Tickets p) (h : 2*p.r≤n) - (u : Vec I) (he : weightsAff u) (P : Knobs p.g n→Prop) : - pr (sketchLaw p n a) (fun x=> P (compound p x u)) ≤ - (labFee p I)⁻¹*pr (spins p n) P := by - classical - have hh x : - sketchLaw p n a x≤(labFee p I)⁻¹*unif x := by - unfold sketchLaw labFee - rw [draws_unif] - have hn i : spins p n (x i)=unif (x i) := by rw [spins,← draws_unif] - apply le_trans (Finset.prod_le_prod₀ (fun i (_: i∈(univ:Finset I)) => (ticketLaw n _ h).nz - (x i)) (fun i _=>(ticketCap n (a i) h (x i)))) - simp_rw [Finset.prod_mul_distrib,hn] - simp only [Finset.prod_const, card_univ, inv_pow] - exact le_rfl - have hs : Surjective (compoundAll p n u) := by - intro x - refine ⟨fun y => x,?_⟩ - change ∑ i,u i • x=x - rw [← Finset.sum_smul,show ∑ i,u i=1 from he,one_smul] - have ht : - pr unif (fun x => P (compound p x u))=pr (spins p n) P := by - unfold spins - rw [← draws_unif] - change pr unif (fun x=>P (compoundAll p n u x))=_ - rw [← mapW_pr,map_unif_surjective _ hs] - exact (pr_cap hh _).trans_eq (congrArg _ ht) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SyntheticSliceExperiments + +namespace OAI + +/-! # Nominal Point Arrays -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Function Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I J U : Type} [Fintype I] [Fintype J] [Fintype U] +variable [DecidableEq I] [DecidableEq J] [DecidableEq U] + +def incision (p : Shape) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) + (x : I →Knobs p.g n) : + Mat (Row p n) I := Matrix.of (fun i j=> spring p l s f (x j) i) +def sketchLaw (p : Shape) (n : ℕ) (a : I→ Tickets p) := + prodW (fun i => rung p n (a i)) +theorem sketch_law (p : Shape) (n : ℕ) (a : I→ Tickets p) (h : 2*p.r≤n) : + IsLaw (sketchLaw p n a) := prodW_law (fun _ =>ticketLaw n _ h) + +omit [DecidableEq I] in +theorem sketch_matrix (p : Shape) (l s f) (m : Mixer p n) (a : I→ Tickets p) + (hj : 1 ≤ p.j) (x : I→Knobs p.g n) (h : sketchLaw p n a x ≠0) : + let A:= incision p l s f x + pullM A A (selfM p n m.mixM)= Matrix.of (fun i j=>tabGram p l f (a i) (a j)) := by + classical + intro A + have he i : punchField p (x i)=a i := by + by_contra! hv + refine h (Finset.prod_eq_zero (mem_univ i) (f:=fun i=>rung p n (a i) (x i)) ?_) + unfold rung; rw [onW_val,ind_zero (show ¬ issued p _ _ from hv),mul_zero,zero_div] + ext i j + let E := selfM p n m.mixM + have hi : (pullM A A E) i j=evmat E (spring p l s f (x i)) (spring p l s f (x j)) := by + rw [pullM_def,Matrix.mul_assoc]; rfl + rw [hi,tabGram_sound _ n l s f (x i) (x j) m hj,he,he]; rfl + +def weightsAff (u : Vec I) := ∑ i,u i=(1:F) +def compound (p : Shape) (x : I →Knobs p.g n) (u : Vec I) := ∑ i:I,u i • x i + +omit [DecidableEq I] in +set_option maxHeartbeats 600000 in +theorem inc_compound (p : Shape) (l s f) (x : I→ Knobs p.g n) (u : Vec I) (h : weightsAff u) : + incision p l s f x *ᵥ u=spring p l s f (compound p x u) := by + classical + funext i + rcases i with ⟨i,_|k⟩ + · unfold Matrix.mulVec dotProduct incision; simp only [Matrix.of_apply,spring,point_eval] + change ∑ j,monoBit s i.val*1*_ = monoBit s i.val *1 + rw [← Finset.mul_sum,show ∑ i,u i=1 from h,mul_one] + unfold Matrix.mulVec dotProduct incision; simp only [Matrix.of_apply,spring,point_eval] + change ∑ j,monoBit s i.val*lit f l (x j) k*_ = monoBit s i.val* lit f l (compound p x u) k + have hz : + lit f l (compound p x u) k=∑ i,u i*lit f l (x i) k := by + unfold lit compound + by_cases h : f.keeps l k.1 + · simp only [Finset.sum_apply,ite_eq_left h,Pi.smul_apply,smul_eq_mul] + simp only [ite_eq_right h,mul_zero,Finset.sum_const_zero] + rw [hz,Finset.mul_sum]; exact Finset.sum_congr rfl fun i _=> by ring + +omit [DecidableEq I] in +theorem inc_diag (p : Shape) (l s f) (m : Mixer p n) (x : I →Knobs p.g n) + (u : Vec I) (h : weightsAff u) (hj : 1 ≤ p.j) : + let A:=incision p l s f x; let y:=compound p x u + evmat (pullM A A (selfM p n m.mixM)) u u=dialed p l f y := by + intro A y + rw [evmat_pull,inc_compound p l s f x u h,←mpair_outer] + exact (selfM_pair p hj _ (show mom p _ (lit f l y)∈ Wspace p n from Submodule.subset_span + ⟨s,_,rfl⟩)).trans (etaScan p l s f y).symm + +def labFee (p : Shape) (I : Type) [Fintype I] := (ticketsFee p)^Fintype.card I +theorem labFee_pos (p : Shape) (I : Type) [Fintype I] : 0 smul_comm _ _ _) + +theorem sketch_point (p : Shape) (n : ℕ) (a:I→ Tickets p) (h : 2*p.r≤n) + (u : Vec I) (he : weightsAff u) (P : Knobs p.g n→Prop) : + pr (sketchLaw p n a) (fun x=> P (compound p x u)) ≤ + (labFee p I)⁻¹*pr (spins p n) P := by + classical + have hh x : + sketchLaw p n a x≤(labFee p I)⁻¹*unif x := by + unfold sketchLaw labFee + rw [draws_unif] + have hn i : spins p n (x i)=unif (x i) := by rw [spins,← draws_unif] + apply le_trans (Finset.prod_le_prod₀ (fun i (_: i∈(univ:Finset I)) => (ticketLaw n _ h).nz + (x i)) (fun i _=>(ticketCap n (a i) h (x i)))) + simp_rw [Finset.prod_mul_distrib,hn] + simp only [Finset.prod_const, card_univ, inv_pow] + exact le_rfl + have hs : Surjective (compoundAll p n u) := by + intro x + refine ⟨fun y => x,?_⟩ + change ∑ i,u i • x=x + rw [← Finset.sum_smul,show ∑ i,u i=1 from he,one_smul] + have ht : + pr unif (fun x => P (compound p x u))=pr (spins p n) P := by + unfold spins + rw [← draws_unif] + change pr unif (fun x=>P (compoundAll p n u x))=_ + rw [← mapW_pr,map_unif_surjective _ hs] + exact (pr_cap hh _).trans_eq (congrArg _ ht) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/NominalSpaces.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/NominalSpaces.lean index e8ae61bea69fe04fa11fb25e3a1ff0bc6b0b2487..e8a951c5fd9a9c4fe96623c14c75d1d1e1741ae2 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/NominalSpaces.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/NominalSpaces.lean @@ -1,202 +1,202 @@ -import OAI.Combinatorics.HadwigerCounterexample.MatrixQuotients -import OAI.Combinatorics.HadwigerCounterexample.SparseLabelBounds - -namespace OAI - -/-! # Nominal Spaces -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module -open scoped BigOperators - -variable {p : Shape} {n N : ℕ} - -def onSide {A : Type} (x : A × A) (b : Bool) := if b then x.1 else x.2 -def putFull (p : Shape) (n : ℕ) : Bool → Full p n → JointIdx p n -| true => Sum.inl -| false => Sum.inr - -instance jointDecidableEq (p : Shape) (n : ℕ) : DecidableEq (JointIdx p n) := inferInstance - -abbrev Chan (p : Shape) := Fin p.h -def IP (p : Shape) (n : ℕ) (b : Bool) : Mat (JointIdx p n) (Row p n) := - embedMat (fun i => putFull p n b (.inl i)) -def IH (p : Shape) (n : ℕ) (b : Bool) : Mat (JointIdx p n) (Chan p) := - embedMat (fun i => putFull p n b (.inr i)) - -theorem IP_self (b) : (IP p n b)ᵀ*IP p n b=1 := by - apply embedMat_self - intro i j; cases b <;> simp [putFull] -theorem IH_self (b) : (IH p n b)ᵀ*IH p n b=1 := by - apply embedMat_self - intro i j; cases b <;> simp [putFull] -theorem IP_IH (a b : Bool) : (IP p n a)ᵀ * IH p n b=0 := by - unfold IP IH; rw [embedMat_mul] - ext i j; cases a <;> cases b <;> simp [embedMat,putFull] - -theorem IP_cross {a b : Bool} (h : a ≠ b) : (IP p n a)ᵀ * IP p n b=0 := by - unfold IP; rw [embedMat_mul] - ext i j; cases a <;> cases b <;> first | contradiction | simp [embedMat,putFull] -theorem IH_cross {a b : Bool} (h : a ≠ b) : (IH p n a)ᵀ * IH p n b=0 := by - unfold IH; rw [embedMat_mul] - ext i j; cases a <;> cases b <;> first | contradiction | simp [embedMat,putFull] -theorem IH_IP (a b : Bool) : (IH p n a)ᵀ * IP p n b=0 := by - simpa only [transpose_mul,Matrix.transpose_zero,transpose_transpose] using - congrArg Matrix.transpose (IP_IH (p:=p) (n:=n) b a) - -theorem ip_decomp (x : Dir p n) : - (∑ b : Bool, ((IP p n b) *ᵥ ((IP p n b)ᵀ*ᵥx)+ (IH p n b)*ᵥ ((IH p n b)ᵀ*ᵥx)))=x := by - rw [Fintype.sum_bool] - unfold IP IH - simp_rw [embedMatT] - ext i - rcases i with (i|i)|(i|i) <;> - simp [embedMat,putFull,Matrix.mulVec,dotProduct,Pi.add_apply] - -theorem images_ip (x : UnitType p n N) (z : Place p) (b : Bool) : - images x z * IP p n b = primary (takeSign (onSide x b z.1) z.2) := by - unfold IP; rw [mul_embedMat] - cases b <;> ext <;> rfl -theorem images_ih (x : UnitType p n N) (z : Place p) (b : Bool) : - images x z * IH p n b = channel (takeSign (onSide x b z.1) z.2) := by - unfold IH; rw [mul_embedMat] - cases b <;> ext <;> rfl - -def sPin (s : Plan p n) (z : Place p) (i : Bool) : Space (Ray p n) := - (s z).map (IP p n i)ᵀ.mulVecLin - -def hPin (s : Plan p n) (z : Place p) (i : Bool) : Space (Vec (Chan p)) := - (s z).map (IH p n i)ᵀ.mulVecLin - -/-- small table-coordinate space J. -/ -def halfTable (s : Plan p n) (z : Place p) (i : Bool) := - (sPin s z i).map (IP p n i).mulVecLin ⊔ colSp (IH p n i) -def tabSpace (s : Plan p n) : Plan p n := - fun z => halfTable s z true ⊔ halfTable s z false - -theorem half_le_table (s : Plan p n) (z) (i) : halfTable s z i ≤ tabSpace s z := by - cases i - · exact le_sup_right - exact le_sup_left - -theorem channel_le_table (s : Plan p n) (z i) : colSp (IH p n i)≤tabSpace s z := - le_trans le_sup_right (half_le_table s z i) - -theorem tab_mem (s : Plan p n) (z : Place p) (x : Dir p n) : - x∈tabSpace s z ↔ ∀ i,(IP p n i)ᵀ *ᵥ x ∈ sPin s z i := by - constructor - · intro h i - let Q := (sPin s z i).comap (IP p n i)ᵀ.mulVecLin - suffices he : tabSpace s z ≤ Q from he h - have hg (j : Bool) : halfTable s z j≤Q := by - refine sup_le ?_ ?_ - · rintro y ⟨x,hx,rfl⟩ - change (IP p n i)ᵀ *ᵥ (IP p n j *ᵥ x) ∈ sPin s z i - by_cases e : i = j - · subst j; rwa [mulVec_mulVec,IP_self,Matrix.one_mulVec] - rw [mulVec_mulVec,IP_cross e,Matrix.zero_mulVec]; exact Submodule.zero_mem _ - rintro y ⟨x,rfl⟩ - change (IP p n i)ᵀ *ᵥ (IH p n j *ᵥ x) ∈ sPin s z i - rw [mulVec_mulVec,IP_IH,Matrix.zero_mulVec]; exact Submodule.zero_mem _ - exact sup_le (hg _) (hg _) - intro h - rw [←ip_decomp x] - refine Submodule.sum_mem _ (fun i _ => ?_) - apply (half_le_table s z i) - exact Submodule.add_mem_sup (show IP p n i *ᵥ _ ∈ (sPin s z i).map (IP p n i).mulVecLin from - ⟨_,h i,rfl⟩) (show IH p n i *ᵥ _ ∈ colSp (IH p n i) from ⟨_,rfl⟩) - -theorem pin_le_table (s : Plan p n) (z : Place p) : s z ≤ tabSpace s z := fun x h => - (tab_mem ..).mpr fun _ => ⟨x,h,rfl⟩ - -/-- effective test space on endpoint i. -/ -def effective (s : Plan p n) (i : Bool) : Space (Profile p n) := - Xspace p n ⊓ Submodule.pi Set.univ (fun e => box (sPin s (e,true) i) (sPin s (e,false) i)) - -theorem effective_mem {s : Plan p n} {i} {x : Profile p n} : x∈effective s i ↔ - x∈Xspace p n ∧ ∀ e, x e∈box (sPin s (e,true) i) (sPin s (e,false) i) := - and_congr Iff.rfl (by simp) - -theorem sPin_dim (s : Plan p n) (z : Place p) (i) : dim (sPin s z i)≤dim (s z) := - Submodule.finrank_map_le _ _ -theorem hPin_dim (s : Plan p n) (z : Place p) (i) : dim (hPin s z i)≤dim (s z) := - Submodule.finrank_map_le _ _ - -theorem sPin_sum (s : Plan p n) (b i : Bool) : - ∑ e : Comp p.g, dim (sPin s (e,b) i) ≤ planRank s := by - unfold planRank - rw [Fintype.sum_prod_type] - refine Finset.sum_le_sum (fun e _ => (sPin_dim _ _ _).trans ?_) - exact Finset.single_le_sum (fun j _ => Nat.zero_le ((fun b => dim (s (e,b))) j)) - (Finset.mem_univ b) - -theorem dim_le_plan (s : Plan p n) (e : Place p) : - dim (s e) ≤ planRank s := Finset.single_le_sum (fun j _ => Nat.zero_le (dim (s j))) - (Finset.mem_univ _) - -theorem effective_rank {s : Plan p n} {x : Profile p n} {i} (hx : x ∈ effective s i) : - totalRank x ≤ planRank s := by - apply le_trans (Finset.sum_le_sum ?_) (sPin_sum s true i) - intro j _ - exact (Submodule.finrank_mono ((box_mem ..).mp ((effective_mem.mp hx).2 j)).1) - -private theorem pi_dim_le {V J : Type} [AddCommGroup V] [Module F V] [FiniteDimensional F V] - [Fintype J] (s : J→ Submodule F V) : - dim (Submodule.pi Set.univ s) ≤ ∑ i, dim (s i) := by - let T := Submodule.pi Set.univ s - have h (i : J) (x : T) : x.val i∈ s i := x.property i (Set.mem_univ i) - let f : T →ₗ[F] (∀ i,s i) := { - toFun := fun x i => ⟨_,h i x⟩ - map_add' := by intro x y; rfl - map_smul' := by intro x y; rfl } - have hf : Function.Injective f := fun x y e => Subtype.ext (funext (fun i => - show x.val i=y.val i from congrArg (fun t:s i => t.val) (congr_fun e i))) - exact (LinearMap.finrank_le_finrank_of_injective hf).trans_eq - (Module.finrank_pi_fintype _) - -theorem effective_dim (s : Plan p n) (i : Bool) : - dim (effective s i) ≤ (planRank s)^2 := by - unfold effective - let p' (e : Comp p.g) := (sPin s (e,true) i) - let q (e : Comp p.g) := (sPin s (e,false) i) - refine ((Submodule.finrank_mono (show _ ⊓ _ ≤ Submodule.pi Set.univ (fun e => box (p' e) - (q e)) from inf_le_right)).trans (pi_dim_le _)).trans ?_ - simp_rw [box_dim] - calc ∑ i, dim (p' i) * dim (q i) ≤ ∑ i, dim (p' i)* planRank s := Finset.sum_le_sum (fun j _ => - Nat.mul_le_mul_left _ ((sPin_dim s _ i).trans (dim_le_plan s _))) - _ ≤ _ := by rw [← Finset.sum_mul,pow_two]; exact Nat.mul_le_mul_right _ (sPin_sum s true i) - -theorem table_dim (s : Plan p n) (e : Place p) : - dim (tabSpace s e) ≤ 2*(planRank s + p.h) := by - have hh i : dim (halfTable s e i)≤ planRank s+p.h := by - have hg : dim (colSp (IH p n i)) ≤ p.h := (IH p n i).rank_le_card_width.trans_eq - (Fintype.card_fin _) - apply le_trans (Submodule.finrank_add_le_finrank_add_finrank ..) - exact Nat.add_le_add ((Submodule.finrank_map_le _ _).trans - ((sPin_dim ..).trans (dim_le_plan s e))) hg - exact ((Submodule.finrank_add_le_finrank_add_finrank ..).trans - (Nat.add_le_add (hh true) (hh false))).trans_eq (two_mul _).symm - -theorem pin_protection (s : Plan p n) (i : Bool) (K q : ℕ) - (hk : planRank s ≤ K) (hj : (K+1)*q≤p.j+1) : - ∃ L : Finset (Label p.b), - L.card ≤ 2*Fintype.card (Comp p.g)*K*q ∧ - ∀ z : Place p, protectedBy p (sPin s z i) q L := by - classical - have he z : dim (sPin s z i)≤K := ((sPin_dim s z i).trans (dim_le_plan s z)).trans hk - choose L hL hP using fun z => protect_labels p (sPin s z i) q - (le_trans (Nat.mul_le_mul_right _ (Nat.add_le_add_right (he z) 1)) hj) - refine ⟨Finset.univ.biUnion L, ?_,fun z B v h hq x hx hl => - hP z B v h hq x hx (fun ht => hl (Finset.mem_biUnion.mpr ⟨z,Finset.mem_univ _,ht⟩))⟩ - calc (Finset.univ.biUnion L).card - _ ≤ _ := Finset.card_biUnion_le - _ ≤ ∑ z : Place p, K*q := Finset.sum_le_sum - (fun j _ => (hL j).trans (Nat.mul_le_mul_right _ (he j))) - _ = _ := by simp [Place]; ring - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.MatrixQuotients +import OAI.Combinatorics.HadwigerCounterexample.SparseLabelBounds + +namespace OAI + +/-! # Nominal Spaces -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module +open scoped BigOperators + +variable {p : Shape} {n N : ℕ} + +def onSide {A : Type} (x : A × A) (b : Bool) := if b then x.1 else x.2 +def putFull (p : Shape) (n : ℕ) : Bool → Full p n → JointIdx p n +| true => Sum.inl +| false => Sum.inr + +instance jointDecidableEq (p : Shape) (n : ℕ) : DecidableEq (JointIdx p n) := inferInstance + +abbrev Chan (p : Shape) := Fin p.h +def IP (p : Shape) (n : ℕ) (b : Bool) : Mat (JointIdx p n) (Row p n) := + embedMat (fun i => putFull p n b (.inl i)) +def IH (p : Shape) (n : ℕ) (b : Bool) : Mat (JointIdx p n) (Chan p) := + embedMat (fun i => putFull p n b (.inr i)) + +theorem IP_self (b) : (IP p n b)ᵀ*IP p n b=1 := by + apply embedMat_self + intro i j; cases b <;> simp [putFull] +theorem IH_self (b) : (IH p n b)ᵀ*IH p n b=1 := by + apply embedMat_self + intro i j; cases b <;> simp [putFull] +theorem IP_IH (a b : Bool) : (IP p n a)ᵀ * IH p n b=0 := by + unfold IP IH; rw [embedMat_mul] + ext i j; cases a <;> cases b <;> simp [embedMat,putFull] + +theorem IP_cross {a b : Bool} (h : a ≠ b) : (IP p n a)ᵀ * IP p n b=0 := by + unfold IP; rw [embedMat_mul] + ext i j; cases a <;> cases b <;> first | contradiction | simp [embedMat,putFull] +theorem IH_cross {a b : Bool} (h : a ≠ b) : (IH p n a)ᵀ * IH p n b=0 := by + unfold IH; rw [embedMat_mul] + ext i j; cases a <;> cases b <;> first | contradiction | simp [embedMat,putFull] +theorem IH_IP (a b : Bool) : (IH p n a)ᵀ * IP p n b=0 := by + simpa only [transpose_mul,Matrix.transpose_zero,transpose_transpose] using + congrArg Matrix.transpose (IP_IH (p:=p) (n:=n) b a) + +theorem ip_decomp (x : Dir p n) : + (∑ b : Bool, ((IP p n b) *ᵥ ((IP p n b)ᵀ*ᵥx)+ (IH p n b)*ᵥ ((IH p n b)ᵀ*ᵥx)))=x := by + rw [Fintype.sum_bool] + unfold IP IH + simp_rw [embedMatT] + ext i + rcases i with (i|i)|(i|i) <;> + simp [embedMat,putFull,Matrix.mulVec,dotProduct,Pi.add_apply] + +theorem images_ip (x : UnitType p n N) (z : Place p) (b : Bool) : + images x z * IP p n b = primary (takeSign (onSide x b z.1) z.2) := by + unfold IP; rw [mul_embedMat] + cases b <;> ext <;> rfl +theorem images_ih (x : UnitType p n N) (z : Place p) (b : Bool) : + images x z * IH p n b = channel (takeSign (onSide x b z.1) z.2) := by + unfold IH; rw [mul_embedMat] + cases b <;> ext <;> rfl + +def sPin (s : Plan p n) (z : Place p) (i : Bool) : Space (Ray p n) := + (s z).map (IP p n i)ᵀ.mulVecLin + +def hPin (s : Plan p n) (z : Place p) (i : Bool) : Space (Vec (Chan p)) := + (s z).map (IH p n i)ᵀ.mulVecLin + +/-- small table-coordinate space J. -/ +def halfTable (s : Plan p n) (z : Place p) (i : Bool) := + (sPin s z i).map (IP p n i).mulVecLin ⊔ colSp (IH p n i) +def tabSpace (s : Plan p n) : Plan p n := + fun z => halfTable s z true ⊔ halfTable s z false + +theorem half_le_table (s : Plan p n) (z) (i) : halfTable s z i ≤ tabSpace s z := by + cases i + · exact le_sup_right + exact le_sup_left + +theorem channel_le_table (s : Plan p n) (z i) : colSp (IH p n i)≤tabSpace s z := + le_trans le_sup_right (half_le_table s z i) + +theorem tab_mem (s : Plan p n) (z : Place p) (x : Dir p n) : + x∈tabSpace s z ↔ ∀ i,(IP p n i)ᵀ *ᵥ x ∈ sPin s z i := by + constructor + · intro h i + let Q := (sPin s z i).comap (IP p n i)ᵀ.mulVecLin + suffices he : tabSpace s z ≤ Q from he h + have hg (j : Bool) : halfTable s z j≤Q := by + refine sup_le ?_ ?_ + · rintro y ⟨x,hx,rfl⟩ + change (IP p n i)ᵀ *ᵥ (IP p n j *ᵥ x) ∈ sPin s z i + by_cases e : i = j + · subst j; rwa [mulVec_mulVec,IP_self,Matrix.one_mulVec] + rw [mulVec_mulVec,IP_cross e,Matrix.zero_mulVec]; exact Submodule.zero_mem _ + rintro y ⟨x,rfl⟩ + change (IP p n i)ᵀ *ᵥ (IH p n j *ᵥ x) ∈ sPin s z i + rw [mulVec_mulVec,IP_IH,Matrix.zero_mulVec]; exact Submodule.zero_mem _ + exact sup_le (hg _) (hg _) + intro h + rw [←ip_decomp x] + refine Submodule.sum_mem _ (fun i _ => ?_) + apply (half_le_table s z i) + exact Submodule.add_mem_sup (show IP p n i *ᵥ _ ∈ (sPin s z i).map (IP p n i).mulVecLin from + ⟨_,h i,rfl⟩) (show IH p n i *ᵥ _ ∈ colSp (IH p n i) from ⟨_,rfl⟩) + +theorem pin_le_table (s : Plan p n) (z : Place p) : s z ≤ tabSpace s z := fun x h => + (tab_mem ..).mpr fun _ => ⟨x,h,rfl⟩ + +/-- effective test space on endpoint i. -/ +def effective (s : Plan p n) (i : Bool) : Space (Profile p n) := + Xspace p n ⊓ Submodule.pi Set.univ (fun e => box (sPin s (e,true) i) (sPin s (e,false) i)) + +theorem effective_mem {s : Plan p n} {i} {x : Profile p n} : x∈effective s i ↔ + x∈Xspace p n ∧ ∀ e, x e∈box (sPin s (e,true) i) (sPin s (e,false) i) := + and_congr Iff.rfl (by simp) + +theorem sPin_dim (s : Plan p n) (z : Place p) (i) : dim (sPin s z i)≤dim (s z) := + Submodule.finrank_map_le _ _ +theorem hPin_dim (s : Plan p n) (z : Place p) (i) : dim (hPin s z i)≤dim (s z) := + Submodule.finrank_map_le _ _ + +theorem sPin_sum (s : Plan p n) (b i : Bool) : + ∑ e : Comp p.g, dim (sPin s (e,b) i) ≤ planRank s := by + unfold planRank + rw [Fintype.sum_prod_type] + refine Finset.sum_le_sum (fun e _ => (sPin_dim _ _ _).trans ?_) + exact Finset.single_le_sum (fun j _ => Nat.zero_le ((fun b => dim (s (e,b))) j)) + (Finset.mem_univ b) + +theorem dim_le_plan (s : Plan p n) (e : Place p) : + dim (s e) ≤ planRank s := Finset.single_le_sum (fun j _ => Nat.zero_le (dim (s j))) + (Finset.mem_univ _) + +theorem effective_rank {s : Plan p n} {x : Profile p n} {i} (hx : x ∈ effective s i) : + totalRank x ≤ planRank s := by + apply le_trans (Finset.sum_le_sum ?_) (sPin_sum s true i) + intro j _ + exact (Submodule.finrank_mono ((box_mem ..).mp ((effective_mem.mp hx).2 j)).1) + +private theorem pi_dim_le {V J : Type} [AddCommGroup V] [Module F V] [FiniteDimensional F V] + [Fintype J] (s : J→ Submodule F V) : + dim (Submodule.pi Set.univ s) ≤ ∑ i, dim (s i) := by + let T := Submodule.pi Set.univ s + have h (i : J) (x : T) : x.val i∈ s i := x.property i (Set.mem_univ i) + let f : T →ₗ[F] (∀ i,s i) := { + toFun := fun x i => ⟨_,h i x⟩ + map_add' := by intro x y; rfl + map_smul' := by intro x y; rfl } + have hf : Function.Injective f := fun x y e => Subtype.ext (funext (fun i => + show x.val i=y.val i from congrArg (fun t:s i => t.val) (congr_fun e i))) + exact (LinearMap.finrank_le_finrank_of_injective hf).trans_eq + (Module.finrank_pi_fintype _) + +theorem effective_dim (s : Plan p n) (i : Bool) : + dim (effective s i) ≤ (planRank s)^2 := by + unfold effective + let p' (e : Comp p.g) := (sPin s (e,true) i) + let q (e : Comp p.g) := (sPin s (e,false) i) + refine ((Submodule.finrank_mono (show _ ⊓ _ ≤ Submodule.pi Set.univ (fun e => box (p' e) + (q e)) from inf_le_right)).trans (pi_dim_le _)).trans ?_ + simp_rw [box_dim] + calc ∑ i, dim (p' i) * dim (q i) ≤ ∑ i, dim (p' i)* planRank s := Finset.sum_le_sum (fun j _ => + Nat.mul_le_mul_left _ ((sPin_dim s _ i).trans (dim_le_plan s _))) + _ ≤ _ := by rw [← Finset.sum_mul,pow_two]; exact Nat.mul_le_mul_right _ (sPin_sum s true i) + +theorem table_dim (s : Plan p n) (e : Place p) : + dim (tabSpace s e) ≤ 2*(planRank s + p.h) := by + have hh i : dim (halfTable s e i)≤ planRank s+p.h := by + have hg : dim (colSp (IH p n i)) ≤ p.h := (IH p n i).rank_le_card_width.trans_eq + (Fintype.card_fin _) + apply le_trans (Submodule.finrank_add_le_finrank_add_finrank ..) + exact Nat.add_le_add ((Submodule.finrank_map_le _ _).trans + ((sPin_dim ..).trans (dim_le_plan s e))) hg + exact ((Submodule.finrank_add_le_finrank_add_finrank ..).trans + (Nat.add_le_add (hh true) (hh false))).trans_eq (two_mul _).symm + +theorem pin_protection (s : Plan p n) (i : Bool) (K q : ℕ) + (hk : planRank s ≤ K) (hj : (K+1)*q≤p.j+1) : + ∃ L : Finset (Label p.b), + L.card ≤ 2*Fintype.card (Comp p.g)*K*q ∧ + ∀ z : Place p, protectedBy p (sPin s z i) q L := by + classical + have he z : dim (sPin s z i)≤K := ((sPin_dim s z i).trans (dim_le_plan s z)).trans hk + choose L hL hP using fun z => protect_labels p (sPin s z i) q + (le_trans (Nat.mul_le_mul_right _ (Nat.add_le_add_right (he z) 1)) hj) + refine ⟨Finset.univ.biUnion L, ?_,fun z B v h hq x hx hl => + hP z B v h hq x hx (fun ht => hl (Finset.mem_biUnion.mpr ⟨z,Finset.mem_univ _,ht⟩))⟩ + calc (Finset.univ.biUnion L).card + _ ≤ _ := Finset.card_biUnion_le + _ ≤ ∑ z : Place p, K*q := Finset.sum_le_sum + (fun j _ => (hL j).trans (Nat.mul_le_mul_right _ (he j))) + _ = _ := by simp [Place]; ring + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/NumericalGradientTests.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/NumericalGradientTests.lean index c702a06fb15f766e9a6ed602f5f5bb34b8b6dce5..8e0e6ecbe3ca248671476a4b8ab953ff99b89135 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/NumericalGradientTests.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/NumericalGradientTests.lean @@ -1,138 +1,138 @@ -import OAI.Combinatorics.HadwigerCounterexample.StatusRecipes - -namespace OAI - -/-! # Numerical Gradient Tests -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module LinearMap Function Submodule -open scoped BigOperators -namespace StatusAnalysis -variable {p : Shape} {n N : ℕ} {q : Format} {d e : Rates} -def mailRole {b} (a : Amounts p q d b) := - fun i=>(a i).2.1.1 -def mailBias {b} (a : Amounts p q d b) := - fun i=>(a i).2.2 - -theorem aim_sum {H : Type} [AddCommMonoid H] (b : Bool) (x : Grid) (u : Messenger q→H) : - ∑ j∈aiming (parcel b) (parcel (!b)) (sendId b x) (sendId (!b) x),u j=∑ i:Fin (q x),u ⟨x,i⟩ := by - let p : Shape := ⟨0,0,0,0,0,0⟩ - let v : Volley p 0 (Messenger q) := ⟨parcel b,fun _ =>0,fun _=>0⟩ - exact sum_shots b v x rfl _ -def TMill (p : Shape) {b} {d} (t : Tagging p (Messenger q)) (w : Amounts p q d b) : - Mat (Messenger q) (Messenger q) := - let a (x : Tag p.g) (i : Messenger q) := ∑ z:Tag p.g,(w i).1 (Sum.inl (z,x)) - let f (x : Tag p.g) (i : Messenger q) := - let c:=(w i).1 (Sum.inr ()) - c+(if t i=x then c else 0) - Matrix.of fun i j => mailRole w i * mailRole w j + - ∑ x:Tag p.g,(a x i * f x j + f x i * a x j) -theorem tmill_sym {b} (t : Tagging p (Messenger q)) (w : Amounts p q d b) : - (TMill p t w)ᵀ=TMill p t w := by - classical - ext i j - unfold TMill; simp only [transpose_apply,Matrix.of_apply]; congr 1 - · ring - exact Finset.sum_congr rfl fun _ _ => by ring - -def proclaims {b : Bool} (p : Shape) {d e} - (a : Amounts p q d b) (w : Amounts p q e (!b)) (t : Tagging p (Messenger q)) - (g : Script p (Messenger q)) := - fulfills p t (mailRole a) (mailBias w) (TMill p t a) g (parcel b) (parcel (!b)) - -theorem funds_roles {b} (a : Amounts p q d b) (i : Grid) : - (funds a i).1.1=∑ x : Fin (q i), mailRole a ⟨i,x⟩ := by - let entries : Fin (q i) → Whole (d (sendId b i)) := fun k => (a ⟨i,k⟩).2 - change (∑ k, entries k).1.1 = _ - rw [Prod.fst_sum,Prod.fst_sum] - rfl -theorem funds_duos {b} (a : Amounts p q d b) (i : Grid) : - couple _ (funds a i)= - ∑ x: Fin (q i), (mailRole a ⟨i,x⟩+mailBias a ⟨i,x⟩) := by - let entries : Fin (q i) → Whole (d (sendId b i)) := fun k => (a ⟨i,k⟩).2 - change couple _ (∑ k, entries k) = _ - rw [map_sum] - rfl - -set_option maxHeartbeats 800000 in -theorem proclaim_script (b : Bool) (a : Amounts p q d b) (w : Amounts p q e (!b)) (t : Tagging p - (Messenger q)) - (v : Charts p n e) (M : Cross p n) - (h : rhyme a w) (hb : ∀ i,1≤ q i) - (hr : still (!b) w v M) - (hg : 2≤p.g) (hj : 1≤p.J) : ∃ s, proclaims p a w t s := by - have ha {H : Type} [AddCommMonoid H] (a e : Nodes) (f : Messenger q→ H) : - ∑ x∈aiming (parcel b) (parcel (!b)) a e, f x=∑ i:Fin (q (transit b (a,e))),f - ⟨transit b (a,e),i⟩ := by - have hA := aim_sum b (transit b (a,e)) f - have he := (sendPair b (transit b (a,e))).trans (transit_inv b _) - rw [show sendId b _ = a from congrArg Prod.fst he, - show sendId (!b) _=e from congrArg Prod.snd he] at hA - exact hA - apply choose_script p t _ _ _ _ (mailRole w) _ _ _ _ (tmill_sym ..) hg hj - · intro i - rw [ha,ha,←funds_duos w,←funds_duos w] - have hx:=hr.2 i; cases b <;> exact hx - · intro i j; rw [ha,sum_add_distrib,←funds_roles a, ←funds_roles w] - exact h _ - intro i j - let k:=transit b (i,j) - let x : Messenger q:=⟨k,0,(hb k)⟩ - have he := (sendPair b k).trans (transit_inv b (i,j)) - exact ⟨x,Finset.mem_filter.mpr ⟨mem_univ _,congrArg Prod.fst he,congrArg Prod.snd he⟩⟩ - -theorem tmill_formula {b} (t : Tagging p (Messenger q)) (hg : Odd p.g) (v : Charts p n d) - (l f) (x : Inputs p n (Messenger q)) (m : Mixer p n) (o : UnitType p n N) - (a : Amounts p q d b) (h : printed b v t l f m o x=a) (i j : Messenger q) : - T0 p n (useAtom p (t i) (l i) (f i) (x i)) (useAtom p (t j) (l j) (f j) (x j)) = - TMill p t a i j := by - classical - rw [← h] - simp_rw [T0_val, roleT_scan,sharedT_scan _ hg] - rfl - -theorem procl_grad (t : Tagging p (Messenger q)) - {b} (a : Amounts p q d b) (w : Amounts p q e (!b)) - (hg : Odd p.g) (v : Charts p n d) (v' : Charts p n e) - (l f l' f') (x y : Inputs p n (Messenger q)) - (m : Mixer p n) (o z : UnitType p n N) - (h : printed b v t l f m o x=a) (hz : printed (!b) v' t l' f' m z y=w) - (s : Script p (Messenger q)) (hs : proclaims p a w t s) : - let u:=(manager b t l f).draw x - u.reads s m → u.attackGrad ((manager (!b) t l' f').draw y) t m z := by - intro u hu - apply Volley.grads_by_script (v:=u) t m ((manager (!b) t l' f').draw y) z (d:=mailRole a) (f:=mailBias w) (u:=TMill p t a) (s:=s) hs hu - · rw [← h]; intro; rfl - · rw [←hz]; intro; rfl - exact tmill_formula t hg v l f x m o a h - -set_option maxHeartbeats 600000 in -theorem rhyme_match (t : Tagging p (Messenger q)) (a : Amounts p q d true) - (w : Amounts p q e false) - (v : Charts p n d) (v' : Charts p n e) - (l f l' f') (x y : Inputs p n (Messenger q)) - (m : Mixer p n) (o z : UnitType p n N) - (h : printed true v t l f m o x=a) (hz : printed false v' t l' f' m z y=w) - (he : rhyme a w) : - let u:=(manager true t l f).draw x - u.roleMatch ((manager false t l' f').draw y) t := by - classical - intro u i j - let q:= (i,j) - let s:= (manager false t l' f').draw y - have hh : u.sumAt t s.obj i j=unionAt (u.atomAt t) (i,j) := - sumAtSend true u t (i,j) rfl - have hf : s.sumAt t u.obj j i=unionAt (s.atomAt t) (i,j) := sumAtSend false s t (i,j) rfl - change _ + role _ _ (s.sumAt _ _ _ _)=_ - rw [hh,hf] - specialize he (i,j) - change (funds a (i,j)).1.1+(funds w (i,j)).1.1=1 at he - rw [funds_reg t true v m o l f x a h,funds_reg t false v' m z l' f' y w hz] at he - exact he -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.StatusRecipes + +namespace OAI + +/-! # Numerical Gradient Tests -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module LinearMap Function Submodule +open scoped BigOperators +namespace StatusAnalysis +variable {p : Shape} {n N : ℕ} {q : Format} {d e : Rates} +def mailRole {b} (a : Amounts p q d b) := + fun i=>(a i).2.1.1 +def mailBias {b} (a : Amounts p q d b) := + fun i=>(a i).2.2 + +theorem aim_sum {H : Type} [AddCommMonoid H] (b : Bool) (x : Grid) (u : Messenger q→H) : + ∑ j∈aiming (parcel b) (parcel (!b)) (sendId b x) (sendId (!b) x),u j=∑ i:Fin (q x),u ⟨x,i⟩ := by + let p : Shape := ⟨0,0,0,0,0,0⟩ + let v : Volley p 0 (Messenger q) := ⟨parcel b,fun _ =>0,fun _=>0⟩ + exact sum_shots b v x rfl _ +def TMill (p : Shape) {b} {d} (t : Tagging p (Messenger q)) (w : Amounts p q d b) : + Mat (Messenger q) (Messenger q) := + let a (x : Tag p.g) (i : Messenger q) := ∑ z:Tag p.g,(w i).1 (Sum.inl (z,x)) + let f (x : Tag p.g) (i : Messenger q) := + let c:=(w i).1 (Sum.inr ()) + c+(if t i=x then c else 0) + Matrix.of fun i j => mailRole w i * mailRole w j + + ∑ x:Tag p.g,(a x i * f x j + f x i * a x j) +theorem tmill_sym {b} (t : Tagging p (Messenger q)) (w : Amounts p q d b) : + (TMill p t w)ᵀ=TMill p t w := by + classical + ext i j + unfold TMill; simp only [transpose_apply,Matrix.of_apply]; congr 1 + · ring + exact Finset.sum_congr rfl fun _ _ => by ring + +def proclaims {b : Bool} (p : Shape) {d e} + (a : Amounts p q d b) (w : Amounts p q e (!b)) (t : Tagging p (Messenger q)) + (g : Script p (Messenger q)) := + fulfills p t (mailRole a) (mailBias w) (TMill p t a) g (parcel b) (parcel (!b)) + +theorem funds_roles {b} (a : Amounts p q d b) (i : Grid) : + (funds a i).1.1=∑ x : Fin (q i), mailRole a ⟨i,x⟩ := by + let entries : Fin (q i) → Whole (d (sendId b i)) := fun k => (a ⟨i,k⟩).2 + change (∑ k, entries k).1.1 = _ + rw [Prod.fst_sum,Prod.fst_sum] + rfl +theorem funds_duos {b} (a : Amounts p q d b) (i : Grid) : + couple _ (funds a i)= + ∑ x: Fin (q i), (mailRole a ⟨i,x⟩+mailBias a ⟨i,x⟩) := by + let entries : Fin (q i) → Whole (d (sendId b i)) := fun k => (a ⟨i,k⟩).2 + change couple _ (∑ k, entries k) = _ + rw [map_sum] + rfl + +set_option maxHeartbeats 800000 in +theorem proclaim_script (b : Bool) (a : Amounts p q d b) (w : Amounts p q e (!b)) (t : Tagging p + (Messenger q)) + (v : Charts p n e) (M : Cross p n) + (h : rhyme a w) (hb : ∀ i,1≤ q i) + (hr : still (!b) w v M) + (hg : 2≤p.g) (hj : 1≤p.J) : ∃ s, proclaims p a w t s := by + have ha {H : Type} [AddCommMonoid H] (a e : Nodes) (f : Messenger q→ H) : + ∑ x∈aiming (parcel b) (parcel (!b)) a e, f x=∑ i:Fin (q (transit b (a,e))),f + ⟨transit b (a,e),i⟩ := by + have hA := aim_sum b (transit b (a,e)) f + have he := (sendPair b (transit b (a,e))).trans (transit_inv b _) + rw [show sendId b _ = a from congrArg Prod.fst he, + show sendId (!b) _=e from congrArg Prod.snd he] at hA + exact hA + apply choose_script p t _ _ _ _ (mailRole w) _ _ _ _ (tmill_sym ..) hg hj + · intro i + rw [ha,ha,←funds_duos w,←funds_duos w] + have hx:=hr.2 i; cases b <;> exact hx + · intro i j; rw [ha,sum_add_distrib,←funds_roles a, ←funds_roles w] + exact h _ + intro i j + let k:=transit b (i,j) + let x : Messenger q:=⟨k,0,(hb k)⟩ + have he := (sendPair b k).trans (transit_inv b (i,j)) + exact ⟨x,Finset.mem_filter.mpr ⟨mem_univ _,congrArg Prod.fst he,congrArg Prod.snd he⟩⟩ + +theorem tmill_formula {b} (t : Tagging p (Messenger q)) (hg : Odd p.g) (v : Charts p n d) + (l f) (x : Inputs p n (Messenger q)) (m : Mixer p n) (o : UnitType p n N) + (a : Amounts p q d b) (h : printed b v t l f m o x=a) (i j : Messenger q) : + T0 p n (useAtom p (t i) (l i) (f i) (x i)) (useAtom p (t j) (l j) (f j) (x j)) = + TMill p t a i j := by + classical + rw [← h] + simp_rw [T0_val, roleT_scan,sharedT_scan _ hg] + rfl + +theorem procl_grad (t : Tagging p (Messenger q)) + {b} (a : Amounts p q d b) (w : Amounts p q e (!b)) + (hg : Odd p.g) (v : Charts p n d) (v' : Charts p n e) + (l f l' f') (x y : Inputs p n (Messenger q)) + (m : Mixer p n) (o z : UnitType p n N) + (h : printed b v t l f m o x=a) (hz : printed (!b) v' t l' f' m z y=w) + (s : Script p (Messenger q)) (hs : proclaims p a w t s) : + let u:=(manager b t l f).draw x + u.reads s m → u.attackGrad ((manager (!b) t l' f').draw y) t m z := by + intro u hu + apply Volley.grads_by_script (v:=u) t m ((manager (!b) t l' f').draw y) z (d:=mailRole a) (f:=mailBias w) (u:=TMill p t a) (s:=s) hs hu + · rw [← h]; intro; rfl + · rw [←hz]; intro; rfl + exact tmill_formula t hg v l f x m o a h + +set_option maxHeartbeats 600000 in +theorem rhyme_match (t : Tagging p (Messenger q)) (a : Amounts p q d true) + (w : Amounts p q e false) + (v : Charts p n d) (v' : Charts p n e) + (l f l' f') (x y : Inputs p n (Messenger q)) + (m : Mixer p n) (o z : UnitType p n N) + (h : printed true v t l f m o x=a) (hz : printed false v' t l' f' m z y=w) + (he : rhyme a w) : + let u:=(manager true t l f).draw x + u.roleMatch ((manager false t l' f').draw y) t := by + classical + intro u i j + let q:= (i,j) + let s:= (manager false t l' f').draw y + have hh : u.sumAt t s.obj i j=unionAt (u.atomAt t) (i,j) := + sumAtSend true u t (i,j) rfl + have hf : s.sumAt t u.obj j i=unionAt (s.atomAt t) (i,j) := sumAtSend false s t (i,j) rfl + change _ + role _ _ (s.sumAt _ _ _ _)=_ + rw [hh,hf] + specialize he (i,j) + change (funds a (i,j)).1.1+(funds w (i,j)).1.1=1 at he + rw [funds_reg t true v m o l f x a h,funds_reg t false v' m z l' f' y w hz] at he + exact he +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/NumericalGramPrescriptions.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/NumericalGramPrescriptions.lean index 2b8617eec5e2e91f0a503fda10f3e3882a0cf138..e028445fe3012c22ad77cd8b07450fbbe6e0231f 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/NumericalGramPrescriptions.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/NumericalGramPrescriptions.lean @@ -1,100 +1,100 @@ -import OAI.Combinatorics.HadwigerCounterexample.SyntheticArraySlices - -namespace OAI - -/-! # Numerical Gram Prescriptions -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Function LinearMap Module -open scoped BigOperators Pointwise -variable {p : Shape} {n N d e : ℕ} {I : Type} [Fintype I] [DecidableEq I] - -def spacePunch (p : Shape) (l : Tag p.g) (f : Flavor p.g) := - (Finset.univ.filter (usesPunch p l f)).card - -omit [DecidableEq I] in -set_option maxHeartbeats 800000 in -theorem punch_real (p : Shape) (l : Tag p.g) (f : Flavor p.g) (G : Mat I I) - (h : G.rank≤spacePunch p l f) : - ∃ a : I→ Tickets p,labGram p l f a=G := by - classical - let P:= Finset.univ.filter (usesPunch p l f) - let q:=Fintype.equivFinOfCardEq (Fintype.card_coe P) - obtain ⟨u,v,hg⟩:=mul_factor G P.card h - let x (i:I) (j:Punch p) := if h:j∈P then u i (q ⟨j,h⟩) else 0 - let y (i:I) (j:Punch p) := if h:j∈P then v (q ⟨j,h⟩) i else 0 - let a (i:I) : Tickets p := fun j => if j.2 then x i j.1 else y i j.1 - refine ⟨a,?_⟩ - rw [←hg]; ext i j - change (∑ t:Punch p,(if usesPunch p l f t then a i (t,true)*a j (t,false) else 0))=∑ t,u i t * v t j - have ht (t:Punch p) : a i (t,true)*a j (t,false)=x i t*y j t := rfl - simp_rw [ht,← Finset.sum_filter] - change ∑ t∈P,x i t*y j t=_ - calc _ = ∑ t:P,x i t.val*y j t.val := Eq.symm (Finset.sum_coe_sort P (fun t=>x i t*y j t)) - _ = _ := by - have hh (t : ↑P) : x i t.val*y j t.val=u i (q t)*v (q t) j := by - unfold x y; rw [dite_eq_left t.property,dite_eq_left t.property] - simp_rw [hh]; exact Equiv.sum_comp q (fun t=>u i t*v t j) - -theorem beam_rank (f : Sextant d e) : (pullM (cartM f) (cartM f) (beamMap e)).rank≤d := by - classical - rw [cart_target] - let V := (beamMap e).submatrix (reflectSextant f) (reflectSextant f) - let P : Mat (Hue d) (Fin d) := embedMat (fun x=>incarn x true) - let Q : Mat (Fin d) (Hue d) := Matrix.of fun i j => V (incarn i true) j - have hnone (j : Hue d) : V none j = 0 := rfl - have hfalse (i : Fin d) (j : Hue d) : V (some (false,i)) j = 0 := by - cases j with - | none => rfl - | some j => rcases j with ⟨b,j⟩; cases b <;> rfl - have h : P*Q=V := by - ext i j - rcases i with _|⟨b,i⟩ - · simp [Matrix.mul_apply,P,embedMat,incarn,hnone] - cases b - · simp [Matrix.mul_apply,P,embedMat,incarn,hfalse] - · simp [Matrix.mul_apply,P,Q,embedMat,incarn] - change V.rank≤ d - rw [←h] - exact (Matrix.rank_mul_le_left ..).trans ((P.rank_le_card_width).trans_eq (by simp)) - -theorem sharedPunch (p : Shape) (hr : 1≤p.r) (l : Tag p.g) : - 1 ≤ spacePunch p l Flavor.sharedOnly := by - let i : Punch p := (.inr (),⟨0,hr⟩) - exact Finset.card_pos.mpr ⟨i,Finset.mem_filter.mpr ⟨mem_univ _,trivial⟩⟩ - -/-- selected pure excludes second tags -/ -def creed (p : Shape) (E : Finset (Tag p.g)) := - Flavor.pure (Finset.univ.filter fun i : Tag p.g×Tag p.g => i.2∉E) - -theorem purePunch (p : Shape) (l : Tag p.g) (E : Finset (Tag p.g)) : - ((p.g-1)/2)*(p.g-E.card)*p.r≤spacePunch p l (creed p E) := by - classical - let u := Finset.univ.filter (fun i=> allowed i l) - let v := Finset.univ\ E - let Z := u ×ˢ (v ×ˢ (Finset.univ : Finset (Fin p.r))) - let f (i : Tag p.g × Tag p.g × Fin p.r) : Punch p := (.inl (i.1,i.2.1),i.2.2) - have hf : Injective f := by - rintro ⟨i,j,k⟩ ⟨x,y,z⟩ h - simpa only [Prod.mk.injEq,Sum.inl.injEq,f,and_assoc] using h - have he : Z.image f⊆ Finset.univ.filter (usesPunch p l (creed p E)) := by - rintro i hi - obtain ⟨⟨i,j,k⟩,hv,rfl⟩:=mem_image.mp hi - simp only [Z,u,v,mem_product,mem_sdiff,mem_filter,mem_univ,true_and,and_true] at hv - refine mem_filter.mpr ⟨mem_univ _,?_⟩ - exact ⟨hv.1,mem_filter.mpr ⟨mem_univ _,hv.2⟩⟩ - have ht := card_le_card he - rw [card_image_of_injective _ hf] at ht - have hu : u.card=(p.g-1)/2 := by - have h:= card_allowed' l; rw [Fintype.card_subtype] at h; exact h - unfold spacePunch - refine le_trans ?_ ht - unfold Z v; rw [card_product,card_product,Finset.card_sdiff_of_subset (subset_univ _), - card_univ,card_univ,hu,Fintype.card_fin,Fintype.card_fin, - mul_assoc] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SyntheticArraySlices + +namespace OAI + +/-! # Numerical Gram Prescriptions -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Function LinearMap Module +open scoped BigOperators Pointwise +variable {p : Shape} {n N d e : ℕ} {I : Type} [Fintype I] [DecidableEq I] + +def spacePunch (p : Shape) (l : Tag p.g) (f : Flavor p.g) := + (Finset.univ.filter (usesPunch p l f)).card + +omit [DecidableEq I] in +set_option maxHeartbeats 800000 in +theorem punch_real (p : Shape) (l : Tag p.g) (f : Flavor p.g) (G : Mat I I) + (h : G.rank≤spacePunch p l f) : + ∃ a : I→ Tickets p,labGram p l f a=G := by + classical + let P:= Finset.univ.filter (usesPunch p l f) + let q:=Fintype.equivFinOfCardEq (Fintype.card_coe P) + obtain ⟨u,v,hg⟩:=mul_factor G P.card h + let x (i:I) (j:Punch p) := if h:j∈P then u i (q ⟨j,h⟩) else 0 + let y (i:I) (j:Punch p) := if h:j∈P then v (q ⟨j,h⟩) i else 0 + let a (i:I) : Tickets p := fun j => if j.2 then x i j.1 else y i j.1 + refine ⟨a,?_⟩ + rw [←hg]; ext i j + change (∑ t:Punch p,(if usesPunch p l f t then a i (t,true)*a j (t,false) else 0))=∑ t,u i t * v t j + have ht (t:Punch p) : a i (t,true)*a j (t,false)=x i t*y j t := rfl + simp_rw [ht,← Finset.sum_filter] + change ∑ t∈P,x i t*y j t=_ + calc _ = ∑ t:P,x i t.val*y j t.val := Eq.symm (Finset.sum_coe_sort P (fun t=>x i t*y j t)) + _ = _ := by + have hh (t : ↑P) : x i t.val*y j t.val=u i (q t)*v (q t) j := by + unfold x y; rw [dite_eq_left t.property,dite_eq_left t.property] + simp_rw [hh]; exact Equiv.sum_comp q (fun t=>u i t*v t j) + +theorem beam_rank (f : Sextant d e) : (pullM (cartM f) (cartM f) (beamMap e)).rank≤d := by + classical + rw [cart_target] + let V := (beamMap e).submatrix (reflectSextant f) (reflectSextant f) + let P : Mat (Hue d) (Fin d) := embedMat (fun x=>incarn x true) + let Q : Mat (Fin d) (Hue d) := Matrix.of fun i j => V (incarn i true) j + have hnone (j : Hue d) : V none j = 0 := rfl + have hfalse (i : Fin d) (j : Hue d) : V (some (false,i)) j = 0 := by + cases j with + | none => rfl + | some j => rcases j with ⟨b,j⟩; cases b <;> rfl + have h : P*Q=V := by + ext i j + rcases i with _|⟨b,i⟩ + · simp [Matrix.mul_apply,P,embedMat,incarn,hnone] + cases b + · simp [Matrix.mul_apply,P,embedMat,incarn,hfalse] + · simp [Matrix.mul_apply,P,Q,embedMat,incarn] + change V.rank≤ d + rw [←h] + exact (Matrix.rank_mul_le_left ..).trans ((P.rank_le_card_width).trans_eq (by simp)) + +theorem sharedPunch (p : Shape) (hr : 1≤p.r) (l : Tag p.g) : + 1 ≤ spacePunch p l Flavor.sharedOnly := by + let i : Punch p := (.inr (),⟨0,hr⟩) + exact Finset.card_pos.mpr ⟨i,Finset.mem_filter.mpr ⟨mem_univ _,trivial⟩⟩ + +/-- selected pure excludes second tags -/ +def creed (p : Shape) (E : Finset (Tag p.g)) := + Flavor.pure (Finset.univ.filter fun i : Tag p.g×Tag p.g => i.2∉E) + +theorem purePunch (p : Shape) (l : Tag p.g) (E : Finset (Tag p.g)) : + ((p.g-1)/2)*(p.g-E.card)*p.r≤spacePunch p l (creed p E) := by + classical + let u := Finset.univ.filter (fun i=> allowed i l) + let v := Finset.univ\ E + let Z := u ×ˢ (v ×ˢ (Finset.univ : Finset (Fin p.r))) + let f (i : Tag p.g × Tag p.g × Fin p.r) : Punch p := (.inl (i.1,i.2.1),i.2.2) + have hf : Injective f := by + rintro ⟨i,j,k⟩ ⟨x,y,z⟩ h + simpa only [Prod.mk.injEq,Sum.inl.injEq,f,and_assoc] using h + have he : Z.image f⊆ Finset.univ.filter (usesPunch p l (creed p E)) := by + rintro i hi + obtain ⟨⟨i,j,k⟩,hv,rfl⟩:=mem_image.mp hi + simp only [Z,u,v,mem_product,mem_sdiff,mem_filter,mem_univ,true_and,and_true] at hv + refine mem_filter.mpr ⟨mem_univ _,?_⟩ + exact ⟨hv.1,mem_filter.mpr ⟨mem_univ _,hv.2⟩⟩ + have ht := card_le_card he + rw [card_image_of_injective _ hf] at ht + have hu : u.card=(p.g-1)/2 := by + have h:= card_allowed' l; rw [Fintype.card_subtype] at h; exact h + unfold spacePunch + refine le_trans ?_ ht + unfold Z v; rw [card_product,card_product,Finset.card_sdiff_of_subset (subset_univ _), + card_univ,card_univ,hu,Fintype.card_fin,Fintype.card_fin, + mul_assoc] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetEnergy.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetEnergy.lean index 674a17f0659b5701388fb9450f4736df0b8360ed..2f240e022c54edf7fcec7a5be1cf07d5ce8cc234 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetEnergy.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetEnergy.lean @@ -1,132 +1,132 @@ -import OAI.Combinatorics.HadwigerCounterexample.OffsetRecords - -namespace OAI - -/-! # Offset Energy -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Finset Function -open scoped BigOperators -variable {p : Shape} {r n N : ℕ} -variable {q t : Place p→ℕ} {S : Cov p N} - -def unary (i : Bool) : Party := Pi.single i 1 - -def heat (p : Shape) {n N} (x : UnitType p n N) (v : Party) (z : Place p) : - Mat (Fin N) (Fin N) := - ∑ i : Bool,v i • (fyAt p (onSide x i) z * (fyAt p (onSide x i) (flipZ p z))ᵀ) -def thermal (p : Shape) {n N} (x : UnitType p n N) (v : Party) {q : Place p→ℕ} - (A : DTuple (p:=p) q N) : DTuple (p:=p) q N := - fun z => heat p x v z * A z - -def sparks (p : Shape) {n N} (x : UnitType p n N) (v : Party) {q : Place p→ℕ} - (A : DTuple (p:=p) q N) (i : Bool) : DTuple (p:=p) q p.h := - fun z => v i • ((fyAt p (onSide x i) (flipZ p z))ᵀ * A z) - -def glimpse (p : Shape) {n N} (x : UnitType p n N) (i : Bool) {q : Place p→ℕ} - (A : DTuple (p:=p) q N) := - ∀ z,Injective ((fyAt p (onSide x i) (flipZ p z))ᵀ * A z).mulVec - -def hfused (p : Shape) (n : ℕ) (r : Place p→ℕ) (A : Bool→DTuple (p:=p) r p.h) : - WTuple (p:=p) r n := - fun z => ∑ i : Bool, IH p n i * A i z - -theorem heat_flip (p : Shape) {n N} (x : UnitType p n N) (v : Party) (z : Place p) : - (heat p x v (flipZ p z))ᵀ=heat p x v z := by - simp only [heat,Matrix.transpose_sum,Matrix.transpose_smul,Matrix.transpose_mul, - Matrix.transpose_transpose,flipZ_flip] - -theorem heat_unary (x : UnitType p n N) (i) (z : Place p) : - heat p x (unary i) z=fyAt p (onSide x i) z * (fyAt p (onSide x i) (flipZ p z))ᵀ := by - rw [heat,Finset.sum_eq_single i] - · simp [unary] - · intro j _ hj; simp [unary,hj] - simp - -theorem fuse_val (x : UnitType p n N) (v : Party) (A : DTuple (p:=p) q N) (z : Place p) : - images x z * hfused p n q (sparks p x v A) z=thermal p x v A z := by - classical - unfold hfused thermal heat sparks - rw [Fintype.sum_bool,Fintype.sum_bool] - simp only [Matrix.smul_mul,Matrix.mul_smul,Matrix.add_mul,Matrix.mul_add] - have he (i : Bool) : - images x z * (IH p n i * ((fyAt p (onSide x i) (flipZ p z))ᵀ * A z))= - fyAt p (onSide x i) z*(fyAt p (onSide x i) (flipZ p z))ᵀ * A z := by - rw [← Matrix.mul_assoc (images x z),images_ih] - change _ * (_ * _) = _ * _ * _ - exact (Matrix.mul_assoc ..).symm - rw [he,he] - -theorem fused_support (B : Bool→DTuple (p:=p) q p.h) (z : Place p) : - colSp (hfused p n q B z)≤channels p n := by - unfold hfused - rw [Fintype.sum_bool] - rintro x ⟨y,rfl⟩ - rw [mulVecLin_apply,Matrix.add_mulVec,← Matrix.mulVec_mulVec,← Matrix.mulVec_mulVec] - exact Submodule.add_mem _ (ih_le_channels true ⟨_,rfl⟩) (ih_le_channels false ⟨_,rfl⟩) - -theorem fused_inj (A : Bool→DTuple (p:=p) q p.h) (z : Place p) (i : Bool) - (h : Injective (A i z).mulVec) : - Injective (hfused p n q A z).mulVec := by - have hh : (IH p n i)ᵀ*hfused p n q A z=A i z := by - unfold hfused - rw [Fintype.sum_bool,Matrix.mul_add] - simp only [← Matrix.mul_assoc] - cases i <;> - simp only [IH_self,IH_cross (show false≠true by decide),IH_cross (show true≠false by decide), - Matrix.zero_mul,Matrix.one_mul,add_zero,zero_add] - intro x y hx - apply h - rw [←hh, ← Matrix.mulVec_mulVec, ← Matrix.mulVec_mulVec,hx] - -theorem hotfused (x : UnitType p n N) (v : Party) (A : DTuple (p:=p) q N) - (i : Bool) (h : v i=1) (hh : glimpse p x i A) (z) : - Injective (hfused p n q (sparks p x v A) z).mulVec := by - refine fused_inj _ _ i ?_ - unfold sparks; rw [h,one_smul] - exact hh z - -theorem tone_heat (x : UnitType p n N) (v : Party) (T : Ambient p N) : - tone p x v T = ∑ e : Comp p.g, mpair (heat p x v (e,false)) (T e) := by - classical - simp only [tone,joinPhase,uPhase,heat,mpair_sum,mpair_smul,LinearMap.sum_apply, - LinearMap.comp_apply,LinearMap.smul_apply,smul_eq_mul,mul_sum] - rw [Finset.sum_comm] - refine Finset.sum_congr rfl fun j _ => Finset.sum_congr rfl fun i _ => ?_ - cases i <;> rfl - -variable {I J : Type} [Fintype I] [Fintype J] - -private theorem trace_shift_l (M : Mat I I) (A V : Mat I J) : - mpair M (A*Vᵀ)=mpair V (Mᵀ*A) := by - rw [mpair_comm V] - change (M*(A*Vᵀ)ᵀ).trace=((Mᵀ*A)* Vᵀ).trace - rw [Matrix.transpose_mul,Matrix.transpose_transpose, - ←Matrix.trace_transpose ((Mᵀ*A) * Vᵀ),Matrix.transpose_mul,Matrix.transpose_mul, - Matrix.transpose_transpose,Matrix.transpose_transpose,←Matrix.mul_assoc V, - Matrix.trace_mul_comm _ M] - -private theorem trace_shift_r (M : Mat I I) (A V : Mat I J) : - mpair M (V*Aᵀ)=mpair V (M*A) := by - rw [mpair_comm V] - change (M*(V*Aᵀ)ᵀ).trace=((M*A)* Vᵀ).trace - rw [Matrix.transpose_mul,Matrix.transpose_transpose,Matrix.mul_assoc] - -theorem tone_offset (x : UnitType p n N) (v : Party) (M : Atlas p r S) (A : Batch M N) : - tone p x v (spelled M A)=tupleB p (breadth M) N A (thermal p x v (src M))+ - tone p x v (edgeCost M) := by - rw [tone_heat,tone_heat,tupleB_val,Fintype.sum_prod_type] - simp only [spelled,map_add,Finset.sum_add_distrib,Fintype.sum_bool] - refine congrArg (fun z => z+_) (congrArg₂ (·+·) ?_ ?_) - · refine Finset.sum_congr rfl fun e _ => ?_ - rw [trace_shift_l,show (heat p x v (e,false))ᵀ=heat p x v (e,true) from - heat_flip p x v (e,true)] - rfl - refine Finset.sum_congr rfl fun e _ => ?_ - rw [trace_shift_r]; rfl -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.OffsetRecords + +namespace OAI + +/-! # Offset Energy -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Finset Function +open scoped BigOperators +variable {p : Shape} {r n N : ℕ} +variable {q t : Place p→ℕ} {S : Cov p N} + +def unary (i : Bool) : Party := Pi.single i 1 + +def heat (p : Shape) {n N} (x : UnitType p n N) (v : Party) (z : Place p) : + Mat (Fin N) (Fin N) := + ∑ i : Bool,v i • (fyAt p (onSide x i) z * (fyAt p (onSide x i) (flipZ p z))ᵀ) +def thermal (p : Shape) {n N} (x : UnitType p n N) (v : Party) {q : Place p→ℕ} + (A : DTuple (p:=p) q N) : DTuple (p:=p) q N := + fun z => heat p x v z * A z + +def sparks (p : Shape) {n N} (x : UnitType p n N) (v : Party) {q : Place p→ℕ} + (A : DTuple (p:=p) q N) (i : Bool) : DTuple (p:=p) q p.h := + fun z => v i • ((fyAt p (onSide x i) (flipZ p z))ᵀ * A z) + +def glimpse (p : Shape) {n N} (x : UnitType p n N) (i : Bool) {q : Place p→ℕ} + (A : DTuple (p:=p) q N) := + ∀ z,Injective ((fyAt p (onSide x i) (flipZ p z))ᵀ * A z).mulVec + +def hfused (p : Shape) (n : ℕ) (r : Place p→ℕ) (A : Bool→DTuple (p:=p) r p.h) : + WTuple (p:=p) r n := + fun z => ∑ i : Bool, IH p n i * A i z + +theorem heat_flip (p : Shape) {n N} (x : UnitType p n N) (v : Party) (z : Place p) : + (heat p x v (flipZ p z))ᵀ=heat p x v z := by + simp only [heat,Matrix.transpose_sum,Matrix.transpose_smul,Matrix.transpose_mul, + Matrix.transpose_transpose,flipZ_flip] + +theorem heat_unary (x : UnitType p n N) (i) (z : Place p) : + heat p x (unary i) z=fyAt p (onSide x i) z * (fyAt p (onSide x i) (flipZ p z))ᵀ := by + rw [heat,Finset.sum_eq_single i] + · simp [unary] + · intro j _ hj; simp [unary,hj] + simp + +theorem fuse_val (x : UnitType p n N) (v : Party) (A : DTuple (p:=p) q N) (z : Place p) : + images x z * hfused p n q (sparks p x v A) z=thermal p x v A z := by + classical + unfold hfused thermal heat sparks + rw [Fintype.sum_bool,Fintype.sum_bool] + simp only [Matrix.smul_mul,Matrix.mul_smul,Matrix.add_mul,Matrix.mul_add] + have he (i : Bool) : + images x z * (IH p n i * ((fyAt p (onSide x i) (flipZ p z))ᵀ * A z))= + fyAt p (onSide x i) z*(fyAt p (onSide x i) (flipZ p z))ᵀ * A z := by + rw [← Matrix.mul_assoc (images x z),images_ih] + change _ * (_ * _) = _ * _ * _ + exact (Matrix.mul_assoc ..).symm + rw [he,he] + +theorem fused_support (B : Bool→DTuple (p:=p) q p.h) (z : Place p) : + colSp (hfused p n q B z)≤channels p n := by + unfold hfused + rw [Fintype.sum_bool] + rintro x ⟨y,rfl⟩ + rw [mulVecLin_apply,Matrix.add_mulVec,← Matrix.mulVec_mulVec,← Matrix.mulVec_mulVec] + exact Submodule.add_mem _ (ih_le_channels true ⟨_,rfl⟩) (ih_le_channels false ⟨_,rfl⟩) + +theorem fused_inj (A : Bool→DTuple (p:=p) q p.h) (z : Place p) (i : Bool) + (h : Injective (A i z).mulVec) : + Injective (hfused p n q A z).mulVec := by + have hh : (IH p n i)ᵀ*hfused p n q A z=A i z := by + unfold hfused + rw [Fintype.sum_bool,Matrix.mul_add] + simp only [← Matrix.mul_assoc] + cases i <;> + simp only [IH_self,IH_cross (show false≠true by decide),IH_cross (show true≠false by decide), + Matrix.zero_mul,Matrix.one_mul,add_zero,zero_add] + intro x y hx + apply h + rw [←hh, ← Matrix.mulVec_mulVec, ← Matrix.mulVec_mulVec,hx] + +theorem hotfused (x : UnitType p n N) (v : Party) (A : DTuple (p:=p) q N) + (i : Bool) (h : v i=1) (hh : glimpse p x i A) (z) : + Injective (hfused p n q (sparks p x v A) z).mulVec := by + refine fused_inj _ _ i ?_ + unfold sparks; rw [h,one_smul] + exact hh z + +theorem tone_heat (x : UnitType p n N) (v : Party) (T : Ambient p N) : + tone p x v T = ∑ e : Comp p.g, mpair (heat p x v (e,false)) (T e) := by + classical + simp only [tone,joinPhase,uPhase,heat,mpair_sum,mpair_smul,LinearMap.sum_apply, + LinearMap.comp_apply,LinearMap.smul_apply,smul_eq_mul,mul_sum] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun j _ => Finset.sum_congr rfl fun i _ => ?_ + cases i <;> rfl + +variable {I J : Type} [Fintype I] [Fintype J] + +private theorem trace_shift_l (M : Mat I I) (A V : Mat I J) : + mpair M (A*Vᵀ)=mpair V (Mᵀ*A) := by + rw [mpair_comm V] + change (M*(A*Vᵀ)ᵀ).trace=((Mᵀ*A)* Vᵀ).trace + rw [Matrix.transpose_mul,Matrix.transpose_transpose, + ←Matrix.trace_transpose ((Mᵀ*A) * Vᵀ),Matrix.transpose_mul,Matrix.transpose_mul, + Matrix.transpose_transpose,Matrix.transpose_transpose,←Matrix.mul_assoc V, + Matrix.trace_mul_comm _ M] + +private theorem trace_shift_r (M : Mat I I) (A V : Mat I J) : + mpair M (V*Aᵀ)=mpair V (M*A) := by + rw [mpair_comm V] + change (M*(V*Aᵀ)ᵀ).trace=((M*A)* Vᵀ).trace + rw [Matrix.transpose_mul,Matrix.transpose_transpose,Matrix.mul_assoc] + +theorem tone_offset (x : UnitType p n N) (v : Party) (M : Atlas p r S) (A : Batch M N) : + tone p x v (spelled M A)=tupleB p (breadth M) N A (thermal p x v (src M))+ + tone p x v (edgeCost M) := by + rw [tone_heat,tone_heat,tupleB_val,Fintype.sum_prod_type] + simp only [spelled,map_add,Finset.sum_add_distrib,Fintype.sum_bool] + refine congrArg (fun z => z+_) (congrArg₂ (·+·) ?_ ?_) + · refine Finset.sum_congr rfl fun e _ => ?_ + rw [trace_shift_l,show (heat p x v (e,false))ᵀ=heat p x v (e,true) from + heat_flip p x v (e,true)] + rfl + refine Finset.sum_congr rfl fun e _ => ?_ + rw [trace_shift_r]; rfl +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetFourierBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetFourierBounds.lean index 589a0fc8df8f79b5b03944b46d8f2dba0439c160..ae2f983bce66f0958c8786c8de5d2fe1d6eb48e2 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetFourierBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetFourierBounds.lean @@ -1,195 +1,195 @@ -import OAI.Combinatorics.HadwigerCounterexample.SupportedPhaseLaws - -namespace OAI - -/-! # Offset Fourier Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix LinearMap Module Submodule Function Finset -variable {p : Shape} {n N r : ℕ} {T : Cov p N} - -def chant (p : Shape) {n N} (Δ : UnitType p n N → Ambient p N) (S R : Party) : - Wgt (UnitType p n N × UnitType p n N) := - fun x => wsign (tone p x.1 R (Δ x.2)+tone p x.2 S (Δ x.1)) - -variable {U V : Type} [AddCommGroup U] [AddCommGroup V] [Module F U] [Module F V] - -def coupledB (A : U →ₗ[F] U →ₗ[F] F) (B : V →ₗ[F] V →ₗ[F] F) : - U × V→ₗ[F] U × V→ₗ[F] F where - toFun x := (A x.1).coprod (B x.2) - map_add' x y := LinearMap.ext fun z => by - simp only [Prod.fst_add,Prod.snd_add,map_add,LinearMap.add_apply,LinearMap.coprod_apply] - abel - map_smul' a x := LinearMap.ext fun z => by - simp only [Prod.smul_fst,Prod.smul_snd,map_smul,RingHom.id_apply,LinearMap.smul_apply, - LinearMap.coprod_apply,smul_add] - -theorem coupledB_inj {A : U →ₗ[F] U →ₗ[F] F} {B : V →ₗ[F] V →ₗ[F] F} - (ha : Injective A) (hb : Injective B) : - Injective (coupledB A B) := by - intro x y h - apply Prod.ext - · apply ha - refine LinearMap.ext fun z => ?_ - have he : A x.1 z+B x.2 0=A y.1 z+B y.2 0 := LinearMap.congr_fun h (z,0) - simpa only [map_zero,add_zero] using he - apply hb - refine LinearMap.ext fun z => ?_ - have he : A x.1 0+B x.2 z=A y.1 0+B y.2 z := LinearMap.congr_fun h (0,z) - simpa only [map_zero,zero_add] using he - -theorem tupleB_comm (p : Shape) (r : Place p→ℕ) (N : ℕ) (x y) : - tupleB p r N x y=tupleB p r N y x := by - rw [tupleB_val,tupleB_val] - exact Finset.sum_congr rfl fun i _ => mpair_comm .. - -namespace Bazaar -variable (s : Bazaar p n r T) - -abbrev Sales (p : Shape) {N} (n r : ℕ) (T : Cov p N) := - Atlas p r T → Atlas p r T → UnitType p n N → Prop - -def discard {s : Bazaar p n r T} (w : Wgt (UnitType p n N)) (C : Sales p n r T) := - pr (pairW w w) (fun x => ¬ C (s.ix x.1) (s.ix x.2) x.2) - -set_option maxHeartbeats 800000 in -private theorem beat_one {w : Wgt (UnitType p n N)} {Δ} - (hl : s.opened Δ w) (hv : SubLaw w) (M G : Atlas p r T) - (S R : Party) (i : Bool) (C : UnitType p n N → Prop) - (hA : ∀ x,mapW (s.chart w M) (s.bag M i) x ≤ loseA p N (cells M) 0) - (hB : standard M → standard G → ∀ y,mapW (subW (s.chart w G) C) - (s.pay M G i S) y ≤ prize p N (cells G)) : - |avg (pairW (s.chart w M) (subW (s.chart w G) C)) (chant p Δ S R)| ≤ beat N := by - classical - let u := s.chart w M - let v := subW (s.chart w G) C - have hw : SubLaw u := subLaw_sub hv _ - have ht : SubLaw v := subLaw_sub (subLaw_sub hv _) _ - let y := avg (pairW u v) (chant p Δ S R) - by_cases hy : y=0 - · change |y|≤_ - rw [hy, abs_zero]; exact (bp_pos _).le - have h : ∃ x,pairW u v x ≠ 0 := by - by_contra! he - apply hy; unfold y avg; simp_rw [he]; simp - obtain ⟨⟨x0,y0⟩,hx⟩ := h - have hV x (hh : v x≠0) : s.chart w G x≠0 := left_ne_zero_of_mul hh - have H (x : UnitType p n N) (hh : u x≠0) := s.active hl x hh - have H' (x : UnitType p n N) (hh : v x≠0) := s.active hl x (hV x hh) - let a (x) := (s.bag M i x,thermal p x R (src G)) - let b := s.pay M G i S - let f (x : UnitType p n N) := wsign (tone p x R (edgeCost G)) - let g (x : UnitType p n N) := wsign (tone p x S (edgeCost M)) - let B := coupledB (tupleB p (breadth M) N) (tupleB p (breadth G) N) - have hc : - y=avg (pairW u v) (fun x => f x.1*g x.2*wsign (B (a x.1) (b x.2))) := by - refine avg_congr fun ⟨x,y⟩ hh => ?_ - have h1 := ((H x (left_ne_zero_of_mul hh)).2.2 i).2 - have h2 := ((H' y (right_ne_zero_of_mul hh)).2.2 i).2 - unfold chant; dsimp only - rw [h1,h2,tone_offset,tone_offset] - unfold f g - rw [←wsign_add,←wsign_add] - apply congrArg wsign - change _=_+(tupleB p (breadth M) N _ _+tupleB p (breadth G) N _ _) - rw [tupleB_comm p (breadth G) N (s.bag G i y)] - dsimp only [coupledB,b,pay,a] - simp only [LinearMap.fst_apply,LinearMap.snd_apply] - abel - let D := Batch M N × Batch G N - have ha (x : D) : mapW u a x ≤ loseA p N (cells M) 0 := by - refine (pr_mono hw.nz (p:=fun y => a y=x) (q:=fun y => s.bag M i y=x.1) - (fun y h => ?_)).trans (hA x.1) - exact congrArg Prod.fst h - have hb (x : D) : mapW v b x ≤ prize p N (cells G) := - hB ((H x0 (left_ne_zero_of_mul hx)).2.1) ((H' y0 (right_ne_zero_of_mul hx)).2.1) x - have he := walsh_weighted B - (coupledB_inj (tupleB_inj ..) (tupleB_inj ..)) u v hw ht a b f g (fun x => by simp [f]) - (fun x => by simp [g]) ha hb - have hi : y^2 ≤ beat N^2 := by - rw [hc] - refine he.trans ?_ - let F := Batch M N - let G' := Batch G N - unfold num - rw [card_space,dim,finrank_prod] - have hf : finrank HadwigerCounterexample.F F=N*cells M := tuple_dim - have hg : finrank HadwigerCounterexample.F G'=N*cells G := tuple_dim - rw [hf,hg,loseA,prize,beat,←bp_add,←bp_add,pow_two,←bp_add] - apply le_of_eq; push_cast; ring_nf - change |y|≤_ - exact le_of_pow_le_pow_left₀ (show 2 ≠ (0:ℕ) by decide) (bp_pos _).le - (sq_abs y ▸ hi) - -set_option maxHeartbeats 800000 in -theorem beat_mix {w : Wgt (UnitType p n N)} {Δ} - (hl : s.opened Δ w) (hv : IsLaw w) (S R : Party) (i : Bool) (C : Sales p n r T) - (hA : ∀ M x,mapW (s.chart w M) (s.bag M i) x ≤ loseA p N (cells M) 0) - (hB : ∀ M G,standard M → standard G → ∀ y,mapW (subW (s.chart w G) (C M G)) - (s.pay M G i S) y ≤ prize p N (cells G)) - (ht : num (Atlas p r T) ≤ bp (0.002*N)) : - |pitch p Δ w S R| ≤ discard (s:=s) w C + bp (-0.24*N) := by - classical - let V := pairW w w - let F := chant p Δ S R - let P := fun x : (UnitType p n N)×_ => C (s.ix x.1) (s.ix x.2) x.2 - let g := fun x => ind (P x)*F x - let f := fun x => ind (¬P x)*F x - let μ := s.chart w - let W := fun M G => subW (μ G) (C M G) - have hn x : 0≤ V x := (pairW_law hv hv).nz x - have he x : F x=f x+ g x := by - unfold f g - by_cases h : P x <;> simp [h] - have hf : |avg V f| ≤ discard (s:=s) w C := by - refine (abs_avg_le hn).trans_eq ?_ - unfold discard pr - refine avg_congr (fun x _ => ?_) - rw [show f x= _*_ from rfl, abs_mul, abs_of_nonneg (ind_nonneg (¬P x))] - simp [F,P,chant] - have hg : - avg V g=∑ M : Atlas p r T,∑ G : Atlas p r T, avg (pairW (μ M) (W M G)) F := by - let U (M G : Atlas p r T) (x : UnitType p n N × UnitType p n N) := - ind (s.ix x.1=M)*ind (s.ix x.2=G)*ind (C M G x.2)*F x - have hu (M G : Atlas p r T) : - avg (pairW (μ M) (W M G)) F=avg V (U M G) := by - unfold avg - refine Finset.sum_congr rfl fun i _ => ?_ - unfold U W μ V pairW chart subW; ring - simp_rw [hu,← avg_sum] - refine avg_congr fun x _ => ?_ - rw [Finset.sum_eq_single (s.ix x.1)] - · rw [Finset.sum_eq_single (s.ix x.2)] - · simp only [U,ind_true,one_mul]; rfl - · intro j _ hj; simp [U,ind_zero hj.symm] - simp - · intro j _ hj; simp [U,ind_zero hj.symm] - simp - have hh : |avg V g| ≤ bp (-0.24*N) := by - rw [hg]; apply le_trans (Finset.abs_sum_le_sum_abs ..) - let J := num (Atlas p r T) - have hz (M : Atlas p r T) : - |∑ G : Atlas p r T, avg (pairW (μ M) (W M G)) F|≤ J*beat N := by - refine (Finset.abs_sum_le_sum_abs ..).trans - ((Finset.sum_le_sum (fun i' _ => - beat_one s hl hv.sub M i' S R i (C M i') (hA M) (hB M i'))).trans_eq ?_) - simp only [J,Finset.sum_const, Finset.card_univ,nsmul_eq_mul,num] - calc ∑ M : Atlas p r T,|∑ G : Atlas p r T,avg (pairW (μ M) (W M G)) F| - _ ≤ ∑ _ : Atlas p r T,J*beat N := Finset.sum_le_sum fun M _ => hz M - _ = J*J*beat N := by simp [J,mul_assoc,num] - _ ≤ bp (0.002*N)*bp (0.002*N)*beat N := mul_le_mul_of_nonneg_right - (mul_self_le_mul_self (Nat.cast_nonneg _ : 0≤J) ht) (bp_pos _).le - _ ≤ bp (-0.24*N) := by - unfold beat; rw [← bp_add,← bp_add]; apply bp_le; linarith [(Nat.cast_nonneg N : 0≤(N:ℝ))] - change |avg V F|≤ _ - rw [show F=(fun x => f x+g x) from funext he,avg_add] - exact (abs_add_le ..).trans (add_le_add hf hh) - -end Bazaar -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SupportedPhaseLaws + +namespace OAI + +/-! # Offset Fourier Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix LinearMap Module Submodule Function Finset +variable {p : Shape} {n N r : ℕ} {T : Cov p N} + +def chant (p : Shape) {n N} (Δ : UnitType p n N → Ambient p N) (S R : Party) : + Wgt (UnitType p n N × UnitType p n N) := + fun x => wsign (tone p x.1 R (Δ x.2)+tone p x.2 S (Δ x.1)) + +variable {U V : Type} [AddCommGroup U] [AddCommGroup V] [Module F U] [Module F V] + +def coupledB (A : U →ₗ[F] U →ₗ[F] F) (B : V →ₗ[F] V →ₗ[F] F) : + U × V→ₗ[F] U × V→ₗ[F] F where + toFun x := (A x.1).coprod (B x.2) + map_add' x y := LinearMap.ext fun z => by + simp only [Prod.fst_add,Prod.snd_add,map_add,LinearMap.add_apply,LinearMap.coprod_apply] + abel + map_smul' a x := LinearMap.ext fun z => by + simp only [Prod.smul_fst,Prod.smul_snd,map_smul,RingHom.id_apply,LinearMap.smul_apply, + LinearMap.coprod_apply,smul_add] + +theorem coupledB_inj {A : U →ₗ[F] U →ₗ[F] F} {B : V →ₗ[F] V →ₗ[F] F} + (ha : Injective A) (hb : Injective B) : + Injective (coupledB A B) := by + intro x y h + apply Prod.ext + · apply ha + refine LinearMap.ext fun z => ?_ + have he : A x.1 z+B x.2 0=A y.1 z+B y.2 0 := LinearMap.congr_fun h (z,0) + simpa only [map_zero,add_zero] using he + apply hb + refine LinearMap.ext fun z => ?_ + have he : A x.1 0+B x.2 z=A y.1 0+B y.2 z := LinearMap.congr_fun h (0,z) + simpa only [map_zero,zero_add] using he + +theorem tupleB_comm (p : Shape) (r : Place p→ℕ) (N : ℕ) (x y) : + tupleB p r N x y=tupleB p r N y x := by + rw [tupleB_val,tupleB_val] + exact Finset.sum_congr rfl fun i _ => mpair_comm .. + +namespace Bazaar +variable (s : Bazaar p n r T) + +abbrev Sales (p : Shape) {N} (n r : ℕ) (T : Cov p N) := + Atlas p r T → Atlas p r T → UnitType p n N → Prop + +def discard {s : Bazaar p n r T} (w : Wgt (UnitType p n N)) (C : Sales p n r T) := + pr (pairW w w) (fun x => ¬ C (s.ix x.1) (s.ix x.2) x.2) + +set_option maxHeartbeats 800000 in +private theorem beat_one {w : Wgt (UnitType p n N)} {Δ} + (hl : s.opened Δ w) (hv : SubLaw w) (M G : Atlas p r T) + (S R : Party) (i : Bool) (C : UnitType p n N → Prop) + (hA : ∀ x,mapW (s.chart w M) (s.bag M i) x ≤ loseA p N (cells M) 0) + (hB : standard M → standard G → ∀ y,mapW (subW (s.chart w G) C) + (s.pay M G i S) y ≤ prize p N (cells G)) : + |avg (pairW (s.chart w M) (subW (s.chart w G) C)) (chant p Δ S R)| ≤ beat N := by + classical + let u := s.chart w M + let v := subW (s.chart w G) C + have hw : SubLaw u := subLaw_sub hv _ + have ht : SubLaw v := subLaw_sub (subLaw_sub hv _) _ + let y := avg (pairW u v) (chant p Δ S R) + by_cases hy : y=0 + · change |y|≤_ + rw [hy, abs_zero]; exact (bp_pos _).le + have h : ∃ x,pairW u v x ≠ 0 := by + by_contra! he + apply hy; unfold y avg; simp_rw [he]; simp + obtain ⟨⟨x0,y0⟩,hx⟩ := h + have hV x (hh : v x≠0) : s.chart w G x≠0 := left_ne_zero_of_mul hh + have H (x : UnitType p n N) (hh : u x≠0) := s.active hl x hh + have H' (x : UnitType p n N) (hh : v x≠0) := s.active hl x (hV x hh) + let a (x) := (s.bag M i x,thermal p x R (src G)) + let b := s.pay M G i S + let f (x : UnitType p n N) := wsign (tone p x R (edgeCost G)) + let g (x : UnitType p n N) := wsign (tone p x S (edgeCost M)) + let B := coupledB (tupleB p (breadth M) N) (tupleB p (breadth G) N) + have hc : + y=avg (pairW u v) (fun x => f x.1*g x.2*wsign (B (a x.1) (b x.2))) := by + refine avg_congr fun ⟨x,y⟩ hh => ?_ + have h1 := ((H x (left_ne_zero_of_mul hh)).2.2 i).2 + have h2 := ((H' y (right_ne_zero_of_mul hh)).2.2 i).2 + unfold chant; dsimp only + rw [h1,h2,tone_offset,tone_offset] + unfold f g + rw [←wsign_add,←wsign_add] + apply congrArg wsign + change _=_+(tupleB p (breadth M) N _ _+tupleB p (breadth G) N _ _) + rw [tupleB_comm p (breadth G) N (s.bag G i y)] + dsimp only [coupledB,b,pay,a] + simp only [LinearMap.fst_apply,LinearMap.snd_apply] + abel + let D := Batch M N × Batch G N + have ha (x : D) : mapW u a x ≤ loseA p N (cells M) 0 := by + refine (pr_mono hw.nz (p:=fun y => a y=x) (q:=fun y => s.bag M i y=x.1) + (fun y h => ?_)).trans (hA x.1) + exact congrArg Prod.fst h + have hb (x : D) : mapW v b x ≤ prize p N (cells G) := + hB ((H x0 (left_ne_zero_of_mul hx)).2.1) ((H' y0 (right_ne_zero_of_mul hx)).2.1) x + have he := walsh_weighted B + (coupledB_inj (tupleB_inj ..) (tupleB_inj ..)) u v hw ht a b f g (fun x => by simp [f]) + (fun x => by simp [g]) ha hb + have hi : y^2 ≤ beat N^2 := by + rw [hc] + refine he.trans ?_ + let F := Batch M N + let G' := Batch G N + unfold num + rw [card_space,dim,finrank_prod] + have hf : finrank HadwigerCounterexample.F F=N*cells M := tuple_dim + have hg : finrank HadwigerCounterexample.F G'=N*cells G := tuple_dim + rw [hf,hg,loseA,prize,beat,←bp_add,←bp_add,pow_two,←bp_add] + apply le_of_eq; push_cast; ring_nf + change |y|≤_ + exact le_of_pow_le_pow_left₀ (show 2 ≠ (0:ℕ) by decide) (bp_pos _).le + (sq_abs y ▸ hi) + +set_option maxHeartbeats 800000 in +theorem beat_mix {w : Wgt (UnitType p n N)} {Δ} + (hl : s.opened Δ w) (hv : IsLaw w) (S R : Party) (i : Bool) (C : Sales p n r T) + (hA : ∀ M x,mapW (s.chart w M) (s.bag M i) x ≤ loseA p N (cells M) 0) + (hB : ∀ M G,standard M → standard G → ∀ y,mapW (subW (s.chart w G) (C M G)) + (s.pay M G i S) y ≤ prize p N (cells G)) + (ht : num (Atlas p r T) ≤ bp (0.002*N)) : + |pitch p Δ w S R| ≤ discard (s:=s) w C + bp (-0.24*N) := by + classical + let V := pairW w w + let F := chant p Δ S R + let P := fun x : (UnitType p n N)×_ => C (s.ix x.1) (s.ix x.2) x.2 + let g := fun x => ind (P x)*F x + let f := fun x => ind (¬P x)*F x + let μ := s.chart w + let W := fun M G => subW (μ G) (C M G) + have hn x : 0≤ V x := (pairW_law hv hv).nz x + have he x : F x=f x+ g x := by + unfold f g + by_cases h : P x <;> simp [h] + have hf : |avg V f| ≤ discard (s:=s) w C := by + refine (abs_avg_le hn).trans_eq ?_ + unfold discard pr + refine avg_congr (fun x _ => ?_) + rw [show f x= _*_ from rfl, abs_mul, abs_of_nonneg (ind_nonneg (¬P x))] + simp [F,P,chant] + have hg : + avg V g=∑ M : Atlas p r T,∑ G : Atlas p r T, avg (pairW (μ M) (W M G)) F := by + let U (M G : Atlas p r T) (x : UnitType p n N × UnitType p n N) := + ind (s.ix x.1=M)*ind (s.ix x.2=G)*ind (C M G x.2)*F x + have hu (M G : Atlas p r T) : + avg (pairW (μ M) (W M G)) F=avg V (U M G) := by + unfold avg + refine Finset.sum_congr rfl fun i _ => ?_ + unfold U W μ V pairW chart subW; ring + simp_rw [hu,← avg_sum] + refine avg_congr fun x _ => ?_ + rw [Finset.sum_eq_single (s.ix x.1)] + · rw [Finset.sum_eq_single (s.ix x.2)] + · simp only [U,ind_true,one_mul]; rfl + · intro j _ hj; simp [U,ind_zero hj.symm] + simp + · intro j _ hj; simp [U,ind_zero hj.symm] + simp + have hh : |avg V g| ≤ bp (-0.24*N) := by + rw [hg]; apply le_trans (Finset.abs_sum_le_sum_abs ..) + let J := num (Atlas p r T) + have hz (M : Atlas p r T) : + |∑ G : Atlas p r T, avg (pairW (μ M) (W M G)) F|≤ J*beat N := by + refine (Finset.abs_sum_le_sum_abs ..).trans + ((Finset.sum_le_sum (fun i' _ => + beat_one s hl hv.sub M i' S R i (C M i') (hA M) (hB M i'))).trans_eq ?_) + simp only [J,Finset.sum_const, Finset.card_univ,nsmul_eq_mul,num] + calc ∑ M : Atlas p r T,|∑ G : Atlas p r T,avg (pairW (μ M) (W M G)) F| + _ ≤ ∑ _ : Atlas p r T,J*beat N := Finset.sum_le_sum fun M _ => hz M + _ = J*J*beat N := by simp [J,mul_assoc,num] + _ ≤ bp (0.002*N)*bp (0.002*N)*beat N := mul_le_mul_of_nonneg_right + (mul_self_le_mul_self (Nat.cast_nonneg _ : 0≤J) ht) (bp_pos _).le + _ ≤ bp (-0.24*N) := by + unfold beat; rw [← bp_add,← bp_add]; apply bp_le; linarith [(Nat.cast_nonneg N : 0≤(N:ℝ))] + change |avg V F|≤ _ + rw [show F=(fun x => f x+g x) from funext he,avg_add] + exact (abs_add_le ..).trans (add_le_add hf hh) + +end Bazaar +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetLifting.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetLifting.lean index 409327b7ac1f37c4971fc6d33acd437ce094d7fe..7b3516157b2de29be807648dc019ecac93fbdfcd 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetLifting.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetLifting.lean @@ -1,209 +1,209 @@ -import OAI.Combinatorics.HadwigerCounterexample.IndependentPhaseBounds - -namespace OAI - -/-! # Offset Lifting -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix LinearMap Submodule Module Finset Function -variable {I J K L : Type} [Fintype I] [Fintype J] [Fintype K] [Fintype L] - -omit [Fintype I] in -theorem col_follow (A : Mat I J) (B : Mat J K) : - colSp (A*B)≤colSp A := by - rw [colSp,Matrix.mulVecLin_mul] - exact LinearMap.range_comp_le_range .. - -omit [Fintype I] in -theorem col_retain {A : Mat I J} {B : Mat J K} (h : Surjective B.mulVec) : - colSp (A*B)=colSp A := by - rw [colSp,Matrix.mulVecLin_mul,LinearMap.range_comp, - LinearMap.range_eq_top.mpr (show Surjective B.mulVecLin from h),Submodule.map_top,colSp] - -private theorem trans_surj {A : Mat I J} (hA : Surjective A.mulVec) : Injective Aᵀ.mulVec := - transpose_surj_iff.mp (by rwa [Matrix.transpose_transpose]) - -omit [Fintype I] in -theorem pull_cols (A : Mat I J) (B : Mat I K) (h : colSp B≤colSp A) : - ∃ Q : Mat J K,A*Q=B := by - classical - have hf (i : K) : B.col i ∈ colSp A := h (colSp_mem i) - choose v hv using show ∀ (i:K),∃ v : Vec J,A *ᵥ v = B.col i from hf - refine ⟨Matrix.of (fun i j => v j i),?_⟩ - ext i j - exact congr_fun (hv j) i - -variable [DecidableEq I] - -theorem chop_inj_pack {S : Space (Vec I)} {T : Mat I J} (h : Injective T.mulVec) - (he : Disjoint S (colSp T)) : - Injective (chop S*T).mulVec := by - rw [← Matrix.coe_mulVecLin,← LinearMap.ker_eq_bot, Matrix.ker_mulVecLin_eq_bot_iff] - intro x hx - rw [← Matrix.mulVec_mulVec] at hx - have hh : T *ᵥ x∈S⊓colSp T := ⟨(chop_ker ..).mp hx,⟨_,rfl⟩⟩ - rw [he.eq_bot,Submodule.mem_bot] at hh - exact h (hh.trans (Matrix.mulVec_zero T).symm) - -private theorem frame_image_lift {S T : Space (Vec I)} {A : Mat I J} - (h : colSp A≤chopSpace S T) : - ∃ A' : Mat I J,colSp A'≤T ∧ chop S * A'=A := by - classical - have hf : chopSpace S T=colSp (chop S*pack T) := by - rw [chopSpace,colSp,Matrix.mulVecLin_mul,LinearMap.range_comp, - show LinearMap.range (pack T).mulVecLin=_ from colSp_pack T] - obtain ⟨V,hV⟩ := pull_cols (chop S*pack T) A (hf ▸ h) - refine ⟨pack T*V,(col_follow ..).trans_eq (colSp_pack T),?_⟩ - rw [←Matrix.mul_assoc,hV] - -private theorem projected_unique {M V : Space (Vec I)} {M' V' : Space (Vec I)} - (h : Disjoint M M') (h' : Disjoint V V') (A B : Mat I I) - (hA : A∈ box M' V') (hB : B∈box M' V') - (hf : liftM (chop M) (chop V) A=liftM (chop M) (chop V) B) : - A=B := by - classical - obtain ⟨A,rfl⟩ := hA - obtain ⟨B,rfl⟩ := hB - have he := chop_inj_pack (S:=M) (pack_inj M') (by rw [colSp_pack]; exact h) - have he' := chop_inj_pack (S:=V) (pack_inj V') (by rw [colSp_pack]; exact h') - rw [liftM_comp,liftM_comp] at hf - rw [liftM_inj he he' hf] - -structure FrameProduct (M : Mat I I) (S T : Space (Vec I)) (X Y : Mat I J) : Prop where - xin : Injective X.mulVec - yin : Injective Y.mulVec - xcol : colSp X ≤ S - ycol : colSp Y ≤ T - prod : X*Yᵀ=M - -private theorem frame_extend (M : Mat I I) (S T V W : Space (Vec I)) (A B : Mat I K) - (hV : M ∈ box V W) - (hx : Disjoint S V) (hy : Disjoint T W) - (hA : Injective A.mulVec) (hB : Injective B.mulVec) - (he : liftM (chop S) (chop T) M=A*Bᵀ) : - ∃ X Y : Mat I K, - FrameProduct M V W X Y ∧ chop S*X=A ∧ chop T*Y=B := by - classical - have heq : A*Bᵀ ∈box (chopSpace S V) (chopSpace T W) := he ▸ lift_mem_box _ _ hV - obtain ⟨hL,hH⟩ := (box_mem ..).mp heq - rw [col_retain (transpose_surj_iff.mpr hB)] at hL - rw [Matrix.transpose_mul,Matrix.transpose_transpose,col_retain (transpose_surj_iff.mpr hA)] at hH - obtain ⟨X,hX,hZ⟩ := frame_image_lift hL - obtain ⟨Y,hY,hU⟩ := frame_image_lift hH - have hi {A B : Mat I K} (f : Mat I I) - (h : f*A=B) (hB : Injective B.mulVec) : Injective A.mulVec := by - rw [←h] at hB - intro x y he - apply hB - rw [← Matrix.mulVec_mulVec, ← Matrix.mulVec_mulVec,he] - refine ⟨X,Y,⟨hi _ hZ hA,hi _ hU hB,hX,hY,?_⟩,hZ,hU⟩ - refine projected_unique hx hy _ _ ((box_mem ..).mpr ⟨(col_follow ..).trans hX,?_⟩) hV ?_ - · rw [Matrix.transpose_mul,Matrix.transpose_transpose] - exact (col_follow ..).trans hY - rw [he,liftM_def,←hU,←hZ,Matrix.transpose_mul] - simp only [Matrix.mul_assoc] - -private theorem frame_products (M : Bool → Mat I I) (S T : Space (Vec I)) - (a b : Bool → Space (Vec I)) - (h : ∀ i,M i∈box (a i) (b i)) (hg : vanish S T (M true+M false)) - (ha : ∀ i,Disjoint S (a i)) (hb : ∀ i,Disjoint T (b i)) : - ∃ X Y : Bool → Mat I (Fin (M true).rank), (∀ i,FrameProduct (M i) (a i) (b i) (X i) (Y i)) ∧ - chop S*X true=chop S*X false ∧ chop T*Y true=chop T*Y false := by - classical - obtain ⟨A,B,hA,hB,hM⟩ := rank_product (M true) - let C := Bᵀ - have hC : Injective C.mulVec := trans_surj hB - obtain ⟨hL,hR⟩ := (box_mem ..).mp (h true) - rw [← hM,col_retain hB] at hL - rw [←hM,Matrix.transpose_mul,col_retain (transpose_surj_iff.mpr hA)] at hR - have hf : liftM (chop S) (chop T) (M true)= (chop S*A)*(chop T*C)ᵀ := by - rw [liftM_def,Matrix.transpose_mul, show Cᵀ=B from rfl,Matrix.mul_assoc,Matrix.mul_assoc (chop S),← Matrix.mul_assoc A, - hM] - obtain ⟨P,Q,hP,hQ,hF⟩ := frame_extend (M false) S T (a false) (b false) - (chop S*A) (chop T*C) (h false) (ha false) (hb false) - (chop_inj_pack hA (Disjoint.mono_right hL (ha true))) - (chop_inj_pack hC (Disjoint.mono_right hR (hb true))) (by - have he := (vanish_chop _).mp hg - rw [map_add] at he - rw [←hf] - exact add_left_cancel (he.trans (char_two _).symm)) - refine ⟨onSide (A,P), onSide (C,Q),fun i => ?_,hQ.symm,hF.symm⟩ - cases i - · exact hP - exact ⟨hA,hC,hL,hR,hM⟩ - -private theorem diff_into (a : Bool → Mat I J) (S : Space (Vec I)) - (h : chop S*a true=chop S*a false) : - ∃ (k : ℕ) (P : Mat (Fin (dim S)) (Fin k)) (B : Mat (Fin k) J), - k≤Fintype.card J ∧ Injective (pack S * P).mulVec ∧ Surjective B.mulVec ∧ - a true+a false=(pack S*P)*B := by - classical - let X := a true+a false - obtain ⟨A,B,hA,hB,hX⟩ := rank_product X - have hi : colSp X≤S := by - rintro x ⟨y,rfl⟩ - apply (chop_ker ..).mp - rw [mulVecLin_apply,Matrix.mulVec_mulVec,show X=_+_ from rfl,Matrix.mul_add,h,char_two, - Matrix.zero_mulVec] - obtain ⟨P,hP⟩ := pull_cols (pack S) A (by rw [← col_retain hB,hX,colSp_pack]; exact hi) - refine ⟨X.rank,P,B,X.rank_le_card_width,?_,hB,?_⟩ - · rw [hP]; exact hA - rw [hP,hX] - -/-- δ expansion at one component: S*T offsets bases plus paired -companions Z for either reference endpoint. Cost recorded in actual -offset widths kp/km and kernel matrices. -/ -theorem one_offsets (M : Bool → Mat I I) (S T : Space (Vec I)) - (a b : Bool → Space (Vec I)) - (h : ∀ i,M i∈box (a i) (b i)) (hg : vanish S T (M true+M false)) - (ha : ∀ i,Disjoint S (a i)) (hb : ∀ i,Disjoint T (b i)) : - ∃ (kp km : ℕ) (A : Mat (Fin (dim S)) (Fin kp)) (B : Mat (Fin (dim T)) (Fin km)) - (H : Mat (Fin kp) (Fin km)), - let X := pack S * A - let Y := pack T * B - kp≤(M true).rank ∧ km≤ (M true).rank ∧ Injective X.mulVec ∧ Injective Y.mulVec ∧ - ∀ i,∃ (Z : Mat I (Fin kp)) (W : Mat I (Fin km)), Injective Z.mulVec ∧ Injective W.mulVec ∧ - colSp Z≤ b i ∧ colSp W≤ a i ∧ M true+M false=X*Zᵀ+W*Yᵀ+X*H*Yᵀ := by - classical - obtain ⟨P,Q,hP,hQ,hF⟩ := frame_products M S T a b h hg ha hb - obtain ⟨k,A,E,hk,hA,hE,hX⟩ := diff_into P S hQ - obtain ⟨k',B,D,hk',hB,hD,hY⟩ := diff_into Q T hF - rw [Fintype.card_fin] at hk hk' - let X := pack S * A - let Y := pack T * B - refine ⟨k,k',A,B,E*Dᵀ,hk,hk',hA,hB,fun i => ?_⟩ - let V := P i - let U := Q i - have ht : M true+M false=M i+M (!i) := by cases i; exact add_comm _ _; rfl - have hx : P (!i) = V+X*E := by - rw [show X*E=P true+P false from hX.symm] - cases i - · change P true=P false+(P true+P false); rw [add_left_comm,char_two,add_zero] - · change P false=P true+(P true+P false); rw [←add_assoc,char_two,zero_add] - have hy : Q (!i)=U+Y*D := by - rw [show Y*D=Q true+Q false from hY.symm] - cases i - · change Q true=Q false+(Q true+Q false); rw [add_left_comm,char_two,add_zero] - · change Q false=Q true+(Q true+Q false); rw [←add_assoc,char_two,zero_add] - refine ⟨U*Eᵀ,V*Dᵀ,inj_comp_mat _ _ (hP i).yin (trans_surj hE), - inj_comp_mat _ _ (hP i).xin (trans_surj hD), (col_follow ..).trans (hP i).ycol, - (col_follow ..).trans (hP i).xcol,?_⟩ - - have hm : - M true+M false=V*Uᵀ+(V+X*E)*(U+Y*D)ᵀ := ht.trans (congrArg₂ (· + ·) - (hP i).prod.symm ((hP (!i)).prod.symm.trans (congrArg₂ (· * ·) hx - (congrArg Matrix.transpose hy)))) - apply hm.trans - change _=X * _ + _ * Yᵀ+ X * _ * Yᵀ - simp only [transpose_add,transpose_mul,transpose_transpose,Matrix.add_mul,Matrix.mul_add, - Matrix.mul_assoc,add_assoc] - calc _ = (V*Uᵀ + V*Uᵀ) + (X * (E * Uᵀ) + (V * (Dᵀ*Yᵀ) + X * (E * (Dᵀ*Yᵀ)))) := by abel - _ = _ := by rw [char_two,zero_add] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.IndependentPhaseBounds + +namespace OAI + +/-! # Offset Lifting -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix LinearMap Submodule Module Finset Function +variable {I J K L : Type} [Fintype I] [Fintype J] [Fintype K] [Fintype L] + +omit [Fintype I] in +theorem col_follow (A : Mat I J) (B : Mat J K) : + colSp (A*B)≤colSp A := by + rw [colSp,Matrix.mulVecLin_mul] + exact LinearMap.range_comp_le_range .. + +omit [Fintype I] in +theorem col_retain {A : Mat I J} {B : Mat J K} (h : Surjective B.mulVec) : + colSp (A*B)=colSp A := by + rw [colSp,Matrix.mulVecLin_mul,LinearMap.range_comp, + LinearMap.range_eq_top.mpr (show Surjective B.mulVecLin from h),Submodule.map_top,colSp] + +private theorem trans_surj {A : Mat I J} (hA : Surjective A.mulVec) : Injective Aᵀ.mulVec := + transpose_surj_iff.mp (by rwa [Matrix.transpose_transpose]) + +omit [Fintype I] in +theorem pull_cols (A : Mat I J) (B : Mat I K) (h : colSp B≤colSp A) : + ∃ Q : Mat J K,A*Q=B := by + classical + have hf (i : K) : B.col i ∈ colSp A := h (colSp_mem i) + choose v hv using show ∀ (i:K),∃ v : Vec J,A *ᵥ v = B.col i from hf + refine ⟨Matrix.of (fun i j => v j i),?_⟩ + ext i j + exact congr_fun (hv j) i + +variable [DecidableEq I] + +theorem chop_inj_pack {S : Space (Vec I)} {T : Mat I J} (h : Injective T.mulVec) + (he : Disjoint S (colSp T)) : + Injective (chop S*T).mulVec := by + rw [← Matrix.coe_mulVecLin,← LinearMap.ker_eq_bot, Matrix.ker_mulVecLin_eq_bot_iff] + intro x hx + rw [← Matrix.mulVec_mulVec] at hx + have hh : T *ᵥ x∈S⊓colSp T := ⟨(chop_ker ..).mp hx,⟨_,rfl⟩⟩ + rw [he.eq_bot,Submodule.mem_bot] at hh + exact h (hh.trans (Matrix.mulVec_zero T).symm) + +private theorem frame_image_lift {S T : Space (Vec I)} {A : Mat I J} + (h : colSp A≤chopSpace S T) : + ∃ A' : Mat I J,colSp A'≤T ∧ chop S * A'=A := by + classical + have hf : chopSpace S T=colSp (chop S*pack T) := by + rw [chopSpace,colSp,Matrix.mulVecLin_mul,LinearMap.range_comp, + show LinearMap.range (pack T).mulVecLin=_ from colSp_pack T] + obtain ⟨V,hV⟩ := pull_cols (chop S*pack T) A (hf ▸ h) + refine ⟨pack T*V,(col_follow ..).trans_eq (colSp_pack T),?_⟩ + rw [←Matrix.mul_assoc,hV] + +private theorem projected_unique {M V : Space (Vec I)} {M' V' : Space (Vec I)} + (h : Disjoint M M') (h' : Disjoint V V') (A B : Mat I I) + (hA : A∈ box M' V') (hB : B∈box M' V') + (hf : liftM (chop M) (chop V) A=liftM (chop M) (chop V) B) : + A=B := by + classical + obtain ⟨A,rfl⟩ := hA + obtain ⟨B,rfl⟩ := hB + have he := chop_inj_pack (S:=M) (pack_inj M') (by rw [colSp_pack]; exact h) + have he' := chop_inj_pack (S:=V) (pack_inj V') (by rw [colSp_pack]; exact h') + rw [liftM_comp,liftM_comp] at hf + rw [liftM_inj he he' hf] + +structure FrameProduct (M : Mat I I) (S T : Space (Vec I)) (X Y : Mat I J) : Prop where + xin : Injective X.mulVec + yin : Injective Y.mulVec + xcol : colSp X ≤ S + ycol : colSp Y ≤ T + prod : X*Yᵀ=M + +private theorem frame_extend (M : Mat I I) (S T V W : Space (Vec I)) (A B : Mat I K) + (hV : M ∈ box V W) + (hx : Disjoint S V) (hy : Disjoint T W) + (hA : Injective A.mulVec) (hB : Injective B.mulVec) + (he : liftM (chop S) (chop T) M=A*Bᵀ) : + ∃ X Y : Mat I K, + FrameProduct M V W X Y ∧ chop S*X=A ∧ chop T*Y=B := by + classical + have heq : A*Bᵀ ∈box (chopSpace S V) (chopSpace T W) := he ▸ lift_mem_box _ _ hV + obtain ⟨hL,hH⟩ := (box_mem ..).mp heq + rw [col_retain (transpose_surj_iff.mpr hB)] at hL + rw [Matrix.transpose_mul,Matrix.transpose_transpose,col_retain (transpose_surj_iff.mpr hA)] at hH + obtain ⟨X,hX,hZ⟩ := frame_image_lift hL + obtain ⟨Y,hY,hU⟩ := frame_image_lift hH + have hi {A B : Mat I K} (f : Mat I I) + (h : f*A=B) (hB : Injective B.mulVec) : Injective A.mulVec := by + rw [←h] at hB + intro x y he + apply hB + rw [← Matrix.mulVec_mulVec, ← Matrix.mulVec_mulVec,he] + refine ⟨X,Y,⟨hi _ hZ hA,hi _ hU hB,hX,hY,?_⟩,hZ,hU⟩ + refine projected_unique hx hy _ _ ((box_mem ..).mpr ⟨(col_follow ..).trans hX,?_⟩) hV ?_ + · rw [Matrix.transpose_mul,Matrix.transpose_transpose] + exact (col_follow ..).trans hY + rw [he,liftM_def,←hU,←hZ,Matrix.transpose_mul] + simp only [Matrix.mul_assoc] + +private theorem frame_products (M : Bool → Mat I I) (S T : Space (Vec I)) + (a b : Bool → Space (Vec I)) + (h : ∀ i,M i∈box (a i) (b i)) (hg : vanish S T (M true+M false)) + (ha : ∀ i,Disjoint S (a i)) (hb : ∀ i,Disjoint T (b i)) : + ∃ X Y : Bool → Mat I (Fin (M true).rank), (∀ i,FrameProduct (M i) (a i) (b i) (X i) (Y i)) ∧ + chop S*X true=chop S*X false ∧ chop T*Y true=chop T*Y false := by + classical + obtain ⟨A,B,hA,hB,hM⟩ := rank_product (M true) + let C := Bᵀ + have hC : Injective C.mulVec := trans_surj hB + obtain ⟨hL,hR⟩ := (box_mem ..).mp (h true) + rw [← hM,col_retain hB] at hL + rw [←hM,Matrix.transpose_mul,col_retain (transpose_surj_iff.mpr hA)] at hR + have hf : liftM (chop S) (chop T) (M true)= (chop S*A)*(chop T*C)ᵀ := by + rw [liftM_def,Matrix.transpose_mul, show Cᵀ=B from rfl,Matrix.mul_assoc,Matrix.mul_assoc (chop S),← Matrix.mul_assoc A, + hM] + obtain ⟨P,Q,hP,hQ,hF⟩ := frame_extend (M false) S T (a false) (b false) + (chop S*A) (chop T*C) (h false) (ha false) (hb false) + (chop_inj_pack hA (Disjoint.mono_right hL (ha true))) + (chop_inj_pack hC (Disjoint.mono_right hR (hb true))) (by + have he := (vanish_chop _).mp hg + rw [map_add] at he + rw [←hf] + exact add_left_cancel (he.trans (char_two _).symm)) + refine ⟨onSide (A,P), onSide (C,Q),fun i => ?_,hQ.symm,hF.symm⟩ + cases i + · exact hP + exact ⟨hA,hC,hL,hR,hM⟩ + +private theorem diff_into (a : Bool → Mat I J) (S : Space (Vec I)) + (h : chop S*a true=chop S*a false) : + ∃ (k : ℕ) (P : Mat (Fin (dim S)) (Fin k)) (B : Mat (Fin k) J), + k≤Fintype.card J ∧ Injective (pack S * P).mulVec ∧ Surjective B.mulVec ∧ + a true+a false=(pack S*P)*B := by + classical + let X := a true+a false + obtain ⟨A,B,hA,hB,hX⟩ := rank_product X + have hi : colSp X≤S := by + rintro x ⟨y,rfl⟩ + apply (chop_ker ..).mp + rw [mulVecLin_apply,Matrix.mulVec_mulVec,show X=_+_ from rfl,Matrix.mul_add,h,char_two, + Matrix.zero_mulVec] + obtain ⟨P,hP⟩ := pull_cols (pack S) A (by rw [← col_retain hB,hX,colSp_pack]; exact hi) + refine ⟨X.rank,P,B,X.rank_le_card_width,?_,hB,?_⟩ + · rw [hP]; exact hA + rw [hP,hX] + +/-- δ expansion at one component: S*T offsets bases plus paired +companions Z for either reference endpoint. Cost recorded in actual +offset widths kp/km and kernel matrices. -/ +theorem one_offsets (M : Bool → Mat I I) (S T : Space (Vec I)) + (a b : Bool → Space (Vec I)) + (h : ∀ i,M i∈box (a i) (b i)) (hg : vanish S T (M true+M false)) + (ha : ∀ i,Disjoint S (a i)) (hb : ∀ i,Disjoint T (b i)) : + ∃ (kp km : ℕ) (A : Mat (Fin (dim S)) (Fin kp)) (B : Mat (Fin (dim T)) (Fin km)) + (H : Mat (Fin kp) (Fin km)), + let X := pack S * A + let Y := pack T * B + kp≤(M true).rank ∧ km≤ (M true).rank ∧ Injective X.mulVec ∧ Injective Y.mulVec ∧ + ∀ i,∃ (Z : Mat I (Fin kp)) (W : Mat I (Fin km)), Injective Z.mulVec ∧ Injective W.mulVec ∧ + colSp Z≤ b i ∧ colSp W≤ a i ∧ M true+M false=X*Zᵀ+W*Yᵀ+X*H*Yᵀ := by + classical + obtain ⟨P,Q,hP,hQ,hF⟩ := frame_products M S T a b h hg ha hb + obtain ⟨k,A,E,hk,hA,hE,hX⟩ := diff_into P S hQ + obtain ⟨k',B,D,hk',hB,hD,hY⟩ := diff_into Q T hF + rw [Fintype.card_fin] at hk hk' + let X := pack S * A + let Y := pack T * B + refine ⟨k,k',A,B,E*Dᵀ,hk,hk',hA,hB,fun i => ?_⟩ + let V := P i + let U := Q i + have ht : M true+M false=M i+M (!i) := by cases i; exact add_comm _ _; rfl + have hx : P (!i) = V+X*E := by + rw [show X*E=P true+P false from hX.symm] + cases i + · change P true=P false+(P true+P false); rw [add_left_comm,char_two,add_zero] + · change P false=P true+(P true+P false); rw [←add_assoc,char_two,zero_add] + have hy : Q (!i)=U+Y*D := by + rw [show Y*D=Q true+Q false from hY.symm] + cases i + · change Q true=Q false+(Q true+Q false); rw [add_left_comm,char_two,add_zero] + · change Q false=Q true+(Q true+Q false); rw [←add_assoc,char_two,zero_add] + refine ⟨U*Eᵀ,V*Dᵀ,inj_comp_mat _ _ (hP i).yin (trans_surj hE), + inj_comp_mat _ _ (hP i).xin (trans_surj hD), (col_follow ..).trans (hP i).ycol, + (col_follow ..).trans (hP i).xcol,?_⟩ + + have hm : + M true+M false=V*Uᵀ+(V+X*E)*(U+Y*D)ᵀ := ht.trans (congrArg₂ (· + ·) + (hP i).prod.symm ((hP (!i)).prod.symm.trans (congrArg₂ (· * ·) hx + (congrArg Matrix.transpose hy)))) + apply hm.trans + change _=X * _ + _ * Yᵀ+ X * _ * Yᵀ + simp only [transpose_add,transpose_mul,transpose_transpose,Matrix.add_mul,Matrix.mul_add, + Matrix.mul_assoc,add_assoc] + calc _ = (V*Uᵀ + V*Uᵀ) + (X * (E * Uᵀ) + (V * (Dᵀ*Yᵀ) + X * (E * (Dᵀ*Yᵀ)))) := by abel + _ = _ := by rw [char_two,zero_add] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetRecords.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetRecords.lean index 872164691a7f474a1b542672edbfb2c085b26d9d..77ec04bccf26054bce9b582a06fbf77317307d5d 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetRecords.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/OffsetRecords.lean @@ -1,219 +1,219 @@ -import OAI.Combinatorics.HadwigerCounterexample.OffsetLifting - -namespace OAI - -/-! # Offset Records -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Finset Function -open scoped BigOperators -variable {p : Shape} {r n N : ℕ} - -def fpAt (p : Shape) {n N} (w : Orient p n N) (z : Place p) := - primary (takeSign (w z.1) z.2) -def fyAt (p : Shape) {n N} (w : Orient p n N) (z : Place p) := - channel (takeSign (w z.1) z.2) -def imageP (p : Shape) {n N} (w : UnitType p n N) (i : Bool) : Cov p N := - fun z => colSp (fpAt p (onSide w i) z) - -abbrev BMark (p : Shape) (n N : ℕ) := UnitType p n N → Bool → Profile p n -def mrAmbient {p : Shape} {n N} (m : BMark p n N) (x : UnitType p n N) (i : Bool) := - Uembed (onSide x i) (m x i) -def delta {p : Shape} {n N} (m : BMark p n N) (x : UnitType p n N) := - mrAmbient m x true+mrAmbient m x false - -theorem mr_box (m : BMark p n N) (x) (i) (e : Comp p.g) : - mrAmbient m x i e∈box (imageP p x i (e,true)) (imageP p x i (e,false)) := by - let P := fpAt p (onSide x i) (e,true) - let Q := fpAt p (onSide x i) (e,false) - change liftM P Q _∈box (colSp P) (colSp Q) - rw [box_mem,liftM_transpose] - exact ⟨colSp_lift_le .., colSp_lift_le ..⟩ - -abbrev Wide (p : Shape) (r : ℕ) := Place p → Fin (r+1) -abbrev OffBasis (p : Shape) (r : ℕ) {N} (S : Cov p N) (q : Wide p r) := - ∀ z, Mat (Fin (dim (S z))) (Fin (q z).val) -abbrev OffAux (p : Shape) (r : ℕ) (q : Wide p r) := - ∀ e : Comp p.g,Mat (Fin (q (e,true)).val) (Fin (q (e,false)).val) -abbrev Atlas (p : Shape) (r : ℕ) {N} (S : Cov p N) := - Σ q : Wide p r, OffBasis p r S q × OffAux p r q - -instance aFintype (S : Cov p N) : Fintype (Atlas p r S) := by - classical - letI : (q : Wide p r) → Fintype (OffBasis p r S q) := fun q => inferInstance - letI : (q : Wide p r) → Fintype (OffAux p r q) := fun q => inferInstance - exact inferInstanceAs (Fintype (Atlas p r S)) -instance aDefault (S : Cov p N) : Inhabited (Atlas p r S) := - ⟨⟨fun _ => (0:Fin (r+1)),0,0⟩⟩ - -variable {S : Cov p N} - -abbrev breadth {p : Shape} {N r} {S : Cov p N} (X : Atlas p r S) := fun z : Place p => (X.1 z).val -def cells {p : Shape} {N r} {S : Cov p N} (X : Atlas p r S) := ∑ z : Place p,breadth X z - -abbrev Batch {p : Shape} {N r} {S : Cov p N} (X : Atlas p r S) (n) := - DTuple (p:=p) (breadth X) n - -def src (X : Atlas p r S) : Batch X N := - fun z => pack (S z) * X.2.1 z - -def edgeCost (X : Atlas p r S) : Ambient p N := - fun e => liftM (src X (e,true)) (src X (e,false)) (X.2.2 e) -def spelled (X : Atlas p r S) (A : Batch X N) : Ambient p N := fun e => - src X (e,true)*(A (e,true))ᵀ + A (e,false) * (src X (e,false))ᵀ + edgeCost X e - -/-- comp for A play Zplus paired offset+, Zminus paired offset-. -Companion columns at each compared sign in **opposite** sign primal frame. --/ -def compFor (X : Atlas p r S) (A : Batch X N) (C : Cov p N) - (D : Ambient p N) := - (∀ z, Injective (A z).mulVec ∧ colSp (A z) ≤ C (flipZ p z)) ∧ D=spelled X A - -def locIndep (X : Atlas p r S) := ∀ z, Injective (src X z).mulVec - -def standard (X : Atlas p r S) := cells X ≠ 0 ∧ cells X≤2*r ∧ locIndep X - -private theorem join_order (p : Shape) {N r} (g : Ambient p N) - (q p' : Comp p.g → ℕ) (hyp : ∀ e, q e≤ (g e).rank) (hyp' : ∀ e,p' e ≤ (g e).rank) - (h : epoch p g≤r) : - ∃ ω : Wide p r, (∀ e,(ω (e,true)).val=q e) ∧ (∀ e,(ω (e,false)).val=p' e) ∧ - (∑ z,(ω z).val) ≤2*r := by - classical - have ht (e) : (g e).rank ≤ r := - (Finset.single_le_sum (fun i _ => Nat.zero_le ((g i).rank)) (Finset.mem_univ e)).trans h - let Q := fun e => (⟨q e,Nat.lt_succ_of_le ((hyp e).trans (ht e))⟩ : Fin (r+1)) - let P := fun e => (⟨p' e,Nat.lt_succ_of_le ((hyp' e).trans (ht e))⟩ : Fin (r+1)) - let ω : Wide p r := fun x => if x.2 then Q x.1 else P x.1 - refine ⟨ω,fun _ => rfl, fun _ => rfl,?_⟩ - rw [Fintype.sum_prod_type] - simp only [Fintype.sum_bool,Finset.sum_add_distrib] - rw [two_mul] - exact Nat.add_le_add ((Finset.sum_le_sum fun i _ => hyp i).trans h) - ((Finset.sum_le_sum fun i _ => hyp' i).trans h) - -set_option maxHeartbeats 800000 in -theorem delta_offset (m : BMark p n N) (x) - (h : covered p S (delta m x)) - (hz : delta m x ≠0) - (hs : ∀ i z,Disjoint (S z) (imageP p x i z)) - (hr : epoch p (mrAmbient m x true)≤r) : - ∃ X : Atlas p r S,standard X ∧ ∀ i,∃ A,compFor X A (imageP p x i) (delta m x) := by - classical - choose q p' A B H hT using fun e : Comp p.g => - one_offsets (fun i => mrAmbient m x i e) (S (e,true)) (S (e,false)) - (fun i => imageP p x i (e,true)) (fun i => imageP p x i (e,false)) - (fun i => mr_box m x i e) - ((covered_iff ..).mp h e) - (fun i => hs i _) (fun i => hs i _) - obtain ⟨g,hg,hG,hS⟩ := join_order p (mrAmbient m x true) q p' - (fun i => (hT i).1) (fun i => (hT i).2.1) hr - - have ht (e : Comp p.g) : - ∃ (A' : Mat (Fin (dim (S (e,true)))) (Fin (g (e,true)).val)) - (B' : Mat (Fin (dim (S (e,false)))) (Fin (g (e,false)).val)) - (H' : Mat (Fin (g (e,true)).val) (Fin (g (e,false)).val)), - let X := pack (S (e,true)) * A' - let Y := pack (S (e,false))* B' - Injective X.mulVec ∧ Injective Y.mulVec ∧ - ∀ i : Bool,∃ (Z : Mat (Fin N) (Fin (g (e,true)).val)) (W : Mat (Fin N) (Fin (g (e,false)).val)), - Injective Z.mulVec ∧ Injective W.mulVec ∧ - colSp Z≤ imageP p x i (e,false) ∧ colSp W≤ imageP p x i (e,true) ∧ - delta m x e=X*Zᵀ+W*Yᵀ+X*H'*Yᵀ := by - rw [hg,hG] - exact ⟨A e,B e,H e,(hT e).2.2⟩ - choose A' B' H' hL hR hyp using fun e => by simpa only using ht e - let X : Atlas p r S := ⟨g, (fun z => match z with - | ⟨e,true⟩ => A' e - | ⟨e,false⟩ => B' e),H'⟩ - have he (i) : ∃ Z,compFor X Z (imageP p x i) (delta m x) := by - choose Z W hZ hW hC hD hJ using fun e => hyp e i - refine ⟨(fun z => match z with | ⟨e,true⟩ => Z e | ⟨e,false⟩ => W e),?_,funext fun e => ?_⟩ - · rintro ⟨e,c|c⟩ - · exact ⟨hW e,hD e⟩ - exact ⟨hZ e,hC e⟩ - exact hJ e - refine ⟨X,⟨?_,hS,?_⟩,he⟩ - · intro hc - have h1 (z) : breadth X z = 0 := Nat.eq_zero_of_le_zero - (show _≤0 from le_trans - (Finset.single_le_sum (fun z _ => Nat.zero_le (breadth X z)) (Finset.mem_univ z)) - hc.le) - obtain ⟨A,_,hA⟩ := he true - apply hz - rw [hA] - funext e - let (z : Place p) : IsEmpty (Fin (breadth X z)) := by rw [h1]; infer_instance - unfold spelled edgeCost - ext - simp only [liftM_def,Matrix.add_apply,Matrix.mul_apply] - change _ = 0 - - simp - · rintro ⟨e,c|c⟩ - · exact hR e - exact hL e - -def offsetCov (X : Atlas p r S) : Cov p N := fun z => colSp (src X z) - -theorem offsetCov_dim (p : Shape) {r N} {S : Cov p N} (X : Atlas p r S) : - cdim p (offsetCov X)≤cells X := Finset.sum_le_sum fun i _ => - (src X i).rank_le_card_width.trans_eq (Fintype.card_fin _) - -/-- Capturing offsets suffices to cover the tensor. -/ -theorem covered_spelled (X : Atlas p r S) (A) (T : Cov p N) (he : offsetCov X ≤ T) : - covered p T (spelled X A) := by - apply (cover_mem ..).mpr - intro e - let P := src X (e,true) - let Q := src X (e,false) - have h : ∀ V : Mat (Fin (breadth X (e,true))) (Fin N), P*V∈box (T (e,true)) ⊤ := - fun V => (box_mem ..).mpr ⟨(col_follow ..).trans (he _),le_top⟩ - have h' (V : Mat (Fin N) (Fin (breadth X (e,false)))) : - V*Qᵀ ∈box ⊤ (T (e,false)) := by - rw [box_mem,transpose_mul,transpose_transpose] - exact ⟨le_top,(col_follow ..).trans (he _)⟩ - unfold spelled - refine Submodule.add_mem _ (add_mem_sup (h _) (h' _)) (Submodule.mem_sup_left ?_) - unfold edgeCost - rw [liftM_def,Matrix.mul_assoc] - exact h _ - -theorem atlas_size (S : Cov p N) (r : ℕ) : - num (Atlas p r S) ≤ num (Wide p r) * bp (cdim p S*r+(num (Comp p.g))*r*r) := by - classical - change (↑(Fintype.card (Atlas p r S)) : ℝ) ≤ _ - unfold Atlas - rw [Fintype.card_sigma,Nat.cast_sum] - have hg (q : Wide p r) : - (↑(Fintype.card (OffBasis p r S q×OffAux p r q)):ℝ) ≤ bp (cdim p S*r+(num (Comp p.g))*r*r) := by - rw [card_space] - apply bp_le - have ht : dim (OffBasis p r S q)≤ cdim p S*r := by - unfold dim OffBasis - rw [finrank_pi_fintype] - unfold cdim; rw [Finset.sum_mul] - refine Finset.sum_le_sum fun i _ => ?_ - have h := dim_mat (Fin (dim (S i))) (Fin (q i).val) - rw [Fintype.card_fin,Fintype.card_fin] at h - exact h.trans_le (Nat.mul_le_mul_left _ (Nat.lt_add_one_iff.mp (q i).isLt)) - have hu : dim (OffAux p r q) ≤ Fintype.card (Comp p.g)*r*r := by - unfold dim OffAux - rw [finrank_pi_fintype] - refine (Finset.sum_le_sum (g:=fun _ => r*r) fun i _ => ?_).trans_eq ?_ - · refine (dim_mat _ _).trans_le ?_ - rw [Fintype.card_fin,Fintype.card_fin] - exact Nat.mul_le_mul (Nat.lt_add_one_iff.mp (q _).isLt) (Nat.lt_add_one_iff.mp (q _).isLt) - simp [mul_assoc] - unfold dim - rw [Module.finrank_prod,Nat.cast_add] - have hsum := add_le_add ht hu - unfold num - exact_mod_cast hsum - exact (Finset.sum_le_sum fun i _ => hg i).trans_eq (by simp [num]) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.OffsetLifting + +namespace OAI + +/-! # Offset Records -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Finset Function +open scoped BigOperators +variable {p : Shape} {r n N : ℕ} + +def fpAt (p : Shape) {n N} (w : Orient p n N) (z : Place p) := + primary (takeSign (w z.1) z.2) +def fyAt (p : Shape) {n N} (w : Orient p n N) (z : Place p) := + channel (takeSign (w z.1) z.2) +def imageP (p : Shape) {n N} (w : UnitType p n N) (i : Bool) : Cov p N := + fun z => colSp (fpAt p (onSide w i) z) + +abbrev BMark (p : Shape) (n N : ℕ) := UnitType p n N → Bool → Profile p n +def mrAmbient {p : Shape} {n N} (m : BMark p n N) (x : UnitType p n N) (i : Bool) := + Uembed (onSide x i) (m x i) +def delta {p : Shape} {n N} (m : BMark p n N) (x : UnitType p n N) := + mrAmbient m x true+mrAmbient m x false + +theorem mr_box (m : BMark p n N) (x) (i) (e : Comp p.g) : + mrAmbient m x i e∈box (imageP p x i (e,true)) (imageP p x i (e,false)) := by + let P := fpAt p (onSide x i) (e,true) + let Q := fpAt p (onSide x i) (e,false) + change liftM P Q _∈box (colSp P) (colSp Q) + rw [box_mem,liftM_transpose] + exact ⟨colSp_lift_le .., colSp_lift_le ..⟩ + +abbrev Wide (p : Shape) (r : ℕ) := Place p → Fin (r+1) +abbrev OffBasis (p : Shape) (r : ℕ) {N} (S : Cov p N) (q : Wide p r) := + ∀ z, Mat (Fin (dim (S z))) (Fin (q z).val) +abbrev OffAux (p : Shape) (r : ℕ) (q : Wide p r) := + ∀ e : Comp p.g,Mat (Fin (q (e,true)).val) (Fin (q (e,false)).val) +abbrev Atlas (p : Shape) (r : ℕ) {N} (S : Cov p N) := + Σ q : Wide p r, OffBasis p r S q × OffAux p r q + +instance aFintype (S : Cov p N) : Fintype (Atlas p r S) := by + classical + letI : (q : Wide p r) → Fintype (OffBasis p r S q) := fun q => inferInstance + letI : (q : Wide p r) → Fintype (OffAux p r q) := fun q => inferInstance + exact inferInstanceAs (Fintype (Atlas p r S)) +instance aDefault (S : Cov p N) : Inhabited (Atlas p r S) := + ⟨⟨fun _ => (0:Fin (r+1)),0,0⟩⟩ + +variable {S : Cov p N} + +abbrev breadth {p : Shape} {N r} {S : Cov p N} (X : Atlas p r S) := fun z : Place p => (X.1 z).val +def cells {p : Shape} {N r} {S : Cov p N} (X : Atlas p r S) := ∑ z : Place p,breadth X z + +abbrev Batch {p : Shape} {N r} {S : Cov p N} (X : Atlas p r S) (n) := + DTuple (p:=p) (breadth X) n + +def src (X : Atlas p r S) : Batch X N := + fun z => pack (S z) * X.2.1 z + +def edgeCost (X : Atlas p r S) : Ambient p N := + fun e => liftM (src X (e,true)) (src X (e,false)) (X.2.2 e) +def spelled (X : Atlas p r S) (A : Batch X N) : Ambient p N := fun e => + src X (e,true)*(A (e,true))ᵀ + A (e,false) * (src X (e,false))ᵀ + edgeCost X e + +/-- comp for A play Zplus paired offset+, Zminus paired offset-. +Companion columns at each compared sign in **opposite** sign primal frame. +-/ +def compFor (X : Atlas p r S) (A : Batch X N) (C : Cov p N) + (D : Ambient p N) := + (∀ z, Injective (A z).mulVec ∧ colSp (A z) ≤ C (flipZ p z)) ∧ D=spelled X A + +def locIndep (X : Atlas p r S) := ∀ z, Injective (src X z).mulVec + +def standard (X : Atlas p r S) := cells X ≠ 0 ∧ cells X≤2*r ∧ locIndep X + +private theorem join_order (p : Shape) {N r} (g : Ambient p N) + (q p' : Comp p.g → ℕ) (hyp : ∀ e, q e≤ (g e).rank) (hyp' : ∀ e,p' e ≤ (g e).rank) + (h : epoch p g≤r) : + ∃ ω : Wide p r, (∀ e,(ω (e,true)).val=q e) ∧ (∀ e,(ω (e,false)).val=p' e) ∧ + (∑ z,(ω z).val) ≤2*r := by + classical + have ht (e) : (g e).rank ≤ r := + (Finset.single_le_sum (fun i _ => Nat.zero_le ((g i).rank)) (Finset.mem_univ e)).trans h + let Q := fun e => (⟨q e,Nat.lt_succ_of_le ((hyp e).trans (ht e))⟩ : Fin (r+1)) + let P := fun e => (⟨p' e,Nat.lt_succ_of_le ((hyp' e).trans (ht e))⟩ : Fin (r+1)) + let ω : Wide p r := fun x => if x.2 then Q x.1 else P x.1 + refine ⟨ω,fun _ => rfl, fun _ => rfl,?_⟩ + rw [Fintype.sum_prod_type] + simp only [Fintype.sum_bool,Finset.sum_add_distrib] + rw [two_mul] + exact Nat.add_le_add ((Finset.sum_le_sum fun i _ => hyp i).trans h) + ((Finset.sum_le_sum fun i _ => hyp' i).trans h) + +set_option maxHeartbeats 800000 in +theorem delta_offset (m : BMark p n N) (x) + (h : covered p S (delta m x)) + (hz : delta m x ≠0) + (hs : ∀ i z,Disjoint (S z) (imageP p x i z)) + (hr : epoch p (mrAmbient m x true)≤r) : + ∃ X : Atlas p r S,standard X ∧ ∀ i,∃ A,compFor X A (imageP p x i) (delta m x) := by + classical + choose q p' A B H hT using fun e : Comp p.g => + one_offsets (fun i => mrAmbient m x i e) (S (e,true)) (S (e,false)) + (fun i => imageP p x i (e,true)) (fun i => imageP p x i (e,false)) + (fun i => mr_box m x i e) + ((covered_iff ..).mp h e) + (fun i => hs i _) (fun i => hs i _) + obtain ⟨g,hg,hG,hS⟩ := join_order p (mrAmbient m x true) q p' + (fun i => (hT i).1) (fun i => (hT i).2.1) hr + + have ht (e : Comp p.g) : + ∃ (A' : Mat (Fin (dim (S (e,true)))) (Fin (g (e,true)).val)) + (B' : Mat (Fin (dim (S (e,false)))) (Fin (g (e,false)).val)) + (H' : Mat (Fin (g (e,true)).val) (Fin (g (e,false)).val)), + let X := pack (S (e,true)) * A' + let Y := pack (S (e,false))* B' + Injective X.mulVec ∧ Injective Y.mulVec ∧ + ∀ i : Bool,∃ (Z : Mat (Fin N) (Fin (g (e,true)).val)) (W : Mat (Fin N) (Fin (g (e,false)).val)), + Injective Z.mulVec ∧ Injective W.mulVec ∧ + colSp Z≤ imageP p x i (e,false) ∧ colSp W≤ imageP p x i (e,true) ∧ + delta m x e=X*Zᵀ+W*Yᵀ+X*H'*Yᵀ := by + rw [hg,hG] + exact ⟨A e,B e,H e,(hT e).2.2⟩ + choose A' B' H' hL hR hyp using fun e => by simpa only using ht e + let X : Atlas p r S := ⟨g, (fun z => match z with + | ⟨e,true⟩ => A' e + | ⟨e,false⟩ => B' e),H'⟩ + have he (i) : ∃ Z,compFor X Z (imageP p x i) (delta m x) := by + choose Z W hZ hW hC hD hJ using fun e => hyp e i + refine ⟨(fun z => match z with | ⟨e,true⟩ => Z e | ⟨e,false⟩ => W e),?_,funext fun e => ?_⟩ + · rintro ⟨e,c|c⟩ + · exact ⟨hW e,hD e⟩ + exact ⟨hZ e,hC e⟩ + exact hJ e + refine ⟨X,⟨?_,hS,?_⟩,he⟩ + · intro hc + have h1 (z) : breadth X z = 0 := Nat.eq_zero_of_le_zero + (show _≤0 from le_trans + (Finset.single_le_sum (fun z _ => Nat.zero_le (breadth X z)) (Finset.mem_univ z)) + hc.le) + obtain ⟨A,_,hA⟩ := he true + apply hz + rw [hA] + funext e + let (z : Place p) : IsEmpty (Fin (breadth X z)) := by rw [h1]; infer_instance + unfold spelled edgeCost + ext + simp only [liftM_def,Matrix.add_apply,Matrix.mul_apply] + change _ = 0 + + simp + · rintro ⟨e,c|c⟩ + · exact hR e + exact hL e + +def offsetCov (X : Atlas p r S) : Cov p N := fun z => colSp (src X z) + +theorem offsetCov_dim (p : Shape) {r N} {S : Cov p N} (X : Atlas p r S) : + cdim p (offsetCov X)≤cells X := Finset.sum_le_sum fun i _ => + (src X i).rank_le_card_width.trans_eq (Fintype.card_fin _) + +/-- Capturing offsets suffices to cover the tensor. -/ +theorem covered_spelled (X : Atlas p r S) (A) (T : Cov p N) (he : offsetCov X ≤ T) : + covered p T (spelled X A) := by + apply (cover_mem ..).mpr + intro e + let P := src X (e,true) + let Q := src X (e,false) + have h : ∀ V : Mat (Fin (breadth X (e,true))) (Fin N), P*V∈box (T (e,true)) ⊤ := + fun V => (box_mem ..).mpr ⟨(col_follow ..).trans (he _),le_top⟩ + have h' (V : Mat (Fin N) (Fin (breadth X (e,false)))) : + V*Qᵀ ∈box ⊤ (T (e,false)) := by + rw [box_mem,transpose_mul,transpose_transpose] + exact ⟨le_top,(col_follow ..).trans (he _)⟩ + unfold spelled + refine Submodule.add_mem _ (add_mem_sup (h _) (h' _)) (Submodule.mem_sup_left ?_) + unfold edgeCost + rw [liftM_def,Matrix.mul_assoc] + exact h _ + +theorem atlas_size (S : Cov p N) (r : ℕ) : + num (Atlas p r S) ≤ num (Wide p r) * bp (cdim p S*r+(num (Comp p.g))*r*r) := by + classical + change (↑(Fintype.card (Atlas p r S)) : ℝ) ≤ _ + unfold Atlas + rw [Fintype.card_sigma,Nat.cast_sum] + have hg (q : Wide p r) : + (↑(Fintype.card (OffBasis p r S q×OffAux p r q)):ℝ) ≤ bp (cdim p S*r+(num (Comp p.g))*r*r) := by + rw [card_space] + apply bp_le + have ht : dim (OffBasis p r S q)≤ cdim p S*r := by + unfold dim OffBasis + rw [finrank_pi_fintype] + unfold cdim; rw [Finset.sum_mul] + refine Finset.sum_le_sum fun i _ => ?_ + have h := dim_mat (Fin (dim (S i))) (Fin (q i).val) + rw [Fintype.card_fin,Fintype.card_fin] at h + exact h.trans_le (Nat.mul_le_mul_left _ (Nat.lt_add_one_iff.mp (q i).isLt)) + have hu : dim (OffAux p r q) ≤ Fintype.card (Comp p.g)*r*r := by + unfold dim OffAux + rw [finrank_pi_fintype] + refine (Finset.sum_le_sum (g:=fun _ => r*r) fun i _ => ?_).trans_eq ?_ + · refine (dim_mat _ _).trans_le ?_ + rw [Fintype.card_fin,Fintype.card_fin] + exact Nat.mul_le_mul (Nat.lt_add_one_iff.mp (q _).isLt) (Nat.lt_add_one_iff.mp (q _).isLt) + simp [mul_assoc] + unfold dim + rw [Module.finrank_prod,Nat.cast_add] + have hsum := add_le_add ht hu + unfold num + exact_mod_cast hsum + exact (Finset.sum_le_sum fun i _ => hg i).trans_eq (by simp [num]) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/OppositeEndpointForms.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/OppositeEndpointForms.lean index 9371ff976505604cd22113641b4dc00035118a46..4a21dd4d37d7aadfabdff9e5f9d51c6084dd6ba6 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/OppositeEndpointForms.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/OppositeEndpointForms.lean @@ -1,131 +1,131 @@ -import OAI.Combinatorics.HadwigerCounterexample.ProductCoordinateReplacement -import OAI.Combinatorics.HadwigerCounterexample.MixerConditions - -namespace OAI - -/-! # Opposite Endpoint Forms -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Module Finset Function Filter -variable {p : Shape} {n N : ℕ} - -abbrev Notches (p : Shape) := Comp p.g × Bool - -def duel (p : Shape) {n N : ℕ} (s t : Oframe p n N) (b : Bool) : Moment p n := - (primary (takeSign (p:=p) s b))ᵀ * primary (takeSign (p:=p) t (!b)) - -def duelPart (p : Shape) (c : Vec Bool) (x y : Oframe p n N) := - ∑ b:Bool,c b • duel p x y b -def issue (p : Shape) (c : Vec (Notches p)) (x : UnitType p n N) := - ∑ i:Comp p.g,duelPart p (fun b=>c (i,b)) (x.1 i) (x.2 i) - -set_option maxHeartbeats 800000 in -theorem duel_live (p : Shape) : - ∀ᶠ n : ℕ in atTop,∀ N : ℕ, 4*n≤ N → 2*num (Full p n) 5*(pullM R S (duelPart p c x.1 x.2)+W).rank peer p R R x - let g := fun x : Oframe p n N => peer p S S x - let A := pullM R R (selfM p n m.mixM) - let B := pullM S S (selfM p n m.mixM) - let u := rawC m N - have he (x y : Oframe p n N) : pullM R S (duelPart p c x y)+W = - crossSquare n N W (c false) (f x,g y) := by - unfold duelPart; rw [Fintype.sum_bool,map_add,map_smul,map_smul,hc,one_smul] - unfold duel crossSquare f g peer; simp only [pullM_def,transpose_mul,Matrix.mul_assoc] - exact add_assoc .. - simp_rw [he] - have h : mapW (pairW u u) (Prod.map f g) = pairW (unifOn (gramGood A)) (unifOn (gramGood B)) := by - rw [map_pair_law] - exact congrArg₂ pairW (peer_cap m N hN' hR hR) (peer_cap m N hN' hS hS) - refine le_trans ?_ (hn N hN A B W (c false)) - rw [←h,mapW_pr]; exact le_rfl - -theorem duel_turn (p : Shape) {n N : ℕ} (s t : Oframe p n N) (c : Vec Bool) : - (duelPart p c s t)ᵀ= duelPart p (fun b => c (!b)) t s := by - unfold duelPart duel; simp only [Fintype.sum_bool,transpose_add,transpose_mul,transpose_smul, - transpose_transpose]; exact add_comm .. - -set_option maxHeartbeats 800000 in -theorem duel_survives (p : Shape) : - ∀ᶠ n : ℕ in atTop,∀ N : ℕ, 4*n≤ N → 2*num (Full p n) 5*(pullM R S (duelPart p c x.1 x.2)+W).rank by cases i; exact h; exact (bit_cases _).resolve_right he) - let d := fun i:Bool => c (!i) - have hh := hn N hN hN' m S R hS hR Wᵀ d ht - let f (s t : Oframe p n N) := pullM R S (duelPart p c s t)+W - have he (s t : Oframe p n N) : - (f s t).rank = (pullM S R (duelPart p d t s)+Wᵀ).rank := by - rw [← duel_turn (p:=p) s t c] - simp only [pullM_def,f] - have h : Sᵀ*(duelPart p c s t)ᵀ*R+Wᵀ=(f s t)ᵀ := by - unfold f; simp only [pullM_def,transpose_add,transpose_mul,transpose_transpose, - Matrix.mul_assoc] - rw [h,Matrix.rank_transpose] - rfl - refine le_trans ?_ hh - let u:=rawC m N - change pr (pairW u u) (fun x => 5*(f x.1 x.2).rank 5*blockRank Block.Z s t (issue p c x) rawC m N - let R := blockRay p n s Block.Z; let S:= blockRay p n t Block.Z - let d := fun z : Bool => c (j,z) - let F (x : UnitType p n N) := 5*(pullM R S (issue p c x)).rank < n - have hd : d≠0 := fun h => hb (congr_fun h b) - have hf i : IsLaw (f i) := unifOn_law (framesAt_exists (gramCond_exists m) - (by rw [←two_mul]; simpa only [num,Fintype.card_fin] using hN')) - have hU : IsLaw u := raw_law m hN' - have hi (x : UnitType p n N) : - pr (pairW (f j) (f j)) (fun y => F (update x.1 j y.1,update x.2 j y.2)) - ≤ bp (-(n:ℝ)*n/4) := by - let g := fun x : UnitType p n N => fun i => - duelPart p (fun b => c (i,b)) (x.1 i) (x.2 i) - let W := pullM R S (∑ i∈univ.erase j,g x i) - have he (y : Oframe p n N×Oframe p n N) : - F (update x.1 j y.1,update x.2 j y.2) ↔ - 5*(pullM R S (duelPart p d y.1 y.2) + W).rank by unfold g; simp only [update_of_ne ((mem_erase.mp hi).1)] - rw [h] - simp_rw [he] - exact hn N hN hN' m R S (blockRay_inj ..) (blockRay_inj ..) W d hd - change avg (pairW (prodW f) (prodW f)) (fun x => ind (F x))≤_ - rw [update2_avg f f j _ (hf j) (hf j)] - exact (pairW_law hU hU).avg_le hi -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ProductCoordinateReplacement +import OAI.Combinatorics.HadwigerCounterexample.MixerConditions + +namespace OAI + +/-! # Opposite Endpoint Forms -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Module Finset Function Filter +variable {p : Shape} {n N : ℕ} + +abbrev Notches (p : Shape) := Comp p.g × Bool + +def duel (p : Shape) {n N : ℕ} (s t : Oframe p n N) (b : Bool) : Moment p n := + (primary (takeSign (p:=p) s b))ᵀ * primary (takeSign (p:=p) t (!b)) + +def duelPart (p : Shape) (c : Vec Bool) (x y : Oframe p n N) := + ∑ b:Bool,c b • duel p x y b +def issue (p : Shape) (c : Vec (Notches p)) (x : UnitType p n N) := + ∑ i:Comp p.g,duelPart p (fun b=>c (i,b)) (x.1 i) (x.2 i) + +set_option maxHeartbeats 800000 in +theorem duel_live (p : Shape) : + ∀ᶠ n : ℕ in atTop,∀ N : ℕ, 4*n≤ N → 2*num (Full p n) 5*(pullM R S (duelPart p c x.1 x.2)+W).rank peer p R R x + let g := fun x : Oframe p n N => peer p S S x + let A := pullM R R (selfM p n m.mixM) + let B := pullM S S (selfM p n m.mixM) + let u := rawC m N + have he (x y : Oframe p n N) : pullM R S (duelPart p c x y)+W = + crossSquare n N W (c false) (f x,g y) := by + unfold duelPart; rw [Fintype.sum_bool,map_add,map_smul,map_smul,hc,one_smul] + unfold duel crossSquare f g peer; simp only [pullM_def,transpose_mul,Matrix.mul_assoc] + exact add_assoc .. + simp_rw [he] + have h : mapW (pairW u u) (Prod.map f g) = pairW (unifOn (gramGood A)) (unifOn (gramGood B)) := by + rw [map_pair_law] + exact congrArg₂ pairW (peer_cap m N hN' hR hR) (peer_cap m N hN' hS hS) + refine le_trans ?_ (hn N hN A B W (c false)) + rw [←h,mapW_pr]; exact le_rfl + +theorem duel_turn (p : Shape) {n N : ℕ} (s t : Oframe p n N) (c : Vec Bool) : + (duelPart p c s t)ᵀ= duelPart p (fun b => c (!b)) t s := by + unfold duelPart duel; simp only [Fintype.sum_bool,transpose_add,transpose_mul,transpose_smul, + transpose_transpose]; exact add_comm .. + +set_option maxHeartbeats 800000 in +theorem duel_survives (p : Shape) : + ∀ᶠ n : ℕ in atTop,∀ N : ℕ, 4*n≤ N → 2*num (Full p n) 5*(pullM R S (duelPart p c x.1 x.2)+W).rank by cases i; exact h; exact (bit_cases _).resolve_right he) + let d := fun i:Bool => c (!i) + have hh := hn N hN hN' m S R hS hR Wᵀ d ht + let f (s t : Oframe p n N) := pullM R S (duelPart p c s t)+W + have he (s t : Oframe p n N) : + (f s t).rank = (pullM S R (duelPart p d t s)+Wᵀ).rank := by + rw [← duel_turn (p:=p) s t c] + simp only [pullM_def,f] + have h : Sᵀ*(duelPart p c s t)ᵀ*R+Wᵀ=(f s t)ᵀ := by + unfold f; simp only [pullM_def,transpose_add,transpose_mul,transpose_transpose, + Matrix.mul_assoc] + rw [h,Matrix.rank_transpose] + rfl + refine le_trans ?_ hh + let u:=rawC m N + change pr (pairW u u) (fun x => 5*(f x.1 x.2).rank 5*blockRank Block.Z s t (issue p c x) rawC m N + let R := blockRay p n s Block.Z; let S:= blockRay p n t Block.Z + let d := fun z : Bool => c (j,z) + let F (x : UnitType p n N) := 5*(pullM R S (issue p c x)).rank < n + have hd : d≠0 := fun h => hb (congr_fun h b) + have hf i : IsLaw (f i) := unifOn_law (framesAt_exists (gramCond_exists m) + (by rw [←two_mul]; simpa only [num,Fintype.card_fin] using hN')) + have hU : IsLaw u := raw_law m hN' + have hi (x : UnitType p n N) : + pr (pairW (f j) (f j)) (fun y => F (update x.1 j y.1,update x.2 j y.2)) + ≤ bp (-(n:ℝ)*n/4) := by + let g := fun x : UnitType p n N => fun i => + duelPart p (fun b => c (i,b)) (x.1 i) (x.2 i) + let W := pullM R S (∑ i∈univ.erase j,g x i) + have he (y : Oframe p n N×Oframe p n N) : + F (update x.1 j y.1,update x.2 j y.2) ↔ + 5*(pullM R S (duelPart p d y.1 y.2) + W).rank by unfold g; simp only [update_of_ne ((mem_erase.mp hi).1)] + rw [h] + simp_rw [he] + exact hn N hN hN' m R S (blockRay_inj ..) (blockRay_inj ..) W d hd + change avg (pairW (prodW f) (prodW f)) (fun x => ind (F x))≤_ + rw [update2_avg f f j _ (hf j) (hf j)] + exact (pairW_law hU hU).avg_le hi +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/OppositePredictions.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/OppositePredictions.lean index d21f11f35b28b8c7fbf0c289240913d88cfe1b0c..917949d2bff000c1a28662a8c9e4d49a94674960 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/OppositePredictions.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/OppositePredictions.lean @@ -1,160 +1,160 @@ -import OAI.Combinatorics.HadwigerCounterexample.SyntheticFailureBounds - -namespace OAI - -/-! # Opposite Predictions -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module LinearMap Function Filter Real -open scoped BigOperators -variable {p : Shape} {e d n N : ℕ} - -def singleEx {I : Type} (x : Vec I) : Mat I Unit := Matrix.of (fun i _=>x i) - -theorem single_jet {I : Type} [Fintype I] (x : Vec I) : - singleEx x *ᵥ jet ()=x := by funext j; simp [singleEx,jet,Matrix.mulVec,dotProduct] -theorem single_ind {I : Type} [Fintype I] (x : Vec I) (h : weightsAff x) : - Injective (singleEx x).mulVec := by - classical - obtain ⟨j,hj⟩ : ∃ j,x j≠0 := by - by_contra! hz - unfold weightsAff at h - simp only [hz,Finset.sum_const_zero] at h; exact zero_ne_one h - intro a b ha; funext k - have hh := congr_fun ha j - unfold singleEx Matrix.mulVec dotProduct at hh; simp at hh - cases k; exact hh.resolve_right hj - -private theorem collision_front (p : Shape) {r e : ℕ} (h : p.g*(2*r)rfl) - have hi : arches Q=1 := arches_beam _ - rw [← hQ,hi] at hz - have h1 l : (arches (A l)).rank ≤ 2*r := by - apply Nat.le_of_lt_succ - apply rank_torpedo - intro f - have hv := hA f l - unfold havoc at hv - rw [cart_cross p f l g x] at hv - exact Nat.lt_succ_of_le (le_of_not_gt hv) - have ht := mrk_sum_le univ (fun l:Tag p.g=> arches (A l)) - rw [hz,Matrix.rank_one,Fintype.card_fin] at ht - have he' := ht.trans (Finset.sum_le_sum (g:=fun _=>2*r) (fun i _=>h1 i)) - simp only [Finset.sum_const,Finset.card_univ,Tag,Fintype.card_fin,nsmul_eq_mul,Nat.cast_id] at he' - exact not_lt_of_ge he' h - -set_option maxHeartbeats 1600000 in -theorem screen_calendar (p : Shape) (r M : ℕ) (hM : 1 ≤ M) (L : ℝ) (hL : 0≤ L) - (hr : 1≤p.r) (hj : 1≤p.j) (hg : Odd p.g) : - ∃ ε : ℝ,0<ε ∧ ∀ᶠ n : ℕ in atTop, let N:= M*n; ∀ m : Mixer p n,2*num (Full p n) nlinarith only [he,hε,hb,hc] - refine ⟨ε,hε,?_⟩ - filter_upwards [magazine_calendar p Unit M hM hj L u hL hu, - magazine_calendar p (Hue d) M hM hj L u hL hu, - (cast_tops M hM).eventually (eventually_ge_atTop (2*num (Hue e)+1)), - eventually_ge_atTop (2*p.r)] with n hn hF hB hU N m hN E hE s g w hw h h' - let W:= Display p (Hue e) N; let Q:= displayLaw p (Hue e) N (beamMap e) - change 2*num (Hue e)+1≤ (N:ℝ) at hB - have hB : 2*num (Hue e)-(N:ℝ) ≤ -1 := by linarith only [hB] - have hQ : IsLaw Q := display_law p (beamMap e) N hB - let f:= Flavor.sharedOnly (g:=p.g); let z:=creed p E - let P (i:A) (x:W) := - match i with - | .inl i => weightsAff i ∧ ∑ j:Tag p.g,libPredict p j g (beamMap e) x i≠0 - | .inr (j,i) => havoc p i g (pullM (cartM j) (cartM j) (beamMap e)) r (exhibit p (cartM j) x) - have he (i:A) : pr Q (P i) ≤ u := by - rcases i with i|⟨i,j⟩ - · by_cases hi : weightsAff i - · let V:=singleEx i; let G:=pullM V V (beamMap e) - let R:=mute p g G - have hv : - P (.inl i)= (fun x=>R (exhibit p V x)) := by - unfold P - simp only [hi,true_and,R,mute,libPredict,G,evmat_pull,exhibit_color, - V,single_jet]; rfl - have hG : 0False) := by funext; simp [P,hi] - rw [ht]; exact (pr_false Q).le.trans hu.le - let V:= cartM i; let G:=pullM V V (beamMap e) - let R:= havoc p j g G r - have hv : - P (Sum.inr (i,j))=(fun x=>R (exhibit p V x)) := rfl - have he : Injective V.mulVec := embedMat_inj (reflectSextant i).injective - have h1 : d ≤ spacePunch p j z := hE.trans (purePunch p j E) - obtain ⟨a,ha⟩ := punch_real p j z G ((beam_rank i).trans h1) - rw [hv,←mapW_pr] - unfold Q; rw [exhibit_law p _ _ he hB,show pullM _ _ _=_ from ha.symm] - apply hF j s z m hN R a w hw h - intro x hx - have hz := havoc_rate p j x g E s r m ε a hj hU (h' x hx) - unfold R; rw [←ha]; exact hz.trans hh.1 - have hh x : ∃ i,P i x := by - by_contra! hh - refine collision_front p (r:=r) (Nat.lt_succ_self _) hg x g ?_ ?_ - · intro i hi - exact not_ne_iff.mp fun h=> hh (.inl i) ⟨hi,h⟩ - exact fun i j=>hh (Sum.inr (i,j)) - have hi := pr_exists_le hQ.nz P - have he' := hi.trans ((Finset.sum_le_sum (fun i _=>he i)).trans_eq (by - rw [Finset.sum_const,Finset.card_univ,nsmul_eq_mul])) - change pr Q _≤ num A*u at he' - rw [show (fun x=>∃ i,P i x)=(fun x=>True) from funext (fun i=>propext ⟨fun _=> trivial,fun _=>hh i⟩), - pr_true,hQ.total,show num A*u=(1/2:ℝ) by unfold u; field_simp] at he' - linarith only [he'] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SyntheticFailureBounds + +namespace OAI + +/-! # Opposite Predictions -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module LinearMap Function Filter Real +open scoped BigOperators +variable {p : Shape} {e d n N : ℕ} + +def singleEx {I : Type} (x : Vec I) : Mat I Unit := Matrix.of (fun i _=>x i) + +theorem single_jet {I : Type} [Fintype I] (x : Vec I) : + singleEx x *ᵥ jet ()=x := by funext j; simp [singleEx,jet,Matrix.mulVec,dotProduct] +theorem single_ind {I : Type} [Fintype I] (x : Vec I) (h : weightsAff x) : + Injective (singleEx x).mulVec := by + classical + obtain ⟨j,hj⟩ : ∃ j,x j≠0 := by + by_contra! hz + unfold weightsAff at h + simp only [hz,Finset.sum_const_zero] at h; exact zero_ne_one h + intro a b ha; funext k + have hh := congr_fun ha j + unfold singleEx Matrix.mulVec dotProduct at hh; simp at hh + cases k; exact hh.resolve_right hj + +private theorem collision_front (p : Shape) {r e : ℕ} (h : p.g*(2*r)rfl) + have hi : arches Q=1 := arches_beam _ + rw [← hQ,hi] at hz + have h1 l : (arches (A l)).rank ≤ 2*r := by + apply Nat.le_of_lt_succ + apply rank_torpedo + intro f + have hv := hA f l + unfold havoc at hv + rw [cart_cross p f l g x] at hv + exact Nat.lt_succ_of_le (le_of_not_gt hv) + have ht := mrk_sum_le univ (fun l:Tag p.g=> arches (A l)) + rw [hz,Matrix.rank_one,Fintype.card_fin] at ht + have he' := ht.trans (Finset.sum_le_sum (g:=fun _=>2*r) (fun i _=>h1 i)) + simp only [Finset.sum_const,Finset.card_univ,Tag,Fintype.card_fin,nsmul_eq_mul,Nat.cast_id] at he' + exact not_lt_of_ge he' h + +set_option maxHeartbeats 1600000 in +theorem screen_calendar (p : Shape) (r M : ℕ) (hM : 1 ≤ M) (L : ℝ) (hL : 0≤ L) + (hr : 1≤p.r) (hj : 1≤p.j) (hg : Odd p.g) : + ∃ ε : ℝ,0<ε ∧ ∀ᶠ n : ℕ in atTop, let N:= M*n; ∀ m : Mixer p n,2*num (Full p n) nlinarith only [he,hε,hb,hc] + refine ⟨ε,hε,?_⟩ + filter_upwards [magazine_calendar p Unit M hM hj L u hL hu, + magazine_calendar p (Hue d) M hM hj L u hL hu, + (cast_tops M hM).eventually (eventually_ge_atTop (2*num (Hue e)+1)), + eventually_ge_atTop (2*p.r)] with n hn hF hB hU N m hN E hE s g w hw h h' + let W:= Display p (Hue e) N; let Q:= displayLaw p (Hue e) N (beamMap e) + change 2*num (Hue e)+1≤ (N:ℝ) at hB + have hB : 2*num (Hue e)-(N:ℝ) ≤ -1 := by linarith only [hB] + have hQ : IsLaw Q := display_law p (beamMap e) N hB + let f:= Flavor.sharedOnly (g:=p.g); let z:=creed p E + let P (i:A) (x:W) := + match i with + | .inl i => weightsAff i ∧ ∑ j:Tag p.g,libPredict p j g (beamMap e) x i≠0 + | .inr (j,i) => havoc p i g (pullM (cartM j) (cartM j) (beamMap e)) r (exhibit p (cartM j) x) + have he (i:A) : pr Q (P i) ≤ u := by + rcases i with i|⟨i,j⟩ + · by_cases hi : weightsAff i + · let V:=singleEx i; let G:=pullM V V (beamMap e) + let R:=mute p g G + have hv : + P (.inl i)= (fun x=>R (exhibit p V x)) := by + unfold P + simp only [hi,true_and,R,mute,libPredict,G,evmat_pull,exhibit_color, + V,single_jet]; rfl + have hG : 0False) := by funext; simp [P,hi] + rw [ht]; exact (pr_false Q).le.trans hu.le + let V:= cartM i; let G:=pullM V V (beamMap e) + let R:= havoc p j g G r + have hv : + P (Sum.inr (i,j))=(fun x=>R (exhibit p V x)) := rfl + have he : Injective V.mulVec := embedMat_inj (reflectSextant i).injective + have h1 : d ≤ spacePunch p j z := hE.trans (purePunch p j E) + obtain ⟨a,ha⟩ := punch_real p j z G ((beam_rank i).trans h1) + rw [hv,←mapW_pr] + unfold Q; rw [exhibit_law p _ _ he hB,show pullM _ _ _=_ from ha.symm] + apply hF j s z m hN R a w hw h + intro x hx + have hz := havoc_rate p j x g E s r m ε a hj hU (h' x hx) + unfold R; rw [←ha]; exact hz.trans hh.1 + have hh x : ∃ i,P i x := by + by_contra! hh + refine collision_front p (r:=r) (Nat.lt_succ_self _) hg x g ?_ ?_ + · intro i hi + exact not_ne_iff.mp fun h=> hh (.inl i) ⟨hi,h⟩ + exact fun i j=>hh (Sum.inr (i,j)) + have hi := pr_exists_le hQ.nz P + have he' := hi.trans ((Finset.sum_le_sum (fun i _=>he i)).trans_eq (by + rw [Finset.sum_const,Finset.card_univ,nsmul_eq_mul])) + change pr Q _≤ num A*u at he' + rw [show (fun x=>∃ i,P i x)=(fun x=>True) from funext (fun i=>propext ⟨fun _=> trivial,fun _=>hh i⟩), + pr_true,hQ.total,show num A*u=(1/2:ℝ) by unfold u; field_simp] at he' + linarith only [he'] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/OrientationRankBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/OrientationRankBounds.lean index a82be9737dcf43a7ce0109cd568221a331539440..4900415b8c81abff0430295d181aef226ef50a04 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/OrientationRankBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/OrientationRankBounds.lean @@ -1,99 +1,99 @@ -import OAI.Combinatorics.HadwigerCounterexample.BiasedRotationBounds - -namespace OAI - -/-! # Orientation Rank Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module LinearMap Submodule Function Filter Real -open scoped BigOperators -variable {p : Shape} {n N : ℕ} -namespace Template -variable (v : Solo p) -variable {K s : ℕ} -def offBeat (v : Solo p) (P : AtomKey (p:=p) (v.t ()) N →Prop) (o : Orient p n N) := - fun z => P (v.desc z o) - -theorem beat_round (v : Solo p) (P : AtomKey (p:=p) (v.t ()) N →Prop) (o : Orient p n N) - (w f : Wgt (Knobs p.g n)) (hw : flowZ p w) (c : Flit n) : - zsumPeak p w f (offBeat v P (Move.kite p c N o)) = - zsumPeak p w (Move.zreroute p c f) (offBeat v P o) := by - classical - unfold zsumPeak offBeat - have hh (y : Knobs p.g n) : w (Move.vault p c y)=w y := hw y _ - conv_rhs => rw [← avg_bij (Move.vault p c)] - simp_rw [hh,Move.kite_keys,Move.zreroute,Equiv.symm_apply_apply] -theorem beat_morph (v : Solo p) (P : AtomKey (p:=p) (v.t ()) N →Prop) (o : Orient p n N) - (w : Wgt (Knobs p.g n)) (hw : flowZ p w) (c : Flit n) : - pr w (offBeat v P (Move.kite p c N o)) = pr w (offBeat v P o) := by - have h := beat_round v P o w (fun _=>1) hw c - simp only [zsumPeak,Move.zreroute,mul_one] at h - exact h - -def glow (m : Mixer p n) (w : Wgt (Knobs p.g n)) (A : AtomKey (p:=p) (v.t ()) N →Prop) - (g δ : ℝ) (x : Profile p n) (o : Orient p n N) := - let P := offBeat v A o - δ ≤ pr w P ∧ g*pr w P ≤ |zsumPeak p w (shanty v m x) P| - -set_option maxHeartbeats 800000 in -theorem radiance_calendar (v : Solo p) - (hs : 2*profileA p K ∃ x, 0 F x (Move.kite p c N o))≤b := by - unfold F glow - simp_rw [beat_round _ _ _ _ _ h,beat_morph _ _ _ _ h] - let f := offBeat v P o - by_cases hb : δ≤pr w f - · change pr unif (fun c => δ≤pr w f ∧ _)≤_ - simp only [hb,true_and] - exact hn m hM x hy he w hw h f hb - change pr unif (fun c => δ≤pr w f ∧ _)≤_ - simp only [hb,false_and,pr_false]; exact (bp_pos _).le - have hz (c : Flit n) : - pr μ (F x)=pr μ (fun o => F x (Move.kite p c N o)) := by - unfold pr μ - conv_lhs => rw [← avg_bij (Move.kite p c N)] - simp_rw [Move.kite_weights] - have hh : - pr μ (F x)=avg unif (fun c => pr μ (fun o => F x (Move.kite p c N o))) := by - simp_rw [←hz]; exact (unif_law.avg_const _).symm - rw [hh] - unfold pr; rw [avg_avg]; exact hμ.avg_le hi - let Q (x : Profile p n) (o : Orient p n N) := 0 hi i)).trans ?_ - rw [← Finset.sum_mul]; change nbr L*b ≤ _ - refine (mul_le_mul_of_nonneg_right ht (bp_pos _).le).trans_eq ?_ - unfold d; rw [←bp_add]; congr 1; ring -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BiasedRotationBounds + +namespace OAI + +/-! # Orientation Rank Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module LinearMap Submodule Function Filter Real +open scoped BigOperators +variable {p : Shape} {n N : ℕ} +namespace Template +variable (v : Solo p) +variable {K s : ℕ} +def offBeat (v : Solo p) (P : AtomKey (p:=p) (v.t ()) N →Prop) (o : Orient p n N) := + fun z => P (v.desc z o) + +theorem beat_round (v : Solo p) (P : AtomKey (p:=p) (v.t ()) N →Prop) (o : Orient p n N) + (w f : Wgt (Knobs p.g n)) (hw : flowZ p w) (c : Flit n) : + zsumPeak p w f (offBeat v P (Move.kite p c N o)) = + zsumPeak p w (Move.zreroute p c f) (offBeat v P o) := by + classical + unfold zsumPeak offBeat + have hh (y : Knobs p.g n) : w (Move.vault p c y)=w y := hw y _ + conv_rhs => rw [← avg_bij (Move.vault p c)] + simp_rw [hh,Move.kite_keys,Move.zreroute,Equiv.symm_apply_apply] +theorem beat_morph (v : Solo p) (P : AtomKey (p:=p) (v.t ()) N →Prop) (o : Orient p n N) + (w : Wgt (Knobs p.g n)) (hw : flowZ p w) (c : Flit n) : + pr w (offBeat v P (Move.kite p c N o)) = pr w (offBeat v P o) := by + have h := beat_round v P o w (fun _=>1) hw c + simp only [zsumPeak,Move.zreroute,mul_one] at h + exact h + +def glow (m : Mixer p n) (w : Wgt (Knobs p.g n)) (A : AtomKey (p:=p) (v.t ()) N →Prop) + (g δ : ℝ) (x : Profile p n) (o : Orient p n N) := + let P := offBeat v A o + δ ≤ pr w P ∧ g*pr w P ≤ |zsumPeak p w (shanty v m x) P| + +set_option maxHeartbeats 800000 in +theorem radiance_calendar (v : Solo p) + (hs : 2*profileA p K ∃ x, 0 F x (Move.kite p c N o))≤b := by + unfold F glow + simp_rw [beat_round _ _ _ _ _ h,beat_morph _ _ _ _ h] + let f := offBeat v P o + by_cases hb : δ≤pr w f + · change pr unif (fun c => δ≤pr w f ∧ _)≤_ + simp only [hb,true_and] + exact hn m hM x hy he w hw h f hb + change pr unif (fun c => δ≤pr w f ∧ _)≤_ + simp only [hb,false_and,pr_false]; exact (bp_pos _).le + have hz (c : Flit n) : + pr μ (F x)=pr μ (fun o => F x (Move.kite p c N o)) := by + unfold pr μ + conv_lhs => rw [← avg_bij (Move.kite p c N)] + simp_rw [Move.kite_weights] + have hh : + pr μ (F x)=avg unif (fun c => pr μ (fun o => F x (Move.kite p c N o))) := by + simp_rw [←hz]; exact (unif_law.avg_const _).symm + rw [hh] + unfold pr; rw [avg_avg]; exact hμ.avg_le hi + let Q (x : Profile p n) (o : Orient p n N) := 0 hi i)).trans ?_ + rw [← Finset.sum_mul]; change nbr L*b ≤ _ + refine (mul_le_mul_of_nonneg_right ht (bp_pos _).le).trans_eq ?_ + unfold d; rw [←bp_add]; congr 1; ring +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/OrthogonalSpectrumBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/OrthogonalSpectrumBounds.lean index c1eff52ba5c34e7b457b478d081a8febf9686a74..8f44beca9ec37cc83decc5022365395cb557fc5f 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/OrthogonalSpectrumBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/OrthogonalSpectrumBounds.lean @@ -1,105 +1,105 @@ -import OAI.Combinatorics.HadwigerCounterexample.ReindexedFourierSupport - -namespace OAI - -/-! # Orthogonal Spectrum Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module LinearMap Submodule Function -open scoped BigOperators -variable {p : Shape} {n : ℕ} - -def fieldRad (S : Space (Vec (Fin n))) : Finset (Vec (Fin n)) := - open Classical in univ.filter (fun i => i∈S) -@[simp] theorem mem_fieldRad (S : Space (Vec (Fin n))) (i) : - i∈fieldRad S↔i∈S := by simp [fieldRad] -theorem card_fieldRad (S : Space (Vec (Fin n))) : ((fieldRad S).card:ℝ)=bp (dim S) := by - classical - rw [←card_space] - let e : S≃ (↑(fieldRad S) : Type) := { - toFun x := ⟨x.val, by simp⟩ - invFun x := ⟨x.val,(mem_fieldRad ..).mp x.property⟩ - left_inv _ := rfl - right_inv _ := rfl } - exact_mod_cast (Fintype.card_coe (fieldRad S)).symm.trans (Fintype.card_congr e).symm - -def zsafe (p : Shape) (w f : Wgt (Knobs p.g n)) (S : Space (Vec (Fin n))) := - ∀ (g : Wgt (Knobs p.g n)) (t : Finset (Vec (Fin n))), - (∀ i∈t,i∉S) → avg w (fun i => f i * zim p g t i)=0 -def zsumPeak (p : Shape) (w f : Wgt (Knobs p.g n)) (P : Knobs p.g n → Prop) := - avg w (fun i => ind (P i)*f i) - -set_option maxHeartbeats 800000 in -theorem clear_band (p : Shape) (w f : Wgt (Knobs p.g n)) (P : Knobs p.g n→Prop) - (hw : IsLaw w) (hf : ∀ i, |f i|≤1) (h : flowZ p w) - (b g : ℝ) (hb : 0≤b) (hq : g*pr w P≤ |zsumPeak p w f P|) - (S T : Space (Vec (Fin n))) (s : ℕ) (hS : dim (S⊓T : Space (Vec (Fin n))) ≤ s) - (hh : ∀ x i, |zchar p f i x|≤b ∧ (i∉T → zchar p f i x=0)) : - ∃ (t : Finset (Vec (Fin n))) (a : ℝ), |a|=1 ∧ - (∀ i∈ t,i∉S ∧ i∈T) ∧ - let F i := a * zim p f t i - (g-b*bp s)*pr w P ≤ zsumPeak p w F P ∧ avg w (fun i => F i ^ 2)≤1 := by - classical - let A := fieldRad T - let B := fieldRad (S⊓T); let D := A\B - have hB : B⊆A := fun i hi => (mem_fieldRad T i).mpr (((mem_fieldRad (S⊓T) i).mp hi).2) - have he x : f x=zim p f D x+zim p f B x := by - unfold zim D - rw [Finset.sum_sdiff hB] - change f x=∑ i∈A,_ - exact (z_atlas p f x).symm.trans (Finset.sum_subset (subset_univ A) - (fun i _ hi=> (hh x i).2 (fun h => hi ((mem_fieldRad ..).mpr h)))).symm - let V x := zsumPeak p w x P - have hm (x) : - |zim p f B x|≤b*bp s := by - have hx : ((B.card:ℝ))≤bp s := le_trans (le_of_eq (card_fieldRad (S⊓T))) - (bp_le (by exact_mod_cast hS)) - refine (abs_sum_le_sum_abs ..).trans ((Finset.sum_le_sum - (s:=B) (fun i _ => (hh x i).1)).trans ?_) - simp only [Finset.sum_const,nsmul_eq_mul,mul_comm b] - exact mul_le_mul_of_nonneg_right hx hb - have hz : - |V (zim p f B)| ≤ b*bp s*pr w P := by - apply (abs_avg_le hw.nz).trans - have he (x : Knobs p.g n) : - |ind (P x)*zim p f B x|≤ (b*bp s)*ind (P x) := by - rw [abs_mul,abs_of_nonneg (ind_nonneg _),mul_comm (b*bp s)] - exact mul_le_mul_of_nonneg_left (hm x) (ind_nonneg _) - exact (avg_mono hw.nz he).trans_eq (avg_mul' ..) - have h2 : - |V f|≤|V (zim p f D)| + |V (zim p f B)| := by - have ht : - V f= V (zim p f D)+V (zim p f B) := by - unfold V zsumPeak; rw [← avg_add] - apply avg_congr; intro x _ - conv_lhs => rhs; rw [he x] - rw [mul_add] - rw [ht]; exact abs_add_le .. - have hb : - (g-b*bp s)*pr w P≤|V (zim p f D)| := by linarith only [hq,h2,hz] - let a : ℝ := if 0≤ V (zim p f D) then 1 else -1 - have ha : |a|=1 := by unfold a; split <;> norm_num - have hi : - V (fun i=>a*zim p f D i) = |V (zim p f D)| := by - have he (i : Knobs p.g n) : ind (P i)*(a*zim p f D i)=a*(ind (P i)*zim p f D i) := by ring - have hh : V (fun i=>a*zim p f D i)=a*V (zim p f D) := by - unfold V zsumPeak; simp_rw [he,avg_mul'] - rw [hh]; unfold a - split - next h => rw [one_mul,abs_of_nonneg h] - next h => simp only [neg_mul,one_mul,abs_of_neg (lt_of_not_ge h)] - refine ⟨D,a,ha,fun i hit => ?_,hb.trans_eq hi.symm,?_⟩ - · obtain ⟨h0,h1⟩ := mem_sdiff.mp hit - obtain h2 := (mem_fieldRad ..).mp h0 - exact ⟨fun h => h1 ((mem_fieldRad (S⊓T) _).mpr ⟨h,h2⟩),h2⟩ - have ha' : a^2=1 := by rw [←sq_abs,ha]; norm_num - simp_rw [mul_pow,ha',one_mul] - exact (zsplit_cost p f w h hw.nz D).trans (hw.avg_le (fun i=>by - have h := hf i - nlinarith only [sq_abs (f i),abs_nonneg (f i),h])) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ReindexedFourierSupport + +namespace OAI + +/-! # Orthogonal Spectrum Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module LinearMap Submodule Function +open scoped BigOperators +variable {p : Shape} {n : ℕ} + +def fieldRad (S : Space (Vec (Fin n))) : Finset (Vec (Fin n)) := + open Classical in univ.filter (fun i => i∈S) +@[simp] theorem mem_fieldRad (S : Space (Vec (Fin n))) (i) : + i∈fieldRad S↔i∈S := by simp [fieldRad] +theorem card_fieldRad (S : Space (Vec (Fin n))) : ((fieldRad S).card:ℝ)=bp (dim S) := by + classical + rw [←card_space] + let e : S≃ (↑(fieldRad S) : Type) := { + toFun x := ⟨x.val, by simp⟩ + invFun x := ⟨x.val,(mem_fieldRad ..).mp x.property⟩ + left_inv _ := rfl + right_inv _ := rfl } + exact_mod_cast (Fintype.card_coe (fieldRad S)).symm.trans (Fintype.card_congr e).symm + +def zsafe (p : Shape) (w f : Wgt (Knobs p.g n)) (S : Space (Vec (Fin n))) := + ∀ (g : Wgt (Knobs p.g n)) (t : Finset (Vec (Fin n))), + (∀ i∈t,i∉S) → avg w (fun i => f i * zim p g t i)=0 +def zsumPeak (p : Shape) (w f : Wgt (Knobs p.g n)) (P : Knobs p.g n → Prop) := + avg w (fun i => ind (P i)*f i) + +set_option maxHeartbeats 800000 in +theorem clear_band (p : Shape) (w f : Wgt (Knobs p.g n)) (P : Knobs p.g n→Prop) + (hw : IsLaw w) (hf : ∀ i, |f i|≤1) (h : flowZ p w) + (b g : ℝ) (hb : 0≤b) (hq : g*pr w P≤ |zsumPeak p w f P|) + (S T : Space (Vec (Fin n))) (s : ℕ) (hS : dim (S⊓T : Space (Vec (Fin n))) ≤ s) + (hh : ∀ x i, |zchar p f i x|≤b ∧ (i∉T → zchar p f i x=0)) : + ∃ (t : Finset (Vec (Fin n))) (a : ℝ), |a|=1 ∧ + (∀ i∈ t,i∉S ∧ i∈T) ∧ + let F i := a * zim p f t i + (g-b*bp s)*pr w P ≤ zsumPeak p w F P ∧ avg w (fun i => F i ^ 2)≤1 := by + classical + let A := fieldRad T + let B := fieldRad (S⊓T); let D := A\B + have hB : B⊆A := fun i hi => (mem_fieldRad T i).mpr (((mem_fieldRad (S⊓T) i).mp hi).2) + have he x : f x=zim p f D x+zim p f B x := by + unfold zim D + rw [Finset.sum_sdiff hB] + change f x=∑ i∈A,_ + exact (z_atlas p f x).symm.trans (Finset.sum_subset (subset_univ A) + (fun i _ hi=> (hh x i).2 (fun h => hi ((mem_fieldRad ..).mpr h)))).symm + let V x := zsumPeak p w x P + have hm (x) : + |zim p f B x|≤b*bp s := by + have hx : ((B.card:ℝ))≤bp s := le_trans (le_of_eq (card_fieldRad (S⊓T))) + (bp_le (by exact_mod_cast hS)) + refine (abs_sum_le_sum_abs ..).trans ((Finset.sum_le_sum + (s:=B) (fun i _ => (hh x i).1)).trans ?_) + simp only [Finset.sum_const,nsmul_eq_mul,mul_comm b] + exact mul_le_mul_of_nonneg_right hx hb + have hz : + |V (zim p f B)| ≤ b*bp s*pr w P := by + apply (abs_avg_le hw.nz).trans + have he (x : Knobs p.g n) : + |ind (P x)*zim p f B x|≤ (b*bp s)*ind (P x) := by + rw [abs_mul,abs_of_nonneg (ind_nonneg _),mul_comm (b*bp s)] + exact mul_le_mul_of_nonneg_left (hm x) (ind_nonneg _) + exact (avg_mono hw.nz he).trans_eq (avg_mul' ..) + have h2 : + |V f|≤|V (zim p f D)| + |V (zim p f B)| := by + have ht : + V f= V (zim p f D)+V (zim p f B) := by + unfold V zsumPeak; rw [← avg_add] + apply avg_congr; intro x _ + conv_lhs => rhs; rw [he x] + rw [mul_add] + rw [ht]; exact abs_add_le .. + have hb : + (g-b*bp s)*pr w P≤|V (zim p f D)| := by linarith only [hq,h2,hz] + let a : ℝ := if 0≤ V (zim p f D) then 1 else -1 + have ha : |a|=1 := by unfold a; split <;> norm_num + have hi : + V (fun i=>a*zim p f D i) = |V (zim p f D)| := by + have he (i : Knobs p.g n) : ind (P i)*(a*zim p f D i)=a*(ind (P i)*zim p f D i) := by ring + have hh : V (fun i=>a*zim p f D i)=a*V (zim p f D) := by + unfold V zsumPeak; simp_rw [he,avg_mul'] + rw [hh]; unfold a + split + next h => rw [one_mul,abs_of_nonneg h] + next h => simp only [neg_mul,one_mul,abs_of_neg (lt_of_not_ge h)] + refine ⟨D,a,ha,fun i hit => ?_,hb.trans_eq hi.symm,?_⟩ + · obtain ⟨h0,h1⟩ := mem_sdiff.mp hit + obtain h2 := (mem_fieldRad ..).mp h0 + exact ⟨fun h => h1 ((mem_fieldRad (S⊓T) _).mpr ⟨h,h2⟩),h2⟩ + have ha' : a^2=1 := by rw [←sq_abs,ha]; norm_num + simp_rw [mul_pow,ha',one_mul] + exact (zsplit_cost p f w h hw.nz D).trans (hw.avg_le (fun i=>by + have h := hf i + nlinarith only [sq_abs (f i),abs_nonneg (f i),h])) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PairIndexedTests.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PairIndexedTests.lean index a181197beec92c6424a986418865f7675ec59264..60cecdc4df93c4cbc40684ac31d3644acbe5dc54 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PairIndexedTests.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PairIndexedTests.lean @@ -1,85 +1,85 @@ -import OAI.Combinatorics.HadwigerCounterexample.ProductCharacterTests - -namespace OAI - -/-! # Pair Indexed Tests -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module Function -open scoped BigOperators -variable {I J A : Type} [Fintype I] [DecidableEq I] [Fintype J] [DecidableEq J] [Fintype A] -variable {s : Stage I J} {B : J→ Type} -variable [∀ i,Fintype (B i)] [∀ i,DecidableEq (B i)] - -def listen (s : Stage I J) (f : ∀ i,A→A→Vec (B i)) (x : I→ A) := fun i => - f i (x (s.first i)) (x (s.nextP i)) - -def prism (B : J →Type) [∀ i,Fintype (B i)] [∀ i,DecidableEq (B i)] : - Wgt (∀ i,Vec (B i)) := prodW (fun _ : J => unif) -def wavelength (B : J →Type) [∀ i,Fintype (B i)] [∀ i,DecidableEq (B i)] := - prism B 0 - -omit [DecidableEq J] in -theorem wavelength_pos (B : J →Type) [∀ i,Fintype (B i)] [∀ i,DecidableEq (B i)] : - 0 by simp only [unif_apply]; positivity) - -omit [Fintype I] [DecidableEq I] [Fintype A] in -theorem prism_expand (s : Stage I J) (F : ∀ i,A→A→Vec (B i)) (v : ∀ i,Vec (B i)) (x : I→A) : - ind (listen s F x=v)=avg (prism B) (fun u => ∏ i:J, - (vectorPhase (u i) (F i (x (s.first i)) (x (s.nextP i)))*vectorPhase (u i) (v i))) := by - classical - rw [funext_iff, ind_all]; simp_rw [listen,vector_expand] - exact (prodW_avg (fun i => unif) (fun i u => - vectorPhase u (F i (x (s.first i)) (x (s.nextP i)))*vectorPhase u (v i))).symm - -set_option maxHeartbeats 800000 in -theorem hear_band (s : Stage I J) (F : ∀ i,A→A→Vec (B i)) (v : ∀ i,Vec (B i)) - (w : I → Wgt A) (hw : ∀ i,IsLaw (w i)) - (η : ℝ) (hη : 0≤η) - (h : ∀ i:J,∀ u:Vec (B i),u≠0 → ∀ p q : Wgt A,(∀ i,|p i|≤1) → (∀ i,|q i|≤1) → - |avg (pairW (w (s.first i)) (w (s.nextP i))) (fun x => - vectorPhase u (F i x.1 x.2)*(p x.1*q x.2))|≤η) : - ∀ p : I→ Wgt A,(∀ i x,|p i x|≤1) → - |avg (prodW w) (fun x => ind (listen s F x=v)*prodW p x)- - wavelength B*∏ i:I,avg (w i) (p i)|≤η := by - classical - intro p hp - let P (u : ∀ i, Vec (B i)) (i:J) (x y : A) := vectorPhase (u i) (F i x y) - let Q (u : ∀ i,Vec (B i)) := ∏ i:J,vectorPhase (u i) (v i) - let U (u:∀ i,Vec (B i)) := avg (prodW w) (fun x => - (∏ i:J,P u i (x (s.first i)) (x (s.nextP i)))*prodW p x) - have he : - avg (prodW w) (fun x => ind (listen s F x=v)*prodW p x)= - avg (prism B) (fun u => Q u*U u) := by - simp_rw [prism_expand,←avg_mul] - rw [avg_avg]; unfold Q U P; simp_rw [←avg_mul',Finset.prod_mul_distrib] - apply avg_congr; intro x _; refine avg_congr fun i _ => ?_ - ring - have hU : U 0=∏ i:I,avg (w i) (p i) := by - unfold U P - simp only [vectorPhase,Pi.zero_apply,zero_dotProduct,wsign_zero,prod_const_one,one_mul] - exact prodW_avg .. - have hQ : Q 0=1 := by simp [Q,vectorPhase] - have hq u : |Q u|=1 := by simp [Q,abs_prod,vectorPhase] - let V := ∏ i:I,avg (w i) (p i) - let L (u : ∀ i,Vec (B i)) := ind (u=0)*V - have hi : avg (prism B) L=wavelength B*V := by - unfold L; rw [avg_mul,show avg (prism B) (fun i => ind (i=0))= _ from pr_point' (prism B) 0]; rfl - have hh u : |Q u*U u-L u| ≤ η := by - by_cases hg : u=0 - · subst u; unfold L V; rw [ind_one (show (0:∀ i,Vec (B i))=0 from rfl),hU,hQ,sub_self,abs_zero] - exact hη - obtain ⟨i,ha⟩ := Function.ne_iff.mp hg - unfold L; rw [ind_zero hg,zero_mul,sub_zero,abs_mul,hq,one_mul] - exact band_res s w hw p hp (P u) (by intro k x y; simp [P,vectorPhase]) i η (h i (u i) ha) - have h0 : IsLaw (prism B) := prodW_law (fun _ => unif_law) - rw [he]; change |_ - wavelength B * V|≤_ - rw [←hi,←avg_sub] - exact (abs_avg_le h0.nz).trans (h0.avg_le hh) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ProductCharacterTests + +namespace OAI + +/-! # Pair Indexed Tests -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module Function +open scoped BigOperators +variable {I J A : Type} [Fintype I] [DecidableEq I] [Fintype J] [DecidableEq J] [Fintype A] +variable {s : Stage I J} {B : J→ Type} +variable [∀ i,Fintype (B i)] [∀ i,DecidableEq (B i)] + +def listen (s : Stage I J) (f : ∀ i,A→A→Vec (B i)) (x : I→ A) := fun i => + f i (x (s.first i)) (x (s.nextP i)) + +def prism (B : J →Type) [∀ i,Fintype (B i)] [∀ i,DecidableEq (B i)] : + Wgt (∀ i,Vec (B i)) := prodW (fun _ : J => unif) +def wavelength (B : J →Type) [∀ i,Fintype (B i)] [∀ i,DecidableEq (B i)] := + prism B 0 + +omit [DecidableEq J] in +theorem wavelength_pos (B : J →Type) [∀ i,Fintype (B i)] [∀ i,DecidableEq (B i)] : + 0 by simp only [unif_apply]; positivity) + +omit [Fintype I] [DecidableEq I] [Fintype A] in +theorem prism_expand (s : Stage I J) (F : ∀ i,A→A→Vec (B i)) (v : ∀ i,Vec (B i)) (x : I→A) : + ind (listen s F x=v)=avg (prism B) (fun u => ∏ i:J, + (vectorPhase (u i) (F i (x (s.first i)) (x (s.nextP i)))*vectorPhase (u i) (v i))) := by + classical + rw [funext_iff, ind_all]; simp_rw [listen,vector_expand] + exact (prodW_avg (fun i => unif) (fun i u => + vectorPhase u (F i (x (s.first i)) (x (s.nextP i)))*vectorPhase u (v i))).symm + +set_option maxHeartbeats 800000 in +theorem hear_band (s : Stage I J) (F : ∀ i,A→A→Vec (B i)) (v : ∀ i,Vec (B i)) + (w : I → Wgt A) (hw : ∀ i,IsLaw (w i)) + (η : ℝ) (hη : 0≤η) + (h : ∀ i:J,∀ u:Vec (B i),u≠0 → ∀ p q : Wgt A,(∀ i,|p i|≤1) → (∀ i,|q i|≤1) → + |avg (pairW (w (s.first i)) (w (s.nextP i))) (fun x => + vectorPhase u (F i x.1 x.2)*(p x.1*q x.2))|≤η) : + ∀ p : I→ Wgt A,(∀ i x,|p i x|≤1) → + |avg (prodW w) (fun x => ind (listen s F x=v)*prodW p x)- + wavelength B*∏ i:I,avg (w i) (p i)|≤η := by + classical + intro p hp + let P (u : ∀ i, Vec (B i)) (i:J) (x y : A) := vectorPhase (u i) (F i x y) + let Q (u : ∀ i,Vec (B i)) := ∏ i:J,vectorPhase (u i) (v i) + let U (u:∀ i,Vec (B i)) := avg (prodW w) (fun x => + (∏ i:J,P u i (x (s.first i)) (x (s.nextP i)))*prodW p x) + have he : + avg (prodW w) (fun x => ind (listen s F x=v)*prodW p x)= + avg (prism B) (fun u => Q u*U u) := by + simp_rw [prism_expand,←avg_mul] + rw [avg_avg]; unfold Q U P; simp_rw [←avg_mul',Finset.prod_mul_distrib] + apply avg_congr; intro x _; refine avg_congr fun i _ => ?_ + ring + have hU : U 0=∏ i:I,avg (w i) (p i) := by + unfold U P + simp only [vectorPhase,Pi.zero_apply,zero_dotProduct,wsign_zero,prod_const_one,one_mul] + exact prodW_avg .. + have hQ : Q 0=1 := by simp [Q,vectorPhase] + have hq u : |Q u|=1 := by simp [Q,abs_prod,vectorPhase] + let V := ∏ i:I,avg (w i) (p i) + let L (u : ∀ i,Vec (B i)) := ind (u=0)*V + have hi : avg (prism B) L=wavelength B*V := by + unfold L; rw [avg_mul,show avg (prism B) (fun i => ind (i=0))= _ from pr_point' (prism B) 0]; rfl + have hh u : |Q u*U u-L u| ≤ η := by + by_cases hg : u=0 + · subst u; unfold L V; rw [ind_one (show (0:∀ i,Vec (B i))=0 from rfl),hU,hQ,sub_self,abs_zero] + exact hη + obtain ⟨i,ha⟩ := Function.ne_iff.mp hg + unfold L; rw [ind_zero hg,zero_mul,sub_zero,abs_mul,hq,one_mul] + exact band_res s w hw p hp (P u) (by intro k x y; simp [P,vectorPhase]) i η (h i (u i) ha) + have h0 : IsLaw (prism B) := prodW_law (fun _ => unif_law) + rw [he]; change |_ - wavelength B * V|≤_ + rw [←hi,←avg_sub] + exact (abs_avg_le h0.nz).trans (h0.avg_le hh) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PairedCollisionBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PairedCollisionBounds.lean index 7d2bba838c4a7329fe300bcb853252dae084d013..7be46ce26bc02c3501b65e78c7f7fd3bec2fc590 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PairedCollisionBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PairedCollisionBounds.lean @@ -1,126 +1,126 @@ -import OAI.Combinatorics.HadwigerCounterexample.PairedOptions - -namespace OAI - -/-! # Paired Collision Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Finset Submodule Filter -open scoped BigOperators Topology -namespace StatusAnalysis -variable {p : Shape} {n N K : ℕ} {q : Format} {d e : Rates} - -theorem quillState {i : Bool} {w : Quill p q d i} {t z} (h : w.moral t z) (hr : 1≤p.r) - (hn : 2*p.r ≤ n) : - IsLaw ((w.pen t).state z n) := prodW_law (fun j=> dial_law p n _ _ _ hr hn (Quill.canDraw _ _ h j)) - -namespace Station -variable {s : LeafMixture p n N} (v : Station p n N K s) - -def clash (p : Shape) (m : Mixer p n) (N : ℕ) := - fun x : UnitType p n N × UnitType p n N => (rawHoles m).conflict x.1 x.2 - -def beamPrice (p : Shape) (N : ℕ) := bp (((kmax p:ℝ)+0.02)*N) - -structure earnsScore (p : Shape) (n N K : ℕ) (ζ : ℝ) : Prop where - hr : 1≤p.r - hn : 2*p.r≤n - solid : realizeAssum p K - smooth : 0 ≤ ζ - low : ζ ≤ 0.004 - light : ζ*(kmax p) ≤ 0.004 - hN : 100 ≤ N - gram : (dim (CheckGram p n) : ℝ) ≤ 0.01*N - budget : (K+(kmax p:ℝ))*num (JointIdx p n) ≤ 0.005*N - -set_option maxHeartbeats 1400000 in -theorem sellPoint (w : Typus p q d e) - (m :Mixer p n) (μ : Wgt (UnitType p n N)) (i j : s.T) (k : Fin (2^deckMax p K)) - {C ζ : ℝ} (hp : s.strength μ (PreparationParameters.usual p m N) C ζ K) (hw : IsLaw μ) - (he : earnsScore p n N K ζ) : - matchScore v w m μ i j k ≤ beamPrice p N * - pr (pairW (partW μ i.val) (partW μ j.val)) (clash p m N)+2* bp (-0.005*N) := by - classical - have hA := hp.leaf i.val i.property; have hB := hp.leaf j.val j.property - let a:=w.qA.pen w.t; let b:=w.qB.pen w.t - let ia:=s.pin i.val; let ib:=s.pin j.val - let u:=partW μ i.val; let u':=partW μ j.val - let F:=frontPage v w m i j k; let G:=backPage v w m i j k - let T:=v.mails i j k; let x:=v.cAxes i d; let y:=v.cAxes j e - let Q (z : Inputs p n (Messenger q)) (o : UnitType p n N) := - F o ∧ w.qA.deposit w.t w.z m o x z - let R (z : Inputs p n (Messenger q)) (o : UnitType p n N) := - G o ∧ w.qB.deposit w.t w.z m o y z - have hu : IsLaw u:= on_law hw.nz hA.pos - have hu' : IsLaw u':= on_law hw.nz hB.pos - let δ := pr (pairW u u') (clash p m N) - have hδ : 0≤δ := pr_nonneg (pairW_law hu hu').nz - change overlap (lawNu p N w.t w.z) - (Volley.hist a.draw w.t u (a.state w.z n) Q) (Volley.hist b.draw w.t u' (b.state w.z n) R) ≤ - beamPrice p N*δ+ _ - by_cases hg : news v w i j k - · obtain ⟨⟨hf,hE,hF,hQ,hR,hr,hr'⟩,⟨hX,ha,hS,hT⟩,hY,hb,hS',hT'⟩:=hg - have hq : kslots p (Messenger q) ≤ kmax p := - slots_budget (a.draw (n:=n) (fun _=>0)) (shots_ok true (a.draw (fun _ => 0)) rfl hf) - apply le_trans (Volley.collision a.draw b.draw m (a:=ia) (b:=ib) (q:=qorth K) (K:=K) - (a.state w.z n) (b.state w.z n) Q R (fun i x (h:Q i x)=> ⟨h.1.2.1,h.1.2.2.1⟩) - (fun i x (h:R i x)=>⟨h.1.2.1,h.1.2.2.1⟩) - _ ha hb hA.bound hB.bound he.low (le_trans - (mul_le_mul_of_nonneg_left (Nat.cast_le.mpr hq) he.smooth) he.light) hq hu.sub hu'.sub - (quillState hE he.hr he.hn).sub (quillState hF he.hr he.hn).sub hA.clear hB.clear - he.hN he.gram he.budget (ownPart w.t w.z)) - · refine add_le_add_left (mul_le_mul_of_nonneg_right (bp_le ?_) hδ) _ - exact mul_le_mul_of_nonneg_right (add_le_add_left (Nat.cast_le.mpr hq) _) (by positivity) - intro u v o ho z hz hv - have h1 (u:Inputs p n (Messenger q)) (v:Inputs p n (Messenger q)) : (a.draw u).bounded - (b.draw v).obj := shots_ok true _ rfl hf - have h2 (u:Inputs p n (Messenger q)) (v:Inputs p n (Messenger q)) : (b.draw v).bounded - (a.draw u).obj := shots_ok false _ rfl hf - obtain ⟨⟨_,ha',ha0,ham⟩,hG,hh',_⟩:= ho - obtain ⟨⟨_,hb',hb0,hbm⟩,hH,hh0,_⟩:= hz - refine ⟨a.draw_legal _, b.draw_legal _,rhyme_match _ _ _ x y _ _ _ _ u v m o z hG hH hR,?_⟩ - apply gradient_realization (a.draw u) (b.draw v) m o z ia ib T K he.solid (h1 u v) (h2 u v) - (a.draw_legal _) (b.draw_legal _) (ha _) (hb _) hA.bound hB.bound ha' hb' ham hbm hT hT' - _ _ hv ha0 hb0 _ _ - · exact still_recipe _ true _ _ _ hX _ _ _ _ _ _ hG _ rfl w.z hE.2.1 hQ hS - · exact still_recipe _ false _ _ _ hY _ _ _ _ _ _ hH _ rfl w.z hF.2.1 hQ hS' - · exact procl_grad _ _ _ he.solid.odd _ _ _ _ _ _ _ _ m _ _ hG hH w.qA.script hr hh' - exact procl_grad _ _ _ he.solid.odd _ _ _ _ _ _ _ _ m _ _ hH hG w.qB.script hr' hh0 - · have hh (x): Volley.hist a.draw w.t u (a.state w.z n) Q x=0 := by - unfold Volley.hist - have ht y : pr u (fun i=> Q y i ∧ (a.draw y).keys w.t i=x)=0 := by - simp [Q,F,frontPage,notified,hg,pr_false] - simp_rw [ht]; simp - unfold overlap - simp only [density,hh,zero_div,zero_mul] - have hz : 0≤ beamPrice p N*δ:=mul_nonneg (bp_pos _).le hδ - rw [show avg (lawNu p N w.t w.z) (fun _ => 0) = 0 from (by simp only [avg_const,mul_zero])] - exact add_nonneg hz (mul_nonneg (by norm_num) (bp_pos _).le) - -set_option maxHeartbeats 800000 in -theorem arena_bound (w : Typus p q d e) - (m: Mixer p n) (μ : Wgt (UnitType p n N)) (k : Fin (2^deckMax p K)) - {C ζ : ℝ} (hp : s.strength μ (PreparationParameters.usual p m N) C ζ K) (hw : IsLaw μ) - (h : 0(hp.leaf _ hi).pos) h - let t:=portionW μ s.T - let S := pairW t t - have hm : IsLaw S:=pairW_law hx hx - refine (avg_mono hm.nz (fun x=>sellPoint v w m μ x.1 x.2 k hp hw he)).trans_eq ?_ - rw [avg_add,avg_mul',hm.avg_const] - change s.sap μ=_ at hy - rw [hy,←mix_data] - unfold pr - congr 1; rw [mixW_avg] - -end Station -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PairedOptions + +namespace OAI + +/-! # Paired Collision Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Finset Submodule Filter +open scoped BigOperators Topology +namespace StatusAnalysis +variable {p : Shape} {n N K : ℕ} {q : Format} {d e : Rates} + +theorem quillState {i : Bool} {w : Quill p q d i} {t z} (h : w.moral t z) (hr : 1≤p.r) + (hn : 2*p.r ≤ n) : + IsLaw ((w.pen t).state z n) := prodW_law (fun j=> dial_law p n _ _ _ hr hn (Quill.canDraw _ _ h j)) + +namespace Station +variable {s : LeafMixture p n N} (v : Station p n N K s) + +def clash (p : Shape) (m : Mixer p n) (N : ℕ) := + fun x : UnitType p n N × UnitType p n N => (rawHoles m).conflict x.1 x.2 + +def beamPrice (p : Shape) (N : ℕ) := bp (((kmax p:ℝ)+0.02)*N) + +structure earnsScore (p : Shape) (n N K : ℕ) (ζ : ℝ) : Prop where + hr : 1≤p.r + hn : 2*p.r≤n + solid : realizeAssum p K + smooth : 0 ≤ ζ + low : ζ ≤ 0.004 + light : ζ*(kmax p) ≤ 0.004 + hN : 100 ≤ N + gram : (dim (CheckGram p n) : ℝ) ≤ 0.01*N + budget : (K+(kmax p:ℝ))*num (JointIdx p n) ≤ 0.005*N + +set_option maxHeartbeats 1400000 in +theorem sellPoint (w : Typus p q d e) + (m :Mixer p n) (μ : Wgt (UnitType p n N)) (i j : s.T) (k : Fin (2^deckMax p K)) + {C ζ : ℝ} (hp : s.strength μ (PreparationParameters.usual p m N) C ζ K) (hw : IsLaw μ) + (he : earnsScore p n N K ζ) : + matchScore v w m μ i j k ≤ beamPrice p N * + pr (pairW (partW μ i.val) (partW μ j.val)) (clash p m N)+2* bp (-0.005*N) := by + classical + have hA := hp.leaf i.val i.property; have hB := hp.leaf j.val j.property + let a:=w.qA.pen w.t; let b:=w.qB.pen w.t + let ia:=s.pin i.val; let ib:=s.pin j.val + let u:=partW μ i.val; let u':=partW μ j.val + let F:=frontPage v w m i j k; let G:=backPage v w m i j k + let T:=v.mails i j k; let x:=v.cAxes i d; let y:=v.cAxes j e + let Q (z : Inputs p n (Messenger q)) (o : UnitType p n N) := + F o ∧ w.qA.deposit w.t w.z m o x z + let R (z : Inputs p n (Messenger q)) (o : UnitType p n N) := + G o ∧ w.qB.deposit w.t w.z m o y z + have hu : IsLaw u:= on_law hw.nz hA.pos + have hu' : IsLaw u':= on_law hw.nz hB.pos + let δ := pr (pairW u u') (clash p m N) + have hδ : 0≤δ := pr_nonneg (pairW_law hu hu').nz + change overlap (lawNu p N w.t w.z) + (Volley.hist a.draw w.t u (a.state w.z n) Q) (Volley.hist b.draw w.t u' (b.state w.z n) R) ≤ + beamPrice p N*δ+ _ + by_cases hg : news v w i j k + · obtain ⟨⟨hf,hE,hF,hQ,hR,hr,hr'⟩,⟨hX,ha,hS,hT⟩,hY,hb,hS',hT'⟩:=hg + have hq : kslots p (Messenger q) ≤ kmax p := + slots_budget (a.draw (n:=n) (fun _=>0)) (shots_ok true (a.draw (fun _ => 0)) rfl hf) + apply le_trans (Volley.collision a.draw b.draw m (a:=ia) (b:=ib) (q:=qorth K) (K:=K) + (a.state w.z n) (b.state w.z n) Q R (fun i x (h:Q i x)=> ⟨h.1.2.1,h.1.2.2.1⟩) + (fun i x (h:R i x)=>⟨h.1.2.1,h.1.2.2.1⟩) + _ ha hb hA.bound hB.bound he.low (le_trans + (mul_le_mul_of_nonneg_left (Nat.cast_le.mpr hq) he.smooth) he.light) hq hu.sub hu'.sub + (quillState hE he.hr he.hn).sub (quillState hF he.hr he.hn).sub hA.clear hB.clear + he.hN he.gram he.budget (ownPart w.t w.z)) + · refine add_le_add_left (mul_le_mul_of_nonneg_right (bp_le ?_) hδ) _ + exact mul_le_mul_of_nonneg_right (add_le_add_left (Nat.cast_le.mpr hq) _) (by positivity) + intro u v o ho z hz hv + have h1 (u:Inputs p n (Messenger q)) (v:Inputs p n (Messenger q)) : (a.draw u).bounded + (b.draw v).obj := shots_ok true _ rfl hf + have h2 (u:Inputs p n (Messenger q)) (v:Inputs p n (Messenger q)) : (b.draw v).bounded + (a.draw u).obj := shots_ok false _ rfl hf + obtain ⟨⟨_,ha',ha0,ham⟩,hG,hh',_⟩:= ho + obtain ⟨⟨_,hb',hb0,hbm⟩,hH,hh0,_⟩:= hz + refine ⟨a.draw_legal _, b.draw_legal _,rhyme_match _ _ _ x y _ _ _ _ u v m o z hG hH hR,?_⟩ + apply gradient_realization (a.draw u) (b.draw v) m o z ia ib T K he.solid (h1 u v) (h2 u v) + (a.draw_legal _) (b.draw_legal _) (ha _) (hb _) hA.bound hB.bound ha' hb' ham hbm hT hT' + _ _ hv ha0 hb0 _ _ + · exact still_recipe _ true _ _ _ hX _ _ _ _ _ _ hG _ rfl w.z hE.2.1 hQ hS + · exact still_recipe _ false _ _ _ hY _ _ _ _ _ _ hH _ rfl w.z hF.2.1 hQ hS' + · exact procl_grad _ _ _ he.solid.odd _ _ _ _ _ _ _ _ m _ _ hG hH w.qA.script hr hh' + exact procl_grad _ _ _ he.solid.odd _ _ _ _ _ _ _ _ m _ _ hH hG w.qB.script hr' hh0 + · have hh (x): Volley.hist a.draw w.t u (a.state w.z n) Q x=0 := by + unfold Volley.hist + have ht y : pr u (fun i=> Q y i ∧ (a.draw y).keys w.t i=x)=0 := by + simp [Q,F,frontPage,notified,hg,pr_false] + simp_rw [ht]; simp + unfold overlap + simp only [density,hh,zero_div,zero_mul] + have hz : 0≤ beamPrice p N*δ:=mul_nonneg (bp_pos _).le hδ + rw [show avg (lawNu p N w.t w.z) (fun _ => 0) = 0 from (by simp only [avg_const,mul_zero])] + exact add_nonneg hz (mul_nonneg (by norm_num) (bp_pos _).le) + +set_option maxHeartbeats 800000 in +theorem arena_bound (w : Typus p q d e) + (m: Mixer p n) (μ : Wgt (UnitType p n N)) (k : Fin (2^deckMax p K)) + {C ζ : ℝ} (hp : s.strength μ (PreparationParameters.usual p m N) C ζ K) (hw : IsLaw μ) + (h : 0(hp.leaf _ hi).pos) h + let t:=portionW μ s.T + let S := pairW t t + have hm : IsLaw S:=pairW_law hx hx + refine (avg_mono hm.nz (fun x=>sellPoint v w m μ x.1 x.2 k hp hw he)).trans_eq ?_ + rw [avg_add,avg_mul',hm.avg_const] + change s.sap μ=_ at hy + rw [hy,←mix_data] + unfold pr + congr 1; rw [mixW_avg] + +end Station +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PairedEventBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PairedEventBounds.lean index 04c0d406183056b423707a69721e3f46c85f6b56..c810ba31a49c4443e74e0f047e9f89d3fc7cb958 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PairedEventBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PairedEventBounds.lean @@ -1,164 +1,164 @@ -import OAI.Combinatorics.HadwigerCounterexample.RareLeafEvents - -namespace OAI - -/-! # Paired Event Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix -open scoped BigOperators Topology -open Template -namespace StatusAnalysis -open Station PreparationParameters -variable {l:Filter ℕ} {b:PreparationParameters} {p:Shape} {M r:ℕ} {m:cycleM p} {s:rhythms p M} {w:tale p M} - {q:Format} {d e:Rates} - -private theorem thick_roster {A:Type} [Fintype A] {P : Wgt A→Prop} {r:ℕ} {ε:ℝ} - (h:roster P r ε) : - ∃ f:Fin r→Wgt A,∀ y,P y→∃ i,varOne y (f i)≤ε := by - classical - obtain ⟨d,hd,g,hg⟩:=h - let f(k:Fin r) := if h:k.val?_⟩; obtain ⟨j,hj⟩:=hg x h - refine ⟨Fin.castLE hd j,?_⟩; unfold f; simpa using hj - -set_option maxHeartbeats 2000000 in -theorem dimBerth (t: Stations p M b.pins s) - (h:veil p M b r l m s w) - (x:Typus p q d e) (k:Fin (2^deckMax p b.pins)) {β:ℝ} (hβ:0<β) : - ExpSmall l (fun n=>(n:ℝ)) (fun n=>(t n).berth x (m n) k (w n) β) := by - classical - by_cases hX:x.permission - · let K:=b.pins; let N:=fun n:ℕ=>M*n - have hq:=h.easel; have hp:= hq.enter.first - have ha:=hX.2.1; have hb:= hX.2.2.1 - - obtain ⟨y,c2,hy,hc2,hB⟩:= x.qB.soberCalendar x.t x.z hq hb 1 zero_lt_one - - let a:=β*y/6; have hα:0bp (-c*n); let b2:=fun n:ℕ=>bp (-c2*n) - - obtain ⟨f,hf,hξ⟩ := h.score_cost t - let e_ (n:ℕ):=(num (Fin r0)*(b1 n/β)+b2 n/β) - let D : ℕ→ℝ:=fun n=> e_ n+|f n|/(a*b0) - have ht:= (trend_sizes l h.timeL hp.hM).2 - have hz : Tendsto (fun n:ℕ=>(n:ℝ)) l atTop := tendsto_natCast_atTop_atTop.mono_left h.timeL - have hD : ExpSmall l (fun n:ℕ=>(n:ℝ)) D := by - have h1 := ExpSmall.bp_n (l:=l) (z:=fun i:ℕ=>(i:ℝ)) hc - have h2:=ExpSmall.bp_n (l:=l) (z:=fun i:ℕ=>(i:ℝ)) hc2 - have hg : ExpSmall l (fun n:ℕ=>(n:ℝ)) e_ := by - have hi := (h1.mul (expO_const hz (num (Fin r0)/β))).add hz (h2.mul (expO_const hz β⁻¹)) - refine hi.mono (.of_forall (fun i=>?_)) - exact le_of_eq (congrArg abs (by unfold e_ b1 b2; ring)) - obtain ⟨C,hC,hf⟩:= hf - have h : ExpSmall l (fun n:ℕ=>(n:ℝ)) (fun n=>|f n|) := by - refine ⟨C*M, by have hm:=hp.hM; positivity,?_⟩ - filter_upwards [hf] with n hn - rw [abs_abs]; push_cast at hn; rwa [←mul_assoc,neg_mul] at hn - simpa [D,div_eq_mul_inv] using hg.add hz (h.mul (expO_const hz (a*b0)⁻¹)) - refine hD.mono ?_ - have hl := h.timeL - filter_upwards [h.upright,h.durableS.shape,h.moment,h.durableS.mass.positive, - hF.filter_mono hl,hQ.filter_mono hl,hW.filter_mono hl,hB.filter_mono hl,hA.filter_mono hl,hξ, - ht.eventually (eventually_ge_atTop (2*num (Messenger q×Toast p)+1))] - with n hn hr ht hx hf hg hh hB hA hξ hN - let W:=w n; let s':=s n; let I:=s'.T; let V (i:↑I):=partW W i.val - let u:=portionW W I; let R:=pairW u u; let G:=t n; let m':=m n - let ν:= lawNu p (N n) x.t x.z; have hm:=ht.1.law - let P := s'.sap W - have hν:IsLaw ν:=nuLaw _ _ (show 2*num (Messenger q×Toast p)-((M*n:ℕ):ℝ)≤ -1 from - by change _ ≤((M*n:ℕ):ℝ) at hN; linarith only [hN]) - let A i:= x.qA.custom (V i) (G.cAxes i d) x.t x.z m' - - let B i:= x.qB.custom (V i) (G.cAxes i e) x.t x.z m' - let X(i:↑I×↑I):= leftSales G x m' W i.1 i.2 k - let Z(i:↑I×↑I):= rightSales G x m' W i.1 i.2 k - have huv := hr.1 - have hV i : IsLaw (V i):=on_law hm.nz (huv.leaf i.val i.property).pos - have hC (i:↑I) := (huv.leaf (Subtype.val i) i.property).density - choose l hL using show ∀ i:↑I,∃ l:Fin r0→Wgt (Keys (p:=p) x.t (N n)), - ∀ y,B i y→ ∃ j,varOne y (l j) ≤ ε from fun i=> - thick_roster (hg m' (G.cAxes i e) (V i) hn.cols (hV i) (hC i)).2.1 - obtain ⟨hu,hO⟩:=rebuild hm.nz huv.part (fun i hi=>(huv.leaf _ hi).pos) hx - have ho : P=mixW u V:= hO - let S i j:=cliff ν (l i j) a - let T : UnitType p n (N n)→Prop:= fun i=>¬x.qB.sober x.t x.z K (fun _=>True) m' y i - let U i j o:= δ ≤ pr ν (S i j) ∧ ¬x.qA.sober x.t x.z K (S i j) m' Y o - let O (i:↑I×↑I) := (∃ j, β < pr (V i.1) (U i.2 j)) ∨ β < pr (V i.2) T - have hT : pr R O ≤ e_ n := by - refine vacantBound u V U T hu hV hβ (fun i j=>?_) ?_ - · by_cases h:δ ≤ pr ν (S i j) - · simp_rw [U,h,true_and,← ho]; exact hA m' P hn (S i j) h - have hf : U i j = (fun _=>False) := funext fun i=> eq_false (fun hh=> h hh.1) - rw [hf,pr_false]; exact (bp_pos _).le - rw [← ho] - exact hB m' P hn (fun _=>True) (by rw [pr_true]; exact hν.total.ge) - let J:=charter (t n) x m' k W β - let L i := overlap ν (X i) (Z i) - have hL0 i: IsLaw (x.qA.policies x.t x.z n i):= Appearance.witLaw - (x.qA.allure_apt x.t x.z ha _) hp.hR hn.age - have hL1 i:IsLaw (x.qB.policies x.t x.z n i):= Appearance.witLaw - (x.qB.allure_apt x.t x.z hb _) hp.hR hn.age - have hX (i:↑I×↑I):A i.1 (X i):= x.qA.sales_custom _ _ _ _ _ _ - have hZ (i:↑I×↑I):B i.2 (Z i):= x.qB.sales_custom _ _ _ _ _ _ - have heq (i) (hj:J i) (hk:¬O i) : a*b0≤ L i := by - obtain ⟨j,hj'⟩:= hL _ _ (hZ i) - obtain ⟨hP,_,hX',_⟩:=hf m' (G.cAxes i.1 _) (V i.1) hn.cols (hV _) (hC _) - obtain ⟨hR',_,hY',_⟩:=hh m' (G.cAxes i.2 _) (V i.2) hn.cols (hV _) (hC _) - let F:=S i.2 j - have hFt : δ≤ pr ν F := by - have hi := x.qB.qualify_hit m' x.t x.z _ _ _ _ (fun _=>True) hy hj.2.2 (hV _) hL1 - (le_of_not_gt (mt Or.inr hk)) - change β*y≤ pr (Z i) _ at hi - rw [pr_true] at hi - exact (cliff_thick (B i.2) _ (l i.2 j) ν hν (hZ i) a δ hα hY' - (hj'.trans (min_le_left ..)) (show 5*a≤tot (Z i) from by unfold a; nlinarith only [hi,hβ,hy])).le - have hM : β*Y ≤ pr (X i) F := - x.qA.qualify_hit m' x.t x.z _ _ _ _ F hY hj.2.1 (hV _) hL0 (le_of_not_gt (fun h=>hk - (Or.inl ⟨j, by have hf : U i.2 j = fun x_=>¬x.qA.sober x.t x.z K F m' Y x_ := funext fun i=>propext ⟨And.right,fun hi=>⟨hFt,hi⟩⟩; rw [hf]; exact h⟩))) - obtain ⟨hx,hz⟩:= hP _ (hX i) - refine cliff_score _ (X i) (Z i) (l i.2 j) ν hx (hR' _ (hZ i)).1 hν hz b0 a ε - hα (hX i) hj' (fun z hz S hS=> hX' z hz S (hS.trans ?_)) ?_ - · exact (div_le_iff₀ hα).mpr ((min_le_right ..).trans_eq (mul_comm ..)) - change 2*b0 ≤ pr (X i) F - unfold b0; nlinarith only [hM,hβ,hY] - have hn0 (i:↑I×↑I) : 0 ≤ L i := by - have h1 i j : 0≤X i j := Quill.sales_pos x.qA _ _ _ _ m' _ (hV _).nz j - have h2 i j : 0 ≤ Z i j:= Quill.sales_pos x.qB _ _ _ _ m' _ (hV _).nz j - refine avg_nonneg hν.nz fun j=>mul_nonneg (div_nonneg (h1 i j) (hν.nz _)) - (div_nonneg (h2 i j) (hν.nz _)) - have hv := pairW_law hu hu - have hi := le_avg_markov hv.nz hn0 (a*b0) - change |pr R J| ≤ _ - rw [abs_of_nonneg (pr_nonneg hv.nz)] - apply le_trans _ (le_abs_self (D n)) - - have hg (i) (h:J i): O i ∨ a*b0 ≤ L i := by - by_cases hi:O i - · exact Or.inl hi - exact Or.inr (heq i h hi) - refine ((pr_mono hv.nz hg).trans (pr_or_le hv.nz)).trans (add_le_add hT ?_) - refine (le_div_iff₀ (by positivity)).mpr (le_trans ?_ ((le_abs_self _).trans - ((hξ q d _ x k).trans (le_abs_self _)))) - rw [mul_comm]; exact hi - · refine (ExpSmall.zero l (fun n=>(n:ℝ))).mono (.of_forall (fun n=>?_)) - have hh i : ¬charter (t n) x (m n) k (w n) β i :=fun he=>hX he.1 - unfold berth pr - simp only [ind_zero (hh _),avg_const,mul_zero,le_refl] -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RareLeafEvents + +namespace OAI + +/-! # Paired Event Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix +open scoped BigOperators Topology +open Template +namespace StatusAnalysis +open Station PreparationParameters +variable {l:Filter ℕ} {b:PreparationParameters} {p:Shape} {M r:ℕ} {m:cycleM p} {s:rhythms p M} {w:tale p M} + {q:Format} {d e:Rates} + +private theorem thick_roster {A:Type} [Fintype A] {P : Wgt A→Prop} {r:ℕ} {ε:ℝ} + (h:roster P r ε) : + ∃ f:Fin r→Wgt A,∀ y,P y→∃ i,varOne y (f i)≤ε := by + classical + obtain ⟨d,hd,g,hg⟩:=h + let f(k:Fin r) := if h:k.val?_⟩; obtain ⟨j,hj⟩:=hg x h + refine ⟨Fin.castLE hd j,?_⟩; unfold f; simpa using hj + +set_option maxHeartbeats 2000000 in +theorem dimBerth (t: Stations p M b.pins s) + (h:veil p M b r l m s w) + (x:Typus p q d e) (k:Fin (2^deckMax p b.pins)) {β:ℝ} (hβ:0<β) : + ExpSmall l (fun n=>(n:ℝ)) (fun n=>(t n).berth x (m n) k (w n) β) := by + classical + by_cases hX:x.permission + · let K:=b.pins; let N:=fun n:ℕ=>M*n + have hq:=h.easel; have hp:= hq.enter.first + have ha:=hX.2.1; have hb:= hX.2.2.1 + + obtain ⟨y,c2,hy,hc2,hB⟩:= x.qB.soberCalendar x.t x.z hq hb 1 zero_lt_one + + let a:=β*y/6; have hα:0bp (-c*n); let b2:=fun n:ℕ=>bp (-c2*n) + + obtain ⟨f,hf,hξ⟩ := h.score_cost t + let e_ (n:ℕ):=(num (Fin r0)*(b1 n/β)+b2 n/β) + let D : ℕ→ℝ:=fun n=> e_ n+|f n|/(a*b0) + have ht:= (trend_sizes l h.timeL hp.hM).2 + have hz : Tendsto (fun n:ℕ=>(n:ℝ)) l atTop := tendsto_natCast_atTop_atTop.mono_left h.timeL + have hD : ExpSmall l (fun n:ℕ=>(n:ℝ)) D := by + have h1 := ExpSmall.bp_n (l:=l) (z:=fun i:ℕ=>(i:ℝ)) hc + have h2:=ExpSmall.bp_n (l:=l) (z:=fun i:ℕ=>(i:ℝ)) hc2 + have hg : ExpSmall l (fun n:ℕ=>(n:ℝ)) e_ := by + have hi := (h1.mul (expO_const hz (num (Fin r0)/β))).add hz (h2.mul (expO_const hz β⁻¹)) + refine hi.mono (.of_forall (fun i=>?_)) + exact le_of_eq (congrArg abs (by unfold e_ b1 b2; ring)) + obtain ⟨C,hC,hf⟩:= hf + have h : ExpSmall l (fun n:ℕ=>(n:ℝ)) (fun n=>|f n|) := by + refine ⟨C*M, by have hm:=hp.hM; positivity,?_⟩ + filter_upwards [hf] with n hn + rw [abs_abs]; push_cast at hn; rwa [←mul_assoc,neg_mul] at hn + simpa [D,div_eq_mul_inv] using hg.add hz (h.mul (expO_const hz (a*b0)⁻¹)) + refine hD.mono ?_ + have hl := h.timeL + filter_upwards [h.upright,h.durableS.shape,h.moment,h.durableS.mass.positive, + hF.filter_mono hl,hQ.filter_mono hl,hW.filter_mono hl,hB.filter_mono hl,hA.filter_mono hl,hξ, + ht.eventually (eventually_ge_atTop (2*num (Messenger q×Toast p)+1))] + with n hn hr ht hx hf hg hh hB hA hξ hN + let W:=w n; let s':=s n; let I:=s'.T; let V (i:↑I):=partW W i.val + let u:=portionW W I; let R:=pairW u u; let G:=t n; let m':=m n + let ν:= lawNu p (N n) x.t x.z; have hm:=ht.1.law + let P := s'.sap W + have hν:IsLaw ν:=nuLaw _ _ (show 2*num (Messenger q×Toast p)-((M*n:ℕ):ℝ)≤ -1 from + by change _ ≤((M*n:ℕ):ℝ) at hN; linarith only [hN]) + let A i:= x.qA.custom (V i) (G.cAxes i d) x.t x.z m' + + let B i:= x.qB.custom (V i) (G.cAxes i e) x.t x.z m' + let X(i:↑I×↑I):= leftSales G x m' W i.1 i.2 k + let Z(i:↑I×↑I):= rightSales G x m' W i.1 i.2 k + have huv := hr.1 + have hV i : IsLaw (V i):=on_law hm.nz (huv.leaf i.val i.property).pos + have hC (i:↑I) := (huv.leaf (Subtype.val i) i.property).density + choose l hL using show ∀ i:↑I,∃ l:Fin r0→Wgt (Keys (p:=p) x.t (N n)), + ∀ y,B i y→ ∃ j,varOne y (l j) ≤ ε from fun i=> + thick_roster (hg m' (G.cAxes i e) (V i) hn.cols (hV i) (hC i)).2.1 + obtain ⟨hu,hO⟩:=rebuild hm.nz huv.part (fun i hi=>(huv.leaf _ hi).pos) hx + have ho : P=mixW u V:= hO + let S i j:=cliff ν (l i j) a + let T : UnitType p n (N n)→Prop:= fun i=>¬x.qB.sober x.t x.z K (fun _=>True) m' y i + let U i j o:= δ ≤ pr ν (S i j) ∧ ¬x.qA.sober x.t x.z K (S i j) m' Y o + let O (i:↑I×↑I) := (∃ j, β < pr (V i.1) (U i.2 j)) ∨ β < pr (V i.2) T + have hT : pr R O ≤ e_ n := by + refine vacantBound u V U T hu hV hβ (fun i j=>?_) ?_ + · by_cases h:δ ≤ pr ν (S i j) + · simp_rw [U,h,true_and,← ho]; exact hA m' P hn (S i j) h + have hf : U i j = (fun _=>False) := funext fun i=> eq_false (fun hh=> h hh.1) + rw [hf,pr_false]; exact (bp_pos _).le + rw [← ho] + exact hB m' P hn (fun _=>True) (by rw [pr_true]; exact hν.total.ge) + let J:=charter (t n) x m' k W β + let L i := overlap ν (X i) (Z i) + have hL0 i: IsLaw (x.qA.policies x.t x.z n i):= Appearance.witLaw + (x.qA.allure_apt x.t x.z ha _) hp.hR hn.age + have hL1 i:IsLaw (x.qB.policies x.t x.z n i):= Appearance.witLaw + (x.qB.allure_apt x.t x.z hb _) hp.hR hn.age + have hX (i:↑I×↑I):A i.1 (X i):= x.qA.sales_custom _ _ _ _ _ _ + have hZ (i:↑I×↑I):B i.2 (Z i):= x.qB.sales_custom _ _ _ _ _ _ + have heq (i) (hj:J i) (hk:¬O i) : a*b0≤ L i := by + obtain ⟨j,hj'⟩:= hL _ _ (hZ i) + obtain ⟨hP,_,hX',_⟩:=hf m' (G.cAxes i.1 _) (V i.1) hn.cols (hV _) (hC _) + obtain ⟨hR',_,hY',_⟩:=hh m' (G.cAxes i.2 _) (V i.2) hn.cols (hV _) (hC _) + let F:=S i.2 j + have hFt : δ≤ pr ν F := by + have hi := x.qB.qualify_hit m' x.t x.z _ _ _ _ (fun _=>True) hy hj.2.2 (hV _) hL1 + (le_of_not_gt (mt Or.inr hk)) + change β*y≤ pr (Z i) _ at hi + rw [pr_true] at hi + exact (cliff_thick (B i.2) _ (l i.2 j) ν hν (hZ i) a δ hα hY' + (hj'.trans (min_le_left ..)) (show 5*a≤tot (Z i) from by unfold a; nlinarith only [hi,hβ,hy])).le + have hM : β*Y ≤ pr (X i) F := + x.qA.qualify_hit m' x.t x.z _ _ _ _ F hY hj.2.1 (hV _) hL0 (le_of_not_gt (fun h=>hk + (Or.inl ⟨j, by have hf : U i.2 j = fun x_=>¬x.qA.sober x.t x.z K F m' Y x_ := funext fun i=>propext ⟨And.right,fun hi=>⟨hFt,hi⟩⟩; rw [hf]; exact h⟩))) + obtain ⟨hx,hz⟩:= hP _ (hX i) + refine cliff_score _ (X i) (Z i) (l i.2 j) ν hx (hR' _ (hZ i)).1 hν hz b0 a ε + hα (hX i) hj' (fun z hz S hS=> hX' z hz S (hS.trans ?_)) ?_ + · exact (div_le_iff₀ hα).mpr ((min_le_right ..).trans_eq (mul_comm ..)) + change 2*b0 ≤ pr (X i) F + unfold b0; nlinarith only [hM,hβ,hY] + have hn0 (i:↑I×↑I) : 0 ≤ L i := by + have h1 i j : 0≤X i j := Quill.sales_pos x.qA _ _ _ _ m' _ (hV _).nz j + have h2 i j : 0 ≤ Z i j:= Quill.sales_pos x.qB _ _ _ _ m' _ (hV _).nz j + refine avg_nonneg hν.nz fun j=>mul_nonneg (div_nonneg (h1 i j) (hν.nz _)) + (div_nonneg (h2 i j) (hν.nz _)) + have hv := pairW_law hu hu + have hi := le_avg_markov hv.nz hn0 (a*b0) + change |pr R J| ≤ _ + rw [abs_of_nonneg (pr_nonneg hv.nz)] + apply le_trans _ (le_abs_self (D n)) + + have hg (i) (h:J i): O i ∨ a*b0 ≤ L i := by + by_cases hi:O i + · exact Or.inl hi + exact Or.inr (heq i h hi) + refine ((pr_mono hv.nz hg).trans (pr_or_le hv.nz)).trans (add_le_add hT ?_) + refine (le_div_iff₀ (by positivity)).mpr (le_trans ?_ ((le_abs_self _).trans + ((hξ q d _ x k).trans (le_abs_self _)))) + rw [mul_comm]; exact hi + · refine (ExpSmall.zero l (fun n=>(n:ℝ))).mono (.of_forall (fun n=>?_)) + have hh i : ¬charter (t n) x (m n) k (w n) β i :=fun he=>hX he.1 + unfold berth pr + simp only [ind_zero (hh _),avg_const,mul_zero,le_refl] +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PairedMassIdentities.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PairedMassIdentities.lean index 9a6014c4361cf21fc90e2b42537a0ea57ee06b6f..23e4b66f8032c48079c2add8e131474a98852002 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PairedMassIdentities.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PairedMassIdentities.lean @@ -1,106 +1,106 @@ -import OAI.Combinatorics.HadwigerCounterexample.PairedCollisionBounds - -namespace OAI - -/-! # Paired Mass Identities -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Finset Submodule Filter -open scoped BigOperators Topology -namespace StatusAnalysis -variable {p : Shape} {n N K M: ℕ} {q : Format} {d e : Rates} - -namespace Quill -variable {i:Bool} (w : Quill p q d i) - (μ : Wgt (UnitType p n N)) (s : Charts p n d) - (t : Tagging p (Messenger q)) (z : Messenger q → F) - (m : Mixer p n) - (P : UnitType p n N→Prop) - -def customer := fromFlags μ ((w.pen t).state z n) - (Y:=Bool) - (fun o x=> open scoped Classical in decide (w.deposit t z m o s x)) - ((w.pen t).resultKey) -def custom := hung (w.customer μ s t z m) (ownPart t z) - -def billboard := fun (o:UnitType p n N) x=> open scoped Classical in decide (w.deposit t z m o s x) -theorem sales_core : - w.sales t z μ P m s=flaggedW μ ((w.pen t).state z n) (w.billboard (N:=N) s t z m) - ((w.pen t).resultKey) (fun o b=> P o ∧ b) := by - classical - funext x; unfold sales Volley.hist - simp_rw [pr]; rw [avg_avg] - unfold flaggedW mixW mapW - apply avg_congr; intro i hi - simp only [pr,avg,Function.comp_apply,subW,billboard,decide_eq_true_eq] - refine Finset.sum_congr rfl fun a _=> ?_ - rw [mul_assoc,← ind_and]; rfl - -theorem sales_receipt : customer w μ s t z m (w.sales t z μ P m s) := - ⟨_,w.sales_core μ s t z m P⟩ - -theorem sales_part : carried (w.sales t z μ P m s) (ownPart t z) := by - intro o ho - unfold sales Volley.hist - let A:=w.pen t - have hi (x : Inputs p n (Messenger q)) : - pr μ (fun i=>(P i ∧ w.deposit t z m i s x)∧(A.draw x).keys t i=o) = 0 := by - have h i : ¬((P i∧ w.deposit t z m i s x)∧(A.draw x).keys t i=o) := by - rintro ⟨⟨hp,hg⟩,hk⟩ - apply ho; rw [←hk]; exact hg.2.2 - unfold pr;simp only [ind_zero (h _),avg_const,mul_zero] - change avg (A.state z n) _=_ - exact (avg_congr (g:=fun _ => 0) (fun x _ => hi x)).trans (by rw [avg_const,mul_zero]) - -theorem sales_custom : custom w μ s t z m (w.sales t z μ P m s) := by - let v:= w.sales t z μ P m s - refine ⟨v,w.sales_receipt μ s t z m P, funext fun i =>?_⟩ - change v i=_ - unfold subW - by_cases hi : ownPart t z i - · rw [ind_one hi,mul_one] - rw [show v i=0 from w.sales_part μ s t z m P i hi,zero_mul] - -def prowl (o : UnitType p n N) (W : Wgt (Keys (p:=p) t N)) := - avg ((w.pen t).state z n) (fun x=>ind (w.deposit t z m o s x)*W ((w.pen t).resultKey o x)) - -theorem sales_mean (W : Wgt (Keys (p:=p) t N)) : - avg (w.sales t z μ P m s) W = - avg μ (fun o=> ind (P o) * prowl w s t z m o W) := by - classical - rw [sales_core, flaggedW] - refine (mixW_avg μ _ (show Wgt (Keys (p:=p) ((w.pen t).t) N) from W)).trans ?_ - refine avg_congr fun i _ => ?_ - rw [mapW_avg] - unfold prowl subW - simp only [avg,Finset.mul_sum,Function.comp_apply,billboard,decide_eq_true_eq,ind_and] - refine Finset.sum_congr rfl fun _ _=>?_ - ring - -theorem sales_pos (h : ∀ x,0≤μ x) (x) : 0≤ w.sales t z μ P m s x := - avg_nonneg (prodW_nonneg (fun _=> normW_nonneg (subW_nonneg (spins_law ..).nz _))) - (fun _=> pr_nonneg h) -end Quill - -namespace Station -variable {s : LeafMixture p n N} (v : Station p n N K s) - -theorem arena_pos (w : Typus p q d e) - (m: Mixer p n) (μ : Wgt (UnitType p n N)) (k : Fin (2^deckMax p K)) - (h : 0mul_nonneg (hf _) (hf _)) (fun i=>avg_nonneg - (unifOn_sub _).nz (fun x=>mul_nonneg ?_ ?_)) - · exact div_nonneg (w.qA.sales_pos _ _ _ _ m _ (hg _) x) ((unifOn_sub _).nz _) - exact div_nonneg (w.qB.sales_pos _ _ _ _ m _ (hg _) x) ((unifOn_sub _).nz _) - -end Station -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PairedCollisionBounds + +namespace OAI + +/-! # Paired Mass Identities -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Finset Submodule Filter +open scoped BigOperators Topology +namespace StatusAnalysis +variable {p : Shape} {n N K M: ℕ} {q : Format} {d e : Rates} + +namespace Quill +variable {i:Bool} (w : Quill p q d i) + (μ : Wgt (UnitType p n N)) (s : Charts p n d) + (t : Tagging p (Messenger q)) (z : Messenger q → F) + (m : Mixer p n) + (P : UnitType p n N→Prop) + +def customer := fromFlags μ ((w.pen t).state z n) + (Y:=Bool) + (fun o x=> open scoped Classical in decide (w.deposit t z m o s x)) + ((w.pen t).resultKey) +def custom := hung (w.customer μ s t z m) (ownPart t z) + +def billboard := fun (o:UnitType p n N) x=> open scoped Classical in decide (w.deposit t z m o s x) +theorem sales_core : + w.sales t z μ P m s=flaggedW μ ((w.pen t).state z n) (w.billboard (N:=N) s t z m) + ((w.pen t).resultKey) (fun o b=> P o ∧ b) := by + classical + funext x; unfold sales Volley.hist + simp_rw [pr]; rw [avg_avg] + unfold flaggedW mixW mapW + apply avg_congr; intro i hi + simp only [pr,avg,Function.comp_apply,subW,billboard,decide_eq_true_eq] + refine Finset.sum_congr rfl fun a _=> ?_ + rw [mul_assoc,← ind_and]; rfl + +theorem sales_receipt : customer w μ s t z m (w.sales t z μ P m s) := + ⟨_,w.sales_core μ s t z m P⟩ + +theorem sales_part : carried (w.sales t z μ P m s) (ownPart t z) := by + intro o ho + unfold sales Volley.hist + let A:=w.pen t + have hi (x : Inputs p n (Messenger q)) : + pr μ (fun i=>(P i ∧ w.deposit t z m i s x)∧(A.draw x).keys t i=o) = 0 := by + have h i : ¬((P i∧ w.deposit t z m i s x)∧(A.draw x).keys t i=o) := by + rintro ⟨⟨hp,hg⟩,hk⟩ + apply ho; rw [←hk]; exact hg.2.2 + unfold pr;simp only [ind_zero (h _),avg_const,mul_zero] + change avg (A.state z n) _=_ + exact (avg_congr (g:=fun _ => 0) (fun x _ => hi x)).trans (by rw [avg_const,mul_zero]) + +theorem sales_custom : custom w μ s t z m (w.sales t z μ P m s) := by + let v:= w.sales t z μ P m s + refine ⟨v,w.sales_receipt μ s t z m P, funext fun i =>?_⟩ + change v i=_ + unfold subW + by_cases hi : ownPart t z i + · rw [ind_one hi,mul_one] + rw [show v i=0 from w.sales_part μ s t z m P i hi,zero_mul] + +def prowl (o : UnitType p n N) (W : Wgt (Keys (p:=p) t N)) := + avg ((w.pen t).state z n) (fun x=>ind (w.deposit t z m o s x)*W ((w.pen t).resultKey o x)) + +theorem sales_mean (W : Wgt (Keys (p:=p) t N)) : + avg (w.sales t z μ P m s) W = + avg μ (fun o=> ind (P o) * prowl w s t z m o W) := by + classical + rw [sales_core, flaggedW] + refine (mixW_avg μ _ (show Wgt (Keys (p:=p) ((w.pen t).t) N) from W)).trans ?_ + refine avg_congr fun i _ => ?_ + rw [mapW_avg] + unfold prowl subW + simp only [avg,Finset.mul_sum,Function.comp_apply,billboard,decide_eq_true_eq,ind_and] + refine Finset.sum_congr rfl fun _ _=>?_ + ring + +theorem sales_pos (h : ∀ x,0≤μ x) (x) : 0≤ w.sales t z μ P m s x := + avg_nonneg (prodW_nonneg (fun _=> normW_nonneg (subW_nonneg (spins_law ..).nz _))) + (fun _=> pr_nonneg h) +end Quill + +namespace Station +variable {s : LeafMixture p n N} (v : Station p n N K s) + +theorem arena_pos (w : Typus p q d e) + (m: Mixer p n) (μ : Wgt (UnitType p n N)) (k : Fin (2^deckMax p K)) + (h : 0mul_nonneg (hf _) (hf _)) (fun i=>avg_nonneg + (unifOn_sub _).nz (fun x=>mul_nonneg ?_ ?_)) + · exact div_nonneg (w.qA.sales_pos _ _ _ _ m _ (hg _) x) ((unifOn_sub _).nz _) + exact div_nonneg (w.qB.sales_pos _ _ _ _ m _ (hg _) x) ((unifOn_sub _).nz _) + +end Station +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PairedOptions.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PairedOptions.lean index b4bee18af0fbba0da9b1e4454f8f8e71c8a24f2c..847966e77c85800302c8b522049b34379094dea6 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PairedOptions.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PairedOptions.lean @@ -1,170 +1,170 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteTableEnumeration -import OAI.Combinatorics.HadwigerCounterexample.InitialPartitionExistence -import OAI.Combinatorics.HadwigerCounterexample.HistogramBounds -import OAI.Combinatorics.HadwigerCounterexample.KeyTestCorrespondence - -namespace OAI - -/-! # Paired Options -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Finset Submodule Function -open scoped BigOperators -namespace StatusAnalysis -variable {p : Shape} {n N K : ℕ} - -structure Quill (p : Shape) (q : Format) (d : Rates) (b : Bool) where - sel : Messenger q → Label p.b - flav : Messenger q → Flavor p.g - amp : Amounts p q d b - script : Script p (Messenger q) - -structure Typus (p : Shape) (q : Format) (d e : Rates) where - t : Tagging p (Messenger q) - z : Messenger q → F - qA : Quill p q d true - qB : Quill p q e false - -abbrev Volumes := Grid → Fin 8 -abbrev Stakes (K : ℕ) := Nodes → Fin (K^2+1) -abbrev Master (K : ℕ) := Volumes × Stakes K × Stakes K -def toFormat (q : Volumes) : Format := fun i=>(q i).val -def toRates {K : ℕ} (d : Stakes K) : Rates := fun i=>(d i).val -abbrev OnFile (p : Shape) {K : ℕ} (q : Master K) := - Typus p (toFormat q.1) (toRates q.2.1) (toRates q.2.2) -abbrev Scrip (p : Shape) (K : ℕ) := Σ q : Master K, Fin (2^deckMax p K) × OnFile p q - -instance quillFintype (p : Shape) (q : Format) (d : Rates) (b : Bool) : - Fintype (Quill p q d b) := by - classical - let A := (Messenger q → Label p.b) × (Messenger q→Flavor p.g) × Amounts p q d b × Script p (Messenger q) - let E : A≃Quill p q d b := { - toFun x:= ⟨x.1,x.2.1,x.2.2.1,x.2.2.2⟩ - invFun x:= (x.sel,x.flav,x.amp,x.script) - left_inv _ := rfl - right_inv _:=rfl } - letI : Fintype (Messenger q → Flavor p.g):= by infer_instance - letI : Fintype (Amounts p q d b) := by infer_instance - letI : Fintype (MOne p):= by unfold MOne MIdx; infer_instance - letI : Fintype (Vec (MOne p)):= by infer_instance - letI : Fintype (Messenger q →Vec (MOne p)):= by infer_instance - letI : Fintype (Script p (Messenger q)):= by infer_instance - exact Fintype.ofEquiv _ E -instance typusFintype (p : Shape) (q : Format) (d e : Rates) : Fintype (Typus p q d e) := by - classical - let A:=Tagging p (Messenger q)× (Messenger q→F) ×Quill p q d true×Quill p q e false - let E : A≃Typus p q d e := { - toFun x:=⟨x.1,x.2.1,x.2.2.1,x.2.2.2⟩ - invFun x:=(x.t,x.z,x.qA,x.qB) - left_inv _:=rfl - right_inv _:=rfl } - exact Fintype.ofEquiv _ E -instance scripFintype (p : Shape) (K : ℕ) : Fintype (Scrip p K) := by - classical - infer_instance - -variable {q : Format} {d e : Rates} - -namespace Quill -variable {b : Bool} (w : Quill p q d b) (t : Tagging p (Messenger q)) (z : Messenger q→F) - -def pen := manager b t w.sel w.flav -def moral := - Injective w.sel ∧ owing p b w.amp z ∧ ∀ i, (w.amp i).1.feasible (t i) (w.flav i) - -theorem canDraw {w : Quill p q d b} (h : w.moral t z) (i : Messenger q) : - canDial p (t i) (w.flav i) (z i) := - ⟨_,h.2.2 i,h.2.1 i⟩ - -def penSpace (x : Pin p n N) (K : ℕ) := - ∀ y:Inputs p n (Messenger q), ((w.pen t).draw y).avoids x.sp (qorth K) - -def signed (x y : Pin p n N) (s : Charts p n d) (T : Cross p n) (K : ℕ) := - charted s x.sp ∧ w.penSpace t x K ∧ still b w.amp s T ∧ tableInj x.sp y.sp T - -def deposit (m : Mixer p n) (o : UnitType p n N) (v : Charts p n d) - (x : Inputs p n (Messenger q)) := - let u := (w.pen t).draw x - printed b v t w.sel w.flav m o x=w.amp ∧ - u.reads w.script m ∧ ownPart t z (u.keys t o) - -def sales (μ : Wgt (UnitType p n N)) (P : UnitType p n N→Prop) - (m :Mixer p n) (s : Charts p n d) : Wgt (Keys (p:=p) t N) := - Volley.hist (w.pen t).draw t μ ((w.pen t).state z n) - (fun x o=> P o∧w.deposit t z m o s x) - -end Quill - -namespace Typus -variable (w : Typus p q d e) -def permission := - (∀ i,1 ≤ q i∧q i≤7) ∧ - w.qA.moral w.t w.z ∧ w.qB.moral w.t w.z ∧ - (∀ i,fullq w.z i=1) ∧ rhyme w.qA.amp w.qB.amp ∧ - proclaims p w.qA.amp w.qB.amp w.t w.qA.script ∧ - proclaims p w.qB.amp w.qA.amp w.t w.qB.script - -def chances (s : Charts p n d) (v : Charts p n e) - (x y : Pin p n N) (T : Cross p n) (K : ℕ) := - w.permission ∧ w.qA.signed w.t x y s T K ∧ w.qB.signed w.t y x v (reciprocal p T) K -end Typus - -def notified (m : Mixer p n) (x y : Pin p n N) (T : Cross p n) - (C : Prop) (o : UnitType p n N) := - C ∧ x.agree o ∧ (∀ i,frameLaw m (onSide o i)) ∧ tableFlag x y T o - -structure Station (p : Shape) (n N K : ℕ) (s : LeafMixture p n N) where - cAxes : s.T → (d:Rates)→Charts p n d - mails : s.T → s.T → Fin (2^deckMax p K) → Cross p n -namespace Station -variable {s : LeafMixture p n N} (v : Station p n N K s) - -def bank := - (∀ i,dressCode (p:=p) n (s.pin i.val).sp (v.cAxes i)) ∧ - ∀ i j T,∃ k,fitsTable (s.pin i.val).sp (s.pin j.val).sp (v.mails i j k) T -where - dressCode {p : Shape} (n : ℕ) (f : Plan p n) (V : (d:Rates)→ Charts p n d) := - let d:=fun i=>dim (effective f i) - charted (V d) f - -theorem create (h : ∀ i:s.T, planRank (s.pin i.val).sp ≤K) : - ∃ v : Station p n N K s,v.bank := by - classical - let d (i:s.T) j:=dim (effective (s.pin (Subtype.val i)).sp j) - choose F hF using fun i:s.T=> chart_create p n (s.pin i.val).sp - choose G hG using fun i j:s.T=> deck_cast p n K (s.pin i.val).sp (s.pin j.val).sp (h i) (h j) - let axes (i:s.T) (r:Rates): Charts p n r := if ht:r=d i then ht ▸ (F i) else fun _=>0 - refine ⟨⟨axes,G⟩,fun i=>?_,hG⟩ - change charted (axes i (d i)) _ - unfold axes; rw [dite_eq_left rfl]; exact hF i - -variable (w : Typus p q d e) - -def news (i j : s.T) (k : Fin (2^deckMax p K)) := - w.chances (v.cAxes i d) (v.cAxes j e) (s.pin i.val) (s.pin j.val) (v.mails i j k) K -def frontPage (m : Mixer p n) (i j : s.T) (k : Fin (2^deckMax p K)) := - notified m (s.pin i.val) (s.pin j.val) (v.mails i j k) (news v w i j k) -def backPage (m : Mixer p n) (i j : s.T) (k : Fin (2^deckMax p K)) := - notified m (s.pin j.val) (s.pin i.val) (reciprocal p (v.mails i j k)) (news v w i j k) - -def leftSales (m : Mixer p n) (μ : Wgt (UnitType p n N)) (i j : s.T) - (k : Fin (2^deckMax p K)) := - w.qA.sales w.t w.z (partW μ i.val) (frontPage v w m i j k) m (v.cAxes i d) -def rightSales (m : Mixer p n) (μ : Wgt (UnitType p n N)) (i j : s.T) - (k : Fin (2^deckMax p K)) := - w.qB.sales w.t w.z (partW μ j.val) (backPage v w m i j k) m (v.cAxes j e) - -def matchScore (m:Mixer p n) (μ: Wgt (UnitType p n N)) (i j:s.T) - (k : Fin (2^deckMax p K)) := - overlap (lawNu p N w.t w.z) (leftSales v w m μ i j k) (rightSales v w m μ i j k) - -def arena (m:Mixer p n) (μ: Wgt (UnitType p n N)) (k:Fin (2^deckMax p K)) := - avg (pairW (portionW μ s.T) (portionW μ s.T)) (fun x=>matchScore v w m μ x.1 x.2 k) -end Station -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteTableEnumeration +import OAI.Combinatorics.HadwigerCounterexample.InitialPartitionExistence +import OAI.Combinatorics.HadwigerCounterexample.HistogramBounds +import OAI.Combinatorics.HadwigerCounterexample.KeyTestCorrespondence + +namespace OAI + +/-! # Paired Options -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Finset Submodule Function +open scoped BigOperators +namespace StatusAnalysis +variable {p : Shape} {n N K : ℕ} + +structure Quill (p : Shape) (q : Format) (d : Rates) (b : Bool) where + sel : Messenger q → Label p.b + flav : Messenger q → Flavor p.g + amp : Amounts p q d b + script : Script p (Messenger q) + +structure Typus (p : Shape) (q : Format) (d e : Rates) where + t : Tagging p (Messenger q) + z : Messenger q → F + qA : Quill p q d true + qB : Quill p q e false + +abbrev Volumes := Grid → Fin 8 +abbrev Stakes (K : ℕ) := Nodes → Fin (K^2+1) +abbrev Master (K : ℕ) := Volumes × Stakes K × Stakes K +def toFormat (q : Volumes) : Format := fun i=>(q i).val +def toRates {K : ℕ} (d : Stakes K) : Rates := fun i=>(d i).val +abbrev OnFile (p : Shape) {K : ℕ} (q : Master K) := + Typus p (toFormat q.1) (toRates q.2.1) (toRates q.2.2) +abbrev Scrip (p : Shape) (K : ℕ) := Σ q : Master K, Fin (2^deckMax p K) × OnFile p q + +instance quillFintype (p : Shape) (q : Format) (d : Rates) (b : Bool) : + Fintype (Quill p q d b) := by + classical + let A := (Messenger q → Label p.b) × (Messenger q→Flavor p.g) × Amounts p q d b × Script p (Messenger q) + let E : A≃Quill p q d b := { + toFun x:= ⟨x.1,x.2.1,x.2.2.1,x.2.2.2⟩ + invFun x:= (x.sel,x.flav,x.amp,x.script) + left_inv _ := rfl + right_inv _:=rfl } + letI : Fintype (Messenger q → Flavor p.g):= by infer_instance + letI : Fintype (Amounts p q d b) := by infer_instance + letI : Fintype (MOne p):= by unfold MOne MIdx; infer_instance + letI : Fintype (Vec (MOne p)):= by infer_instance + letI : Fintype (Messenger q →Vec (MOne p)):= by infer_instance + letI : Fintype (Script p (Messenger q)):= by infer_instance + exact Fintype.ofEquiv _ E +instance typusFintype (p : Shape) (q : Format) (d e : Rates) : Fintype (Typus p q d e) := by + classical + let A:=Tagging p (Messenger q)× (Messenger q→F) ×Quill p q d true×Quill p q e false + let E : A≃Typus p q d e := { + toFun x:=⟨x.1,x.2.1,x.2.2.1,x.2.2.2⟩ + invFun x:=(x.t,x.z,x.qA,x.qB) + left_inv _:=rfl + right_inv _:=rfl } + exact Fintype.ofEquiv _ E +instance scripFintype (p : Shape) (K : ℕ) : Fintype (Scrip p K) := by + classical + infer_instance + +variable {q : Format} {d e : Rates} + +namespace Quill +variable {b : Bool} (w : Quill p q d b) (t : Tagging p (Messenger q)) (z : Messenger q→F) + +def pen := manager b t w.sel w.flav +def moral := + Injective w.sel ∧ owing p b w.amp z ∧ ∀ i, (w.amp i).1.feasible (t i) (w.flav i) + +theorem canDraw {w : Quill p q d b} (h : w.moral t z) (i : Messenger q) : + canDial p (t i) (w.flav i) (z i) := + ⟨_,h.2.2 i,h.2.1 i⟩ + +def penSpace (x : Pin p n N) (K : ℕ) := + ∀ y:Inputs p n (Messenger q), ((w.pen t).draw y).avoids x.sp (qorth K) + +def signed (x y : Pin p n N) (s : Charts p n d) (T : Cross p n) (K : ℕ) := + charted s x.sp ∧ w.penSpace t x K ∧ still b w.amp s T ∧ tableInj x.sp y.sp T + +def deposit (m : Mixer p n) (o : UnitType p n N) (v : Charts p n d) + (x : Inputs p n (Messenger q)) := + let u := (w.pen t).draw x + printed b v t w.sel w.flav m o x=w.amp ∧ + u.reads w.script m ∧ ownPart t z (u.keys t o) + +def sales (μ : Wgt (UnitType p n N)) (P : UnitType p n N→Prop) + (m :Mixer p n) (s : Charts p n d) : Wgt (Keys (p:=p) t N) := + Volley.hist (w.pen t).draw t μ ((w.pen t).state z n) + (fun x o=> P o∧w.deposit t z m o s x) + +end Quill + +namespace Typus +variable (w : Typus p q d e) +def permission := + (∀ i,1 ≤ q i∧q i≤7) ∧ + w.qA.moral w.t w.z ∧ w.qB.moral w.t w.z ∧ + (∀ i,fullq w.z i=1) ∧ rhyme w.qA.amp w.qB.amp ∧ + proclaims p w.qA.amp w.qB.amp w.t w.qA.script ∧ + proclaims p w.qB.amp w.qA.amp w.t w.qB.script + +def chances (s : Charts p n d) (v : Charts p n e) + (x y : Pin p n N) (T : Cross p n) (K : ℕ) := + w.permission ∧ w.qA.signed w.t x y s T K ∧ w.qB.signed w.t y x v (reciprocal p T) K +end Typus + +def notified (m : Mixer p n) (x y : Pin p n N) (T : Cross p n) + (C : Prop) (o : UnitType p n N) := + C ∧ x.agree o ∧ (∀ i,frameLaw m (onSide o i)) ∧ tableFlag x y T o + +structure Station (p : Shape) (n N K : ℕ) (s : LeafMixture p n N) where + cAxes : s.T → (d:Rates)→Charts p n d + mails : s.T → s.T → Fin (2^deckMax p K) → Cross p n +namespace Station +variable {s : LeafMixture p n N} (v : Station p n N K s) + +def bank := + (∀ i,dressCode (p:=p) n (s.pin i.val).sp (v.cAxes i)) ∧ + ∀ i j T,∃ k,fitsTable (s.pin i.val).sp (s.pin j.val).sp (v.mails i j k) T +where + dressCode {p : Shape} (n : ℕ) (f : Plan p n) (V : (d:Rates)→ Charts p n d) := + let d:=fun i=>dim (effective f i) + charted (V d) f + +theorem create (h : ∀ i:s.T, planRank (s.pin i.val).sp ≤K) : + ∃ v : Station p n N K s,v.bank := by + classical + let d (i:s.T) j:=dim (effective (s.pin (Subtype.val i)).sp j) + choose F hF using fun i:s.T=> chart_create p n (s.pin i.val).sp + choose G hG using fun i j:s.T=> deck_cast p n K (s.pin i.val).sp (s.pin j.val).sp (h i) (h j) + let axes (i:s.T) (r:Rates): Charts p n r := if ht:r=d i then ht ▸ (F i) else fun _=>0 + refine ⟨⟨axes,G⟩,fun i=>?_,hG⟩ + change charted (axes i (d i)) _ + unfold axes; rw [dite_eq_left rfl]; exact hF i + +variable (w : Typus p q d e) + +def news (i j : s.T) (k : Fin (2^deckMax p K)) := + w.chances (v.cAxes i d) (v.cAxes j e) (s.pin i.val) (s.pin j.val) (v.mails i j k) K +def frontPage (m : Mixer p n) (i j : s.T) (k : Fin (2^deckMax p K)) := + notified m (s.pin i.val) (s.pin j.val) (v.mails i j k) (news v w i j k) +def backPage (m : Mixer p n) (i j : s.T) (k : Fin (2^deckMax p K)) := + notified m (s.pin j.val) (s.pin i.val) (reciprocal p (v.mails i j k)) (news v w i j k) + +def leftSales (m : Mixer p n) (μ : Wgt (UnitType p n N)) (i j : s.T) + (k : Fin (2^deckMax p K)) := + w.qA.sales w.t w.z (partW μ i.val) (frontPage v w m i j k) m (v.cAxes i d) +def rightSales (m : Mixer p n) (μ : Wgt (UnitType p n N)) (i j : s.T) + (k : Fin (2^deckMax p K)) := + w.qB.sales w.t w.z (partW μ j.val) (backPage v w m i j k) m (v.cAxes j e) + +def matchScore (m:Mixer p n) (μ: Wgt (UnitType p n N)) (i j:s.T) + (k : Fin (2^deckMax p K)) := + overlap (lawNu p N w.t w.z) (leftSales v w m μ i j k) (rightSales v w m μ i j k) + +def arena (m:Mixer p n) (μ: Wgt (UnitType p n N)) (k:Fin (2^deckMax p K)) := + avg (pairW (portionW μ s.T) (portionW μ s.T)) (fun x=>matchScore v w m μ x.1 x.2 k) +end Station +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PairedRankBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PairedRankBounds.lean index 069c46a7d66576221cd9221257db8893254e94ec..e9614db9937aadf616704bcd3ae058e2de74b934 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PairedRankBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PairedRankBounds.lean @@ -1,115 +1,115 @@ -import OAI.Combinatorics.HadwigerCounterexample.EndpointGramRanks - -namespace OAI - -/-! # Paired Rank Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset LinearMap Module Matrix Function -open scoped BigOperators -variable {I J : Type} [Fintype I] [Fintype J] {n N : ℕ} - -theorem rank_jump_prob (n d N : ℕ) : - pr unif (fun q : PlusRack (Fin n) N× PlusRack (Fin n) N => rankJump q.1 q.2 d) ≤ - bp ((2*n-(N:ℝ))*d) := by - classical - let V := PlusRack (Fin n) N - let e : V×V ≃ PlusRack (Fin n⊕Fin n) N := { - toFun q := fromCols q.1 q.2 - invFun M := (M.submatrix _root_.id Sum.inl,M.submatrix _root_.id Sum.inr) - left_inv x := rfl - right_inv x := by ext i j; cases j <;> rfl } - have ht := pr_deficient (I:=Fin N) (J:=Fin n⊕Fin n) d - rw [←unif_equiv e,mapW_pr] at ht - simp only [num,Fintype.card_fin,Fintype.card_sum,←two_mul,Nat.cast_mul,Nat.cast_ofNat] at ht; exact ht - -set_option maxHeartbeats 800000 in -theorem paired_rank_norm (n d r N : ℕ) (hN : 2*(n:ℝ)-N≤ -1) - (G H W : Mat (Fin n) (Fin n)) (v : F) : - pr (pairW (unifOn (gramGood G)) (unifOn (gramGood H))) - (fun s => (crossSquare n N W v s).rank ≤ r) ≤ - 16*(bp ((2*n-(N:ℝ))*d)+bp ((2*n:ℝ)*r-(n-d:ℝ)*n)) := by - classical - let A := PlusRack (Fin n) N - let P (s : (A×A)×A×A) := gramGood G s.1∧gramGood H s.2 - let Q (s : (A×A)×A×A) := (crossSquare n N W v s).rank≤r - let p := bp (-(n:ℝ)*n); let c := bp ((2*n:ℝ)*r-(n-d:ℝ)*n) - let b := bp ((2*n-(N:ℝ))*d) - have hp : 0

gramGood G i) := by - have hh : num (Fin n)+num (Fin n)-num (Fin N) ≤ -1 := by - simp only [num,Fintype.card_fin]; linarith only [hN] - simpa only [p,num,Fintype.card_fin] using gram_norm_quarter G hh - unfold P; rw [pair_unif,pairW_pr,pow_two] - exact mul_le_mul (he _) (he _) (by positivity) (pr_nonneg unif_law.nz) - have he (x y : A) : - pr unif (fun s : A×A=>P ((x,s.1),(y,s.2))∧Q ((x,s.1),(y,s.2))) ≤ - p^2 * (ind (rankJump x y d)+c) := by - rw [pair_unif] - have h0 : 0 ≤ p^2*(ind (rankJump x y d)+c) := mul_nonneg (sq_nonneg _) (add_nonneg - (ind_nonneg _) hc) - by_cases hx : Injective x.mulVec ∧ Injective y.mulVec - · have hh := shift_square n N r d x y G H W v hx.1 hx.2 - exact (pr_mono (pairW_law unif_law unif_law).nz fun i h => - ⟨⟨h.1.1.1,h.1.2.1⟩,h.2⟩).trans hh - exact le_trans (le_of_eq ((congrArg (pr (pairW _ _)) (show - (fun s : A×A=>P ((x,s.1),(y,s.2))∧Q ((x,s.1),(y,s.2)))=(fun s=>False) from - funext fun i => propext ⟨fun h => hx ⟨h.1.1.2.1,h.1.2.2.1⟩,False.elim⟩)).trans - (pr_false _))) h0 - have ht : pr unif (fun s => P s∧Q s)≤p^2*(b+c) := by - let f : ((A×A)×A×A)≃ ((A×A)×A×A) := { - toFun x := ((x.1.1,x.2.1),(x.1.2,x.2.2)) - invFun x := ((x.1.1,x.2.1),(x.1.2,x.2.2)) - left_inv _ := rfl - right_inv _ := rfl } - rw [←unif_equiv f,mapW_pr,pair_unif,pr,pairW_avg] - refine (avg_mono (unif_law (α:=A×A)).nz (fun x => he x.1 x.2)).trans ?_ - rw [avg_mul',avg_add,unif_law.avg_const] - exact mul_le_mul_of_nonneg_left (add_le_add_left (rank_jump_prob n d N) c) (sq_nonneg _) - rw [←unifOn_and_prod,←on_unif,pr_on] - refine (div_le_div₀ (mul_nonneg (sq_nonneg _) (add_nonneg hb hc)) ht - (show 0 < (p/4)^2 from by positivity) hP).trans_eq ?_ - change p^2*(b+c) / ((p/4)^2)=16*(b+c) - field_simp; ring - -open Filter -theorem paired_rank_scale : - ∀ᶠ n : ℕ in atTop,∀ N : ℕ, 4*n≤ N → - ∀ (G H W : Mat (Fin n) (Fin n)) (v : F), - pr (pairW (unifOn (gramGood G)) (unifOn (gramGood H))) - (fun s => 5*(crossSquare n N W v s).rank < n) ≤ bp (-(n:ℝ)*n/4) := by - filter_upwards [eventually_ge_atTop 100] with n hn N hN G H W v - let d := n/4; let r := n/5 - have hn' : (100:ℝ) ≤ n := by exact_mod_cast hn - have hN' : 4*(n:ℝ)≤N := by exact_mod_cast hN - have hr : 5*(r:ℝ)≤n := by exact_mod_cast (show 5*r ≤ n by unfold r; omega) - have hd : 4*(d:ℝ)≤n := by exact_mod_cast (show 4*d≤n by unfold d; omega) - have hd' : (n:ℝ)≤4*d+3 := by exact_mod_cast (show n ≤ 4*d+3 by unfold d; omega) - have hh := paired_rank_norm n d r N (by linarith only [hN',hn']) G H W v - let z := (-(n:ℝ)*n/4-5) - have hg : 32*bp z=bp (-(n:ℝ)*n/4) := by - have he : bp 5=32 := by norm_num [bp] - rw [←he,←bp_add]; unfold z; ring_nf - rw [←hg] - refine (pr_mono (subLaw_pair (unifOn_sub _) (unifOn_sub _)).nz fun i hi => - (by unfold r; omega : (crossSquare n N W v i).rank ≤ r)).trans (hh.trans ?_) - have hq : bp ((2*n-(N:ℝ))*d)≤bp z := by - apply bp_le - unfold z - nlinarith only [mul_le_mul_of_nonneg_right hN' (Nat.cast_nonneg d : 0≤(d:ℝ)), - mul_le_mul_of_nonneg_right hn' (Nat.cast_nonneg n : 0≤(n:ℝ)),hn', - mul_le_mul_of_nonneg_right hd' (Nat.cast_nonneg n : 0≤(n:ℝ))] - have hm : bp ((2*n:ℝ)*r-(n-d:ℝ)*n)≤bp z := by - apply bp_le; unfold z - nlinarith only [mul_le_mul_of_nonneg_right hr (Nat.cast_nonneg n : 0≤(n:ℝ)), - mul_le_mul_of_nonneg_right hn' (Nat.cast_nonneg n : 0≤(n:ℝ)),hn', - mul_le_mul_of_nonneg_right hd (Nat.cast_nonneg n : 0≤(n:ℝ))] - linarith only [hq,hm] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.EndpointGramRanks + +namespace OAI + +/-! # Paired Rank Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset LinearMap Module Matrix Function +open scoped BigOperators +variable {I J : Type} [Fintype I] [Fintype J] {n N : ℕ} + +theorem rank_jump_prob (n d N : ℕ) : + pr unif (fun q : PlusRack (Fin n) N× PlusRack (Fin n) N => rankJump q.1 q.2 d) ≤ + bp ((2*n-(N:ℝ))*d) := by + classical + let V := PlusRack (Fin n) N + let e : V×V ≃ PlusRack (Fin n⊕Fin n) N := { + toFun q := fromCols q.1 q.2 + invFun M := (M.submatrix _root_.id Sum.inl,M.submatrix _root_.id Sum.inr) + left_inv x := rfl + right_inv x := by ext i j; cases j <;> rfl } + have ht := pr_deficient (I:=Fin N) (J:=Fin n⊕Fin n) d + rw [←unif_equiv e,mapW_pr] at ht + simp only [num,Fintype.card_fin,Fintype.card_sum,←two_mul,Nat.cast_mul,Nat.cast_ofNat] at ht; exact ht + +set_option maxHeartbeats 800000 in +theorem paired_rank_norm (n d r N : ℕ) (hN : 2*(n:ℝ)-N≤ -1) + (G H W : Mat (Fin n) (Fin n)) (v : F) : + pr (pairW (unifOn (gramGood G)) (unifOn (gramGood H))) + (fun s => (crossSquare n N W v s).rank ≤ r) ≤ + 16*(bp ((2*n-(N:ℝ))*d)+bp ((2*n:ℝ)*r-(n-d:ℝ)*n)) := by + classical + let A := PlusRack (Fin n) N + let P (s : (A×A)×A×A) := gramGood G s.1∧gramGood H s.2 + let Q (s : (A×A)×A×A) := (crossSquare n N W v s).rank≤r + let p := bp (-(n:ℝ)*n); let c := bp ((2*n:ℝ)*r-(n-d:ℝ)*n) + let b := bp ((2*n-(N:ℝ))*d) + have hp : 0

gramGood G i) := by + have hh : num (Fin n)+num (Fin n)-num (Fin N) ≤ -1 := by + simp only [num,Fintype.card_fin]; linarith only [hN] + simpa only [p,num,Fintype.card_fin] using gram_norm_quarter G hh + unfold P; rw [pair_unif,pairW_pr,pow_two] + exact mul_le_mul (he _) (he _) (by positivity) (pr_nonneg unif_law.nz) + have he (x y : A) : + pr unif (fun s : A×A=>P ((x,s.1),(y,s.2))∧Q ((x,s.1),(y,s.2))) ≤ + p^2 * (ind (rankJump x y d)+c) := by + rw [pair_unif] + have h0 : 0 ≤ p^2*(ind (rankJump x y d)+c) := mul_nonneg (sq_nonneg _) (add_nonneg + (ind_nonneg _) hc) + by_cases hx : Injective x.mulVec ∧ Injective y.mulVec + · have hh := shift_square n N r d x y G H W v hx.1 hx.2 + exact (pr_mono (pairW_law unif_law unif_law).nz fun i h => + ⟨⟨h.1.1.1,h.1.2.1⟩,h.2⟩).trans hh + exact le_trans (le_of_eq ((congrArg (pr (pairW _ _)) (show + (fun s : A×A=>P ((x,s.1),(y,s.2))∧Q ((x,s.1),(y,s.2)))=(fun s=>False) from + funext fun i => propext ⟨fun h => hx ⟨h.1.1.2.1,h.1.2.2.1⟩,False.elim⟩)).trans + (pr_false _))) h0 + have ht : pr unif (fun s => P s∧Q s)≤p^2*(b+c) := by + let f : ((A×A)×A×A)≃ ((A×A)×A×A) := { + toFun x := ((x.1.1,x.2.1),(x.1.2,x.2.2)) + invFun x := ((x.1.1,x.2.1),(x.1.2,x.2.2)) + left_inv _ := rfl + right_inv _ := rfl } + rw [←unif_equiv f,mapW_pr,pair_unif,pr,pairW_avg] + refine (avg_mono (unif_law (α:=A×A)).nz (fun x => he x.1 x.2)).trans ?_ + rw [avg_mul',avg_add,unif_law.avg_const] + exact mul_le_mul_of_nonneg_left (add_le_add_left (rank_jump_prob n d N) c) (sq_nonneg _) + rw [←unifOn_and_prod,←on_unif,pr_on] + refine (div_le_div₀ (mul_nonneg (sq_nonneg _) (add_nonneg hb hc)) ht + (show 0 < (p/4)^2 from by positivity) hP).trans_eq ?_ + change p^2*(b+c) / ((p/4)^2)=16*(b+c) + field_simp; ring + +open Filter +theorem paired_rank_scale : + ∀ᶠ n : ℕ in atTop,∀ N : ℕ, 4*n≤ N → + ∀ (G H W : Mat (Fin n) (Fin n)) (v : F), + pr (pairW (unifOn (gramGood G)) (unifOn (gramGood H))) + (fun s => 5*(crossSquare n N W v s).rank < n) ≤ bp (-(n:ℝ)*n/4) := by + filter_upwards [eventually_ge_atTop 100] with n hn N hN G H W v + let d := n/4; let r := n/5 + have hn' : (100:ℝ) ≤ n := by exact_mod_cast hn + have hN' : 4*(n:ℝ)≤N := by exact_mod_cast hN + have hr : 5*(r:ℝ)≤n := by exact_mod_cast (show 5*r ≤ n by unfold r; omega) + have hd : 4*(d:ℝ)≤n := by exact_mod_cast (show 4*d≤n by unfold d; omega) + have hd' : (n:ℝ)≤4*d+3 := by exact_mod_cast (show n ≤ 4*d+3 by unfold d; omega) + have hh := paired_rank_norm n d r N (by linarith only [hN',hn']) G H W v + let z := (-(n:ℝ)*n/4-5) + have hg : 32*bp z=bp (-(n:ℝ)*n/4) := by + have he : bp 5=32 := by norm_num [bp] + rw [←he,←bp_add]; unfold z; ring_nf + rw [←hg] + refine (pr_mono (subLaw_pair (unifOn_sub _) (unifOn_sub _)).nz fun i hi => + (by unfold r; omega : (crossSquare n N W v i).rank ≤ r)).trans (hh.trans ?_) + have hq : bp ((2*n-(N:ℝ))*d)≤bp z := by + apply bp_le + unfold z + nlinarith only [mul_le_mul_of_nonneg_right hN' (Nat.cast_nonneg d : 0≤(d:ℝ)), + mul_le_mul_of_nonneg_right hn' (Nat.cast_nonneg n : 0≤(n:ℝ)),hn', + mul_le_mul_of_nonneg_right hd' (Nat.cast_nonneg n : 0≤(n:ℝ))] + have hm : bp ((2*n:ℝ)*r-(n-d:ℝ)*n)≤bp z := by + apply bp_le; unfold z + nlinarith only [mul_le_mul_of_nonneg_right hr (Nat.cast_nonneg n : 0≤(n:ℝ)), + mul_le_mul_of_nonneg_right hn' (Nat.cast_nonneg n : 0≤(n:ℝ)),hn', + mul_le_mul_of_nonneg_right hd (Nat.cast_nonneg n : 0≤(n:ℝ))] + linarith only [hq,hm] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PairedTemplateConcentration.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PairedTemplateConcentration.lean index a5fd334c4f533f1e79575bf69854abb658f75f2c..ba30fbe17a361d3044280e66f0764d74fc34c748 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PairedTemplateConcentration.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PairedTemplateConcentration.lean @@ -1,95 +1,95 @@ -import OAI.Combinatorics.HadwigerCounterexample.EndpointTemplateConcentration - -namespace OAI - -/-! # Paired Template Concentration -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Real Finset Matrix Function -open scoped BigOperators -variable {p : Shape} {M n N : ℕ} -variable {I J K G : Type} [Fintype I] [Fintype J] [Fintype K] [Fintype G] -variable [DecidableEq I] [DecidableEq J] [DecidableEq K] [DecidableEq G] - -theorem paired_price (M : ℕ) (C : ℝ) : - ∀ᶠ n : ℕ in atTop, - let d := bp (-(1/4:ℝ)*n) - let τ := bp (-(1/8:ℝ)*n) - let e := bp (-(C*M+1)*n) - bp ((1/32:ℝ)*n)*(d+d/τ)+bp (C*(M*n:ℕ))*e≤ bp (-(1/16:ℝ)*n) := by - filter_upwards [pay_div_nat (a:=1-1/2+1/2) 1 (1/3) (by norm_num) (b:=1/16) (by norm_num), - pay_div_nat (a:=1/4-1/32) 1 (1/3) (by norm_num) (b:=1/16) (by norm_num), - pay_div_nat (a:=1/8-1/32) 1 (1/3) (by norm_num) (b:=1/16) (by norm_num)] - with n ha hb hc - intro d τ e - unfold d τ e - rw [← bp_sub,mul_add,← bp_add,← bp_add,← bp_add,Nat.cast_mul] - have h : C * ((M:ℝ)*n) + -(C*M+1)*n= - (1-1/2+1/2)*n := by ring - rw [h] - have hg : (1/32:ℝ)*n+(-(1/4:ℝ)*n- -(1/8:ℝ)*n) = -(1/8-1/32:ℝ)*n := by ring - have hf : (1/32:ℝ)*n+ -(1/4:ℝ)*n = -(1/4-1/32:ℝ)*n := by ring - rw [hf,hg] - linarith only [ha,hb,hc] - -namespace Template - -variable (v : Template p I) (z : Template p J) - -abbrev Datum (v : Template p I) (n N : ℕ) := - Inputs p n I×Rack (KeySlots p v.t) N - -instance inpFinite (p : Shape) (I : Type) [Fintype I] [DecidableEq I] (n : ℕ) : - Fintype (Inputs p n I) := inferInstanceAs (Fintype (I→Knobs p.g n)) -instance keySlotFinite (v : Template p I) : Fintype (KeySlots p v.t) := inferInstance -instance datumFinite (v : Template p I) (n N : ℕ) : Fintype (v.Datum n N) := inferInstance -set_option maxHeartbeats 800000 in -theorem twinned (v : Template p I) (z : Template p J) (M : ℕ) (hM : 1≤M) - (C ε : ℝ) (hε : 0<ε) : - ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n) - (w : Wgt (UnitType p n N)), IsLaw w → - let μ := raw m N; let ρ := pairW μ μ - let H := bp ((1/32:ℝ)*n) - (∀ x,mapW w Prod.fst x ≤ H*μ x) → (∀ x,mapW w Prod.snd x ≤ H*μ x) → - (∀ x,w x ≤ bp (C*N) *ρ x) → 2*num (Full p n) - avg (pairW ((v.singleP n).makeData (prodW u) x.1) - ((z.singleP n).makeData (prodW s) x.2)) T - pr w (fun x => ε≤ |f x-avg ρ f|) ≤ bp (-(1/16:ℝ)*n) := by - classical - let g := ownPort (p:=p) v.t; let b := ownPort (p:=p) z.t - let η := ε/5; have hη : 0<η := by positivity - let a := C*M+1 - obtain ⟨l,hl⟩ := Program.thin_calendar p M b a η (1/8) (by norm_num) hη hM - filter_upwards [Program.approx_calendar p M g (num Bool*num I) η hη hM, - Program.approx_calendar p M b (num Bool*num J) η hη hM, - hl (num (Fin l)*num J),paired_price M C] - with n hn ha hq hp N m w hw μ ρ H hA hB hw' hN u s hu hu' hs hs' T hT f - let f' := (v.singleP n).makeData (prodW u) (N:=N) - let g' := (z.singleP n).makeData (prodW s) (N:=N) - let d := bp (-(1/4:ℝ)*n); let τ := bp (-(1/8:ℝ)*n); let e := bp (-a*n) - have hx : approxData μ f' η d := hn m _ _ _ (prodW_law hu) hN - (free_price v n u hu hu' g (own_inj v)) - have hy : approxData μ g' η d := ha m _ _ _ (prodW_law hs) hN - (free_price z n s hs hs' b (own_inj z)) - have hz : thinData μ g' τ η e := hq m _ _ _ (prodW_law hs) hN - (free_price z n s hs hs' b (own_inj z)) - have hm : IsLaw μ := forum_law m hN - have he := paired_spread T f' g' hm hm hw - (fun x => Program.data_law _ _ _ (prodW_law hu)) - (fun x => Program.data_law _ _ _ (prodW_law hs)) - hT η d e τ hη (bp_pos _) (bp_pos _).le hx hy hz - _ _ (bp_pos _).le (bp_pos _).le hA hB hw' - rw [show 5*η=ε by unfold η; ring] at he - exact he.trans hp - -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.EndpointTemplateConcentration + +namespace OAI + +/-! # Paired Template Concentration -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Real Finset Matrix Function +open scoped BigOperators +variable {p : Shape} {M n N : ℕ} +variable {I J K G : Type} [Fintype I] [Fintype J] [Fintype K] [Fintype G] +variable [DecidableEq I] [DecidableEq J] [DecidableEq K] [DecidableEq G] + +theorem paired_price (M : ℕ) (C : ℝ) : + ∀ᶠ n : ℕ in atTop, + let d := bp (-(1/4:ℝ)*n) + let τ := bp (-(1/8:ℝ)*n) + let e := bp (-(C*M+1)*n) + bp ((1/32:ℝ)*n)*(d+d/τ)+bp (C*(M*n:ℕ))*e≤ bp (-(1/16:ℝ)*n) := by + filter_upwards [pay_div_nat (a:=1-1/2+1/2) 1 (1/3) (by norm_num) (b:=1/16) (by norm_num), + pay_div_nat (a:=1/4-1/32) 1 (1/3) (by norm_num) (b:=1/16) (by norm_num), + pay_div_nat (a:=1/8-1/32) 1 (1/3) (by norm_num) (b:=1/16) (by norm_num)] + with n ha hb hc + intro d τ e + unfold d τ e + rw [← bp_sub,mul_add,← bp_add,← bp_add,← bp_add,Nat.cast_mul] + have h : C * ((M:ℝ)*n) + -(C*M+1)*n= - (1-1/2+1/2)*n := by ring + rw [h] + have hg : (1/32:ℝ)*n+(-(1/4:ℝ)*n- -(1/8:ℝ)*n) = -(1/8-1/32:ℝ)*n := by ring + have hf : (1/32:ℝ)*n+ -(1/4:ℝ)*n = -(1/4-1/32:ℝ)*n := by ring + rw [hf,hg] + linarith only [ha,hb,hc] + +namespace Template + +variable (v : Template p I) (z : Template p J) + +abbrev Datum (v : Template p I) (n N : ℕ) := + Inputs p n I×Rack (KeySlots p v.t) N + +instance inpFinite (p : Shape) (I : Type) [Fintype I] [DecidableEq I] (n : ℕ) : + Fintype (Inputs p n I) := inferInstanceAs (Fintype (I→Knobs p.g n)) +instance keySlotFinite (v : Template p I) : Fintype (KeySlots p v.t) := inferInstance +instance datumFinite (v : Template p I) (n N : ℕ) : Fintype (v.Datum n N) := inferInstance +set_option maxHeartbeats 800000 in +theorem twinned (v : Template p I) (z : Template p J) (M : ℕ) (hM : 1≤M) + (C ε : ℝ) (hε : 0<ε) : + ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n) + (w : Wgt (UnitType p n N)), IsLaw w → + let μ := raw m N; let ρ := pairW μ μ + let H := bp ((1/32:ℝ)*n) + (∀ x,mapW w Prod.fst x ≤ H*μ x) → (∀ x,mapW w Prod.snd x ≤ H*μ x) → + (∀ x,w x ≤ bp (C*N) *ρ x) → 2*num (Full p n) + avg (pairW ((v.singleP n).makeData (prodW u) x.1) + ((z.singleP n).makeData (prodW s) x.2)) T + pr w (fun x => ε≤ |f x-avg ρ f|) ≤ bp (-(1/16:ℝ)*n) := by + classical + let g := ownPort (p:=p) v.t; let b := ownPort (p:=p) z.t + let η := ε/5; have hη : 0<η := by positivity + let a := C*M+1 + obtain ⟨l,hl⟩ := Program.thin_calendar p M b a η (1/8) (by norm_num) hη hM + filter_upwards [Program.approx_calendar p M g (num Bool*num I) η hη hM, + Program.approx_calendar p M b (num Bool*num J) η hη hM, + hl (num (Fin l)*num J),paired_price M C] + with n hn ha hq hp N m w hw μ ρ H hA hB hw' hN u s hu hu' hs hs' T hT f + let f' := (v.singleP n).makeData (prodW u) (N:=N) + let g' := (z.singleP n).makeData (prodW s) (N:=N) + let d := bp (-(1/4:ℝ)*n); let τ := bp (-(1/8:ℝ)*n); let e := bp (-a*n) + have hx : approxData μ f' η d := hn m _ _ _ (prodW_law hu) hN + (free_price v n u hu hu' g (own_inj v)) + have hy : approxData μ g' η d := ha m _ _ _ (prodW_law hs) hN + (free_price z n s hs hs' b (own_inj z)) + have hz : thinData μ g' τ η e := hq m _ _ _ (prodW_law hs) hN + (free_price z n s hs hs' b (own_inj z)) + have hm : IsLaw μ := forum_law m hN + have he := paired_spread T f' g' hm hm hw + (fun x => Program.data_law _ _ _ (prodW_law hu)) + (fun x => Program.data_law _ _ _ (prodW_law hs)) + hT η d e τ hη (bp_pos _) (bp_pos _).le hx hy hz + _ _ (bp_pos _).le (bp_pos _).le hA hB hw' + rw [show 5*η=ε by unfold η; ring] at he + exact he.trans hp + +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ParameterExistence.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ParameterExistence.lean index c4612b8990c81be001fa9704718ac2942c1c0ec4..b7d54fe2d00afa7228fa99fbce40c3b3fbc7822e 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ParameterExistence.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ParameterExistence.lean @@ -1,161 +1,161 @@ -import OAI.Combinatorics.HadwigerCounterexample.AnalyticParameters - -namespace OAI - -/-! # Parameter Existence -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Matrix -open scoped BigOperators Topology -open StatusAnalysis StatusAnalysis.Station - -def birthG : ℕ := 10^9+1 -structure Ribbon (b : PreparationParameters) : Prop where - life : b.allows - hd : b.D=4000*birthG - mercury : b.L=bp 1000 - rain : (b.D:ℝ)+b.ζ ≤ (b.ζ-b.ζ/4)*b.e - hk : b.k≤ b.d - beam : b.spJoint+1 ≤ 0.49*b.k - dul : 3*b.d+2*b.e+2≤b.u - size : frameBills birthG b.pins+1000 ≤ b.B - dust : 2*b.ζ ≤0.004∧2*b.ζ*(56*((birthG-1:ℕ):ℝ))≤0.004 - -theorem floor_supply (x : ℝ) (y : ℝ) (hy : 0¬Q x) ≤ pr (pairW (onW w Q) (onW w Q)) P := by - classical - let v:=pairW w w; let u:= onW w Q; let Z (x : A×A) := Q x.1 ∧ Q x.2 - have hv := pairW_law hw hw - have h1 : pr v (fun x=>¬Z x) ≤ 2*pr w (fun x=>¬Q x) := by - let M (x : A×A) := ¬Q x.1; let T (x : A×A) := ¬Q x.2 - have hM : pr v M = pr w (fun x=>¬Q x) := by - have hh := pairW_pr w w (fun x=>¬Q x) (fun _=>True) - simpa only [and_true,pr_true,hw.total,mul_one] using hh - have hT : pr v T = pr w (fun x=>¬Q x) := by - have hh := pairW_pr w w (fun _=>True) (fun x=>¬Q x) - simpa only [true_and,pr_true,hw.total,one_mul] using hh - have hm x : ¬Z x → M x ∨ T x := by unfold M Z T; tauto - exact ((pr_mono hv.nz hm).trans (pr_or_le hv.nz)).trans_eq - (by rw [hM,hT,two_mul]) - have h2 : - pr v (fun x=> P x∧Z x) ≤ pr (pairW u u) P := by - have hh (i) (hi : Q i) : w i ≤ u i := by - unfold u; rw [onW_val,ind_one hi,mul_one] - exact (le_div_iff₀ hq).mpr ((mul_le_mul_of_nonneg_left - ((pr_le_tot hw.nz).trans hw.total.le) (hw.nz _)).trans_eq (mul_one _)) - unfold pr avg - refine Finset.sum_le_sum fun i _ => ?_ - dsimp only - by_cases hi : P i∧Z i - · rw [ind_one hi,ind_one hi.1,mul_one,mul_one] - exact mul_le_mul (hh _ hi.2.1) (hh _ hi.2.2) (hw.nz _) ((on_law hw.nz hq).nz _) - rw [ind_zero hi,mul_zero] - have huv : IsLaw u:=on_law hw.nz hq - exact mul_nonneg ((pairW_law huv huv).nz _) (ind_nonneg _) - exact (sub_le_sub_left h1 _).trans ((pr_shield hv.nz P Z).trans h2) - -/-- Compose several restrictions starting from union T. -P marks on prior union. T restrict -> P -> V union subset of P in T; -user-given skip bound in absolute w. -/ -theorem equity_trim (hw : ∀ x,0≤w x) (T V : A→Prop) (P : A→Prop) - (hf : ∀ x,V x → T x∧P x) - (hT : 0T x ∧ P x ∧ ¬V x) ≤ δ) : - let W := onW (onW w T) P; let z := pr w T*pr (onW w T) P - z-δ ≤ pr w V ∧ - (0?_⟩ - have ht : (fun x=> B x∧V x) = V := by ext x; exact ⟨And.right, fun h=>⟨hf x h,h⟩⟩ - have hu : pr W V=pr w V / pr w B := by unfold W; rw [pr_on,ht] - have hW : 0¬ V x)≤ δ/pr w B := by - unfold W; rw [pr_on] - refine div_le_div_of_nonneg_right ?_ hB.le - unfold B; simpa only [and_assoc] using hδ - rw [← h1] - exact (sub_le_sub_left (mul_le_mul_of_nonneg_left h2 (show (0:ℝ)≤2 by norm_num)) _).trans - (joint_trim (on_law hw hB) V hW Q) - -set_option maxHeartbeats 800000 in -theorem vigor_trim {l : Filter ℕ} (z : ℕ→ℝ) (hz : Tendsto z l atTop) - {A : ℕ→Type} [∀ i,Fintype (A i)] - (w : ∀ i,Wgt (A i)) (hw : ∀ᶠ i in l,∀ x,0 ≤ w i x) - (T V P : ∀ i,A i→Prop) {δ : ℕ→ℝ} (hδ : ExpSmall l z δ) - (hT : warm l z (fun i=>pr (w i) (T i))) - (hP : warm l z (fun i=>pr (onW (w i) (T i)) (P i))) - (hf : ∀ᶠ i in l,(∀ x,V i x → T i x ∧ P i x) ∧ - pr (w i) (fun x=>T i x∧ P i x∧¬V i x)≤δ i) : - warm l z (fun i=>pr (w i) (V i)) ∧ ∃ d : ℕ→ℝ, ExpSmall l z d ∧ - ∀ᶠ i in l, let W:=onW (onW (w i) (T i)) (P i); let X := onW (w i) (V i); - ∀ Q : A i×A i→Prop, pr (pairW W W) Q - d i ≤ pr (pairW X X) Q := by - classical - let c i:=pr (w i) (T i)*pr (onW (w i) (T i)) (P i) - have hc : warm l z c := hT.mul hP - let d i:= 2*(δ i / c i) - have hd : ExpSmall l z d := by - have hh := (hδ.mul hc.inv_cap).mul (expO_const hz 2) - unfold d - rw [show (fun i=>2*(δ i/c i))=(fun i=>δ i*(c i)⁻¹*2) from funext (fun i=>by rw [div_eq_mul_inv,mul_comm])] - exact hh - have he : - ∀ᶠ i in l,c i-δ i≤ pr (w i) (V i) ∧ (0< pr (w i) (V i) → - ∀ Q:A i × A i→Prop, let W:=onW (onW (w i) (T i)) (P i); let X:=onW (w i) (V i) - pr (pairW W W) Q-d i≤pr (pairW X X) Q) := by - filter_upwards [hw,hT.positive,hP.positive,hf] with i hi ht hv hf - exact equity_trim hi _ _ _ hf.1 ht hv hf.2 - have hV := (hc.survive hz hδ).mono (he.mono (fun i hi=> hi.1)) - exact ⟨hV,d,hd,(he.and hV.positive).mono fun i ⟨hi,hv⟩=>hi.2 hv⟩ -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.WeightedPartitions +import OAI.Combinatorics.HadwigerCounterexample.UltrafilterRates + +namespace OAI + +/-! # Partition Deletion Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Filter Finset + +variable {A B : Type} [Fintype A] {w : Wgt A} + +/-- power lost on further restriction: measure removed at most error and +including normalization does not hurt the lower bound. -/ +theorem joint_trim (hw : IsLaw w) (Q : A→Prop) (hq : 0¬Q x) ≤ pr (pairW (onW w Q) (onW w Q)) P := by + classical + let v:=pairW w w; let u:= onW w Q; let Z (x : A×A) := Q x.1 ∧ Q x.2 + have hv := pairW_law hw hw + have h1 : pr v (fun x=>¬Z x) ≤ 2*pr w (fun x=>¬Q x) := by + let M (x : A×A) := ¬Q x.1; let T (x : A×A) := ¬Q x.2 + have hM : pr v M = pr w (fun x=>¬Q x) := by + have hh := pairW_pr w w (fun x=>¬Q x) (fun _=>True) + simpa only [and_true,pr_true,hw.total,mul_one] using hh + have hT : pr v T = pr w (fun x=>¬Q x) := by + have hh := pairW_pr w w (fun _=>True) (fun x=>¬Q x) + simpa only [true_and,pr_true,hw.total,one_mul] using hh + have hm x : ¬Z x → M x ∨ T x := by unfold M Z T; tauto + exact ((pr_mono hv.nz hm).trans (pr_or_le hv.nz)).trans_eq + (by rw [hM,hT,two_mul]) + have h2 : + pr v (fun x=> P x∧Z x) ≤ pr (pairW u u) P := by + have hh (i) (hi : Q i) : w i ≤ u i := by + unfold u; rw [onW_val,ind_one hi,mul_one] + exact (le_div_iff₀ hq).mpr ((mul_le_mul_of_nonneg_left + ((pr_le_tot hw.nz).trans hw.total.le) (hw.nz _)).trans_eq (mul_one _)) + unfold pr avg + refine Finset.sum_le_sum fun i _ => ?_ + dsimp only + by_cases hi : P i∧Z i + · rw [ind_one hi,ind_one hi.1,mul_one,mul_one] + exact mul_le_mul (hh _ hi.2.1) (hh _ hi.2.2) (hw.nz _) ((on_law hw.nz hq).nz _) + rw [ind_zero hi,mul_zero] + have huv : IsLaw u:=on_law hw.nz hq + exact mul_nonneg ((pairW_law huv huv).nz _) (ind_nonneg _) + exact (sub_le_sub_left h1 _).trans ((pr_shield hv.nz P Z).trans h2) + +/-- Compose several restrictions starting from union T. +P marks on prior union. T restrict -> P -> V union subset of P in T; +user-given skip bound in absolute w. -/ +theorem equity_trim (hw : ∀ x,0≤w x) (T V : A→Prop) (P : A→Prop) + (hf : ∀ x,V x → T x∧P x) + (hT : 0T x ∧ P x ∧ ¬V x) ≤ δ) : + let W := onW (onW w T) P; let z := pr w T*pr (onW w T) P + z-δ ≤ pr w V ∧ + (0?_⟩ + have ht : (fun x=> B x∧V x) = V := by ext x; exact ⟨And.right, fun h=>⟨hf x h,h⟩⟩ + have hu : pr W V=pr w V / pr w B := by unfold W; rw [pr_on,ht] + have hW : 0¬ V x)≤ δ/pr w B := by + unfold W; rw [pr_on] + refine div_le_div_of_nonneg_right ?_ hB.le + unfold B; simpa only [and_assoc] using hδ + rw [← h1] + exact (sub_le_sub_left (mul_le_mul_of_nonneg_left h2 (show (0:ℝ)≤2 by norm_num)) _).trans + (joint_trim (on_law hw hB) V hW Q) + +set_option maxHeartbeats 800000 in +theorem vigor_trim {l : Filter ℕ} (z : ℕ→ℝ) (hz : Tendsto z l atTop) + {A : ℕ→Type} [∀ i,Fintype (A i)] + (w : ∀ i,Wgt (A i)) (hw : ∀ᶠ i in l,∀ x,0 ≤ w i x) + (T V P : ∀ i,A i→Prop) {δ : ℕ→ℝ} (hδ : ExpSmall l z δ) + (hT : warm l z (fun i=>pr (w i) (T i))) + (hP : warm l z (fun i=>pr (onW (w i) (T i)) (P i))) + (hf : ∀ᶠ i in l,(∀ x,V i x → T i x ∧ P i x) ∧ + pr (w i) (fun x=>T i x∧ P i x∧¬V i x)≤δ i) : + warm l z (fun i=>pr (w i) (V i)) ∧ ∃ d : ℕ→ℝ, ExpSmall l z d ∧ + ∀ᶠ i in l, let W:=onW (onW (w i) (T i)) (P i); let X := onW (w i) (V i); + ∀ Q : A i×A i→Prop, pr (pairW W W) Q - d i ≤ pr (pairW X X) Q := by + classical + let c i:=pr (w i) (T i)*pr (onW (w i) (T i)) (P i) + have hc : warm l z c := hT.mul hP + let d i:= 2*(δ i / c i) + have hd : ExpSmall l z d := by + have hh := (hδ.mul hc.inv_cap).mul (expO_const hz 2) + unfold d + rw [show (fun i=>2*(δ i/c i))=(fun i=>δ i*(c i)⁻¹*2) from funext (fun i=>by rw [div_eq_mul_inv,mul_comm])] + exact hh + have he : + ∀ᶠ i in l,c i-δ i≤ pr (w i) (V i) ∧ (0< pr (w i) (V i) → + ∀ Q:A i × A i→Prop, let W:=onW (onW (w i) (T i)) (P i); let X:=onW (w i) (V i) + pr (pairW W W) Q-d i≤pr (pairW X X) Q) := by + filter_upwards [hw,hT.positive,hP.positive,hf] with i hi ht hv hf + exact equity_trim hi _ _ _ hf.1 ht hv hf.2 + have hV := (hc.survive hz hδ).mono (he.mono (fun i hi=> hi.1)) + exact ⟨hV,d,hd,(he.and hV.positive).mono fun i ⟨hi,hv⟩=>hi.2 hv⟩ +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PartitionSelection.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PartitionSelection.lean index a8f5f3ac7ade7d05c6bdbad43b7f042273b9afa1..509446eab8698841dbea210fe4fa10ed51d5b2f0 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PartitionSelection.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PartitionSelection.lean @@ -1,200 +1,200 @@ -import OAI.Combinatorics.HadwigerCounterexample.WeightedPartitions - -namespace OAI - -/-! # Partition Selection -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Function Finset -open scoped BigOperators -variable {p : Shape} {n N : ℕ} - -abbrev CTile (p : Shape) (n N : ℕ) := Finset (UnitType p n N) -abbrev Canopy (p : Shape) (n N : ℕ) := Tiles (UnitType p n N) - -structure Ripe (p : Shape) {n N} (w μ : Wgt (UnitType p n N)) - (S : CTile p n N) (a : Pin p n N) (D ζ : ℝ) (K : ℕ) : Prop where - pos : 0 < partMass w S - fixpin : ∀ x∈ S,a.agree x - bound : planRank a.sp≤K - clear : a.clear ζ (partW w S) - density x : partW w S x ≤ bp (D*N) * μ x - -variable {w μ : Wgt (UnitType p n N)} - -def dustPin (p : Shape) (n N : ℕ) : Pin p n N := Pin.make ⊥ 0 - -theorem first_ripe {ζ D : ℝ} {K : ℕ} (hz : 0 < ζ) (hz' : ζ < 1) (hn : 0 x∈R ∧ ¬ inTiles T x) ≤ bp (-ζ*N) := by - let a := dustPin p n N - have h x : a.agree x := by - intro i v hv - have hl : v = 0 := show v∈(⊥:Space _) from hv - rw [hl,Matrix.mulVec_zero,Matrix.mulVec_zero] - obtain ⟨T,hT,hU,hW⟩ := peel_family hz hz' hn hR hc hw R a (fun i _ => h i) hK - have he : planRank a.sp=0 := Finset.sum_eq_zero (fun i _ => finrank_bot ..) - refine ⟨T,hU,fun S h => ?_,hW⟩ - obtain ⟨hh,b,hb⟩ := hT S h - exact ⟨hh,b,hb.pos,hb.fixpin,by simpa only [he,zero_add] using hb.bound,hb.clear,hb.density⟩ - -theorem ripe_restrict (hw : ∀ x,0≤w x) {S Y} {a : Pin p n N} {D ζ : ℝ} {K : ℕ} - (h : Ripe p w μ S a D ζ K) (hz : 0≤ζ) (he : Y⊆S) - (hp : bp (-ζ*N) ≤ partMass (partW w S) Y) : - Ripe p w μ Y a (D+ζ) (2*ζ) K := by - classical - let v := partW w S - have hv : IsLaw v := on_law hw h.pos - have ht := lt_of_lt_of_le (bp_pos _) hp - have hh := on_mon hv.nz (bp_pos _) hp - obtain ⟨h1,h2⟩ := issued_law w hw h.pos he ht - have hk (x) : partW w Y x ≤ bp (ζ*N) * v x := by - rw [h2] - have hg := hh x - rw [neg_mul,bp_neg, inv_inv] at hg - exact hg - have hy : IsLaw (partW w Y) := on_law hw h1 - refine ⟨h1,fun x hx => h.fixpin x (he hx),h.bound,fun b => ?_,fun x => ?_⟩ - · let r := planNew a.sp b.sp - by_cases hr : r=0 - · change pr _ _ ≤ fee N _ r - rw [hr] - simp only [fee,Nat.cast_zero,mul_zero,zero_mul,bp_zero] - exact (pr_le_tot hy.nz).trans hy.total.le - apply ((pr_cap hk _).trans - (mul_le_mul_of_nonneg_left (h.clear b) (bp_pos _).le)).trans - change bp (ζ*N)*fee N ζ r ≤ fee N (2*ζ) r - rw [fee,fee,←bp_add] - apply bp_le - have hh : 1≤(r:ℝ) := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr hr - have he := mul_le_mul_of_nonneg_right hh (mul_nonneg hz - (show 0≤(N:ℝ) from Nat.cast_nonneg _)) - linarith only [he] - exact ((hk x).trans (mul_le_mul_of_nonneg_left (h.density x) (bp_pos _).le)).trans_eq - (by rw [add_mul,bp_add]; ring) - -theorem trim (P : UnitType p n N→Prop) (hw : ∀ x,0≤w x) {D ζ : ℝ} (hz : 0≤ζ) {K} - {T : Canopy p n N} (hT : apart T) (g : CTile p n N → Pin p n N) - (h : ∀ i∈T,Ripe p w μ i (g i) D ζ K) : - ∃ V : Canopy p n N,apart V ∧ - (∀ S∈V,∃ i∈T,S⊆i ∧ Ripe p w μ S (g i) (D+ζ) (2*ζ) K ∧ ∀ x∈S,P x) ∧ - pr w (fun x => inTiles T x ∧ P x ∧ ¬inTiles V x) ≤ allMass w T*bp (-ζ*N) := by - classical - refine improve T w hw P (fun i S => Ripe p w μ S (g i) (D+ζ) (2*ζ) K ∧ ∀ x∈S,P x) - hT (fun i hi => ?_) - let S := i.filter P - have hs : S⊆i := Finset.filter_subset _ _ - let v := partW w i - by_cases he : bp (-ζ*N) ≤ partMass v S - · refine ⟨{S},?_,?_,?_⟩ - · intro x S h T h'; rw [mem_singleton.mp h,mem_singleton.mp h']; simp only [implies_true] - · intro j hj; rw [mem_singleton.mp hj] - exact ⟨hs,ripe_restrict hw (h i hi) hz hs he,fun x h => (mem_filter.mp h).2⟩ - have hh : (fun x => x∈i∧ P x∧ ¬inTiles ({S}:Tiles _) x)=(fun _ => False) := by - ext x; simp [S,inTiles]; tauto - rw [hh,pr_false]; exact (bp_pos _).le - refine ⟨∅,by intro x S h; simp at h, by simp,?_⟩ - have hh (x : UnitType p n N) : x∈S ↔ x∈i∧ P x := by simp [S] - have hn := le_of_not_ge he - unfold partMass at hn - simp_rw [hh] at hn - simpa [inTiles,v] using hn - -variable {I : Type} [Fintype I] - -set_option maxHeartbeats 700000 in -theorem reparts (w μ : Wgt (UnitType p n N)) - (hw : IsLaw w) (S : CTile p n N) (D ζ u : ℝ) (hn : 0 x∈S∧ ¬inTiles V x)≤ - (num I*bp (-u*N)) + bp (-ζ*N) := by - classical - let X := UnitType p n N - let F (i : I) := S.filter (fun x => f x=i) - have hF (i : I) (x : X) : x∈F i ↔ x∈ S ∧ f x=i := mem_filter - choose b hb hL hP using h - let R (G : Finset X) (b : Pin p n N) := Ripe p w μ G b (D+u+K2+1) ζ (K1+K2) ∧ P G b - let C := bp (-ζ*N); let t := bp (-u*N) - have ht (i : I) : - ∃ V : Tiles X, apart V ∧ (∀ G∈V,G⊆F i∧∃ b,R G b) ∧ - pr w (fun x => x∈F i ∧ ¬inTiles V x)≤t+partMass w (F i)*C := by - let S' := F i - let v := partW w S' - by_cases hi : t≤partMass w (F i) - · have ht := lt_of_lt_of_le (bp_pos _ : 0 hb i x ((hF ..).mp h).1 ((hF ..).mp h).2) hK - refine ⟨G,hA,fun S h => ?_,?_⟩ - · obtain ⟨hh,b',hp⟩ := hG S h - obtain ⟨hz,hzm,_⟩ := exists_of_pr_pos hv.nz hp.pos - obtain ⟨h1,h2⟩ := issued_law w hw.nz ht hh hp.pos - refine ⟨hh,b',⟨h1,hp.fixpin,(hp.bound.trans (Nat.add_le_add_right (hL _) _)),?_,?_⟩, - hP i _ _ ⟨hz,hzm⟩ (fun x hx => (hF ..).mp (hh hx)) hp.extendsSp⟩ - · rw [h2]; exact hp.clear - rw [h2]; exact hp.density - · rw [pr_of_on hw.nz (fun x => x∈ F i)] - have hh : pr v (fun x => ¬inTiles G x) = pr v (fun x => x∈F i ∧ ¬inTiles G x) := by - apply avg_congr - intro x h; simp only [show x∈F i from (onW_ne h).1,true_and] - refine le_trans (mul_le_mul_of_nonneg_left (hh.trans_le hB) ht.le) ?_ - exact le_add_of_nonneg_left (bp_pos _).le - · refine ⟨∅,(fun x S h => ?_),by simp,?_⟩ - · simp at h - apply le_trans (pr_mono hw.nz (q:=fun x => x∈F i) fun _ => And.left) - ((le_of_not_ge hi).trans ?_) - exact le_add_of_nonneg_right (mul_nonneg (pr_nonneg hw.nz) (bp_pos _).le) - choose V hV h1 h2 using ht - let G := Finset.univ.biUnion V - refine ⟨G,?_,?_,?_⟩ - · intro x S hS T hT h hx - obtain ⟨i,_,hi⟩ := Finset.mem_biUnion.mp hS - obtain ⟨j,_,hj⟩ := Finset.mem_biUnion.mp hT - obtain rfl : i=j := ((hF ..).mp ((h1 i S hi).1 h)).2.symm.trans - ((hF ..).mp ((h1 j T hj).1 hx)).2 - exact hV i x S hi T hj h hx - · intro S h - obtain ⟨i,_,hi⟩ := Finset.mem_biUnion.mp h - obtain ⟨h,h'⟩ := h1 i S hi - exact ⟨h.trans (Finset.filter_subset _ _),h'⟩ - · let Q (i : I) := fun x : X => x∈ F i ∧ ¬inTiles (V i) x - have hf x (h : x∈ S∧¬inTiles G x) : ∃ i,Q i x := by - refine ⟨f x,(hF ..).mpr ⟨h.1,rfl⟩,?_⟩ - rintro ⟨T,hT,h'⟩ - exact h.2 ⟨T,Finset.mem_biUnion.mpr ⟨_,Finset.mem_univ (f x),hT⟩,h'⟩ - refine ((pr_mono hw.nz hf).trans ((pr_exists_le hw.nz Q).trans - (Finset.sum_le_sum fun i _ => h2 i))).trans ?_ - rw [Finset.sum_add_distrib] - have ht : (∑ i, partMass w (F i)) ≤ 1 := by - simp_rw [partMass, hF,sum_pr_tag] - exact (pr_le_tot hw.nz).trans hw.total.le - calc (∑ _ : I,t)+∑ i,partMass w (F i)*C ≤ num I*t+1*C := by - rw [← Finset.sum_mul] - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,num] - exact add_le_add_right (mul_le_mul_of_nonneg_right ht (bp_pos _).le) _ - _ = _ := by rw [one_mul] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.WeightedPartitions + +namespace OAI + +/-! # Partition Selection -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Function Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} + +abbrev CTile (p : Shape) (n N : ℕ) := Finset (UnitType p n N) +abbrev Canopy (p : Shape) (n N : ℕ) := Tiles (UnitType p n N) + +structure Ripe (p : Shape) {n N} (w μ : Wgt (UnitType p n N)) + (S : CTile p n N) (a : Pin p n N) (D ζ : ℝ) (K : ℕ) : Prop where + pos : 0 < partMass w S + fixpin : ∀ x∈ S,a.agree x + bound : planRank a.sp≤K + clear : a.clear ζ (partW w S) + density x : partW w S x ≤ bp (D*N) * μ x + +variable {w μ : Wgt (UnitType p n N)} + +def dustPin (p : Shape) (n N : ℕ) : Pin p n N := Pin.make ⊥ 0 + +theorem first_ripe {ζ D : ℝ} {K : ℕ} (hz : 0 < ζ) (hz' : ζ < 1) (hn : 0 x∈R ∧ ¬ inTiles T x) ≤ bp (-ζ*N) := by + let a := dustPin p n N + have h x : a.agree x := by + intro i v hv + have hl : v = 0 := show v∈(⊥:Space _) from hv + rw [hl,Matrix.mulVec_zero,Matrix.mulVec_zero] + obtain ⟨T,hT,hU,hW⟩ := peel_family hz hz' hn hR hc hw R a (fun i _ => h i) hK + have he : planRank a.sp=0 := Finset.sum_eq_zero (fun i _ => finrank_bot ..) + refine ⟨T,hU,fun S h => ?_,hW⟩ + obtain ⟨hh,b,hb⟩ := hT S h + exact ⟨hh,b,hb.pos,hb.fixpin,by simpa only [he,zero_add] using hb.bound,hb.clear,hb.density⟩ + +theorem ripe_restrict (hw : ∀ x,0≤w x) {S Y} {a : Pin p n N} {D ζ : ℝ} {K : ℕ} + (h : Ripe p w μ S a D ζ K) (hz : 0≤ζ) (he : Y⊆S) + (hp : bp (-ζ*N) ≤ partMass (partW w S) Y) : + Ripe p w μ Y a (D+ζ) (2*ζ) K := by + classical + let v := partW w S + have hv : IsLaw v := on_law hw h.pos + have ht := lt_of_lt_of_le (bp_pos _) hp + have hh := on_mon hv.nz (bp_pos _) hp + obtain ⟨h1,h2⟩ := issued_law w hw h.pos he ht + have hk (x) : partW w Y x ≤ bp (ζ*N) * v x := by + rw [h2] + have hg := hh x + rw [neg_mul,bp_neg, inv_inv] at hg + exact hg + have hy : IsLaw (partW w Y) := on_law hw h1 + refine ⟨h1,fun x hx => h.fixpin x (he hx),h.bound,fun b => ?_,fun x => ?_⟩ + · let r := planNew a.sp b.sp + by_cases hr : r=0 + · change pr _ _ ≤ fee N _ r + rw [hr] + simp only [fee,Nat.cast_zero,mul_zero,zero_mul,bp_zero] + exact (pr_le_tot hy.nz).trans hy.total.le + apply ((pr_cap hk _).trans + (mul_le_mul_of_nonneg_left (h.clear b) (bp_pos _).le)).trans + change bp (ζ*N)*fee N ζ r ≤ fee N (2*ζ) r + rw [fee,fee,←bp_add] + apply bp_le + have hh : 1≤(r:ℝ) := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr hr + have he := mul_le_mul_of_nonneg_right hh (mul_nonneg hz + (show 0≤(N:ℝ) from Nat.cast_nonneg _)) + linarith only [he] + exact ((hk x).trans (mul_le_mul_of_nonneg_left (h.density x) (bp_pos _).le)).trans_eq + (by rw [add_mul,bp_add]; ring) + +theorem trim (P : UnitType p n N→Prop) (hw : ∀ x,0≤w x) {D ζ : ℝ} (hz : 0≤ζ) {K} + {T : Canopy p n N} (hT : apart T) (g : CTile p n N → Pin p n N) + (h : ∀ i∈T,Ripe p w μ i (g i) D ζ K) : + ∃ V : Canopy p n N,apart V ∧ + (∀ S∈V,∃ i∈T,S⊆i ∧ Ripe p w μ S (g i) (D+ζ) (2*ζ) K ∧ ∀ x∈S,P x) ∧ + pr w (fun x => inTiles T x ∧ P x ∧ ¬inTiles V x) ≤ allMass w T*bp (-ζ*N) := by + classical + refine improve T w hw P (fun i S => Ripe p w μ S (g i) (D+ζ) (2*ζ) K ∧ ∀ x∈S,P x) + hT (fun i hi => ?_) + let S := i.filter P + have hs : S⊆i := Finset.filter_subset _ _ + let v := partW w i + by_cases he : bp (-ζ*N) ≤ partMass v S + · refine ⟨{S},?_,?_,?_⟩ + · intro x S h T h'; rw [mem_singleton.mp h,mem_singleton.mp h']; simp only [implies_true] + · intro j hj; rw [mem_singleton.mp hj] + exact ⟨hs,ripe_restrict hw (h i hi) hz hs he,fun x h => (mem_filter.mp h).2⟩ + have hh : (fun x => x∈i∧ P x∧ ¬inTiles ({S}:Tiles _) x)=(fun _ => False) := by + ext x; simp [S,inTiles]; tauto + rw [hh,pr_false]; exact (bp_pos _).le + refine ⟨∅,by intro x S h; simp at h, by simp,?_⟩ + have hh (x : UnitType p n N) : x∈S ↔ x∈i∧ P x := by simp [S] + have hn := le_of_not_ge he + unfold partMass at hn + simp_rw [hh] at hn + simpa [inTiles,v] using hn + +variable {I : Type} [Fintype I] + +set_option maxHeartbeats 700000 in +theorem reparts (w μ : Wgt (UnitType p n N)) + (hw : IsLaw w) (S : CTile p n N) (D ζ u : ℝ) (hn : 0 x∈S∧ ¬inTiles V x)≤ + (num I*bp (-u*N)) + bp (-ζ*N) := by + classical + let X := UnitType p n N + let F (i : I) := S.filter (fun x => f x=i) + have hF (i : I) (x : X) : x∈F i ↔ x∈ S ∧ f x=i := mem_filter + choose b hb hL hP using h + let R (G : Finset X) (b : Pin p n N) := Ripe p w μ G b (D+u+K2+1) ζ (K1+K2) ∧ P G b + let C := bp (-ζ*N); let t := bp (-u*N) + have ht (i : I) : + ∃ V : Tiles X, apart V ∧ (∀ G∈V,G⊆F i∧∃ b,R G b) ∧ + pr w (fun x => x∈F i ∧ ¬inTiles V x)≤t+partMass w (F i)*C := by + let S' := F i + let v := partW w S' + by_cases hi : t≤partMass w (F i) + · have ht := lt_of_lt_of_le (bp_pos _ : 0 hb i x ((hF ..).mp h).1 ((hF ..).mp h).2) hK + refine ⟨G,hA,fun S h => ?_,?_⟩ + · obtain ⟨hh,b',hp⟩ := hG S h + obtain ⟨hz,hzm,_⟩ := exists_of_pr_pos hv.nz hp.pos + obtain ⟨h1,h2⟩ := issued_law w hw.nz ht hh hp.pos + refine ⟨hh,b',⟨h1,hp.fixpin,(hp.bound.trans (Nat.add_le_add_right (hL _) _)),?_,?_⟩, + hP i _ _ ⟨hz,hzm⟩ (fun x hx => (hF ..).mp (hh hx)) hp.extendsSp⟩ + · rw [h2]; exact hp.clear + rw [h2]; exact hp.density + · rw [pr_of_on hw.nz (fun x => x∈ F i)] + have hh : pr v (fun x => ¬inTiles G x) = pr v (fun x => x∈F i ∧ ¬inTiles G x) := by + apply avg_congr + intro x h; simp only [show x∈F i from (onW_ne h).1,true_and] + refine le_trans (mul_le_mul_of_nonneg_left (hh.trans_le hB) ht.le) ?_ + exact le_add_of_nonneg_left (bp_pos _).le + · refine ⟨∅,(fun x S h => ?_),by simp,?_⟩ + · simp at h + apply le_trans (pr_mono hw.nz (q:=fun x => x∈F i) fun _ => And.left) + ((le_of_not_ge hi).trans ?_) + exact le_add_of_nonneg_right (mul_nonneg (pr_nonneg hw.nz) (bp_pos _).le) + choose V hV h1 h2 using ht + let G := Finset.univ.biUnion V + refine ⟨G,?_,?_,?_⟩ + · intro x S hS T hT h hx + obtain ⟨i,_,hi⟩ := Finset.mem_biUnion.mp hS + obtain ⟨j,_,hj⟩ := Finset.mem_biUnion.mp hT + obtain rfl : i=j := ((hF ..).mp ((h1 i S hi).1 h)).2.symm.trans + ((hF ..).mp ((h1 j T hj).1 hx)).2 + exact hV i x S hi T hj h hx + · intro S h + obtain ⟨i,_,hi⟩ := Finset.mem_biUnion.mp h + obtain ⟨h,h'⟩ := h1 i S hi + exact ⟨h.trans (Finset.filter_subset _ _),h'⟩ + · let Q (i : I) := fun x : X => x∈ F i ∧ ¬inTiles (V i) x + have hf x (h : x∈ S∧¬inTiles G x) : ∃ i,Q i x := by + refine ⟨f x,(hF ..).mpr ⟨h.1,rfl⟩,?_⟩ + rintro ⟨T,hT,h'⟩ + exact h.2 ⟨T,Finset.mem_biUnion.mpr ⟨_,Finset.mem_univ (f x),hT⟩,h'⟩ + refine ((pr_mono hw.nz hf).trans ((pr_exists_le hw.nz Q).trans + (Finset.sum_le_sum fun i _ => h2 i))).trans ?_ + rw [Finset.sum_add_distrib] + have ht : (∑ i, partMass w (F i)) ≤ 1 := by + simp_rw [partMass, hF,sum_pr_tag] + exact (pr_le_tot hw.nz).trans hw.total.le + calc (∑ _ : I,t)+∑ i,partMass w (F i)*C ≤ num I*t+1*C := by + rw [← Finset.sum_mul] + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,num] + exact add_le_add_right (mul_le_mul_of_nonneg_right ht (bp_pos _).le) _ + _ = _ := by rw [one_mul] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseAlternativeSupport.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseAlternativeSupport.lean index f4d9eb2f5163af24c213015914bfd470fbe3110b..ef7a656aa40402e4ca02c2aba9f8319831765f94 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseAlternativeSupport.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseAlternativeSupport.lean @@ -1,169 +1,169 @@ -import OAI.Combinatorics.HadwigerCounterexample.AdaptiveRecordBounds -import OAI.Combinatorics.HadwigerCounterexample.PhaseMomentBounds - -namespace OAI - -/-! # Phase Alternative Support -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Function Finset -open scoped BigOperators -variable {p : Shape} {n N r : ℕ} -variable {A : Type} [Fintype A] - -theorem onW_ne {w : Wgt A} {P : A→Prop} {x : A} (h : onW w P x≠0) : P x ∧ w x≠0 := by - have hh : subW w P x≠0 := fun hx => h (by unfold onW normW; rw [hx,zero_div]) - exact ⟨Classical.byContradiction (fun hx => hh (subW_carried _ _ _ hx)), - left_ne_zero_of_mul hh⟩ - -theorem on_law {w : Wgt A} (hw : ∀ x,0 ≤ w x) {P : A→Prop} (hp : 0 True)=w := by - funext x - simp only [onW_val,ind_true,mul_one,pr_true,h.total,div_one] -theorem on_both (w : Wgt A) (p q : A→Prop) (h : ∀ x,0≤ w x) (hp : 0 p x∧q x) := by - funext x - rw [onW_val,onW_val,onW_val,pr_of_on h p q,ind_and] - field_simp - -theorem pr_shield {w : Wgt A} (h : ∀ x,0≤w x) (P Q : A→Prop) : - pr w P-pr w (fun x => ¬Q x) ≤ pr w (fun x => P x ∧ Q x) := by - have ht x : P x → (P x∧Q x) ∨ ¬Q x := fun h => by by_cases he:Q x <;> simp [h,he] - exact sub_le_iff_le_add.mpr ((pr_mono h ht).trans (pr_or_le h)) - -def rhUp (H c : ℝ) := (c/2)⁻¹ * H -theorem bySide_on {w : Wgt (UnitType p n N)} (m : Mixer p n) - {H : ℝ} (hw : ∀ x,0≤w x) (hh : bySide p w m H) - (P : UnitType p n N → Prop) {c : ℝ} (hc : 0 avg_congr (fun y hy => ?_)) - exact congrArg wsign (add_comm _ _) - -theorem tonal_left (Δ : UnitType p n N → Ambient p N) (w) - (h : ∀ S R,S≠0 → |pitch p Δ w S R|<0.005) : tonalMix p Δ w := by - rintro S R (he|he) - · exact h _ _ he - rw [pitch_turn]; exact h _ _ he - -theorem glimpse_sub (x : UnitType p n N) (i : Bool) (C : Cov p N) {q : Place p→ℕ} - (A : DTuple (p:=p) q N) (h : ∀ z,colSp (A z) ≤ C z) (hA : ∀ z,Injective (A z).mulVec) - (hg : glimpse p x i (q:=fun z => dim (C z)) (fun z => pack (C z))) : - glimpse p x i A := by - classical - intro z - obtain ⟨X,hX⟩ := pull_cols (pack (C z)) (A z) (by rw [colSp_pack]; exact h z) - have hI : Injective X.mulVec := by - have ht := hA z - rw [←hX] at ht - intro a b h - apply ht - rw [← Matrix.mulVec_mulVec,← Matrix.mulVec_mulVec,h] - rw [←hX,← Matrix.mul_assoc]; exact inj_comp_mat _ _ (hg z) hI - -def preGlimpse (x : UnitType p n N) (C : Cov p N) := - ∀ i,glimpse p x i (q:=fun z => dim (C z)) (fun z => pack (C z)) - -theorem glimpse_cover_failure {w : Wgt (UnitType p n N)} (hv : SubLaw w) (m : Mixer p n) - {L : ℝ} (h : bySide p w m L) (hL : 0 ≤ L) - (C : Cov p N) (d : ℕ) (hd : cdim p C≤d) - (hN : 2*num (Full p n)-N ≤ -1) : - pr w (fun x => ¬preGlimpse x C) ≤ 2*glimpsesBill p d L := by - classical - let M : DTuple (p:=p) (fun z => dim (C z)) N := fun z => pack (C z) - let P (i : Bool) := fun x : UnitType p n N => ¬glimpse p x i M - have hp x : ¬preGlimpse x C → ∃ i,P i x := by - intro h - unfold preGlimpse at h; push Not at h; exact h - have hh z : dim (C z) ≤ d := - (Finset.single_le_sum (fun z _ => Nat.zero_le (dim (C z))) (Finset.mem_univ z)).trans hd - refine ((pr_mono hv.nz hp).trans (pr_exists_le hv.nz P)).trans ?_ - rw [Fintype.sum_bool,two_mul] - exact add_le_add (glimpse_failure m hL h hv true hN M d (fun z => pack_inj _) hh) - (glimpse_failure m hL h hv false hN M d (fun z => pack_inj _) hh) - -namespace Bazaar - -variable {T : Cov p N} -variable (s : Bazaar p n r T) - -set_option maxHeartbeats 600000 in -theorem cover_options (Δ : UnitType p n N →Ambient p N) (w : Wgt (UnitType p n N)) - (m : Mixer p n) {ε L H l : ℝ} (hw : IsLaw w) (h : s.opened Δ w) - (hem : IsLaw (raw m N)) (hi : initCap p N m ε) - (hl : 0 ≤ L) (he₀ : 0< l) (he' : l≤1) (hL : bySide p w m L) - (hH : 0 ≤ H) (hF : ∀ x,w x≤H*pairW (raw m N) (raw m N) x) - (hN : 2*num (Full p n)-N≤ -1) - (ht : num (Atlas p r T) ≤ bp (0.002*N)) - (hd : selPrice p r n N L ε) (hd' : selPrice p r n N (rhUp L l) ε) - (k d : ℕ) (hK : k≤d) (hQ : quest p r k n N H ε) - (hk : glimpsesBill p k L+bp (-0.1*N) offsetCov (s.ix x) ≤ C - by_cases hh : ∀ C,cdim p C≤d → pr w (bite C) ≤ l - · refine ⟨fun _ => True,by rw [pr_true,hw.total]; linarith, Or.inl ?_⟩ - rw [onW_true w hw]; apply tonal_left Δ w - intro S R hS - obtain ⟨j,hj⟩ : ∃ i,S i=1 := by - by_contra! he - exact hS (funext fun i => (bit_cases (S i)).resolve_right (he i)) - have heq := s.calm_pitch h hw j R S m hem hi hl hL hd ht - have hφ := s.frequent_sparse hw h S j hj k d hK l he₀ hh - (fun A G Z => s.bids_bound S j A G Z hw.sub (bag_rate m hl hem hi hw.sub hL h hd G j)) - m hN hi hH hQ hF hl hL ht hk - exact ((heq.trans (add_le_add_left hφ _))).trans_lt hψ - push Not at hh - obtain ⟨C,hC,hX⟩ := hh - let P := fun x : UnitType p n N => bite C x ∧ preGlimpse x C - have hp : l/2≤pr w P := by - have ht := glimpse_cover_failure hw.sub m hL hl C d hC hN - have hh := pr_shield hw.nz (bite C) (fun x => preGlimpse x C) - change _ ≤ pr w P at hh - linarith only [hh,hg,ht,hX] - let v := onW w P - have hv : IsLaw v := on_law hw.nz (lt_of_lt_of_le (half_pos he₀) hp) - have he x (h' : v x≠0) : standard (s.ix x) ∧ ∀ i, compFor (s.ix x) - (s.bag (s.ix x) i x) (imageP p x i) (Δ x) := h x (onW_ne h').2 - have ht' (x y : UnitType p n N) (hx : v x≠0) (hy : v y≠0) (i) : - glimpse p y i (src (s.ix x)) := by - have hh := he x hx - exact glimpse_sub y i C _ (onW_ne hx).1.1 hh.1.2.2 ((onW_ne hy).1.2 i) - have hUp := bySide_on m hw.nz hL P he₀ hp - refine ⟨P,hp,Or.inr ⟨C,hC,fun x hx => ?_,fun i R => ?_⟩⟩ - · obtain h := ((he x hx).2 true).2 - rw [h]; exact covered_spelled (s.ix x) _ C (onW_ne hx).1.1 - exact (s.single_pitch he hv i R m hem hi (by unfold rhUp; positivity) hUp hd' ht hN).2 - (fun x hx y hy => ht' x y hx hy i) - -end Bazaar -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.AdaptiveRecordBounds +import OAI.Combinatorics.HadwigerCounterexample.PhaseMomentBounds + +namespace OAI + +/-! # Phase Alternative Support -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Function Finset +open scoped BigOperators +variable {p : Shape} {n N r : ℕ} +variable {A : Type} [Fintype A] + +theorem onW_ne {w : Wgt A} {P : A→Prop} {x : A} (h : onW w P x≠0) : P x ∧ w x≠0 := by + have hh : subW w P x≠0 := fun hx => h (by unfold onW normW; rw [hx,zero_div]) + exact ⟨Classical.byContradiction (fun hx => hh (subW_carried _ _ _ hx)), + left_ne_zero_of_mul hh⟩ + +theorem on_law {w : Wgt A} (hw : ∀ x,0 ≤ w x) {P : A→Prop} (hp : 0 True)=w := by + funext x + simp only [onW_val,ind_true,mul_one,pr_true,h.total,div_one] +theorem on_both (w : Wgt A) (p q : A→Prop) (h : ∀ x,0≤ w x) (hp : 0 p x∧q x) := by + funext x + rw [onW_val,onW_val,onW_val,pr_of_on h p q,ind_and] + field_simp + +theorem pr_shield {w : Wgt A} (h : ∀ x,0≤w x) (P Q : A→Prop) : + pr w P-pr w (fun x => ¬Q x) ≤ pr w (fun x => P x ∧ Q x) := by + have ht x : P x → (P x∧Q x) ∨ ¬Q x := fun h => by by_cases he:Q x <;> simp [h,he] + exact sub_le_iff_le_add.mpr ((pr_mono h ht).trans (pr_or_le h)) + +def rhUp (H c : ℝ) := (c/2)⁻¹ * H +theorem bySide_on {w : Wgt (UnitType p n N)} (m : Mixer p n) + {H : ℝ} (hw : ∀ x,0≤w x) (hh : bySide p w m H) + (P : UnitType p n N → Prop) {c : ℝ} (hc : 0 avg_congr (fun y hy => ?_)) + exact congrArg wsign (add_comm _ _) + +theorem tonal_left (Δ : UnitType p n N → Ambient p N) (w) + (h : ∀ S R,S≠0 → |pitch p Δ w S R|<0.005) : tonalMix p Δ w := by + rintro S R (he|he) + · exact h _ _ he + rw [pitch_turn]; exact h _ _ he + +theorem glimpse_sub (x : UnitType p n N) (i : Bool) (C : Cov p N) {q : Place p→ℕ} + (A : DTuple (p:=p) q N) (h : ∀ z,colSp (A z) ≤ C z) (hA : ∀ z,Injective (A z).mulVec) + (hg : glimpse p x i (q:=fun z => dim (C z)) (fun z => pack (C z))) : + glimpse p x i A := by + classical + intro z + obtain ⟨X,hX⟩ := pull_cols (pack (C z)) (A z) (by rw [colSp_pack]; exact h z) + have hI : Injective X.mulVec := by + have ht := hA z + rw [←hX] at ht + intro a b h + apply ht + rw [← Matrix.mulVec_mulVec,← Matrix.mulVec_mulVec,h] + rw [←hX,← Matrix.mul_assoc]; exact inj_comp_mat _ _ (hg z) hI + +def preGlimpse (x : UnitType p n N) (C : Cov p N) := + ∀ i,glimpse p x i (q:=fun z => dim (C z)) (fun z => pack (C z)) + +theorem glimpse_cover_failure {w : Wgt (UnitType p n N)} (hv : SubLaw w) (m : Mixer p n) + {L : ℝ} (h : bySide p w m L) (hL : 0 ≤ L) + (C : Cov p N) (d : ℕ) (hd : cdim p C≤d) + (hN : 2*num (Full p n)-N ≤ -1) : + pr w (fun x => ¬preGlimpse x C) ≤ 2*glimpsesBill p d L := by + classical + let M : DTuple (p:=p) (fun z => dim (C z)) N := fun z => pack (C z) + let P (i : Bool) := fun x : UnitType p n N => ¬glimpse p x i M + have hp x : ¬preGlimpse x C → ∃ i,P i x := by + intro h + unfold preGlimpse at h; push Not at h; exact h + have hh z : dim (C z) ≤ d := + (Finset.single_le_sum (fun z _ => Nat.zero_le (dim (C z))) (Finset.mem_univ z)).trans hd + refine ((pr_mono hv.nz hp).trans (pr_exists_le hv.nz P)).trans ?_ + rw [Fintype.sum_bool,two_mul] + exact add_le_add (glimpse_failure m hL h hv true hN M d (fun z => pack_inj _) hh) + (glimpse_failure m hL h hv false hN M d (fun z => pack_inj _) hh) + +namespace Bazaar + +variable {T : Cov p N} +variable (s : Bazaar p n r T) + +set_option maxHeartbeats 600000 in +theorem cover_options (Δ : UnitType p n N →Ambient p N) (w : Wgt (UnitType p n N)) + (m : Mixer p n) {ε L H l : ℝ} (hw : IsLaw w) (h : s.opened Δ w) + (hem : IsLaw (raw m N)) (hi : initCap p N m ε) + (hl : 0 ≤ L) (he₀ : 0< l) (he' : l≤1) (hL : bySide p w m L) + (hH : 0 ≤ H) (hF : ∀ x,w x≤H*pairW (raw m N) (raw m N) x) + (hN : 2*num (Full p n)-N≤ -1) + (ht : num (Atlas p r T) ≤ bp (0.002*N)) + (hd : selPrice p r n N L ε) (hd' : selPrice p r n N (rhUp L l) ε) + (k d : ℕ) (hK : k≤d) (hQ : quest p r k n N H ε) + (hk : glimpsesBill p k L+bp (-0.1*N) offsetCov (s.ix x) ≤ C + by_cases hh : ∀ C,cdim p C≤d → pr w (bite C) ≤ l + · refine ⟨fun _ => True,by rw [pr_true,hw.total]; linarith, Or.inl ?_⟩ + rw [onW_true w hw]; apply tonal_left Δ w + intro S R hS + obtain ⟨j,hj⟩ : ∃ i,S i=1 := by + by_contra! he + exact hS (funext fun i => (bit_cases (S i)).resolve_right (he i)) + have heq := s.calm_pitch h hw j R S m hem hi hl hL hd ht + have hφ := s.frequent_sparse hw h S j hj k d hK l he₀ hh + (fun A G Z => s.bids_bound S j A G Z hw.sub (bag_rate m hl hem hi hw.sub hL h hd G j)) + m hN hi hH hQ hF hl hL ht hk + exact ((heq.trans (add_le_add_left hφ _))).trans_lt hψ + push Not at hh + obtain ⟨C,hC,hX⟩ := hh + let P := fun x : UnitType p n N => bite C x ∧ preGlimpse x C + have hp : l/2≤pr w P := by + have ht := glimpse_cover_failure hw.sub m hL hl C d hC hN + have hh := pr_shield hw.nz (bite C) (fun x => preGlimpse x C) + change _ ≤ pr w P at hh + linarith only [hh,hg,ht,hX] + let v := onW w P + have hv : IsLaw v := on_law hw.nz (lt_of_lt_of_le (half_pos he₀) hp) + have he x (h' : v x≠0) : standard (s.ix x) ∧ ∀ i, compFor (s.ix x) + (s.bag (s.ix x) i x) (imageP p x i) (Δ x) := h x (onW_ne h').2 + have ht' (x y : UnitType p n N) (hx : v x≠0) (hy : v y≠0) (i) : + glimpse p y i (src (s.ix x)) := by + have hh := he x hx + exact glimpse_sub y i C _ (onW_ne hx).1.1 hh.1.2.2 ((onW_ne hy).1.2 i) + have hUp := bySide_on m hw.nz hL P he₀ hp + refine ⟨P,hp,Or.inr ⟨C,hC,fun x hx => ?_,fun i R => ?_⟩⟩ + · obtain h := ((he x hx).2 true).2 + rw [h]; exact covered_spelled (s.ix x) _ C (onW_ne hx).1.1 + exact (s.single_pitch he hv i R m hem hi (by unfold rhUp; positivity) hUp hd' ht hN).2 + (fun x hx y hy => ht' x y hx hy i) + +end Bazaar +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseClassCompatibility.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseClassCompatibility.lean index 09b63459dbdcca12b731bcff90b68aac85ddb3c8..887d1ef2d901572d08c6e63f4e3185285e957331 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseClassCompatibility.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseClassCompatibility.lean @@ -1,142 +1,142 @@ -import OAI.Combinatorics.HadwigerCounterexample.PredictionClasses -import OAI.Combinatorics.HadwigerCounterexample.PolynomialCompatibility - -namespace OAI - -/-! # Phase Class Compatibility -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Finset LinearMap -open scoped BigOperators -variable {p : Shape} {n N : ℕ} -namespace PredictionClass -def compatible (α : Party) (x : F) : PredictionClass→Quad→Prop -| dusk,v=> v=repeatQ x -| dawn i,v=> v.1 i+v.2 i=firstBit α i -| twinned,v=> dotProduct allSide v.1 +dotProduct allSide v.2=0 -| noon,_=> True - -def matchUp (Δ : UnitType p n N→Ambient p N) (α : Party) (x : F) - (c : PredictionClass) (v : UnitType p n N × UnitType p n N) := - c.compatible α x (quench p Δ v) - -theorem dusk_lit (α : Party) (h : dusk.lit α) : ∀ i,α i = 1 := fun i=>by - have hh : 1+α i=0 := h.1 i not_false - exact add_left_cancel (hh.trans (char_two 1).symm) -theorem meet (c : PredictionClass) (α : Party) (x : F) : ∃ v,c.compatible α x v := by - cases c - · exact ⟨_,rfl⟩ - · rename_i i; exact ⟨(0,fun _=>firstBit α i),zero_add _⟩ - · exact ⟨0, by simp [compatible]⟩ - exact ⟨0,trivial⟩ -end PredictionClass - -open PredictionClass - -def glint (p : Shape) {n} (x : Bool → Profile p n) := ∑ i, role p n (x i) -def exactInk (p : Shape) (m : Mixer p n) (z : BMark p n N) (x) := - ∀ i:Bool,silent (yoke p m x i (z x i) 1) - -theorem lone (p : Shape) {n N} (x : UnitType p n N) (i : Bool) (v : Ambient p N) : - tone p x (unary i) v= ufun (onSide x i) v := by - classical - unfold tone joinPhase unary; rw [Finset.sum_eq_single i] - · rw [Pi.single_eq_same,one_smul] - rw [show onSide (listens p x) i=hcube p (onSide x i) from by cases i<;>rfl, phase_actual] - · intro j _ h; simp [h] - simp - -theorem zero_delta (z : BMark p n N) (x : UnitType p n N) (h : delta z x=0) : - Uembed x.1 (z x true)=Uembed x.2 (z x false) := by - exact add_right_cancel (h.trans (char_two _).symm) - -theorem exactInner (m : Mixer p n) (z : BMark p n N) (x : UnitType p n N) - (h : exactInk p m z x) : - ∀ i, ∀ v∈Xspace p n,innerP p x i v = grad m (z x i) v := by - intro i v hv - have he := h i v hv - change innerP p x i v+(Tsym m (z x i) v +1*role p n v)=0 at he - rw [one_mul,add_comm (Tsym m (z x i) v),← grad_val] at he - exact add_right_cancel (he.trans (char_two _).symm) - -theorem delta_dusk (m : Mixer p n) (z : BMark p n N) (x : UnitType p n N) - (hx : ∀ i,z x i∈Xspace p n) - (h : exactInk p m z x) (hz : delta z x=0) - (he : (rawHoles m).unit x) (hi : ∀ i,frameLaw m (onSide x i)) : - glint p (z x)=0 := by - apply (bit_cases _).resolve_right - intro hh - have heq := exactInner m z x h - unfold glint at hh; rw [Fintype.sum_bool] at hh - apply he - exact ⟨hi true,hi false,z x true,z x false,hx _,hx _,zero_delta z x hz,heq true,heq false,hh⟩ - -theorem diag_dusk (m : Mixer p n) (z : BMark p n N) (x : UnitType p n N) - (hx : ∀ i,z x i∈Xspace p n) - (h : exactInk p m z x) (hi : ∀ i,frameLaw m (onSide x i)) : - tone p x allSide (delta z x)=0 := by - have he (i) : innerP p x i (z x i)=0 := by - rw [exactInner m z x h _ _ (hx i),grad_val,T_diag,char_two] - have he1 : ufun x.1 (mrAmbient z x false)=0 := he false - have he2 : ufun x.2 (mrAmbient z x true)=0 := he true - rw [tone_vec] - unfold dotProduct; simp_rw [Fintype.sum_bool,allSide,one_mul,lone,delta,map_add] - have h1 : ufun x.1 (mrAmbient z x true)=0 := ufun_self (hi true) _ - have h2 : ufun x.2 (mrAmbient z x false)=0 := ufun_self (hi false) _ - simp [onSide,h1,h2,he1,he2] - -theorem fade (c : PredictionClass) (α : Party) (r : F) - (h : c.lit α) (hα : α true=α false) (hd : c=dusk → r=0) - (Δ : UnitType p n N→Ambient p N) (x : UnitType p n N × UnitType p n N) - (hx : Δ x.1=0) (hy : Δ x.2=0) : - c.matchUp Δ α r x := by - classical - have ht : quench p Δ x=0 := by - unfold quench tone; rw [hx,hy] - simp only [map_zero]; rfl - unfold matchUp; rw [ht] - cases c - · rw [hd rfl]; rfl - · rename_i i - cases i - · have hh : firstBit α true=0 := h.1 true (show false≠true from Bool.false_ne_true) - unfold firstBit at hh; rw [hα] at hh - exact (zero_add _).trans hh.symm - have hh : firstBit α false=0 := h.1 false (show true≠false from Ne.symm Bool.false_ne_true) - unfold firstBit at hh; rw [←hα] at hh - exact (zero_add _).trans hh.symm - · simp [compatible] - trivial - -theorem tiny_morn (p : Shape) {n N : ℕ} (Δ : UnitType p n N→Ambient p N) - (w : Wgt (UnitType p n N)) (hw : IsLaw w) (d : ℕ) (h : tonalTiny p Δ w d) - (hN : bp (-0.24*N) < 0.1) (α r i) : - 0.4 ≤ pr (pairW w w) (matchUp Δ α r (dawn i)) := by - classical - obtain ⟨_,_,_,hx⟩:= h - have hi : |pitch p Δ w (unary i) (unary i)| ≤0.1 := (hx i _).trans hN.le - let P := matchUp Δ α r (dawn i) - let v := firstBit α i - let x (x : UnitType p n N×UnitType p n N) := - tone p x.1 (unary i) (Δ x.2)+tone p x.2 (unary i) (Δ x.1) - let C:=pairW w w - have he (j) : P j ↔ x j = v := by - unfold P matchUp compatible quench x v; simp only [add_comm] - have hU : pr C P=(1/2)*(avg C (fun _=>1)+wsign v * avg C (fun i=> wsign (x i))) := by - unfold pr - rw [←avg_mul',←avg_add,←avg_mul'] - apply avg_congr - intro i _ - rcases bit_cases v with h|h<;> rcases bit_cases (x i) with hx|hx <;> norm_num [he,h,hx,ind] - have hz := abs_le.mp hi - change |avg C (fun i=> wsign (x i))| ≤_ at hi - change _≤pr C P - rw [hU,(pairW_law hw hw).avg_const] - rcases bit_cases v with h|h <;> rw [h] <;> simp only [wsign_zero, wsign_one,one_mul,neg_mul] <;> - linarith only [(abs_le.mp hi).1,(abs_le.mp hi).2] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PredictionClasses +import OAI.Combinatorics.HadwigerCounterexample.PolynomialCompatibility + +namespace OAI + +/-! # Phase Class Compatibility -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Finset LinearMap +open scoped BigOperators +variable {p : Shape} {n N : ℕ} +namespace PredictionClass +def compatible (α : Party) (x : F) : PredictionClass→Quad→Prop +| dusk,v=> v=repeatQ x +| dawn i,v=> v.1 i+v.2 i=firstBit α i +| twinned,v=> dotProduct allSide v.1 +dotProduct allSide v.2=0 +| noon,_=> True + +def matchUp (Δ : UnitType p n N→Ambient p N) (α : Party) (x : F) + (c : PredictionClass) (v : UnitType p n N × UnitType p n N) := + c.compatible α x (quench p Δ v) + +theorem dusk_lit (α : Party) (h : dusk.lit α) : ∀ i,α i = 1 := fun i=>by + have hh : 1+α i=0 := h.1 i not_false + exact add_left_cancel (hh.trans (char_two 1).symm) +theorem meet (c : PredictionClass) (α : Party) (x : F) : ∃ v,c.compatible α x v := by + cases c + · exact ⟨_,rfl⟩ + · rename_i i; exact ⟨(0,fun _=>firstBit α i),zero_add _⟩ + · exact ⟨0, by simp [compatible]⟩ + exact ⟨0,trivial⟩ +end PredictionClass + +open PredictionClass + +def glint (p : Shape) {n} (x : Bool → Profile p n) := ∑ i, role p n (x i) +def exactInk (p : Shape) (m : Mixer p n) (z : BMark p n N) (x) := + ∀ i:Bool,silent (yoke p m x i (z x i) 1) + +theorem lone (p : Shape) {n N} (x : UnitType p n N) (i : Bool) (v : Ambient p N) : + tone p x (unary i) v= ufun (onSide x i) v := by + classical + unfold tone joinPhase unary; rw [Finset.sum_eq_single i] + · rw [Pi.single_eq_same,one_smul] + rw [show onSide (listens p x) i=hcube p (onSide x i) from by cases i<;>rfl, phase_actual] + · intro j _ h; simp [h] + simp + +theorem zero_delta (z : BMark p n N) (x : UnitType p n N) (h : delta z x=0) : + Uembed x.1 (z x true)=Uembed x.2 (z x false) := by + exact add_right_cancel (h.trans (char_two _).symm) + +theorem exactInner (m : Mixer p n) (z : BMark p n N) (x : UnitType p n N) + (h : exactInk p m z x) : + ∀ i, ∀ v∈Xspace p n,innerP p x i v = grad m (z x i) v := by + intro i v hv + have he := h i v hv + change innerP p x i v+(Tsym m (z x i) v +1*role p n v)=0 at he + rw [one_mul,add_comm (Tsym m (z x i) v),← grad_val] at he + exact add_right_cancel (he.trans (char_two _).symm) + +theorem delta_dusk (m : Mixer p n) (z : BMark p n N) (x : UnitType p n N) + (hx : ∀ i,z x i∈Xspace p n) + (h : exactInk p m z x) (hz : delta z x=0) + (he : (rawHoles m).unit x) (hi : ∀ i,frameLaw m (onSide x i)) : + glint p (z x)=0 := by + apply (bit_cases _).resolve_right + intro hh + have heq := exactInner m z x h + unfold glint at hh; rw [Fintype.sum_bool] at hh + apply he + exact ⟨hi true,hi false,z x true,z x false,hx _,hx _,zero_delta z x hz,heq true,heq false,hh⟩ + +theorem diag_dusk (m : Mixer p n) (z : BMark p n N) (x : UnitType p n N) + (hx : ∀ i,z x i∈Xspace p n) + (h : exactInk p m z x) (hi : ∀ i,frameLaw m (onSide x i)) : + tone p x allSide (delta z x)=0 := by + have he (i) : innerP p x i (z x i)=0 := by + rw [exactInner m z x h _ _ (hx i),grad_val,T_diag,char_two] + have he1 : ufun x.1 (mrAmbient z x false)=0 := he false + have he2 : ufun x.2 (mrAmbient z x true)=0 := he true + rw [tone_vec] + unfold dotProduct; simp_rw [Fintype.sum_bool,allSide,one_mul,lone,delta,map_add] + have h1 : ufun x.1 (mrAmbient z x true)=0 := ufun_self (hi true) _ + have h2 : ufun x.2 (mrAmbient z x false)=0 := ufun_self (hi false) _ + simp [onSide,h1,h2,he1,he2] + +theorem fade (c : PredictionClass) (α : Party) (r : F) + (h : c.lit α) (hα : α true=α false) (hd : c=dusk → r=0) + (Δ : UnitType p n N→Ambient p N) (x : UnitType p n N × UnitType p n N) + (hx : Δ x.1=0) (hy : Δ x.2=0) : + c.matchUp Δ α r x := by + classical + have ht : quench p Δ x=0 := by + unfold quench tone; rw [hx,hy] + simp only [map_zero]; rfl + unfold matchUp; rw [ht] + cases c + · rw [hd rfl]; rfl + · rename_i i + cases i + · have hh : firstBit α true=0 := h.1 true (show false≠true from Bool.false_ne_true) + unfold firstBit at hh; rw [hα] at hh + exact (zero_add _).trans hh.symm + have hh : firstBit α false=0 := h.1 false (show true≠false from Ne.symm Bool.false_ne_true) + unfold firstBit at hh; rw [←hα] at hh + exact (zero_add _).trans hh.symm + · simp [compatible] + trivial + +theorem tiny_morn (p : Shape) {n N : ℕ} (Δ : UnitType p n N→Ambient p N) + (w : Wgt (UnitType p n N)) (hw : IsLaw w) (d : ℕ) (h : tonalTiny p Δ w d) + (hN : bp (-0.24*N) < 0.1) (α r i) : + 0.4 ≤ pr (pairW w w) (matchUp Δ α r (dawn i)) := by + classical + obtain ⟨_,_,_,hx⟩:= h + have hi : |pitch p Δ w (unary i) (unary i)| ≤0.1 := (hx i _).trans hN.le + let P := matchUp Δ α r (dawn i) + let v := firstBit α i + let x (x : UnitType p n N×UnitType p n N) := + tone p x.1 (unary i) (Δ x.2)+tone p x.2 (unary i) (Δ x.1) + let C:=pairW w w + have he (j) : P j ↔ x j = v := by + unfold P matchUp compatible quench x v; simp only [add_comm] + have hU : pr C P=(1/2)*(avg C (fun _=>1)+wsign v * avg C (fun i=> wsign (x i))) := by + unfold pr + rw [←avg_mul',←avg_add,←avg_mul'] + apply avg_congr + intro i _ + rcases bit_cases v with h|h<;> rcases bit_cases (x i) with hx|hx <;> norm_num [he,h,hx,ind] + have hz := abs_le.mp hi + change |avg C (fun i=> wsign (x i))| ≤_ at hi + change _≤pr C P + rw [hU,(pairW_law hw hw).avg_const] + rcases bit_cases v with h|h <;> rw [h] <;> simp only [wsign_zero, wsign_one,one_mul,neg_mul] <;> + linarith only [(abs_le.mp hi).1,(abs_le.mp hi).2] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseMomentBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseMomentBounds.lean index bea5308d9bd3ba4d8fd883de9335daa443037f6c..551eda7159eb126bcc8ab9985656e939878ff846 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseMomentBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseMomentBounds.lean @@ -1,175 +1,175 @@ -import OAI.Combinatorics.HadwigerCounterexample.IndependentPhaseBounds - -namespace OAI - -/-! # Phase Moment Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Finset -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {A : Type} [Fintype A] - -theorem poweravg (w f : Wgt A) (s : ℕ) : - avg w f ^ s=avg (draws (Fin s) w) (fun x => ∏ i : Fin s,f (x i)) := by - classical - change _=avg (prodW _) (prodW (fun _ : Fin s => f)) - rw [prodW_avg]; simp - -def sweep (p : Shape) {N} (f : A→Ambient p N) (w g : Wgt A) (S : Party) - (q : PhasePair p N) := avg w (fun x => g x*wsign (joinPhase p q S (f x))) - -theorem phase_power (p : Shape) {N} (f : A→Ambient p N) (w g : Wgt A) (S : Party) (s : ℕ) - (hw : IsLaw w) (hg : ∀ x,|g x|≤1) (hs : S≠0) : - avg (freeH p N) (fun q => (sweep p f w g S q)^s) ≤ - avg (draws (Fin s) w) (fun x => bp (- (p.h:ℝ)*epoch p (∑ i,f (x i)))) := by - classical - simp_rw [sweep,poweravg] - rw [avg_avg] - refine avg_mono (draws_law hw).nz fun x => ?_ - let y := ∑ i : Fin s,f (x i) - have hh := free_phase y hs - simp_rw [Finset.prod_mul_distrib,← wsign_sum,←map_sum,avg_mul'] - let T := ∏ i : Fin s,g (x i) - have hi : T≤1 := by - have he : |T| ≤ ∏ (_ : Fin s), (1:ℝ) := by - unfold T; rw [Finset.abs_prod] - exact Finset.prod_le_prod₀ (fun i _ => abs_nonneg _) (fun i _ => hg _) - exact (le_abs_self _).trans (by simpa using he) - exact ((mul_le_mul_of_nonneg_right hi hh.1).trans_eq (one_mul _)).trans hh.2 - -theorem abs_sweep (p : Shape) {N} (f : A→Ambient p N) (w g : Wgt A) (S : Party) - (hw : IsLaw w) (hg : ∀ x,|g x|≤1) : - ∀ q,|sweep p f w g S q| ≤1 := by - intro q - apply (abs_avg_le hw.nz).trans (hw.avg_le (fun x => ?_)) - rw [abs_mul, wsign_abs,mul_one]; exact hg x - -def exponentErr (p : Shape) (m b : ℕ) (c : ℝ) := - let s := 2^m*(2*b) - ((2:ℝ)^s*(2:ℝ)^s)*c^b + bp (- (p.h:ℝ)*b/2) - -theorem rare_sweep (p : Shape) {N} (f : A→Ambient p N) (w g : Wgt A) (S : Party) - (hw : IsLaw w) (hg : ∀ x,|g x| ≤1) (hs : S≠0) (r m b : ℕ) (hr : ∀ x,epoch p (f x) ≤ r) - (hm : 16*r covered p t (f i)) ≤ c) - (hψ : 0<ψ) : - pr (freeH p N) (fun y => ψ ≤ |sweep p f w g S y|) ≤ - exponentErr p m b c / ψ^(2^m*(2*b)) := by - classical - let s := 2^m*(2*b) - let v := draws (Fin s) w - let y := sweep p f w g S - have he := phase_power p f w g S s hw hg hs - have ht : avg (freeH p N) (fun q => (y q)^s) ≤ exponentErr p m b c := by - apply le_trans he - let k (x : Fin s→A) := epoch p (∑ i,f (x i)) - let t := bp (-(p.h:ℝ)*b / 2) - have hg (x : Fin s→A) : - bp (-(p.h:ℝ)*k x) ≤ ind (2*k x ≤ b)+t := by - by_cases hl : 2*k x ≤ b - · rw [ind_one hl] - refine (bp_le (show -(p.h:ℝ)*k x ≤0 by - exact mul_nonpos_of_nonpos_of_nonneg (by simp) (by positivity))).trans ?_ - rw [bp_zero] - exact le_add_of_nonneg_right (bp_pos _).le - rw [ind_zero hl,zero_add] - apply bp_le - have hh : (b:ℝ) ≤ 2*(k x:ℝ) := by exact_mod_cast (le_of_not_ge hl) - have he := mul_le_mul_of_nonneg_left hh (show 0≤(p.h:ℝ) from Nat.cast_nonneg _) - linarith only [he] - have hv : IsLaw v := draws_law hw - refine le_trans (avg_mono hv.nz hg) ?_ - rw [avg_add,hv.avg_const] - exact add_le_add_left (no_cover_rank p f w hw m b r hb hm hr c hc hh) _ - have hEv : Even s := ⟨2^m*b, by unfold s; ring⟩ - have hi : avg (freeH p N) (fun q => |y q|^s) ≤ exponentErr p m b c := by - have hs (q) : |y q|^s=y q^s := hEv.pow_abs _ - simp_rw [hs]; exact ht - change pr (freeH p N) _ ≤ _/ψ^s - apply (le_div_iff₀ (pow_pos hψ s)).mpr - rw [mul_comm] - let u := freeH p N - have hu : IsLaw u := freeH_law p N - refine (mul_le_mul_of_nonneg_left (pr_mono (q:=fun q => ψ^s ≤ |y q|^s) hu.nz - (fun q h => pow_le_pow_left₀ hψ.le h s)) (pow_pos hψ s).le).trans ?_ - exact (le_avg_markov hu.nz (fun q => pow_nonneg (abs_nonneg (y q)) s) _).trans hi - -theorem epoch_count (p : Shape) (N r : ℕ) : - nbr (fun x : Ambient p N => epoch p x ≤ r) ≤ bp (2*(r:ℝ)*num (Comp p.g)*N) := by - classical - let P := fun (M : Mat (Fin N) (Fin N)) => M.rank ≤r - have hi : ∀ x : Ambient p N,epoch p x ≤ r → ∀ i,P (x i) := fun x hx i => - (Finset.single_le_sum (fun i _ => Nat.zero_le ((x i).rank)) (Finset.mem_univ i)).trans hx - have hg : nbr (fun x : Ambient p N => ∀ i,P (x i)) = - ∏ _ : Comp p.g,nbr P := by - unfold nbr; simp_rw [ind_all] - change tot (prodW (β:=fun _ : Comp p.g => Mat (Fin N) (Fin N)) (fun i a => ind (P a))) = _ - exact prodW_tot _ - refine (tot_mono (fun x => ind_mono (hi x))).trans ?_ - change nbr _ ≤ _ - rw [hg] - let t := bp ((num (Fin N)+num (Fin N))*r) - refine (Finset.prod_le_prod₀ (g:=fun _ => t) (fun _ _ => nbr_nonneg P) (fun _ _ => - nbr_matrix_rank r)).trans_eq ?_ - simp only [t,Finset.prod_const,Finset.card_univ,← bp_mul_nat,num,Fintype.card_fin] - congr 1; ring - -def noSweepBudget (p : Shape) (N m b r : ℕ) (c ψ H : ℝ) := - bp (2*(r:ℝ)*num (Comp p.g)*N) * (H*chanPrice p^2 *(exponentErr p m b c/ψ^(2^m*(2*b)))) - -set_option maxHeartbeats 800000 in -theorem pitch_no_cover (p : Shape) {N n} (Δ : UnitType p n N→ Ambient p N) {w} - (hw : IsLaw w) (S R : Party) (hs : S ≠ 0) - (r m b : ℕ) (hr : ∀ x,epoch p (Δ x) ≤ r) - (hm : 16*r covered p t (Δ i)) ≤ c) - (hψ : 0<ψ) (hH : 0≤H) (mix : Mixer p n) - (hN : 2*num (Full p n)-N≤ -1) - (hc' : ∀ x,w x ≤ H * pairW (raw mix N) (raw mix N) x) : - |pitch p Δ w S R| ≤ ψ+noSweepBudget p N m b r c ψ H := by - classical - let g (v : Ambient p N) (x : UnitType p n N) := wsign (tone p x R v) - have hg v x : |g v x|≤1 := by simp [g] - let y (v : Ambient p N) := sweep p Δ w (g v) S - let Q := exponentErr p m b c / ψ^(2^m*(2*b)) - have h v := rare_sweep p Δ w (g v) S hw (hg v) hs r m b hr hm hb c ψ hc hh hψ - let F' (v : Ambient p N) (x : UnitType p n N) := y v (listens p x) - let A := {v : Ambient p N//epoch p v ≤ r} - let B (x : UnitType p n N) := ∃ v : A, ψ ≤ |F' v.val x| - have ha (x) : |F' (Δ x) x| ≤ ψ+ind (B x) := by - by_cases h : ψ ≤ |F' (Δ x) x| - · rw [ind_one (show B x from ⟨⟨Δ x,hr x⟩,h⟩)] - exact (abs_sweep p Δ w _ S hw (hg _) _).trans (by linarith) - exact le_trans (le_of_not_ge h) (le_add_of_nonneg_right (ind_nonneg _)) - have hZ : pitch p Δ w S R = avg w (fun x => F' (Δ x) x) := by - rw [pitch,pairW_avg,avg_avg] - simp_rw [wsign_add] - rfl - rw [hZ] - refine ((abs_avg_le hw.nz).trans (avg_mono hw.nz ha)).trans ?_ - rw [avg_add,hw.avg_const] - apply add_le_add_right - have hz (v : A) : - pr w (fun x => ψ ≤ |F' v.val x|) ≤ H*chanPrice p^2 * Q := by - let P (y' : PhasePair p N) := ψ ≤ |y v.val y'| - calc pr w (fun x => ψ ≤ |F' v.val x|) - _ = pr (mapW w (listens p)) P := (mapW_pr w (listens p) P).symm - _ ≤ _ := (pr_cap (phase_cap hH mix hc' hN) P).trans - (mul_le_mul_of_nonneg_left (h _) (mul_nonneg hH (sq_nonneg _))) - refine (pr_exists_le hw.nz (fun v : A => fun x => ψ ≤ |F' v.val x|)).trans ?_ - refine (Finset.sum_le_sum fun i _ => hz i).trans ?_ - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - unfold noSweepBudget - apply mul_le_mul_of_nonneg_right - · exact (nbr_eq_card (fun v : Ambient p N => epoch p v≤r)).symm.trans_le (epoch_count p N r) - · exact mul_nonneg (mul_nonneg hH (sq_nonneg _)) ((pr_nonneg (freeH_law p N).nz).trans - (h (0:Ambient p N))) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.IndependentPhaseBounds + +namespace OAI + +/-! # Phase Moment Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {A : Type} [Fintype A] + +theorem poweravg (w f : Wgt A) (s : ℕ) : + avg w f ^ s=avg (draws (Fin s) w) (fun x => ∏ i : Fin s,f (x i)) := by + classical + change _=avg (prodW _) (prodW (fun _ : Fin s => f)) + rw [prodW_avg]; simp + +def sweep (p : Shape) {N} (f : A→Ambient p N) (w g : Wgt A) (S : Party) + (q : PhasePair p N) := avg w (fun x => g x*wsign (joinPhase p q S (f x))) + +theorem phase_power (p : Shape) {N} (f : A→Ambient p N) (w g : Wgt A) (S : Party) (s : ℕ) + (hw : IsLaw w) (hg : ∀ x,|g x|≤1) (hs : S≠0) : + avg (freeH p N) (fun q => (sweep p f w g S q)^s) ≤ + avg (draws (Fin s) w) (fun x => bp (- (p.h:ℝ)*epoch p (∑ i,f (x i)))) := by + classical + simp_rw [sweep,poweravg] + rw [avg_avg] + refine avg_mono (draws_law hw).nz fun x => ?_ + let y := ∑ i : Fin s,f (x i) + have hh := free_phase y hs + simp_rw [Finset.prod_mul_distrib,← wsign_sum,←map_sum,avg_mul'] + let T := ∏ i : Fin s,g (x i) + have hi : T≤1 := by + have he : |T| ≤ ∏ (_ : Fin s), (1:ℝ) := by + unfold T; rw [Finset.abs_prod] + exact Finset.prod_le_prod₀ (fun i _ => abs_nonneg _) (fun i _ => hg _) + exact (le_abs_self _).trans (by simpa using he) + exact ((mul_le_mul_of_nonneg_right hi hh.1).trans_eq (one_mul _)).trans hh.2 + +theorem abs_sweep (p : Shape) {N} (f : A→Ambient p N) (w g : Wgt A) (S : Party) + (hw : IsLaw w) (hg : ∀ x,|g x|≤1) : + ∀ q,|sweep p f w g S q| ≤1 := by + intro q + apply (abs_avg_le hw.nz).trans (hw.avg_le (fun x => ?_)) + rw [abs_mul, wsign_abs,mul_one]; exact hg x + +def exponentErr (p : Shape) (m b : ℕ) (c : ℝ) := + let s := 2^m*(2*b) + ((2:ℝ)^s*(2:ℝ)^s)*c^b + bp (- (p.h:ℝ)*b/2) + +theorem rare_sweep (p : Shape) {N} (f : A→Ambient p N) (w g : Wgt A) (S : Party) + (hw : IsLaw w) (hg : ∀ x,|g x| ≤1) (hs : S≠0) (r m b : ℕ) (hr : ∀ x,epoch p (f x) ≤ r) + (hm : 16*r covered p t (f i)) ≤ c) + (hψ : 0<ψ) : + pr (freeH p N) (fun y => ψ ≤ |sweep p f w g S y|) ≤ + exponentErr p m b c / ψ^(2^m*(2*b)) := by + classical + let s := 2^m*(2*b) + let v := draws (Fin s) w + let y := sweep p f w g S + have he := phase_power p f w g S s hw hg hs + have ht : avg (freeH p N) (fun q => (y q)^s) ≤ exponentErr p m b c := by + apply le_trans he + let k (x : Fin s→A) := epoch p (∑ i,f (x i)) + let t := bp (-(p.h:ℝ)*b / 2) + have hg (x : Fin s→A) : + bp (-(p.h:ℝ)*k x) ≤ ind (2*k x ≤ b)+t := by + by_cases hl : 2*k x ≤ b + · rw [ind_one hl] + refine (bp_le (show -(p.h:ℝ)*k x ≤0 by + exact mul_nonpos_of_nonpos_of_nonneg (by simp) (by positivity))).trans ?_ + rw [bp_zero] + exact le_add_of_nonneg_right (bp_pos _).le + rw [ind_zero hl,zero_add] + apply bp_le + have hh : (b:ℝ) ≤ 2*(k x:ℝ) := by exact_mod_cast (le_of_not_ge hl) + have he := mul_le_mul_of_nonneg_left hh (show 0≤(p.h:ℝ) from Nat.cast_nonneg _) + linarith only [he] + have hv : IsLaw v := draws_law hw + refine le_trans (avg_mono hv.nz hg) ?_ + rw [avg_add,hv.avg_const] + exact add_le_add_left (no_cover_rank p f w hw m b r hb hm hr c hc hh) _ + have hEv : Even s := ⟨2^m*b, by unfold s; ring⟩ + have hi : avg (freeH p N) (fun q => |y q|^s) ≤ exponentErr p m b c := by + have hs (q) : |y q|^s=y q^s := hEv.pow_abs _ + simp_rw [hs]; exact ht + change pr (freeH p N) _ ≤ _/ψ^s + apply (le_div_iff₀ (pow_pos hψ s)).mpr + rw [mul_comm] + let u := freeH p N + have hu : IsLaw u := freeH_law p N + refine (mul_le_mul_of_nonneg_left (pr_mono (q:=fun q => ψ^s ≤ |y q|^s) hu.nz + (fun q h => pow_le_pow_left₀ hψ.le h s)) (pow_pos hψ s).le).trans ?_ + exact (le_avg_markov hu.nz (fun q => pow_nonneg (abs_nonneg (y q)) s) _).trans hi + +theorem epoch_count (p : Shape) (N r : ℕ) : + nbr (fun x : Ambient p N => epoch p x ≤ r) ≤ bp (2*(r:ℝ)*num (Comp p.g)*N) := by + classical + let P := fun (M : Mat (Fin N) (Fin N)) => M.rank ≤r + have hi : ∀ x : Ambient p N,epoch p x ≤ r → ∀ i,P (x i) := fun x hx i => + (Finset.single_le_sum (fun i _ => Nat.zero_le ((x i).rank)) (Finset.mem_univ i)).trans hx + have hg : nbr (fun x : Ambient p N => ∀ i,P (x i)) = + ∏ _ : Comp p.g,nbr P := by + unfold nbr; simp_rw [ind_all] + change tot (prodW (β:=fun _ : Comp p.g => Mat (Fin N) (Fin N)) (fun i a => ind (P a))) = _ + exact prodW_tot _ + refine (tot_mono (fun x => ind_mono (hi x))).trans ?_ + change nbr _ ≤ _ + rw [hg] + let t := bp ((num (Fin N)+num (Fin N))*r) + refine (Finset.prod_le_prod₀ (g:=fun _ => t) (fun _ _ => nbr_nonneg P) (fun _ _ => + nbr_matrix_rank r)).trans_eq ?_ + simp only [t,Finset.prod_const,Finset.card_univ,← bp_mul_nat,num,Fintype.card_fin] + congr 1; ring + +def noSweepBudget (p : Shape) (N m b r : ℕ) (c ψ H : ℝ) := + bp (2*(r:ℝ)*num (Comp p.g)*N) * (H*chanPrice p^2 *(exponentErr p m b c/ψ^(2^m*(2*b)))) + +set_option maxHeartbeats 800000 in +theorem pitch_no_cover (p : Shape) {N n} (Δ : UnitType p n N→ Ambient p N) {w} + (hw : IsLaw w) (S R : Party) (hs : S ≠ 0) + (r m b : ℕ) (hr : ∀ x,epoch p (Δ x) ≤ r) + (hm : 16*r covered p t (Δ i)) ≤ c) + (hψ : 0<ψ) (hH : 0≤H) (mix : Mixer p n) + (hN : 2*num (Full p n)-N≤ -1) + (hc' : ∀ x,w x ≤ H * pairW (raw mix N) (raw mix N) x) : + |pitch p Δ w S R| ≤ ψ+noSweepBudget p N m b r c ψ H := by + classical + let g (v : Ambient p N) (x : UnitType p n N) := wsign (tone p x R v) + have hg v x : |g v x|≤1 := by simp [g] + let y (v : Ambient p N) := sweep p Δ w (g v) S + let Q := exponentErr p m b c / ψ^(2^m*(2*b)) + have h v := rare_sweep p Δ w (g v) S hw (hg v) hs r m b hr hm hb c ψ hc hh hψ + let F' (v : Ambient p N) (x : UnitType p n N) := y v (listens p x) + let A := {v : Ambient p N//epoch p v ≤ r} + let B (x : UnitType p n N) := ∃ v : A, ψ ≤ |F' v.val x| + have ha (x) : |F' (Δ x) x| ≤ ψ+ind (B x) := by + by_cases h : ψ ≤ |F' (Δ x) x| + · rw [ind_one (show B x from ⟨⟨Δ x,hr x⟩,h⟩)] + exact (abs_sweep p Δ w _ S hw (hg _) _).trans (by linarith) + exact le_trans (le_of_not_ge h) (le_add_of_nonneg_right (ind_nonneg _)) + have hZ : pitch p Δ w S R = avg w (fun x => F' (Δ x) x) := by + rw [pitch,pairW_avg,avg_avg] + simp_rw [wsign_add] + rfl + rw [hZ] + refine ((abs_avg_le hw.nz).trans (avg_mono hw.nz ha)).trans ?_ + rw [avg_add,hw.avg_const] + apply add_le_add_right + have hz (v : A) : + pr w (fun x => ψ ≤ |F' v.val x|) ≤ H*chanPrice p^2 * Q := by + let P (y' : PhasePair p N) := ψ ≤ |y v.val y'| + calc pr w (fun x => ψ ≤ |F' v.val x|) + _ = pr (mapW w (listens p)) P := (mapW_pr w (listens p) P).symm + _ ≤ _ := (pr_cap (phase_cap hH mix hc' hN) P).trans + (mul_le_mul_of_nonneg_left (h _) (mul_nonneg hH (sq_nonneg _))) + refine (pr_exists_le hw.nz (fun v : A => fun x => ψ ≤ |F' v.val x|)).trans ?_ + refine (Finset.sum_le_sum fun i _ => hz i).trans ?_ + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + unfold noSweepBudget + apply mul_le_mul_of_nonneg_right + · exact (nbr_eq_card (fun v : Ambient p N => epoch p v≤r)).symm.trans_le (epoch_count p N r) + · exact mul_nonneg (mul_nonneg hH (sq_nonneg _)) ((pr_nonneg (freeH_law p N).nz).trans + (h (0:Ambient p N))) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseParameters.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseParameters.lean index e10710f4d85c70822fe1d1cc54c67734a2ba1029..5b8a07ffd19f64cce54438330a5ef834319a37ee 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseParameters.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PhaseParameters.lean @@ -1,290 +1,290 @@ -import OAI.Combinatorics.HadwigerCounterexample.FinitePhaseAlternative -import OAI.Combinatorics.HadwigerCounterexample.ConstructionScales - -namespace OAI - -/-! # Phase Parameters -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators Topology -open Filter -variable {p : Shape} {n N : ℕ} - -def mstep (r : ℕ) := 100*r+10 -def Bstep (r : ℕ) := 2^(mstep r)*2 -def denomStep (r : ℕ) := 10000*(r+1)^2*Bstep r -theorem Bstep_pos (r) : 0 bp (-c*n)) atTop (𝓝 0) := - (bp_tendsto_zero hc).comp tendsto_natCast_atTop_atTop - -theorem eventually_grid {P : ℕ → Prop} (h : ∀ᶠ N : ℕ in atTop,P N) : - ∀ᶠ M : ℕ in atTop, ∀ᶠ n : ℕ in atTop, P (M*n) := by - obtain ⟨k,hk⟩ := eventually_atTop.mp h - filter_upwards [eventually_ge_atTop 1] with M hM - filter_upwards [eventually_ge_atTop k] with n hn - exact hk _ (by nlinarith) - -private theorem absorb_pow (p : Shape) {D : ℝ} (hD : 0≤D) (r b N : ℕ) - (hN : N ≤2*denomStep r*b) - (hp : 2*pcoef p.g r D ≤ p.h) : - exponentErr p (mstep r) b (tinyPhase p.g r D)/warn^(2^(mstep r)*(2*b)) - ≤ 2*bp (-(stage p.g r D)*N) := by - let Z := pcoef p.g r D - let L := stage p.g r D - let s := 2^(mstep r)*(2*b) - have hl : 0 ≤ L := by unfold L stage num; positivity - have hx : 12*(s:ℝ)+L*N ≤ Z*b := by - have h : (N:ℝ) ≤ 2*(denomStep r:ℝ)*b := by exact_mod_cast hN - have hs : (s:ℝ)=(Bstep r:ℝ)*b := by unfold s Bstep; push_cast; ring - unfold Z pcoef; rw [hs]; change _ ≤ (12*_+2*_ * L)*_ - nlinarith only [mul_le_mul_of_nonneg_left h hl] - have hz : L*N+10*(s:ℝ) ≤ (p.h:ℝ)*b/2 := by - have hb : 2*Z*(b:ℝ) ≤ (p.h:ℝ)*b := - mul_le_mul_of_nonneg_right hp (Nat.cast_nonneg _) - linarith [(Nat.cast_nonneg s : 0≤(s:ℝ))] - unfold exponentErr tinyPhase warn - change (((2:ℝ)^s*2^s)*bp (-Z)^b+bp _)/bp (-10)^s≤_ - rw [←bp_nat s,←bp_mul_nat,←bp_mul_nat, ← bp_add,←bp_add,add_div,← bp_sub,← bp_sub, - two_mul] - refine add_le_add (bp_le ?_) (bp_le ?_) - · change _ ≤ -L*N; linarith only [hx] - change _ ≤ -L*N; linarith only [hz] - -private theorem limit_pow (p : Shape) (r : ℕ) {D : ℝ} (hD : 0≤D) - (hp : 2*pcoef p.g r D ≤ p.h) : - ∀ᶠ N : ℕ in atTop,warn + noSweepBudget p N (mstep r) (N/denomStep r) r - (tinyPhase p.g r D) warn (bp (D*N))<0.005 := by - let C := chanPrice p - have hw : warn < 0.005 := by - unfold warn; rw [bp_neg, show (10:ℝ)=↑(10:ℕ) from by norm_num, bp_nat]; norm_num - have hi : Tendsto (fun N : ℕ => warn+(2*C^2)*bp (-1*N)) atTop (𝓝 warn) := by - have h := (bp_nat_vanish (by norm_num : 0<(1:ℝ))).const_mul (2*C^2) - simpa only [neg_mul,mul_zero,add_zero] using h.const_add warn - filter_upwards [hi.eventually (gt_mem_nhds hw),eventually_ge_atTop (denomStep r)] - with N h hN - let b := N / denomStep r - have he : N≤2*denomStep r*b := by - have h' : 1≤b := (Nat.le_div_iff_mul_le (denom_pos r)).mpr (by simpa using hN) - have h2 : b*denomStep r + N%denomStep r=N := Nat.div_add_mod' .. - have h3 : N%denomStep r < denomStep r := Nat.mod_lt _ (denom_pos r) - nlinarith - have hh : noSweepBudget p N (mstep r) b r (tinyPhase p.g r D) warn (bp (D*N))≤ - 2*C^2*bp (-1*N) := by - let A := bp (2*(r:ℝ)*num (Comp p.g)*N) - unfold noSweepBudget - refine (mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left - (absorb_pow p hD r b N he hp) - (mul_nonneg (bp_pos _).le (sq_nonneg _) - )) (bp_pos _).le).trans_eq ?_ - change A * (bp _ * C^2 * _) = _ - have he : A * bp (D*N) * bp (-(stage p.g r D)*N)= bp (-1*N) := by - unfold A stage; rw [←bp_add,←bp_add]; congr 1; ring - rw [← he]; ring - exact (add_le_add_right hh _).trans_lt h - -theorem span_stage (b r N : ℕ) (hN : denomStep r*b ≤ N) : - (↑(maxSpan (mstep r) b r):ℝ) ≤ 0.001*N ∧ - 2*(↑(maxSpan (mstep r) b r):ℝ)*r ≤ 0.001*N := by - have he : maxSpan (mstep r) b r = r*Bstep r*b := by unfold maxSpan Bstep; ring - rw [he] - have hb : (Bstep r:ℝ)≥0 := Nat.cast_nonneg _ - have hL : (denomStep r:ℝ)*(b:ℝ) ≤ N := by exact_mod_cast hN - unfold denomStep at hL - push_cast at hL ⊢ - have h0 : (0:ℝ)≤r := Nat.cast_nonneg _ - have h1 : 0 ≤ (Bstep r:ℝ)*(b:ℝ) := mul_nonneg hb (Nat.cast_nonneg _) - constructor <;> nlinarith only [hL,h1,h0,mul_nonneg h0 h1, mul_nonneg (sq_nonneg (r:ℝ)) h1] - -private theorem atlas_stage (p : Shape) (r : ℕ) : - ∀ᶠ N : ℕ in atTop,∀ T : Cov p N,(∀ i,cdSign p T i≤maxSpan (mstep r) (N/denomStep r) r) → - num (Atlas p r T)≤bp (0.002*N) := by - let K := num (Wide p r) - let L := bp (num (Comp p.g)*r*r) - have he := bp_poly_dom_nat (by norm_num : 0<(0.001:ℝ)) (K*L) 0 - filter_upwards [he] with N h T hT - apply (atlas_size T _).trans - let W := maxSpan (mstep r) (N/denomStep r) r - have hf : (cdim p T:ℝ) ≤2*W := by - exact_mod_cast (show cdim p T≤ 2*W from (cdim_sign p T).trans_le - ((add_le_add (hT _) (hT _)).trans_eq (two_mul W).symm)) - have h1 := mul_le_mul_of_nonneg_right hf (show 0≤(r:ℝ) from Nat.cast_nonneg _) - have hL : (cdim p T:ℝ)*r≤0.001*N := h1.trans - (span_stage _ r N (Nat.mul_div_le _ _)).2 - have h2 : K*L≤bp (0.001*N) := by simpa using h.le - have h3 : 0≤K := Nat.cast_nonneg _ - rw [bp_add] - change K * (_ * L) ≤ _ - rw [mul_comm _ L, ←mul_assoc] - exact (mul_le_mul h2 (bp_le hL) (bp_pos _).le (bp_pos _).le).trans_eq (by - rw [←bp_add]; congr 1; ring) - -private theorem price_bound {p : Shape} {r n N k : ℕ} {L : ℝ} - (x y : ℕ) (hx : x≤ 2*r) (hy : y≤ 2*r+k) - (hf : (2*(r:ℝ))*num (Full p n)+2*p.h*(2*(r:ℝ)+k) ≤ 0.004*N) - (hl : L ≤ bp (0.004*N)) : - L*heatRate p n N (heatloss r k) x y≤loseA p N x y := by - apply (mul_le_mul_of_nonneg_right hl - (mul_nonneg (bp_pos _).le (bp_pos _).le) - ).trans - unfold loseA - rw [←bp_add,←bp_add] - refine bp_le ?_ - let ε := heatloss r k - have he : ε*(4*r+k + (1:ℝ))=0.001 := by - unfold ε heatloss; field_simp - have hg : (x:ℝ)≤ 2*r := by exact_mod_cast hx - have hh : (y:ℝ)≤ 2*r+k := by exact_mod_cast hy - have ht : ε*(x+y:ℝ) ≤ 0.001 := he ▸ mul_le_mul_of_nonneg_left - (show _≤_ by linarith) (heatloss_pos r k).le - have hN := mul_le_mul_of_nonneg_right ht (Nat.cast_nonneg N : 0≤(N:ℝ)) - have hi : - num (Row p n)*x+2*p.h*(y:ℝ) ≤ 0.004*N := by - have hu := mul_le_mul (row_le p n) hg - (Nat.cast_nonneg x : 0≤(x:ℝ)) (Nat.cast_nonneg _ : 0≤num (Full p n)) - have hv := mul_le_mul_of_nonneg_left hh (show 0≤ 2*(p.h:ℝ) by positivity) - linarith only [hf,hu,hv] - push_cast - unfold ε at hN - linarith [(Nat.cast_nonneg N : 0≤(N:ℝ))] - -private theorem early_spend (W : ℝ) : - ∀ᶠ N : ℕ in atTop,W≤bp (0.004*N) := by - filter_upwards [bp_poly_dom_nat (by norm_num : 0<(0.004:ℝ)) W 0] with N h - simpa using h.le - -private theorem glimpses_stage (g k r d : ℕ) (D L : ℝ) : - ∀ᶠ h : ℕ in atTop,∀ p : Shape,p.g=g → p.h=h → - glimpsesBill p k (rhUp L (tinyPhase g r D)) < coin^(k+1) ∧ - 2*glimpsesBill p d (rhUp L (tinyPhase g r D))≤coin/2 := by - let L' := rhUp L (tinyPhase g r D) - let f (k h : ℕ) := (num (Comp g×Bool))*(L'*2*bp ((k:ℝ)-h)) - have ht k : Tendsto (f k) atTop (𝓝 0) := by - let c : ℝ := num (Comp g×Bool)*L'*2*bp k - have h : f k=fun h : ℕ => c*bp (-1*h) := by - unfold f c; ext; simp [neg_mul,bp_sub,bp_neg]; ring - rw [h] - simpa using (bp_nat_vanish (by norm_num : 0<(1:ℝ))).const_mul c - have hh : 0 z*bp (-0.4*N)) atTop (𝓝 0) := by - simpa using (bp_nat_vanish (by norm_num : 0<(0.4:ℝ))).const_mul z - exact hh.eventually (gt_mem_nhds (half_pos ht)) - filter_upwards [hf1,hf2,hf3] with i hi hj hk - refine ⟨?_,?_,?_⟩ - · unfold P at hi; linarith - · unfold Q at hj; linarith - rw [←mul_assoc] - exact hk.le - have hε : 0 < ε := heatloss_pos r k - filter_upwards [columns_budget p (δ:=0.004) (by norm_num) - (2*(r:ℝ)) (2*p.h*(2*(r:ℝ)+k)) (by positivity) (by positivity), - columns_budget p (δ:=1) zero_lt_one 2 1 (by norm_num) zero_le_one, raw_ready p hε, - eventually_grid he,eventually_grid (limit_pow p r hd hH), eventually_grid (atlas_stage p r), - eventually_grid (early_spend A),eventually_grid (early_spend B), - eventually_grid (early_spend (t/2)⁻¹),eventually_grid (eventually_ge_atTop (denomStep r)) - ] with M hcols hfull hraw hδ hF hQ ha hb hu hN - filter_upwards [eventually_ge_atTop 1,hraw,hδ,hF,hQ,ha,hb,hu,hN] with n hn hz hz' hA hZ - hα hβ hr ht - dsimp only - intro mix - let N := M*n - have h1 := hcols n hn - have h2 := hfull n hn - change 2*num (Full p n)+1≤1*N at h2 - let b := N/denomStep r - refine ⟨(Nat.le_div_iff_mul_le (denom_pos r)).mpr (by simpa using ht),by unfold mstep; omega, - hk,tinyPhase_pos ..,tinyPhase_le _ _ hd,by norm_num [coin],by norm_num [coin], - bp_pos _,hε,hl,(bp_pos _).le,by linarith only [h2],?_,hA,?_,hZ,?_,?_,?_, - hz'.1,hY,hz'.2.1⟩ - · exact (hz.2 mix).2 - · refine le_trans ?_ hz'.2.2 - unfold scaleBill - change (num (Place p)*2)*(L*2 * bp (_+(maxSpan (mstep r) b r : ℝ)-N))≤_ - have hi := bp_le (show num (Row p n)+(maxSpan (mstep r) b r:ℝ) - N ≤ -0.4*N by - have he := (span_stage b r N (Nat.mul_div_le _ _)).1 - linarith only [row_le p n,h2,he,(Nat.cast_nonneg N : 0≤(N:ℝ))]) - exact mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hi (by positivity)) - (by unfold num; positivity) - · intro x y hx hy; exact price_bound x y hx (by omega) h1 hα - · intro x y hx hy; exact price_bound x y hx (by omega) h1 hβ - intro x hx - let H := bp (D*N) - have hh : rhUp H t * heatRate p n N ε x k≤ H * loseA p N x k := by - unfold rhUp; rw [mul_comm _ H,mul_assoc] - exact mul_le_mul_of_nonneg_left (price_bound x _ hx (by omega) h1 hr) (bp_pos _).le - change bp _ * bp _ * _ ≤ _ - refine (mul_le_mul_of_nonneg_left hh - (mul_nonneg (bp_pos _).le (bp_pos _).le) - ).trans ?_ - unfold H loseA - rw [← bp_add,← bp_add,← bp_add] - apply bp_le - change _ ≤ -0.2*(N:ℝ) - have h3 := mul_le_mul_of_nonneg_right hK (Nat.cast_nonneg N : 0≤(N:ℝ)) - linarith only [h3,(Nat.cast_nonneg N : 0≤(N:ℝ))] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FinitePhaseAlternative +import OAI.Combinatorics.HadwigerCounterexample.ConstructionScales + +namespace OAI + +/-! # Phase Parameters -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators Topology +open Filter +variable {p : Shape} {n N : ℕ} + +def mstep (r : ℕ) := 100*r+10 +def Bstep (r : ℕ) := 2^(mstep r)*2 +def denomStep (r : ℕ) := 10000*(r+1)^2*Bstep r +theorem Bstep_pos (r) : 0 bp (-c*n)) atTop (𝓝 0) := + (bp_tendsto_zero hc).comp tendsto_natCast_atTop_atTop + +theorem eventually_grid {P : ℕ → Prop} (h : ∀ᶠ N : ℕ in atTop,P N) : + ∀ᶠ M : ℕ in atTop, ∀ᶠ n : ℕ in atTop, P (M*n) := by + obtain ⟨k,hk⟩ := eventually_atTop.mp h + filter_upwards [eventually_ge_atTop 1] with M hM + filter_upwards [eventually_ge_atTop k] with n hn + exact hk _ (by nlinarith) + +private theorem absorb_pow (p : Shape) {D : ℝ} (hD : 0≤D) (r b N : ℕ) + (hN : N ≤2*denomStep r*b) + (hp : 2*pcoef p.g r D ≤ p.h) : + exponentErr p (mstep r) b (tinyPhase p.g r D)/warn^(2^(mstep r)*(2*b)) + ≤ 2*bp (-(stage p.g r D)*N) := by + let Z := pcoef p.g r D + let L := stage p.g r D + let s := 2^(mstep r)*(2*b) + have hl : 0 ≤ L := by unfold L stage num; positivity + have hx : 12*(s:ℝ)+L*N ≤ Z*b := by + have h : (N:ℝ) ≤ 2*(denomStep r:ℝ)*b := by exact_mod_cast hN + have hs : (s:ℝ)=(Bstep r:ℝ)*b := by unfold s Bstep; push_cast; ring + unfold Z pcoef; rw [hs]; change _ ≤ (12*_+2*_ * L)*_ + nlinarith only [mul_le_mul_of_nonneg_left h hl] + have hz : L*N+10*(s:ℝ) ≤ (p.h:ℝ)*b/2 := by + have hb : 2*Z*(b:ℝ) ≤ (p.h:ℝ)*b := + mul_le_mul_of_nonneg_right hp (Nat.cast_nonneg _) + linarith [(Nat.cast_nonneg s : 0≤(s:ℝ))] + unfold exponentErr tinyPhase warn + change (((2:ℝ)^s*2^s)*bp (-Z)^b+bp _)/bp (-10)^s≤_ + rw [←bp_nat s,←bp_mul_nat,←bp_mul_nat, ← bp_add,←bp_add,add_div,← bp_sub,← bp_sub, + two_mul] + refine add_le_add (bp_le ?_) (bp_le ?_) + · change _ ≤ -L*N; linarith only [hx] + change _ ≤ -L*N; linarith only [hz] + +private theorem limit_pow (p : Shape) (r : ℕ) {D : ℝ} (hD : 0≤D) + (hp : 2*pcoef p.g r D ≤ p.h) : + ∀ᶠ N : ℕ in atTop,warn + noSweepBudget p N (mstep r) (N/denomStep r) r + (tinyPhase p.g r D) warn (bp (D*N))<0.005 := by + let C := chanPrice p + have hw : warn < 0.005 := by + unfold warn; rw [bp_neg, show (10:ℝ)=↑(10:ℕ) from by norm_num, bp_nat]; norm_num + have hi : Tendsto (fun N : ℕ => warn+(2*C^2)*bp (-1*N)) atTop (𝓝 warn) := by + have h := (bp_nat_vanish (by norm_num : 0<(1:ℝ))).const_mul (2*C^2) + simpa only [neg_mul,mul_zero,add_zero] using h.const_add warn + filter_upwards [hi.eventually (gt_mem_nhds hw),eventually_ge_atTop (denomStep r)] + with N h hN + let b := N / denomStep r + have he : N≤2*denomStep r*b := by + have h' : 1≤b := (Nat.le_div_iff_mul_le (denom_pos r)).mpr (by simpa using hN) + have h2 : b*denomStep r + N%denomStep r=N := Nat.div_add_mod' .. + have h3 : N%denomStep r < denomStep r := Nat.mod_lt _ (denom_pos r) + nlinarith + have hh : noSweepBudget p N (mstep r) b r (tinyPhase p.g r D) warn (bp (D*N))≤ + 2*C^2*bp (-1*N) := by + let A := bp (2*(r:ℝ)*num (Comp p.g)*N) + unfold noSweepBudget + refine (mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left + (absorb_pow p hD r b N he hp) + (mul_nonneg (bp_pos _).le (sq_nonneg _) + )) (bp_pos _).le).trans_eq ?_ + change A * (bp _ * C^2 * _) = _ + have he : A * bp (D*N) * bp (-(stage p.g r D)*N)= bp (-1*N) := by + unfold A stage; rw [←bp_add,←bp_add]; congr 1; ring + rw [← he]; ring + exact (add_le_add_right hh _).trans_lt h + +theorem span_stage (b r N : ℕ) (hN : denomStep r*b ≤ N) : + (↑(maxSpan (mstep r) b r):ℝ) ≤ 0.001*N ∧ + 2*(↑(maxSpan (mstep r) b r):ℝ)*r ≤ 0.001*N := by + have he : maxSpan (mstep r) b r = r*Bstep r*b := by unfold maxSpan Bstep; ring + rw [he] + have hb : (Bstep r:ℝ)≥0 := Nat.cast_nonneg _ + have hL : (denomStep r:ℝ)*(b:ℝ) ≤ N := by exact_mod_cast hN + unfold denomStep at hL + push_cast at hL ⊢ + have h0 : (0:ℝ)≤r := Nat.cast_nonneg _ + have h1 : 0 ≤ (Bstep r:ℝ)*(b:ℝ) := mul_nonneg hb (Nat.cast_nonneg _) + constructor <;> nlinarith only [hL,h1,h0,mul_nonneg h0 h1, mul_nonneg (sq_nonneg (r:ℝ)) h1] + +private theorem atlas_stage (p : Shape) (r : ℕ) : + ∀ᶠ N : ℕ in atTop,∀ T : Cov p N,(∀ i,cdSign p T i≤maxSpan (mstep r) (N/denomStep r) r) → + num (Atlas p r T)≤bp (0.002*N) := by + let K := num (Wide p r) + let L := bp (num (Comp p.g)*r*r) + have he := bp_poly_dom_nat (by norm_num : 0<(0.001:ℝ)) (K*L) 0 + filter_upwards [he] with N h T hT + apply (atlas_size T _).trans + let W := maxSpan (mstep r) (N/denomStep r) r + have hf : (cdim p T:ℝ) ≤2*W := by + exact_mod_cast (show cdim p T≤ 2*W from (cdim_sign p T).trans_le + ((add_le_add (hT _) (hT _)).trans_eq (two_mul W).symm)) + have h1 := mul_le_mul_of_nonneg_right hf (show 0≤(r:ℝ) from Nat.cast_nonneg _) + have hL : (cdim p T:ℝ)*r≤0.001*N := h1.trans + (span_stage _ r N (Nat.mul_div_le _ _)).2 + have h2 : K*L≤bp (0.001*N) := by simpa using h.le + have h3 : 0≤K := Nat.cast_nonneg _ + rw [bp_add] + change K * (_ * L) ≤ _ + rw [mul_comm _ L, ←mul_assoc] + exact (mul_le_mul h2 (bp_le hL) (bp_pos _).le (bp_pos _).le).trans_eq (by + rw [←bp_add]; congr 1; ring) + +private theorem price_bound {p : Shape} {r n N k : ℕ} {L : ℝ} + (x y : ℕ) (hx : x≤ 2*r) (hy : y≤ 2*r+k) + (hf : (2*(r:ℝ))*num (Full p n)+2*p.h*(2*(r:ℝ)+k) ≤ 0.004*N) + (hl : L ≤ bp (0.004*N)) : + L*heatRate p n N (heatloss r k) x y≤loseA p N x y := by + apply (mul_le_mul_of_nonneg_right hl + (mul_nonneg (bp_pos _).le (bp_pos _).le) + ).trans + unfold loseA + rw [←bp_add,←bp_add] + refine bp_le ?_ + let ε := heatloss r k + have he : ε*(4*r+k + (1:ℝ))=0.001 := by + unfold ε heatloss; field_simp + have hg : (x:ℝ)≤ 2*r := by exact_mod_cast hx + have hh : (y:ℝ)≤ 2*r+k := by exact_mod_cast hy + have ht : ε*(x+y:ℝ) ≤ 0.001 := he ▸ mul_le_mul_of_nonneg_left + (show _≤_ by linarith) (heatloss_pos r k).le + have hN := mul_le_mul_of_nonneg_right ht (Nat.cast_nonneg N : 0≤(N:ℝ)) + have hi : + num (Row p n)*x+2*p.h*(y:ℝ) ≤ 0.004*N := by + have hu := mul_le_mul (row_le p n) hg + (Nat.cast_nonneg x : 0≤(x:ℝ)) (Nat.cast_nonneg _ : 0≤num (Full p n)) + have hv := mul_le_mul_of_nonneg_left hh (show 0≤ 2*(p.h:ℝ) by positivity) + linarith only [hf,hu,hv] + push_cast + unfold ε at hN + linarith [(Nat.cast_nonneg N : 0≤(N:ℝ))] + +private theorem early_spend (W : ℝ) : + ∀ᶠ N : ℕ in atTop,W≤bp (0.004*N) := by + filter_upwards [bp_poly_dom_nat (by norm_num : 0<(0.004:ℝ)) W 0] with N h + simpa using h.le + +private theorem glimpses_stage (g k r d : ℕ) (D L : ℝ) : + ∀ᶠ h : ℕ in atTop,∀ p : Shape,p.g=g → p.h=h → + glimpsesBill p k (rhUp L (tinyPhase g r D)) < coin^(k+1) ∧ + 2*glimpsesBill p d (rhUp L (tinyPhase g r D))≤coin/2 := by + let L' := rhUp L (tinyPhase g r D) + let f (k h : ℕ) := (num (Comp g×Bool))*(L'*2*bp ((k:ℝ)-h)) + have ht k : Tendsto (f k) atTop (𝓝 0) := by + let c : ℝ := num (Comp g×Bool)*L'*2*bp k + have h : f k=fun h : ℕ => c*bp (-1*h) := by + unfold f c; ext; simp [neg_mul,bp_sub,bp_neg]; ring + rw [h] + simpa using (bp_nat_vanish (by norm_num : 0<(1:ℝ))).const_mul c + have hh : 0 z*bp (-0.4*N)) atTop (𝓝 0) := by + simpa using (bp_nat_vanish (by norm_num : 0<(0.4:ℝ))).const_mul z + exact hh.eventually (gt_mem_nhds (half_pos ht)) + filter_upwards [hf1,hf2,hf3] with i hi hj hk + refine ⟨?_,?_,?_⟩ + · unfold P at hi; linarith + · unfold Q at hj; linarith + rw [←mul_assoc] + exact hk.le + have hε : 0 < ε := heatloss_pos r k + filter_upwards [columns_budget p (δ:=0.004) (by norm_num) + (2*(r:ℝ)) (2*p.h*(2*(r:ℝ)+k)) (by positivity) (by positivity), + columns_budget p (δ:=1) zero_lt_one 2 1 (by norm_num) zero_le_one, raw_ready p hε, + eventually_grid he,eventually_grid (limit_pow p r hd hH), eventually_grid (atlas_stage p r), + eventually_grid (early_spend A),eventually_grid (early_spend B), + eventually_grid (early_spend (t/2)⁻¹),eventually_grid (eventually_ge_atTop (denomStep r)) + ] with M hcols hfull hraw hδ hF hQ ha hb hu hN + filter_upwards [eventually_ge_atTop 1,hraw,hδ,hF,hQ,ha,hb,hu,hN] with n hn hz hz' hA hZ + hα hβ hr ht + dsimp only + intro mix + let N := M*n + have h1 := hcols n hn + have h2 := hfull n hn + change 2*num (Full p n)+1≤1*N at h2 + let b := N/denomStep r + refine ⟨(Nat.le_div_iff_mul_le (denom_pos r)).mpr (by simpa using ht),by unfold mstep; omega, + hk,tinyPhase_pos ..,tinyPhase_le _ _ hd,by norm_num [coin],by norm_num [coin], + bp_pos _,hε,hl,(bp_pos _).le,by linarith only [h2],?_,hA,?_,hZ,?_,?_,?_, + hz'.1,hY,hz'.2.1⟩ + · exact (hz.2 mix).2 + · refine le_trans ?_ hz'.2.2 + unfold scaleBill + change (num (Place p)*2)*(L*2 * bp (_+(maxSpan (mstep r) b r : ℝ)-N))≤_ + have hi := bp_le (show num (Row p n)+(maxSpan (mstep r) b r:ℝ) - N ≤ -0.4*N by + have he := (span_stage b r N (Nat.mul_div_le _ _)).1 + linarith only [row_le p n,h2,he,(Nat.cast_nonneg N : 0≤(N:ℝ))]) + exact mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hi (by positivity)) + (by unfold num; positivity) + · intro x y hx hy; exact price_bound x y hx (by omega) h1 hα + · intro x y hx hy; exact price_bound x y hx (by omega) h1 hβ + intro x hx + let H := bp (D*N) + have hh : rhUp H t * heatRate p n N ε x k≤ H * loseA p N x k := by + unfold rhUp; rw [mul_comm _ H,mul_assoc] + exact mul_le_mul_of_nonneg_left (price_bound x _ hx (by omega) h1 hr) (bp_pos _).le + change bp _ * bp _ * _ ≤ _ + refine (mul_le_mul_of_nonneg_left hh + (mul_nonneg (bp_pos _).le (bp_pos _).le) + ).trans ?_ + unfold H loseA + rw [← bp_add,← bp_add,← bp_add] + apply bp_le + change _ ≤ -0.2*(N:ℝ) + have h3 := mul_le_mul_of_nonneg_right hK (Nat.cast_nonneg N : 0≤(N:ℝ)) + linarith only [h3,(Nat.cast_nonneg N : 0≤(N:ℝ))] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PhasePreparedOutcomes.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PhasePreparedOutcomes.lean index 8d1a70488a7ef1fe7e83fa196062cb6636adcdbe..cf62097c53327591500d41f381a2f21761510351 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PhasePreparedOutcomes.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PhasePreparedOutcomes.lean @@ -1,182 +1,182 @@ -import OAI.Combinatorics.HadwigerCounterexample.PreparedPopulationTrimming - -namespace OAI - -/-! # Phase Prepared Outcomes -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset -open scoped BigOperators Topology -open PredictionClass - -namespace PreparationParameters -variable {l : Filter ℕ} {p : Shape} {M : ℕ} {q : PreparationParameters} - {m : cycleM p} {s : rhythms p M} {w : tale p M} {b : Sketch p M} {P Q : Campaign p M} - -def satisfied (q : PreparationParameters) (l : Filter ℕ) (p : Shape) (M : ℕ) (m : cycleM p) - (w : tale p M) := - ∃ t : rhythms p M,q.durable l p M m w t ∧ (q.silenceOutcome l p M m w t ∨ - q.predOutcome l p M m w t) - -theorem byTorch (hl : l≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) - (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) - (hb : q.citable l p M m w s b P) - (hc : ∀ᶠ n in l,0.05 ≤ charm s w P b n) : - satisfied q l p M m w := by - obtain ⟨t,hT,h1,h2,e,he,hF⟩:= dropHarvest hl hq hw hx hb - refine ⟨t,hT,Or.inr ⟨b,h1,Or.inl (hT.kindles hl hq hw ?_)⟩⟩ - filter_upwards [hF,hc,(he.lim (trend_sizes l hl hq.hM).2).eventually - (gt_mem_nhds (by norm_num : (0:ℝ) < 0.01))] - with n hn ht hv - linarith only [hn,ht,hv] - -theorem byCandle (hl : l≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) - (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) - (hb : q.citable l p M m w s b P) (hn : q.nebulous l s w P b) - {δ : ℝ} (hδ : 0<δ) (hc : ∀ᶠ n in l, δ ≤ charm s w P b n) : - satisfied q l p M m w := by - obtain ⟨t,hT,h1,h2,e,he,hF⟩:= dropHarvest hl hq hw hx hb - have hk : q.domed l t b := by - filter_upwards [hideOn hn hb hx,h2] with n hn hz - obtain ⟨T,hT,hE⟩:=hn - refine ⟨T,hT,fun i hi x hx=>?_⟩ - obtain ⟨⟨j,hj,hx'⟩,hv⟩:= hz i hi x hx - exact hE j hj x hx' hv - refine ⟨t,hT,Or.inr ⟨b,h1,Or.inl (hT.domeGlow hl hq hw hk (half_pos hδ) ?_)⟩⟩ - filter_upwards [hF,hc,(he.lim (trend_sizes l hl hq.hM).2).eventually - (gt_mem_nhds (half_pos hδ))] - with n hn ht hv - linarith only [hn,ht,hv] - -theorem byGlitter (hl : l≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) - (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) - (hb : q.citable l p M m w s b P) (hn : q.nebulous l s w P b) - (hd : b.c=dusk) - {δ : ℝ} (hδ : 0<δ) - (hc : ∀ᶠ n in l, δ/((M*n:ℕ):ℝ)^4 ≤ charm s w P b n) : - satisfied q l p M m w := by - obtain ⟨t,hT,h1,h2,e,he,hF⟩:= pressHarvest hl hq hw hx hb hn - let z (n:ℕ):=((M*n:ℕ):ℝ) - have hz := (trend_sizes l hl hq.hM).2 - have hi : ∀ᶠ n in l,e n * (z n)^4 <δ/2 := - ((he.poly hz 4).lim hz).eventually (gt_mem_nhds (half_pos hδ)) - refine ⟨t,hT,Or.inr ⟨b,h1,Or.inr (hT.domeSpark hl hq hw hd h2 (half_pos hδ) ?_)⟩⟩ - filter_upwards [hF,hc,hz.eventually (eventually_gt_atTop 0),hi] with n hn ht hv h' - have hz : 0< z n := hv - have he := (lt_div_iff₀ (show 0 < (z n)^4 from by positivity)).mpr h' - change (δ/2)/(z n)^4 ≤ _ - change δ/(z n)^4 ≤ _ at ht - rw [show (δ/2)/(z n)^4= (δ/(z n)^4)/2 from by ring] at he ⊢ - linarith only [hn,ht,he] - -theorem citable_interpose (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) - (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) - (hb : q.citable l p M m w s b P) - (h : warm l (fun i=>((M*i:ℕ):ℝ)) (fun i=> pr (potion s w P i) (Q i))) : - let Y:= fun i x=> P i x∧Q i x - q.citable l p M m w s b Y ∧ - ∀ᶠ n in l,potion s w Y n=onW (potion s w P n) (Q n) := by - classical - let Y : Campaign p M := fun i x=>P i x∧Q i x - have hz : ∀ᶠ n in l, IsLaw ((s n).sap (w n)) := by - filter_upwards [hw,hx] with n hn h - exact LeafMixture.sapLaw (lt_of_lt_of_le (by norm_num) h.weight) hn.law - have hm : citable q l p M m w s b Y := by - refine ⟨(hb.mass.mul h).mono ?_,hb.forecast, hb.mark.mono fun i hi j hj x hx h =>hi j hj x hx h.1⟩ - filter_upwards [hz] with n hn - exact (pr_of_on hn.nz (P n) (Q n)).symm.le - refine ⟨hm,?_⟩ - filter_upwards [hz,hb.mass.positive,h.positive] with n hn ht he - exact (on_both ((s n).sap (w n)) (P n) (Q n) hn.nz ht he).symm - -set_option maxHeartbeats 1000000 in -theorem outByMix (hl : l≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) - (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) - (hb : q.citable l p M m w s b P) - (hm : ∀ᶠ n in l, tonalMix p (delta (b.m n)) (potion s w P n)) : - satisfied q l p M m w := by - classical - refine byTorch hl hq hw hx hb ?_ - filter_upwards [hm,hb.on_law hl hq hw hx] with n hn ht - obtain ⟨v,hv⟩:= meet b.c b.α b.r - apply (mix_pattern p _ _ ht hn v).le.trans - refine pr_mono (pairW_law ht ht).nz (fun x h=>?_); unfold matchProg matchUp; rw [h]; exact hv - -variable {U : Ultrafilter ℕ} -set_option maxHeartbeats 1400000 in -theorem outByCover (hl : (U:Filter ℕ)≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in U,q.nascent p (M*n) (w n) (m n)) - (hx : ∀ᶠ n in U,q.entered p (M*n) (m n) (w n) (s n)) - (hb : q.citable (U:Filter ℕ) p M m w s b P) - (hm : ∀ᶠ n in U, tonalTiny p (delta (b.m n)) (potion s w P n) q.d) : - satisfied q (U:Filter ℕ) p M m w := by - classical - let l:Filter ℕ:=U - let v:= potion s w P - have hc : q.nebulous (U:Filter ℕ) s w P b:= hm.mono (fun i h=> by - obtain ⟨T,h1,h2,h3⟩:= h; exact ⟨T,h1,h2⟩) - have hv := hb.on_law hl hq hw hx - cases he : b.c with - | noon => - refine byTorch hl hq hw hx hb ?_ - filter_upwards [hv] with n hn - change _≤pr (pairW (v n) (v n)) _ - unfold matchProg matchUp; rw [he] - simp [compatible, (pairW_law hn hn).total, v]; norm_num - | dawn i => - let z (n : ℕ):=((M*n:ℕ):ℝ); have hz := (trend_sizes (U:Filter ℕ) hl hq.hM).2 - have ht : ∀ᶠ n in U,bp (-0.24*z n)<0.1 := - (((bp_tendsto_zero (by norm_num)).comp hz).eventually (gt_mem_nhds (by norm_num))) - refine byTorch hl hq hw hx hb ?_ - filter_upwards [hv,ht,hm] with n hn ht hk - unfold charm matchProg; rw [he] - exact le_trans (by norm_num) (tiny_morn p _ _ hn q.d hk ht _ _ _) - | twinned => - rcases slight_gap (U:=U) (x:=charm s w P b) with hj|⟨δ,hδ,hj⟩ - · obtain ⟨S,hS,hH⟩:= coFiber (U:Filter ℕ) hl hq.hM q.d p v b.α b.r (fun n=>delta (b.m n)) - (hv.and hc) (by unfold charm matchProg at hj; rwa [he] at hj) - let X : Campaign p M := fun i x=> P i x∧S i x - obtain ⟨h1,h2⟩:= citable_interpose hw hx hb hS - refine byTorch hl hq hw hx (P:=X) (b:=b) h1 ?_ - filter_upwards [h1.on_law hl hq hw hx,h2,hH] with n hn ht hq - let u := potion s w X n - have hp : IsLaw (pairW u u) := pairW_law hn hn - have hz (x) (hx : u x≠0) : S n x := by - rw [show u=onW (v n) (S n) from ht] at hx - exact (onW_ne hx).1 - have hi : charm s w X b n = pr (pairW u u) (fun _=> True) := by - apply avg_congr - intro x hx - have hm : matchProg b n x := by - unfold matchProg; rw [he] - exact hq x (hz _ (left_ne_zero_of_mul hx)) (hz _ (right_ne_zero_of_mul hx)) - change ind (matchProg b n x)=ind True - rw [ind_one hm,ind_true] - rw [hi,pr_true,hp.total]; norm_num - · exact byCandle hl hq hw hx hb hc hδ (hj.mono fun _ h=>h.le) - | dusk => - obtain ⟨δ,hδ,hH⟩:= eventually_tiny_poll q.d - refine byGlitter hl hq hw hx hb hc he hδ ?_ - filter_upwards [hx,hv,hm,hb.mark,(trend_sizes (U:Filter ℕ) hl hq.hM).1.eventually hH] - with n hn ht hv h hH - apply hH.trans - unfold charm matchProg matchUp; rw [he] - refine tiny_poll p _ _ ht hv ?_ b.r - intro x hx - obtain ⟨hp,hx⟩:= onW_ne hx - obtain ⟨⟨i,hi,hx⟩,_⟩:= LeafMixture.present hx - obtain ⟨⟨hE,h1⟩,h2,h3⟩:= h i hi x hx hp - exact diag_dusk (m n) (b.m n) x (fun i=> (effective_mem.mp (hE i).2).1) (h3 he) - (hn.onTile i hi x hx).2.2.2 - -end PreparationParameters -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PreparedPopulationTrimming + +namespace OAI + +/-! # Phase Prepared Outcomes -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset +open scoped BigOperators Topology +open PredictionClass + +namespace PreparationParameters +variable {l : Filter ℕ} {p : Shape} {M : ℕ} {q : PreparationParameters} + {m : cycleM p} {s : rhythms p M} {w : tale p M} {b : Sketch p M} {P Q : Campaign p M} + +def satisfied (q : PreparationParameters) (l : Filter ℕ) (p : Shape) (M : ℕ) (m : cycleM p) + (w : tale p M) := + ∃ t : rhythms p M,q.durable l p M m w t ∧ (q.silenceOutcome l p M m w t ∨ + q.predOutcome l p M m w t) + +theorem byTorch (hl : l≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) + (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) + (hb : q.citable l p M m w s b P) + (hc : ∀ᶠ n in l,0.05 ≤ charm s w P b n) : + satisfied q l p M m w := by + obtain ⟨t,hT,h1,h2,e,he,hF⟩:= dropHarvest hl hq hw hx hb + refine ⟨t,hT,Or.inr ⟨b,h1,Or.inl (hT.kindles hl hq hw ?_)⟩⟩ + filter_upwards [hF,hc,(he.lim (trend_sizes l hl hq.hM).2).eventually + (gt_mem_nhds (by norm_num : (0:ℝ) < 0.01))] + with n hn ht hv + linarith only [hn,ht,hv] + +theorem byCandle (hl : l≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) + (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) + (hb : q.citable l p M m w s b P) (hn : q.nebulous l s w P b) + {δ : ℝ} (hδ : 0<δ) (hc : ∀ᶠ n in l, δ ≤ charm s w P b n) : + satisfied q l p M m w := by + obtain ⟨t,hT,h1,h2,e,he,hF⟩:= dropHarvest hl hq hw hx hb + have hk : q.domed l t b := by + filter_upwards [hideOn hn hb hx,h2] with n hn hz + obtain ⟨T,hT,hE⟩:=hn + refine ⟨T,hT,fun i hi x hx=>?_⟩ + obtain ⟨⟨j,hj,hx'⟩,hv⟩:= hz i hi x hx + exact hE j hj x hx' hv + refine ⟨t,hT,Or.inr ⟨b,h1,Or.inl (hT.domeGlow hl hq hw hk (half_pos hδ) ?_)⟩⟩ + filter_upwards [hF,hc,(he.lim (trend_sizes l hl hq.hM).2).eventually + (gt_mem_nhds (half_pos hδ))] + with n hn ht hv + linarith only [hn,ht,hv] + +theorem byGlitter (hl : l≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) + (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) + (hb : q.citable l p M m w s b P) (hn : q.nebulous l s w P b) + (hd : b.c=dusk) + {δ : ℝ} (hδ : 0<δ) + (hc : ∀ᶠ n in l, δ/((M*n:ℕ):ℝ)^4 ≤ charm s w P b n) : + satisfied q l p M m w := by + obtain ⟨t,hT,h1,h2,e,he,hF⟩:= pressHarvest hl hq hw hx hb hn + let z (n:ℕ):=((M*n:ℕ):ℝ) + have hz := (trend_sizes l hl hq.hM).2 + have hi : ∀ᶠ n in l,e n * (z n)^4 <δ/2 := + ((he.poly hz 4).lim hz).eventually (gt_mem_nhds (half_pos hδ)) + refine ⟨t,hT,Or.inr ⟨b,h1,Or.inr (hT.domeSpark hl hq hw hd h2 (half_pos hδ) ?_)⟩⟩ + filter_upwards [hF,hc,hz.eventually (eventually_gt_atTop 0),hi] with n hn ht hv h' + have hz : 0< z n := hv + have he := (lt_div_iff₀ (show 0 < (z n)^4 from by positivity)).mpr h' + change (δ/2)/(z n)^4 ≤ _ + change δ/(z n)^4 ≤ _ at ht + rw [show (δ/2)/(z n)^4= (δ/(z n)^4)/2 from by ring] at he ⊢ + linarith only [hn,ht,he] + +theorem citable_interpose (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) + (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) + (hb : q.citable l p M m w s b P) + (h : warm l (fun i=>((M*i:ℕ):ℝ)) (fun i=> pr (potion s w P i) (Q i))) : + let Y:= fun i x=> P i x∧Q i x + q.citable l p M m w s b Y ∧ + ∀ᶠ n in l,potion s w Y n=onW (potion s w P n) (Q n) := by + classical + let Y : Campaign p M := fun i x=>P i x∧Q i x + have hz : ∀ᶠ n in l, IsLaw ((s n).sap (w n)) := by + filter_upwards [hw,hx] with n hn h + exact LeafMixture.sapLaw (lt_of_lt_of_le (by norm_num) h.weight) hn.law + have hm : citable q l p M m w s b Y := by + refine ⟨(hb.mass.mul h).mono ?_,hb.forecast, hb.mark.mono fun i hi j hj x hx h =>hi j hj x hx h.1⟩ + filter_upwards [hz] with n hn + exact (pr_of_on hn.nz (P n) (Q n)).symm.le + refine ⟨hm,?_⟩ + filter_upwards [hz,hb.mass.positive,h.positive] with n hn ht he + exact (on_both ((s n).sap (w n)) (P n) (Q n) hn.nz ht he).symm + +set_option maxHeartbeats 1000000 in +theorem outByMix (hl : l≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) + (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) + (hb : q.citable l p M m w s b P) + (hm : ∀ᶠ n in l, tonalMix p (delta (b.m n)) (potion s w P n)) : + satisfied q l p M m w := by + classical + refine byTorch hl hq hw hx hb ?_ + filter_upwards [hm,hb.on_law hl hq hw hx] with n hn ht + obtain ⟨v,hv⟩:= meet b.c b.α b.r + apply (mix_pattern p _ _ ht hn v).le.trans + refine pr_mono (pairW_law ht ht).nz (fun x h=>?_); unfold matchProg matchUp; rw [h]; exact hv + +variable {U : Ultrafilter ℕ} +set_option maxHeartbeats 1400000 in +theorem outByCover (hl : (U:Filter ℕ)≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in U,q.nascent p (M*n) (w n) (m n)) + (hx : ∀ᶠ n in U,q.entered p (M*n) (m n) (w n) (s n)) + (hb : q.citable (U:Filter ℕ) p M m w s b P) + (hm : ∀ᶠ n in U, tonalTiny p (delta (b.m n)) (potion s w P n) q.d) : + satisfied q (U:Filter ℕ) p M m w := by + classical + let l:Filter ℕ:=U + let v:= potion s w P + have hc : q.nebulous (U:Filter ℕ) s w P b:= hm.mono (fun i h=> by + obtain ⟨T,h1,h2,h3⟩:= h; exact ⟨T,h1,h2⟩) + have hv := hb.on_law hl hq hw hx + cases he : b.c with + | noon => + refine byTorch hl hq hw hx hb ?_ + filter_upwards [hv] with n hn + change _≤pr (pairW (v n) (v n)) _ + unfold matchProg matchUp; rw [he] + simp [compatible, (pairW_law hn hn).total, v]; norm_num + | dawn i => + let z (n : ℕ):=((M*n:ℕ):ℝ); have hz := (trend_sizes (U:Filter ℕ) hl hq.hM).2 + have ht : ∀ᶠ n in U,bp (-0.24*z n)<0.1 := + (((bp_tendsto_zero (by norm_num)).comp hz).eventually (gt_mem_nhds (by norm_num))) + refine byTorch hl hq hw hx hb ?_ + filter_upwards [hv,ht,hm] with n hn ht hk + unfold charm matchProg; rw [he] + exact le_trans (by norm_num) (tiny_morn p _ _ hn q.d hk ht _ _ _) + | twinned => + rcases slight_gap (U:=U) (x:=charm s w P b) with hj|⟨δ,hδ,hj⟩ + · obtain ⟨S,hS,hH⟩:= coFiber (U:Filter ℕ) hl hq.hM q.d p v b.α b.r (fun n=>delta (b.m n)) + (hv.and hc) (by unfold charm matchProg at hj; rwa [he] at hj) + let X : Campaign p M := fun i x=> P i x∧S i x + obtain ⟨h1,h2⟩:= citable_interpose hw hx hb hS + refine byTorch hl hq hw hx (P:=X) (b:=b) h1 ?_ + filter_upwards [h1.on_law hl hq hw hx,h2,hH] with n hn ht hq + let u := potion s w X n + have hp : IsLaw (pairW u u) := pairW_law hn hn + have hz (x) (hx : u x≠0) : S n x := by + rw [show u=onW (v n) (S n) from ht] at hx + exact (onW_ne hx).1 + have hi : charm s w X b n = pr (pairW u u) (fun _=> True) := by + apply avg_congr + intro x hx + have hm : matchProg b n x := by + unfold matchProg; rw [he] + exact hq x (hz _ (left_ne_zero_of_mul hx)) (hz _ (right_ne_zero_of_mul hx)) + change ind (matchProg b n x)=ind True + rw [ind_one hm,ind_true] + rw [hi,pr_true,hp.total]; norm_num + · exact byCandle hl hq hw hx hb hc hδ (hj.mono fun _ h=>h.le) + | dusk => + obtain ⟨δ,hδ,hH⟩:= eventually_tiny_poll q.d + refine byGlitter hl hq hw hx hb hc he hδ ?_ + filter_upwards [hx,hv,hm,hb.mark,(trend_sizes (U:Filter ℕ) hl hq.hM).1.eventually hH] + with n hn ht hv h hH + apply hH.trans + unfold charm matchProg matchUp; rw [he] + refine tiny_poll p _ _ ht hv ?_ b.r + intro x hx + obtain ⟨hp,hx⟩:= onW_ne hx + obtain ⟨⟨i,hi,hx⟩,_⟩:= LeafMixture.present hx + obtain ⟨⟨hE,h1⟩,h2,h3⟩:= h i hi x hx hp + exact diag_dusk (m n) (b.m n) x (fun i=> (effective_mem.mp (hE i).2).1) (h3 he) + (hn.onTile i hi x hx).2.2.2 + +end PreparationParameters +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PinInjectionTests.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PinInjectionTests.lean index 9e920b3a9f817c5beac53c81eba76f7ac2f99537..408d0f8be46cc90ecac827eefa1b3454ac557226 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PinInjectionTests.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PinInjectionTests.lean @@ -1,101 +1,101 @@ -import OAI.Combinatorics.HadwigerCounterexample.PhaseParameters - -namespace OAI - -/-! # Pin Injection Tests -/ - -noncomputable section -namespace HadwigerCounterexample - -open Matrix LinearMap Module Submodule Finset Function -open scoped BigOperators -variable {p : Shape} {n N : ℕ} - -abbrev Fpins (p : Shape) (n N : ℕ) := UnitType p n N → Plan p n - -def rootSet (b : Fpins p n N) (x : UnitType p n N) (i : Bool) (z : Place p) : - Space (Vec (Fin N)) := - (sPin (b x) z i).map (fpAt p (onSide x i) z).mulVecLin - -theorem rootSet_dim (b : Fpins p n N) (x : UnitType p n N) (i : Bool) (z : Place p) : - dim (rootSet b x i z)≤planRank (b x) := - (Submodule.finrank_map_le ..).trans ((sPin_dim ..).trans (dim_le_plan ..)) - -theorem rootSet_subset (b : Fpins p n N) (x : UnitType p n N) (i : Bool) (z : Place p) : - rootSet b x i z ≤ imageP p x i z := by - rintro y ⟨v,hv,rfl⟩ - exact ⟨v,rfl⟩ - -def strikeH (b : Fpins p n N) (z : Place p) (j : Bool) (v : Vec (Fin N)) (y : UnitType p n N) := - (fyAt p (onSide y j) (flipZ p z))ᵀ*ᵥ v∈ hPin (b y) z j -def fans (b : Fpins p n N) (z : Place p) (i j : Bool) (x y : UnitType p n N) := - ∃ v∈rootSet b x i z,v≠0 ∧ strikeH b z j v y - -theorem fans_of_not_inj (b : Fpins p n N) (x y : UnitType p n N) (m : Mixer p n) - (hh : ∀ i,frameLaw m (onSide x i)) - (h : ¬tableInj (b x) (b y) (actual p x y)) : - ∃ z i j, fans b z i j x y := by - unfold tableInj at h - push Not at h - obtain ⟨z,i,j,v,hv,he,hg⟩ := h - let B := fpAt p (onSide x i) z - have hf : v∈sPin (b x) z i := ⟨_,hv,(by - change (IP p n i)ᵀ *ᵥ (IP p n i *ᵥ v) = v - rw [Matrix.mulVec_mulVec,IP_self,Matrix.one_mulVec])⟩ - have ht : Injective B.mulVec := by - cases z with - | mk e c => - cases c; exact primary_inj (hh i e).2.1; exact primary_inj (hh i e).1 - refine ⟨z,i,j,B *ᵥ v,⟨v,hf,rfl⟩, fun hx => hg (ht (hx.trans (Matrix.mulVec_zero _).symm)),?_⟩ - have hZ : - channelOut p (actual p x y) j z * IP p n i=(fyAt p (onSide y j) (flipZ p z))ᵀ*B := by - unfold channelOut actual - rw [Matrix.mul_assoc (images x z)ᵀ,images_ih,Matrix.transpose_mul,Matrix.transpose_transpose, - Matrix.mul_assoc,images_ip]; rfl - rw [Matrix.mulVec_mulVec,hZ,← Matrix.mulVec_mulVec] at he - exact he - -def fireBill (p : Shape) (k K : ℕ) (H : ℝ) := - H*2 * bp ((p.h:ℝ)*K+(K-(p.h:ℝ))*k) - -set_option maxHeartbeats 600000 in -theorem strikers (b : Fpins p n N) (K : ℕ) (hb : ∀ x,planRank (b x)≤K) - {k : ℕ} (P : Mat (Fin N) (Fin k)) (h : Injective P.mulVec) - {w : Wgt (UnitType p n N)} (m : Mixer p n) {H : ℝ} (hH : 0 ≤ H) - (hh : bySide p w m H) (hw : SubLaw w) (i : Bool) (z : Place p) (hN : 2*num (Full p n)-N≤ -1) : - pr w (fun y => ∀ j,strikeH b z i (P.col j) y) ≤ fireBill p k K H := by - classical - let f (y : UnitType p n N) := (fyAt p (onSide y i) (flipZ p z))ᵀ*P - have hh' y (hh : ∀ j,strikeH b z i (P.col j) y) : - colSp (f y)≤ hPin (b y) z i := by - rw [colSp, range_mulVecLin] - exact Submodule.span_le.mpr (Set.range_subset_iff.mpr fun j => hh j) - let A := Mat (Chan p) (Fin K) - let D := Mat (Fin K) (Fin k) - have he y (hh : ∀ j,strikeH b z i (P.col j) y) : - ∃ v : A×D, f y=v.1 * v.2 := by - have hr : (f y).rank ≤ K := - (Submodule.finrank_mono (hh' y hh)).trans - (((hPin_dim ..).trans (dim_le_plan ..)).trans (hb y)) - obtain ⟨Q,X,hQ⟩ := mul_factor (f y) K hr - exact ⟨(Q,X),hQ.symm⟩ - let C (v : A×D) (x) := f x=v.1*v.2 - refine ((pr_mono hw.nz he).trans (pr_exists_le hw.nz C)).trans ?_ - have ht v : - pr w (C v)≤H*2* (bp (-(p.h:ℝ)*k)) := by - have he := test_transpose m hH hh i (flipZ p z) hN P h (v.1*v.2) - rw [unif_apply,card_space,dim_mat] at he - exact he.trans_eq (by rw [neg_mul,bp_neg]; simp) - refine (Finset.sum_le_sum fun i _ => ht i).trans_eq ?_ - rw [Finset.sum_const,nsmul_eq_mul,card_univ,Fintype.card_prod,Nat.cast_mul] - have hA : num A=bp ((p.h:ℝ)*K) := by simp only [A,cast_mat,Chan,num,Fintype.card_fin] - have hD : num D=bp ((K:ℝ)*k) := by simp only [D,cast_mat,num,Fintype.card_fin] - unfold fireBill - change num A*num D*_ = _ - rw [hA,hD,←bp_add, mul_left_comm,←bp_add]; congr 2; ring - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PhaseParameters + +namespace OAI + +/-! # Pin Injection Tests -/ + +noncomputable section +namespace HadwigerCounterexample + +open Matrix LinearMap Module Submodule Finset Function +open scoped BigOperators +variable {p : Shape} {n N : ℕ} + +abbrev Fpins (p : Shape) (n N : ℕ) := UnitType p n N → Plan p n + +def rootSet (b : Fpins p n N) (x : UnitType p n N) (i : Bool) (z : Place p) : + Space (Vec (Fin N)) := + (sPin (b x) z i).map (fpAt p (onSide x i) z).mulVecLin + +theorem rootSet_dim (b : Fpins p n N) (x : UnitType p n N) (i : Bool) (z : Place p) : + dim (rootSet b x i z)≤planRank (b x) := + (Submodule.finrank_map_le ..).trans ((sPin_dim ..).trans (dim_le_plan ..)) + +theorem rootSet_subset (b : Fpins p n N) (x : UnitType p n N) (i : Bool) (z : Place p) : + rootSet b x i z ≤ imageP p x i z := by + rintro y ⟨v,hv,rfl⟩ + exact ⟨v,rfl⟩ + +def strikeH (b : Fpins p n N) (z : Place p) (j : Bool) (v : Vec (Fin N)) (y : UnitType p n N) := + (fyAt p (onSide y j) (flipZ p z))ᵀ*ᵥ v∈ hPin (b y) z j +def fans (b : Fpins p n N) (z : Place p) (i j : Bool) (x y : UnitType p n N) := + ∃ v∈rootSet b x i z,v≠0 ∧ strikeH b z j v y + +theorem fans_of_not_inj (b : Fpins p n N) (x y : UnitType p n N) (m : Mixer p n) + (hh : ∀ i,frameLaw m (onSide x i)) + (h : ¬tableInj (b x) (b y) (actual p x y)) : + ∃ z i j, fans b z i j x y := by + unfold tableInj at h + push Not at h + obtain ⟨z,i,j,v,hv,he,hg⟩ := h + let B := fpAt p (onSide x i) z + have hf : v∈sPin (b x) z i := ⟨_,hv,(by + change (IP p n i)ᵀ *ᵥ (IP p n i *ᵥ v) = v + rw [Matrix.mulVec_mulVec,IP_self,Matrix.one_mulVec])⟩ + have ht : Injective B.mulVec := by + cases z with + | mk e c => + cases c; exact primary_inj (hh i e).2.1; exact primary_inj (hh i e).1 + refine ⟨z,i,j,B *ᵥ v,⟨v,hf,rfl⟩, fun hx => hg (ht (hx.trans (Matrix.mulVec_zero _).symm)),?_⟩ + have hZ : + channelOut p (actual p x y) j z * IP p n i=(fyAt p (onSide y j) (flipZ p z))ᵀ*B := by + unfold channelOut actual + rw [Matrix.mul_assoc (images x z)ᵀ,images_ih,Matrix.transpose_mul,Matrix.transpose_transpose, + Matrix.mul_assoc,images_ip]; rfl + rw [Matrix.mulVec_mulVec,hZ,← Matrix.mulVec_mulVec] at he + exact he + +def fireBill (p : Shape) (k K : ℕ) (H : ℝ) := + H*2 * bp ((p.h:ℝ)*K+(K-(p.h:ℝ))*k) + +set_option maxHeartbeats 600000 in +theorem strikers (b : Fpins p n N) (K : ℕ) (hb : ∀ x,planRank (b x)≤K) + {k : ℕ} (P : Mat (Fin N) (Fin k)) (h : Injective P.mulVec) + {w : Wgt (UnitType p n N)} (m : Mixer p n) {H : ℝ} (hH : 0 ≤ H) + (hh : bySide p w m H) (hw : SubLaw w) (i : Bool) (z : Place p) (hN : 2*num (Full p n)-N≤ -1) : + pr w (fun y => ∀ j,strikeH b z i (P.col j) y) ≤ fireBill p k K H := by + classical + let f (y : UnitType p n N) := (fyAt p (onSide y i) (flipZ p z))ᵀ*P + have hh' y (hh : ∀ j,strikeH b z i (P.col j) y) : + colSp (f y)≤ hPin (b y) z i := by + rw [colSp, range_mulVecLin] + exact Submodule.span_le.mpr (Set.range_subset_iff.mpr fun j => hh j) + let A := Mat (Chan p) (Fin K) + let D := Mat (Fin K) (Fin k) + have he y (hh : ∀ j,strikeH b z i (P.col j) y) : + ∃ v : A×D, f y=v.1 * v.2 := by + have hr : (f y).rank ≤ K := + (Submodule.finrank_mono (hh' y hh)).trans + (((hPin_dim ..).trans (dim_le_plan ..)).trans (hb y)) + obtain ⟨Q,X,hQ⟩ := mul_factor (f y) K hr + exact ⟨(Q,X),hQ.symm⟩ + let C (v : A×D) (x) := f x=v.1*v.2 + refine ((pr_mono hw.nz he).trans (pr_exists_le hw.nz C)).trans ?_ + have ht v : + pr w (C v)≤H*2* (bp (-(p.h:ℝ)*k)) := by + have he := test_transpose m hH hh i (flipZ p z) hN P h (v.1*v.2) + rw [unif_apply,card_space,dim_mat] at he + exact he.trans_eq (by rw [neg_mul,bp_neg]; simp) + refine (Finset.sum_le_sum fun i _ => ht i).trans_eq ?_ + rw [Finset.sum_const,nsmul_eq_mul,card_univ,Fintype.card_prod,Nat.cast_mul] + have hA : num A=bp ((p.h:ℝ)*K) := by simp only [A,cast_mat,Chan,num,Fintype.card_fin] + have hD : num D=bp ((K:ℝ)*k) := by simp only [D,cast_mat,num,Fintype.card_fin] + unfold fireBill + change num A*num D*_ = _ + rw [hA,hD,←bp_add, mul_left_comm,←bp_add]; congr 2; ring + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PointAtomVanishing.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PointAtomVanishing.lean index ba614f717e9473001d874e58ffd80a6e9e7f16a2..63607de397da2ba10cd2b36c8dedddfa731212ad 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PointAtomVanishing.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PointAtomVanishing.lean @@ -1,104 +1,104 @@ -import OAI.Combinatorics.HadwigerCounterexample.PolynomialZeroTests - -namespace OAI - -/-! # Point Atom Vanishing -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module Submodule Function Finset LinearMap -open scoped BigOperators -variable {p : Shape} {n : ℕ} {I A : Type} [Fintype I] [Fintype A] -variable [DecidableEq I] [DecidableEq A] - -omit [Fintype A] in -private theorem pointPoly (f : Mat I I→ₗ[F] F) (x : Vec A→Vec I) (d : ℕ) - (hx : ∀ i,(fun s=>x s i)∈Stocks A d) : - (fun s=>f (vecMulVec (x s) (x s))) ∈ Stocks A (2*d) := by - classical - let E (i : I×I) := vecMulVec (Pi.single i.1 (1:F)) (Pi.single i.2 (1:F)) - have he (v : Vec I) : - vecMulVec v v=∑ i:I × I,(v i.1*v i.2) • E i := by - ext i j; rw [Matrix.sum_apply, Finset.sum_eq_single (i,j)] - · simp [E,Matrix.vecMulVec_apply] - · intro z _ hz - have h : i≠z.1 ∨ j≠z.2 := not_and_or.mp (fun h=>hz (Prod.ext h.1.symm h.2.symm)) - rcases h with h|h <;> simp [E,Matrix.vecMulVec_apply,Pi.single_eq_of_ne h] - simp - let P (i : I × I) : Vec (Vec A) := f (E i) • - ((fun s => x s i.1) * (fun s => x s i.2)) - have hm : - (fun s=>f (vecMulVec (x s) (x s)))=∑ i:I×I,P i := by - funext s; simp only [he,map_sum,map_smul,Finset.sum_apply,P, - Pi.smul_apply, Pi.mul_apply,smul_eq_mul]; simp only [mul_comm] - rw [hm] - apply Submodule.sum_mem - intro i _ - unfold P - rw [two_mul]; exact Submodule.smul_mem _ _ (stock_prod (hx _) (hx _)) - -set_option maxHeartbeats 600000 in -theorem vat_erase (l : Tag p.g) (s : Label p.b) (f : Moment p n→ₗ[F] F) - (h : pr (spins p n) - (fun x => f (mom p s (lit Flavor.full l x)) ≠ 0)<1/4) : - ∀ z : Base p.g n,allows l z → f (mom p s z)=0 := by - classical - let e : Base p.g n ≃ Knobs p.g n := ⟨curry,uncurry,fun _=>rfl,fun _=>rfl⟩ - let Z (x : Base p.g n) := lit Flavor.full l (e x) - let Q (x : Base p.g n) := point p s (Z x) - have he (i : Row p n) : (fun x=> Q x i)∈Stocks (BaseIdx p.g n) 1 := by - rcases i with ⟨a,_|k⟩ - · exact stocks_one _ 1 _ - let h := monoBit s a.val - by_cases ha : Flavor.full.keeps l k.1 - · unfold Q Z - simp_rw [point_eval, baseV,Option.elim',lit,ite_eq_left ha] - exact Submodule.smul_mem _ h (stock_var k) - unfold Q Z - simp_rw [point_eval,baseV,Option.elim',lit,ite_eq_right ha] - exact stocks_one _ _ _ - intro z hz; by_contra ht - have hZ : Z z=z := by - funext i - by_cases hh : Flavor.full.keeps l i.1 - · exact ite_eq_left hh - rcases i with ⟨⟨d,t⟩|i,j⟩ - · exact (ite_eq_right hh).trans (hz d t hh j).symm - exact (hh trivial).elim - have hg := stocks_bound (BaseIdx p.g n) _ _ - (pointPoly f Q 1 he) ⟨z,(by unfold Q; rw [hZ]; exact ht)⟩ - have hpr : - pr (spins p n) (fun x => f (mom p s (lit Flavor.full l x))≠0) = - pr unif (fun x => f (vecMulVec (Q x) (Q x))≠0) := by - unfold spins; rw [←draws_unif,←unif_equiv e,mapW_pr]; rfl - rw [hpr] at h - have hi := lt_of_le_of_lt hg h - norm_num [bp] at hi - -set_option maxHeartbeats 800000 in -theorem vat_excluded (z : Base p.g n) (E : Finset (Label p.b)) (f : Moment p n→ₗ[F] F) - (h : ∀ s,s∉E → f (mom p s z)=0) - (hE : (E.card:ℝ) < bp ((p.b:ℝ)-2*p.j)) : ∀ s,f (mom p s z)=0 := by - classical - let Q := fun s=>point p s z - have he (i : Row p n) : (fun s=>Q s i)∈ Stocks (Fin p.b) p.j := by - rcases i with ⟨a,b⟩ - have h : (fun s=>Q s (a,b)) = baseV z b • poly1 a.val := by - unfold Q poly1; funext s; exact mul_comm _ _ - rw [h]; exact Submodule.smul_mem _ _ (subset_span ⟨_,a.property,rfl⟩) - intro s; by_contra! hh - let p' y := f (mom p y z)≠0 - have hz := stocks_bound (Fin p.b) _ _ (pointPoly f Q p.j he) ⟨s,hh⟩ - have ha := hz.trans (pr_mono unif_law.nz (p:=p') (q:=fun s=>s∈ E) fun i hi => - not_not.mp (fun hg=> hi (h i hg))) - rw [pr_unif,nbr_eq_card, card_space (Vec (Fin p.b)), dim_vec,Fintype.card_fin] at ha - have hh : Fintype.card {i // i∈E}=E.card := Fintype.card_coe E - rw [hh,le_div_iff₀ (bp_pos _),←bp_add] at ha - push_cast at ha - rw [show -(2*(p.j:ℝ)) + p.b=p.b-2*(p.j:ℝ) by ring] at ha - exact hE.not_ge ha -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PolynomialZeroTests + +namespace OAI + +/-! # Point Atom Vanishing -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module Submodule Function Finset LinearMap +open scoped BigOperators +variable {p : Shape} {n : ℕ} {I A : Type} [Fintype I] [Fintype A] +variable [DecidableEq I] [DecidableEq A] + +omit [Fintype A] in +private theorem pointPoly (f : Mat I I→ₗ[F] F) (x : Vec A→Vec I) (d : ℕ) + (hx : ∀ i,(fun s=>x s i)∈Stocks A d) : + (fun s=>f (vecMulVec (x s) (x s))) ∈ Stocks A (2*d) := by + classical + let E (i : I×I) := vecMulVec (Pi.single i.1 (1:F)) (Pi.single i.2 (1:F)) + have he (v : Vec I) : + vecMulVec v v=∑ i:I × I,(v i.1*v i.2) • E i := by + ext i j; rw [Matrix.sum_apply, Finset.sum_eq_single (i,j)] + · simp [E,Matrix.vecMulVec_apply] + · intro z _ hz + have h : i≠z.1 ∨ j≠z.2 := not_and_or.mp (fun h=>hz (Prod.ext h.1.symm h.2.symm)) + rcases h with h|h <;> simp [E,Matrix.vecMulVec_apply,Pi.single_eq_of_ne h] + simp + let P (i : I × I) : Vec (Vec A) := f (E i) • + ((fun s => x s i.1) * (fun s => x s i.2)) + have hm : + (fun s=>f (vecMulVec (x s) (x s)))=∑ i:I×I,P i := by + funext s; simp only [he,map_sum,map_smul,Finset.sum_apply,P, + Pi.smul_apply, Pi.mul_apply,smul_eq_mul]; simp only [mul_comm] + rw [hm] + apply Submodule.sum_mem + intro i _ + unfold P + rw [two_mul]; exact Submodule.smul_mem _ _ (stock_prod (hx _) (hx _)) + +set_option maxHeartbeats 600000 in +theorem vat_erase (l : Tag p.g) (s : Label p.b) (f : Moment p n→ₗ[F] F) + (h : pr (spins p n) + (fun x => f (mom p s (lit Flavor.full l x)) ≠ 0)<1/4) : + ∀ z : Base p.g n,allows l z → f (mom p s z)=0 := by + classical + let e : Base p.g n ≃ Knobs p.g n := ⟨curry,uncurry,fun _=>rfl,fun _=>rfl⟩ + let Z (x : Base p.g n) := lit Flavor.full l (e x) + let Q (x : Base p.g n) := point p s (Z x) + have he (i : Row p n) : (fun x=> Q x i)∈Stocks (BaseIdx p.g n) 1 := by + rcases i with ⟨a,_|k⟩ + · exact stocks_one _ 1 _ + let h := monoBit s a.val + by_cases ha : Flavor.full.keeps l k.1 + · unfold Q Z + simp_rw [point_eval, baseV,Option.elim',lit,ite_eq_left ha] + exact Submodule.smul_mem _ h (stock_var k) + unfold Q Z + simp_rw [point_eval,baseV,Option.elim',lit,ite_eq_right ha] + exact stocks_one _ _ _ + intro z hz; by_contra ht + have hZ : Z z=z := by + funext i + by_cases hh : Flavor.full.keeps l i.1 + · exact ite_eq_left hh + rcases i with ⟨⟨d,t⟩|i,j⟩ + · exact (ite_eq_right hh).trans (hz d t hh j).symm + exact (hh trivial).elim + have hg := stocks_bound (BaseIdx p.g n) _ _ + (pointPoly f Q 1 he) ⟨z,(by unfold Q; rw [hZ]; exact ht)⟩ + have hpr : + pr (spins p n) (fun x => f (mom p s (lit Flavor.full l x))≠0) = + pr unif (fun x => f (vecMulVec (Q x) (Q x))≠0) := by + unfold spins; rw [←draws_unif,←unif_equiv e,mapW_pr]; rfl + rw [hpr] at h + have hi := lt_of_le_of_lt hg h + norm_num [bp] at hi + +set_option maxHeartbeats 800000 in +theorem vat_excluded (z : Base p.g n) (E : Finset (Label p.b)) (f : Moment p n→ₗ[F] F) + (h : ∀ s,s∉E → f (mom p s z)=0) + (hE : (E.card:ℝ) < bp ((p.b:ℝ)-2*p.j)) : ∀ s,f (mom p s z)=0 := by + classical + let Q := fun s=>point p s z + have he (i : Row p n) : (fun s=>Q s i)∈ Stocks (Fin p.b) p.j := by + rcases i with ⟨a,b⟩ + have h : (fun s=>Q s (a,b)) = baseV z b • poly1 a.val := by + unfold Q poly1; funext s; exact mul_comm _ _ + rw [h]; exact Submodule.smul_mem _ _ (subset_span ⟨_,a.property,rfl⟩) + intro s; by_contra! hh + let p' y := f (mom p y z)≠0 + have hz := stocks_bound (Fin p.b) _ _ (pointPoly f Q p.j he) ⟨s,hh⟩ + have ha := hz.trans (pr_mono unif_law.nz (p:=p') (q:=fun s=>s∈ E) fun i hi => + not_not.mp (fun hg=> hi (h i hg))) + rw [pr_unif,nbr_eq_card, card_space (Vec (Fin p.b)), dim_vec,Fintype.card_fin] at ha + have hh : Fintype.card {i // i∈E}=E.card := Fintype.card_coe E + rw [hh,le_div_iff₀ (bp_pos _),←bp_add] at ha + push_cast at ha + rw [show -(2*(p.j:ℝ)) + p.b=p.b-2*(p.j:ℝ) by ring] at ha + exact hE.not_ge ha +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PolarRankBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PolarRankBounds.lean index aa8e7aba63a82a600e502811b6642b181afe56f7..371650ae66dfbeb8e243c6c58b5e3890b76e0118 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PolarRankBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PolarRankBounds.lean @@ -1,150 +1,150 @@ -import OAI.Combinatorics.HadwigerCounterexample.MixerProductVariables - -namespace OAI - -/-! # Polar Rank Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix -open scoped BigOperators - -variable {I J U : Type} [Fintype I] [Fintype J] - -def swapM (I : Type) [DecidableEq I] : Mat (I⊕I) (I⊕I) := - fromBlocks (0:Mat I I) (1:Mat I I) (1:Mat I I) 0 - -theorem swapM_rank [DecidableEq I] : - (swapM I).rank = Fintype.card (I⊕I) := by - have h : swapM I * swapM I = 1 := by simp [swapM, fromBlocks_multiply] - apply mrk_inj.mp - intro x y hxy - have he (x) : swapM I *ᵥ (swapM I *ᵥ x)=x := by rw [mulVec_mulVec, h, Matrix.one_mulVec] - change swapM I*ᵥx=swapM I*ᵥy at hxy - rw [← he x,hxy,he] - -theorem alt_of_forms [Fintype U] [DecidableEq J] (P Q : Mat I J) (W : Mat I U) : - pullM W W (P*Qᵀ + (P*Qᵀ)ᵀ) = - liftM (Wᵀ * fromCols P Q) (Wᵀ * fromCols P Q) (swapM J) := by - have hh : P*Qᵀ+(P*Qᵀ)ᵀ = liftM (fromCols P Q) (fromCols P Q) (swapM J) := by - simp only [liftM_def,swapM,fromCols_mul_fromBlocks, - Matrix.mul_one,Matrix.mul_zero,add_zero,transpose_fromCols, - fromCols_mul_fromRows, transpose_mul,transpose_transpose,add_comm] - rw [hh] - apply liftM_comp - -variable {p : Shape} {n : ℕ} - -theorem flarge {r : Comp p.g→ℕ} (P Q : Parts p n r) : - ∃ S : Space (Ray p n), (∀ i,colSp (P i) ≤ S ∧ colSp (Q i) ≤ S) ∧ - dim S ≤ 2*(∑ i, r i) := by - classical - have he (J : Finset (Comp p.g)) : - ∃ S : Space (Ray p n), (∀ i∈J,colSp (P i) ≤ S ∧ colSp (Q i) ≤ S) ∧ - dim S ≤ 2*∑ i∈J,r i := by - induction J using Finset.induction with - | empty => exact ⟨⊥,fun _ h => (Finset.notMem_empty _ h).elim, - (finrank_bot _ _).le.trans (Nat.zero_le _)⟩ - | insert i J hi ih => - obtain ⟨S,hS,h⟩ := ih - let T := colSp (P i) ⊔ colSp (Q i) - refine ⟨S⊔T,fun j hj => ?_, ?_⟩ - · rcases Finset.mem_insert.mp hj with rfl|hj - · exact ⟨le_trans (show colSp _ ≤ T from le_sup_left) le_sup_right, - le_trans (show colSp _ ≤ T from le_sup_right) le_sup_right⟩ - · exact ⟨(hS j hj).1.trans le_sup_left,(hS j hj).2.trans le_sup_left⟩ - have hh : dim T ≤ 2*r i := by - have hp (P : Parts p n r) : dim (colSp (P i)) ≤ r i := by - rw [colSp_dim] - exact (Matrix.rank_le_card_width (P i)).trans_eq (Fintype.card_fin _) - rw [two_mul] - exact (Submodule.finrank_add_le_finrank_add_finrank ..).trans (Nat.add_le_add (hp _) (hp _)) - rw [Finset.sum_insert hi] - apply le_trans (Submodule.finrank_add_le_finrank_add_finrank ..) - exact (Nat.add_le_add h hh).trans (by omega) - obtain ⟨S,h,g⟩ := he Finset.univ - exact ⟨S,fun i => h _ (Finset.mem_univ i),g⟩ - -def urBad (K s0 : ℕ) (x : Profile p n) (l : Tag p.g) (s : Label p.b) (d : Draw p n) := - totalRank x ≤ K ∧ totalRank x>0 ∧ blockRank Block.Z s s - (qmix (drawn d) x l+(qmix (drawn d) x l)ᵀ)<2*(p.J-s0) - -def prodBound (p : Shape) (K : ℕ) := 4*p.J*(p.g-1)*K - -theorem urBad_cap (K s0 : ℕ) (hg : 2≤p.g) (hj : s0≤p.J) - (x : Profile p n) (l : Tag p.g) (s : Label p.b) : - pr unif (urBad K s0 x l s) ≤ - bp (((prodBound p K : ℝ)+2*K-n)*(s0+1)) := by - classical - by_cases h : totalRank x≤K ∧ totalRank x>0 - swap - · rw [show urBad K s0 x l s = fun _ => False by - funext d; exact propext ⟨fun g => h ⟨g.1,g.2.1⟩,False.elim⟩,pr_false] - exact (bp_pos _).le - let R := blockRay p n s Block.Z - let r i := (x i).rank - obtain ⟨P,Q,h1,h2,h3⟩ : - ∃ (P Q : Parts p n r), (∀ i,Function.Injective (P i).mulVec) ∧ - (∀ i,Function.Injective (Q i).mulVec) ∧ (∀ i,x i=P i*(Q i)ᵀ) := by - choose A B h1 h2 h3 using fun i => rank_product (x i) - refine ⟨A,fun i => (B i)ᵀ,h1,fun i => ?_,fun i => (h3 i).symm⟩ - rw [← transpose_surj_iff]; exact h2 i - obtain ⟨S,hS,hrS⟩ := flarge P Q - obtain ⟨T,hT,hv⟩ := choose_free (blockRay_inj p n s Block.Z) S - let W := R*pack T - let V := (Terms p l r) - let A := stackL P Q l W - have hb : Function.Surjective A := by - apply stack_surj _ _ _ _ - (inj_comp_mat _ _ (blockRay_inj p n s Block.Z) (pack_inj T)) h1 h2 - · exact fun i => hv.mono_left (hS i).1 - exact fun i => hv.mono_left (hS i).2 - have hc : Fintype.card (V⊕V)=prodBound p (totalRank x) := by - simp only [Fintype.card_sum,Terms,Fintype.card_prod, - Fintype.card_fin,Fintype.card_sigma,V,Fintype.card_bool,card_star] - unfold prodBound totalRank r; ring - have hcard : 2*p.J ≤ Fintype.card (V⊕V) := by - have he : 1 ≤ p.g-1 := by omega - have hx : 1 ≤ totalRank x := h.2 - rw [hc]; unfold prodBound - nlinarith only [Nat.mul_le_mul_left (p.J*(p.g-1)) hx, - Nat.mul_le_mul_left p.J he, Nat.zero_le p.J] - let Y (M : Mat (Fin (dim T)) (V ⊕ V)) := - M.rank+(s0+1) ≤ Fintype.card (V⊕V) - have he (d) (hh : urBad K s0 x l s d) : Y (A d) := by - let B := qmix (drawn d) x l + (qmix (drawn d) x l)ᵀ - have hineq := rank_ge_congr (swapM V) (A d) - have hx : pullM W W B=liftM (A d) (A d) (swapM V) := by - dsimp only [B] - rw [qmix_eq P Q l d h3] - exact alt_of_forms _ _ W - rw [← hx, swapM_rank] at hineq - have hp : (pullM W W B).rank ≤ (pullM R R B).rank := by - calc _ = (pullM (pack T) (pack T) (pullM R R B)).rank := by - unfold W pullM - rw [liftM_comp, Matrix.transpose_mul] - _ ≤ _ := rank_lift_le _ _ _ - have hh1 : (pullM R R B).rank < 2*(p.J-s0) := hh.2.2 - change _+_ ≤ _ - omega - have hpr := pr_mono (w:=unif) unif_subLaw.nz he - change pr unif (urBad K s0 x l s) ≤ pr unif (fun d => Y (A d)) at hpr - rw [← mapW_pr unif A Y,map_unif_surjective _ hb] at hpr - apply le_trans (hpr.trans (pr_deficient _)) - apply bp_le - have hp : num (V ⊕ V) ≤ prodBound p K := by - have he : Fintype.card (V⊕V) ≤ prodBound p K := by rw [hc]; unfold prodBound; gcongr; exact h.1 - exact_mod_cast he - have hx : n ≤ num (Fin (dim T)) + 2*(K:ℝ) := by - rw [Fintype.card_fin] at hT - have he : n ≤ Fintype.card (Fin (dim T)) + 2*K := by - rw [Fintype.card_fin] - exact hT.trans (Nat.add_le_add_left (hrS.trans (Nat.mul_le_mul_left _ h.1)) _) - exact_mod_cast he - push_cast; apply mul_le_mul_of_nonneg_right _ (by positivity) - linarith only [hp,hx] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.MixerProductVariables + +namespace OAI + +/-! # Polar Rank Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix +open scoped BigOperators + +variable {I J U : Type} [Fintype I] [Fintype J] + +def swapM (I : Type) [DecidableEq I] : Mat (I⊕I) (I⊕I) := + fromBlocks (0:Mat I I) (1:Mat I I) (1:Mat I I) 0 + +theorem swapM_rank [DecidableEq I] : + (swapM I).rank = Fintype.card (I⊕I) := by + have h : swapM I * swapM I = 1 := by simp [swapM, fromBlocks_multiply] + apply mrk_inj.mp + intro x y hxy + have he (x) : swapM I *ᵥ (swapM I *ᵥ x)=x := by rw [mulVec_mulVec, h, Matrix.one_mulVec] + change swapM I*ᵥx=swapM I*ᵥy at hxy + rw [← he x,hxy,he] + +theorem alt_of_forms [Fintype U] [DecidableEq J] (P Q : Mat I J) (W : Mat I U) : + pullM W W (P*Qᵀ + (P*Qᵀ)ᵀ) = + liftM (Wᵀ * fromCols P Q) (Wᵀ * fromCols P Q) (swapM J) := by + have hh : P*Qᵀ+(P*Qᵀ)ᵀ = liftM (fromCols P Q) (fromCols P Q) (swapM J) := by + simp only [liftM_def,swapM,fromCols_mul_fromBlocks, + Matrix.mul_one,Matrix.mul_zero,add_zero,transpose_fromCols, + fromCols_mul_fromRows, transpose_mul,transpose_transpose,add_comm] + rw [hh] + apply liftM_comp + +variable {p : Shape} {n : ℕ} + +theorem flarge {r : Comp p.g→ℕ} (P Q : Parts p n r) : + ∃ S : Space (Ray p n), (∀ i,colSp (P i) ≤ S ∧ colSp (Q i) ≤ S) ∧ + dim S ≤ 2*(∑ i, r i) := by + classical + have he (J : Finset (Comp p.g)) : + ∃ S : Space (Ray p n), (∀ i∈J,colSp (P i) ≤ S ∧ colSp (Q i) ≤ S) ∧ + dim S ≤ 2*∑ i∈J,r i := by + induction J using Finset.induction with + | empty => exact ⟨⊥,fun _ h => (Finset.notMem_empty _ h).elim, + (finrank_bot _ _).le.trans (Nat.zero_le _)⟩ + | insert i J hi ih => + obtain ⟨S,hS,h⟩ := ih + let T := colSp (P i) ⊔ colSp (Q i) + refine ⟨S⊔T,fun j hj => ?_, ?_⟩ + · rcases Finset.mem_insert.mp hj with rfl|hj + · exact ⟨le_trans (show colSp _ ≤ T from le_sup_left) le_sup_right, + le_trans (show colSp _ ≤ T from le_sup_right) le_sup_right⟩ + · exact ⟨(hS j hj).1.trans le_sup_left,(hS j hj).2.trans le_sup_left⟩ + have hh : dim T ≤ 2*r i := by + have hp (P : Parts p n r) : dim (colSp (P i)) ≤ r i := by + rw [colSp_dim] + exact (Matrix.rank_le_card_width (P i)).trans_eq (Fintype.card_fin _) + rw [two_mul] + exact (Submodule.finrank_add_le_finrank_add_finrank ..).trans (Nat.add_le_add (hp _) (hp _)) + rw [Finset.sum_insert hi] + apply le_trans (Submodule.finrank_add_le_finrank_add_finrank ..) + exact (Nat.add_le_add h hh).trans (by omega) + obtain ⟨S,h,g⟩ := he Finset.univ + exact ⟨S,fun i => h _ (Finset.mem_univ i),g⟩ + +def urBad (K s0 : ℕ) (x : Profile p n) (l : Tag p.g) (s : Label p.b) (d : Draw p n) := + totalRank x ≤ K ∧ totalRank x>0 ∧ blockRank Block.Z s s + (qmix (drawn d) x l+(qmix (drawn d) x l)ᵀ)<2*(p.J-s0) + +def prodBound (p : Shape) (K : ℕ) := 4*p.J*(p.g-1)*K + +theorem urBad_cap (K s0 : ℕ) (hg : 2≤p.g) (hj : s0≤p.J) + (x : Profile p n) (l : Tag p.g) (s : Label p.b) : + pr unif (urBad K s0 x l s) ≤ + bp (((prodBound p K : ℝ)+2*K-n)*(s0+1)) := by + classical + by_cases h : totalRank x≤K ∧ totalRank x>0 + swap + · rw [show urBad K s0 x l s = fun _ => False by + funext d; exact propext ⟨fun g => h ⟨g.1,g.2.1⟩,False.elim⟩,pr_false] + exact (bp_pos _).le + let R := blockRay p n s Block.Z + let r i := (x i).rank + obtain ⟨P,Q,h1,h2,h3⟩ : + ∃ (P Q : Parts p n r), (∀ i,Function.Injective (P i).mulVec) ∧ + (∀ i,Function.Injective (Q i).mulVec) ∧ (∀ i,x i=P i*(Q i)ᵀ) := by + choose A B h1 h2 h3 using fun i => rank_product (x i) + refine ⟨A,fun i => (B i)ᵀ,h1,fun i => ?_,fun i => (h3 i).symm⟩ + rw [← transpose_surj_iff]; exact h2 i + obtain ⟨S,hS,hrS⟩ := flarge P Q + obtain ⟨T,hT,hv⟩ := choose_free (blockRay_inj p n s Block.Z) S + let W := R*pack T + let V := (Terms p l r) + let A := stackL P Q l W + have hb : Function.Surjective A := by + apply stack_surj _ _ _ _ + (inj_comp_mat _ _ (blockRay_inj p n s Block.Z) (pack_inj T)) h1 h2 + · exact fun i => hv.mono_left (hS i).1 + exact fun i => hv.mono_left (hS i).2 + have hc : Fintype.card (V⊕V)=prodBound p (totalRank x) := by + simp only [Fintype.card_sum,Terms,Fintype.card_prod, + Fintype.card_fin,Fintype.card_sigma,V,Fintype.card_bool,card_star] + unfold prodBound totalRank r; ring + have hcard : 2*p.J ≤ Fintype.card (V⊕V) := by + have he : 1 ≤ p.g-1 := by omega + have hx : 1 ≤ totalRank x := h.2 + rw [hc]; unfold prodBound + nlinarith only [Nat.mul_le_mul_left (p.J*(p.g-1)) hx, + Nat.mul_le_mul_left p.J he, Nat.zero_le p.J] + let Y (M : Mat (Fin (dim T)) (V ⊕ V)) := + M.rank+(s0+1) ≤ Fintype.card (V⊕V) + have he (d) (hh : urBad K s0 x l s d) : Y (A d) := by + let B := qmix (drawn d) x l + (qmix (drawn d) x l)ᵀ + have hineq := rank_ge_congr (swapM V) (A d) + have hx : pullM W W B=liftM (A d) (A d) (swapM V) := by + dsimp only [B] + rw [qmix_eq P Q l d h3] + exact alt_of_forms _ _ W + rw [← hx, swapM_rank] at hineq + have hp : (pullM W W B).rank ≤ (pullM R R B).rank := by + calc _ = (pullM (pack T) (pack T) (pullM R R B)).rank := by + unfold W pullM + rw [liftM_comp, Matrix.transpose_mul] + _ ≤ _ := rank_lift_le _ _ _ + have hh1 : (pullM R R B).rank < 2*(p.J-s0) := hh.2.2 + change _+_ ≤ _ + omega + have hpr := pr_mono (w:=unif) unif_subLaw.nz he + change pr unif (urBad K s0 x l s) ≤ pr unif (fun d => Y (A d)) at hpr + rw [← mapW_pr unif A Y,map_unif_surjective _ hb] at hpr + apply le_trans (hpr.trans (pr_deficient _)) + apply bp_le + have hp : num (V ⊕ V) ≤ prodBound p K := by + have he : Fintype.card (V⊕V) ≤ prodBound p K := by rw [hc]; unfold prodBound; gcongr; exact h.1 + exact_mod_cast he + have hx : n ≤ num (Fin (dim T)) + 2*(K:ℝ) := by + rw [Fintype.card_fin] at hT + have he : n ≤ Fintype.card (Fin (dim T)) + 2*K := by + rw [Fintype.card_fin] + exact hT.trans (Nat.add_le_add_left (hrS.trans (Nat.mul_le_mul_left _ h.1)) _) + exact_mod_cast he + push_cast; apply mul_le_mul_of_nonneg_right _ (by positivity) + linarith only [hp,hx] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PolynomialCompatibility.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PolynomialCompatibility.lean index 82b6db44d7079ebdba9b9280b72a25d060173e90..5683c5d7285cd6884753dac38a9eae22ee057321 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PolynomialCompatibility.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PolynomialCompatibility.lean @@ -1,86 +1,86 @@ -import OAI.Combinatorics.HadwigerCounterexample.FourPhaseBits - -namespace OAI - -/-! # Polynomial Compatibility -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Module Finset Filter -variable {p : Shape} {n N d : ℕ} - -def poll (d N : ℕ) := (1+(1+d*(N:ℝ))^2)^2 - -set_option maxHeartbeats 600000 in -theorem tiny_poll (p : Shape) {n N : ℕ} (Δ : UnitType p n N→Ambient p N) - (w : Wgt (UnitType p n N)) (hw : IsLaw w) - (h : tonalTiny p Δ w d) - (hd : ∀ x, w x≠0 → tone p x allSide (Δ x) = 0) (i : F) : - (1/4 : ℝ)/poll d N-bp (-0.24*N)≤ - pr (pairW w w) (fun x => quench p Δ x=repeatQ i) := by - classical - obtain ⟨T,hT,hZ,hE⟩ := h - let M := circus p T Δ w - have hM : M.rank≤ d*N := (circus_rank ..).trans ((Nat.mul_le_mul_left N hT).trans_eq - (Nat.mul_comm _ _)) - have hB (x y) (hx : w x≠0) : - tone p y allSide (Δ x)=M x y := (shadow_valid p T Δ hZ x y allSide hx).symm - have hD x : M x x=0 := by - by_cases hx : w x=0 - · change juris p T x _ (cutDown p T Δ w x) = _ - simp [cutDown,hx] - exact (hB _ _ hx).symm.trans (hd x hx) - let u := pairW w w - have hX : - pr u (fun x => M x.1 x.2=0 ∧ M x.2 x.1=0)= - pr u (fun x => repeated (quench p Δ x)) := by - refine avg_congr (fun x hx => ?_) - congr 1 - have h1 := hB x.1 x.2 (left_ne_zero_of_mul hx) - have h2 := hB x.2 x.1 (right_ne_zero_of_mul hx) - unfold repeated quench - simp only [←tone_vec,h1,h2] - have hi : 1 ≤ poll d N*pr u (fun x => repeated (quench p Δ x)) := by - have hh := simultaneous_czeros M (1+d*N) w hw (by omega) hD - rw [show pairW w w=u from rfl,hX] at hh - refine le_trans hh (le_of_eq ?_) - push_cast; unfold poll - ring - have hh : 0 < poll d N := by unfold poll; positivity - apply le_trans _ (tiny_pattern p Δ w i (bp_pos _).le hE) - apply sub_le_sub_right - exact (div_le_iff₀ hh).mpr (by linarith only [hi]) - -theorem eventually_tiny_poll (d : ℕ) : - ∃ b> (0:ℝ),∀ᶠ N : ℕ in atTop, - b/N^ (4:ℕ) ≤ (1/4:ℝ)/poll d N-bp (-0.24*N) := by - classical - let B : ℝ := (1+(1+(d:ℝ))^2)^2 - have hb : 0 < B := by unfold B; positivity - let c := B⁻¹/8 - have hc : 0 < c := by unfold c; positivity - refine ⟨c,hc,?_⟩ - filter_upwards [eventually_ge_atTop 1,bp_poly_dom_nat (by norm_num : 0<(0.24:ℝ)) c⁻¹ 4] with - N hN hE - have h : 1≤ (N:ℝ) := by exact_mod_cast hN - have hh : poll d N ≤ B*N^(4:ℕ) := by - unfold poll B - have hf : 1+d*(N:ℝ) ≤ (1+d)*N := by linarith only [h] - calc (1+(1+d*(N:ℝ))^2)^2 - _ ≤ ((N:ℝ)^2+((1+d)*N)^2)^2 := by - have hi : 1 ≤ (N:ℝ)^2 := by nlinarith - gcongr - _ = _ := by ring - have hB : 2*(c / N^(4:ℕ)) ≤ (1/4:ℝ)/poll d N := by - have hf : 0 < poll d N := by unfold poll; positivity - calc 2*(c/N^(4:ℕ)) = (1/4:ℝ)/(B*N^(4:ℕ)) := by unfold c; field_simp; norm_num - _ ≤ _ := div_le_div_of_nonneg_left (by norm_num) hf hh - have hx := bp_pos (0.24*N) - have hζ : bp (-0.24*N) ≤ c/N^(4:ℕ) := by rw [neg_mul,bp_neg]; field_simp; field_simp at hE; rw [mul_comm _ (0.24:ℝ)] at hE; linarith - linarith only [hB,hζ] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FourPhaseBits + +namespace OAI + +/-! # Polynomial Compatibility -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Module Finset Filter +variable {p : Shape} {n N d : ℕ} + +def poll (d N : ℕ) := (1+(1+d*(N:ℝ))^2)^2 + +set_option maxHeartbeats 600000 in +theorem tiny_poll (p : Shape) {n N : ℕ} (Δ : UnitType p n N→Ambient p N) + (w : Wgt (UnitType p n N)) (hw : IsLaw w) + (h : tonalTiny p Δ w d) + (hd : ∀ x, w x≠0 → tone p x allSide (Δ x) = 0) (i : F) : + (1/4 : ℝ)/poll d N-bp (-0.24*N)≤ + pr (pairW w w) (fun x => quench p Δ x=repeatQ i) := by + classical + obtain ⟨T,hT,hZ,hE⟩ := h + let M := circus p T Δ w + have hM : M.rank≤ d*N := (circus_rank ..).trans ((Nat.mul_le_mul_left N hT).trans_eq + (Nat.mul_comm _ _)) + have hB (x y) (hx : w x≠0) : + tone p y allSide (Δ x)=M x y := (shadow_valid p T Δ hZ x y allSide hx).symm + have hD x : M x x=0 := by + by_cases hx : w x=0 + · change juris p T x _ (cutDown p T Δ w x) = _ + simp [cutDown,hx] + exact (hB _ _ hx).symm.trans (hd x hx) + let u := pairW w w + have hX : + pr u (fun x => M x.1 x.2=0 ∧ M x.2 x.1=0)= + pr u (fun x => repeated (quench p Δ x)) := by + refine avg_congr (fun x hx => ?_) + congr 1 + have h1 := hB x.1 x.2 (left_ne_zero_of_mul hx) + have h2 := hB x.2 x.1 (right_ne_zero_of_mul hx) + unfold repeated quench + simp only [←tone_vec,h1,h2] + have hi : 1 ≤ poll d N*pr u (fun x => repeated (quench p Δ x)) := by + have hh := simultaneous_czeros M (1+d*N) w hw (by omega) hD + rw [show pairW w w=u from rfl,hX] at hh + refine le_trans hh (le_of_eq ?_) + push_cast; unfold poll + ring + have hh : 0 < poll d N := by unfold poll; positivity + apply le_trans _ (tiny_pattern p Δ w i (bp_pos _).le hE) + apply sub_le_sub_right + exact (div_le_iff₀ hh).mpr (by linarith only [hi]) + +theorem eventually_tiny_poll (d : ℕ) : + ∃ b> (0:ℝ),∀ᶠ N : ℕ in atTop, + b/N^ (4:ℕ) ≤ (1/4:ℝ)/poll d N-bp (-0.24*N) := by + classical + let B : ℝ := (1+(1+(d:ℝ))^2)^2 + have hb : 0 < B := by unfold B; positivity + let c := B⁻¹/8 + have hc : 0 < c := by unfold c; positivity + refine ⟨c,hc,?_⟩ + filter_upwards [eventually_ge_atTop 1,bp_poly_dom_nat (by norm_num : 0<(0.24:ℝ)) c⁻¹ 4] with + N hN hE + have h : 1≤ (N:ℝ) := by exact_mod_cast hN + have hh : poll d N ≤ B*N^(4:ℕ) := by + unfold poll B + have hf : 1+d*(N:ℝ) ≤ (1+d)*N := by linarith only [h] + calc (1+(1+d*(N:ℝ))^2)^2 + _ ≤ ((N:ℝ)^2+((1+d)*N)^2)^2 := by + have hi : 1 ≤ (N:ℝ)^2 := by nlinarith + gcongr + _ = _ := by ring + have hB : 2*(c / N^(4:ℕ)) ≤ (1/4:ℝ)/poll d N := by + have hf : 0 < poll d N := by unfold poll; positivity + calc 2*(c/N^(4:ℕ)) = (1/4:ℝ)/(B*N^(4:ℕ)) := by unfold c; field_simp; norm_num + _ ≤ _ := div_le_div_of_nonneg_left (by norm_num) hf hh + have hx := bp_pos (0.24*N) + have hζ : bp (-0.24*N) ≤ c/N^(4:ℕ) := by rw [neg_mul,bp_neg]; field_simp; field_simp at hE; rw [mul_comm _ (0.24:ℝ)] at hE; linarith + linarith only [hB,hζ] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PolynomialRankBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PolynomialRankBounds.lean index 9df9d05aa0a1c2ba7e2ac5b892ef0665680f6c17..c7c93b7313a60570dc704520c30feddf173ce3fe 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PolynomialRankBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PolynomialRankBounds.lean @@ -1,107 +1,107 @@ -import OAI.Combinatorics.HadwigerCounterexample.SmallCoverBounds - -namespace OAI - -/-! # Polynomial Rank Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module Submodule Function Finset -open scoped BigOperators -variable {A B : Type} [Fintype A] [Fintype B] - -def mpMask (P Q : Mat A B) : Mat A B := Matrix.of (fun x y => P x y * Q x y) - -theorem rank_mask (P Q : Mat A B) : - (mpMask P Q).rank ≤ P.rank*Q.rank := by - classical - obtain ⟨X,Y,hX,hY,hP⟩ := rank_product P - obtain ⟨U,V,hU,hV,hQ⟩ := rank_product Q - let R := Fin P.rank × Fin Q.rank - let f : Mat A R := Matrix.of (fun x r => X x r.1*U x r.2) - let g : Mat R B := Matrix.of (fun r y => Y r.1 y * V r.2 y) - have he : mpMask P Q=f*g := by - ext i j - have h (a : Fin P.rank) (b : Fin Q.rank) : - f i (a,b)*g (a,b) j=(X i a*Y a j)*(U i b*V b j) := by - unfold f g; simp only [Matrix.of_apply]; ring - change P i j*Q i j = ∑ x : Fin P.rank × Fin Q.rank, f i x*g x j - have ht : - (∑ a,X i a * Y a j)*(∑ b,U i b*V b j)=P i j*Q i j := - congrArg₂ (·*·) (congr_fun (congr_fun hP i) j) (congr_fun (congr_fun hQ i) j) - exact ht.symm.trans (by - rw [Finset.sum_mul,Fintype.sum_prod_type] - simp_rw [Finset.mul_sum,h]) - rw [he] - exact (Matrix.rank_mul_le_left ..).trans (f.rank_le_card_width.trans_eq (by simp [R])) - -private theorem choose_draws (w : Wgt A) (T : ℕ) (hw : IsLaw w) - (i j : Fin T) (h : i≠j) : - mapW (draws (Fin T) w) (fun x => (x i,x j))=pairW w w := by - classical - let g : Bool → Fin T := fun b => if b then i else j - have hg : Injective g := by intro x y; cases x <;> cases y <;> simp [g,h,h.symm] - funext x - let P (b : Bool) := fun y : A => y=onSide x b - have ht := prodW_pr_inj hg (w:=fun _ => w) (fun _ => hw) P - have hm (z : Fin T → A) : (z i,z j)=x ↔ ∀ b,P b (z (g b)) := by - simp [Bool.forall_bool, P, Prod.ext_iff,onSide,g,and_comm] - unfold mapW - simp_rw [hm] - refine ht.trans ?_ - rw [Fintype.prod_bool]; unfold P onSide - simp only [Bool.false_eq_true,ite_true,ite_false,pr_point'] - - rfl - -/-- Here T counts k^2+1 draws, union bound uses crude T^2. -Even repeats give the event. -/ -theorem simultaneous_czeros (P : Mat A A) (k : ℕ) - (w : Wgt A) (hw : IsLaw w) (hK : 1+P.rank ≤ k) - (h : ∀ x,P x x=0) : - 1 ≤ ((k:ℝ)^2+1)^2 * pr (pairW w w) (fun x => P x.1 x.2=0 ∧ P x.2 x.1=0) := by - classical - let O : Vec A := fun _ => 1 - let Q := vecMulVec O O+P - let V := mpMask Q Qᵀ - have hr : Q.rank≤ k := (mrk_add_le ..).trans - ((Nat.add_le_add_right (Matrix.rank_vecMulVec_le O O) _).trans hK) - have he : V.rank ≤ k^2 := (rank_mask Q Qᵀ).trans (by rw [Matrix.rank_transpose]; nlinarith) - let T := k^2+1 - let p := fun x : A×A => P x.1 x.2=0 ∧ P x.2 x.1=0 - let f := fun i : Fin T × Fin T => fun z : Fin T → A => i.1≠i.2 ∧ p (z i.1,z i.2) - have hx (z : Fin T→A) : ∃ i,f i z := by - by_contra! hz - have heq : V.submatrix z z = 1 := by - ext i j - change (1+P (z i) (z j))*(1+P (z j) (z i)) = (1:Mat (Fin T) (Fin T)) i j - by_cases h' : i=j - · subst j; rw [Matrix.one_apply_eq,h]; simp - rw [Matrix.one_apply_ne h'] - rcases bit_cases (P (z i) (z j)) with hP|hP - · have hv := (bit_cases (P (z j) (z i))).resolve_left - (fun hc => hz (i,j) ⟨h',hP,hc⟩) - rw [hv,char_two,mul_zero] - rw [hP,char_two,zero_mul] - have hk := (V.rank_submatrix_le z z).trans he - rw [heq,Matrix.rank_one,Fintype.card_fin] at hk; omega - let μ := draws (Fin T) w - have hm : IsLaw μ := draws_law hw - have hB (i : Fin T×Fin T) : - pr μ (f i) ≤ pr (pairW w w) p := by - by_cases he : i.1=i.2 - · simp only [f,he,ne_eq,not_true_eq_false,false_and,pr_false] - exact pr_nonneg (pairW_law hw hw).nz - · rw [← choose_draws w T hw _ _ he, mapW_pr] - simp only [μ,f,he,ne_eq,not_false_eq_true,true_and,le_refl] - have hh : 1 = pr μ (fun z => ∃ i,f i z) := by - simp_rw [show ∀ z,(∃ i,f i z)=True from (fun z => eq_true (hx z)),pr_true,hm.total] - refine hh.trans_le (((pr_exists_le hm.nz f).trans - (Finset.sum_le_sum fun i _ => hB i)).trans_eq ?_) - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,Fintype.card_prod,Fintype.card_fin,T] - push_cast; unfold p; ring -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SmallCoverBounds + +namespace OAI + +/-! # Polynomial Rank Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module Submodule Function Finset +open scoped BigOperators +variable {A B : Type} [Fintype A] [Fintype B] + +def mpMask (P Q : Mat A B) : Mat A B := Matrix.of (fun x y => P x y * Q x y) + +theorem rank_mask (P Q : Mat A B) : + (mpMask P Q).rank ≤ P.rank*Q.rank := by + classical + obtain ⟨X,Y,hX,hY,hP⟩ := rank_product P + obtain ⟨U,V,hU,hV,hQ⟩ := rank_product Q + let R := Fin P.rank × Fin Q.rank + let f : Mat A R := Matrix.of (fun x r => X x r.1*U x r.2) + let g : Mat R B := Matrix.of (fun r y => Y r.1 y * V r.2 y) + have he : mpMask P Q=f*g := by + ext i j + have h (a : Fin P.rank) (b : Fin Q.rank) : + f i (a,b)*g (a,b) j=(X i a*Y a j)*(U i b*V b j) := by + unfold f g; simp only [Matrix.of_apply]; ring + change P i j*Q i j = ∑ x : Fin P.rank × Fin Q.rank, f i x*g x j + have ht : + (∑ a,X i a * Y a j)*(∑ b,U i b*V b j)=P i j*Q i j := + congrArg₂ (·*·) (congr_fun (congr_fun hP i) j) (congr_fun (congr_fun hQ i) j) + exact ht.symm.trans (by + rw [Finset.sum_mul,Fintype.sum_prod_type] + simp_rw [Finset.mul_sum,h]) + rw [he] + exact (Matrix.rank_mul_le_left ..).trans (f.rank_le_card_width.trans_eq (by simp [R])) + +private theorem choose_draws (w : Wgt A) (T : ℕ) (hw : IsLaw w) + (i j : Fin T) (h : i≠j) : + mapW (draws (Fin T) w) (fun x => (x i,x j))=pairW w w := by + classical + let g : Bool → Fin T := fun b => if b then i else j + have hg : Injective g := by intro x y; cases x <;> cases y <;> simp [g,h,h.symm] + funext x + let P (b : Bool) := fun y : A => y=onSide x b + have ht := prodW_pr_inj hg (w:=fun _ => w) (fun _ => hw) P + have hm (z : Fin T → A) : (z i,z j)=x ↔ ∀ b,P b (z (g b)) := by + simp [Bool.forall_bool, P, Prod.ext_iff,onSide,g,and_comm] + unfold mapW + simp_rw [hm] + refine ht.trans ?_ + rw [Fintype.prod_bool]; unfold P onSide + simp only [Bool.false_eq_true,ite_true,ite_false,pr_point'] + + rfl + +/-- Here T counts k^2+1 draws, union bound uses crude T^2. +Even repeats give the event. -/ +theorem simultaneous_czeros (P : Mat A A) (k : ℕ) + (w : Wgt A) (hw : IsLaw w) (hK : 1+P.rank ≤ k) + (h : ∀ x,P x x=0) : + 1 ≤ ((k:ℝ)^2+1)^2 * pr (pairW w w) (fun x => P x.1 x.2=0 ∧ P x.2 x.1=0) := by + classical + let O : Vec A := fun _ => 1 + let Q := vecMulVec O O+P + let V := mpMask Q Qᵀ + have hr : Q.rank≤ k := (mrk_add_le ..).trans + ((Nat.add_le_add_right (Matrix.rank_vecMulVec_le O O) _).trans hK) + have he : V.rank ≤ k^2 := (rank_mask Q Qᵀ).trans (by rw [Matrix.rank_transpose]; nlinarith) + let T := k^2+1 + let p := fun x : A×A => P x.1 x.2=0 ∧ P x.2 x.1=0 + let f := fun i : Fin T × Fin T => fun z : Fin T → A => i.1≠i.2 ∧ p (z i.1,z i.2) + have hx (z : Fin T→A) : ∃ i,f i z := by + by_contra! hz + have heq : V.submatrix z z = 1 := by + ext i j + change (1+P (z i) (z j))*(1+P (z j) (z i)) = (1:Mat (Fin T) (Fin T)) i j + by_cases h' : i=j + · subst j; rw [Matrix.one_apply_eq,h]; simp + rw [Matrix.one_apply_ne h'] + rcases bit_cases (P (z i) (z j)) with hP|hP + · have hv := (bit_cases (P (z j) (z i))).resolve_left + (fun hc => hz (i,j) ⟨h',hP,hc⟩) + rw [hv,char_two,mul_zero] + rw [hP,char_two,zero_mul] + have hk := (V.rank_submatrix_le z z).trans he + rw [heq,Matrix.rank_one,Fintype.card_fin] at hk; omega + let μ := draws (Fin T) w + have hm : IsLaw μ := draws_law hw + have hB (i : Fin T×Fin T) : + pr μ (f i) ≤ pr (pairW w w) p := by + by_cases he : i.1=i.2 + · simp only [f,he,ne_eq,not_true_eq_false,false_and,pr_false] + exact pr_nonneg (pairW_law hw hw).nz + · rw [← choose_draws w T hw _ _ he, mapW_pr] + simp only [μ,f,he,ne_eq,not_false_eq_true,true_and,le_refl] + have hh : 1 = pr μ (fun z => ∃ i,f i z) := by + simp_rw [show ∀ z,(∃ i,f i z)=True from (fun z => eq_true (hx z)),pr_true,hm.total] + refine hh.trans_le (((pr_exists_le hm.nz f).trans + (Finset.sum_le_sum fun i _ => hB i)).trans_eq ?_) + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,Fintype.card_prod,Fintype.card_fin,T] + push_cast; unfold p; ring +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PolynomialZeroTests.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PolynomialZeroTests.lean index e693d313233230a4befc6a2ca3982eafdbd01e82..2a1b38b7a373baec775e6ae920d4b79fbf200875 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PolynomialZeroTests.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PolynomialZeroTests.lean @@ -1,156 +1,156 @@ -import OAI.Combinatorics.HadwigerCounterexample.QuadraticFourier - -namespace OAI - -/-! # Polynomial Zero Tests -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module LinearMap Submodule Function -open scoped BigOperators -variable {A I J : Type} [Fintype A] [DecidableEq A] - -def poly1 (s : Finset A) (x : Vec A) := ∏ i∈s,x i - -def Stocks (A : Type) (d : ℕ) : Space (Vec (Vec A)) := - open Classical in Submodule.span F {x | ∃ s : Finset A,s.card ≤ d ∧ x = poly1 s} - -theorem stocks_rise (A : Type) [Fintype A] [DecidableEq A] {d j : ℕ} (h : d≤j) : - Stocks A d≤ Stocks A j := span_mono (fun _ ⟨s,hx,h'⟩=> ⟨s,hx.trans h,h'⟩) -theorem stocks_one (A : Type) [Fintype A] [DecidableEq A] (d : ℕ) (b : F) : - (fun _ : Vec A=>b)∈ Stocks A d := by - have hh : poly1 (∅:Finset A)∈ Stocks A d := subset_span ⟨_,by simp,rfl⟩ - have he : b • poly1 (∅:Finset A)=(fun _ : Vec A=>b) := by ext; simp [poly1] - rw [←he]; exact Submodule.smul_mem _ _ hh -omit [Fintype A] [DecidableEq A] in -theorem stock_var (i : A) : (fun x : Vec A => x i)∈Stocks A 1 := - subset_span ⟨{i},by simp,by funext; simp [poly1]⟩ - -omit [Fintype A] in -theorem poly1_union (x : Vec A) (s t : Finset A) : - poly1 (s∪t) x=poly1 s x*poly1 t x := by - have he (x : Vec A) (s : Finset A) (i : A) : - poly1 (insert i s) x=x i*poly1 s x := by - by_cases h : i∈s - · rw [insert_eq_of_mem h] - unfold poly1; rw [← Finset.mul_prod_erase _ _ h,←mul_assoc,bit_sq] - simp [poly1,h] - induction s using Finset.induction_on with - | empty => simp [poly1] - | insert i s hi ih => rw [insert_union,he,he,ih,mul_assoc] - -omit [Fintype A] in -set_option maxHeartbeats 600000 in -theorem stock_prod {f g : Vec (Vec A)} {d j : ℕ} (hf : f∈ Stocks A d) (hg : g∈Stocks A j) : - f*g∈Stocks A (d+j) := by - classical - unfold Stocks at hf - induction hf using Submodule.span_induction with - | zero => simp - | add f j _ _ hf hj => rw [add_mul]; exact Submodule.add_mem _ hf hj - | smul p j _ hj => - rw [smul_mul_assoc]; exact Submodule.smul_mem _ _ hj - | mem x hx => - obtain ⟨s,hs,rfl⟩ := hx - unfold Stocks at hg - induction hg using Submodule.span_induction with - | mem x hx => - obtain ⟨t,ht,rfl⟩ := hx - exact subset_span ⟨s∪t,(Finset.card_union_le ..).trans (add_le_add hs ht), - funext fun x=>(poly1_union x s t).symm⟩ - | zero => simp - | add f j _ _ hf hj => rw [mul_add]; exact Submodule.add_mem _ hf hj - | smul p j _ hj => rw [mul_smul_comm]; exact Submodule.smul_mem _ _ hj - -def spoil (p : Vec A) : Vec (Vec A) →ₗ[F] Vec (Vec A) where - toFun f := fun i => f (i+p)-f i - map_add' a b := funext fun i=>by simp only [Pi.add_apply]; ring - map_smul' a b := funext fun i=>by - simp only [Pi.smul_apply,smul_eq_mul,RingHom.id_apply]; ring - -set_option maxHeartbeats 600000 in -theorem stock_decay (p : Vec A) {d : ℕ} {f} (h : f∈ Stocks A (d+1)) : - spoil p f ∈ Stocks A d := by - classical - unfold Stocks at h - induction h using Submodule.span_induction with - | zero => simp - | add f j _ _ hf hj => rw [map_add]; exact Submodule.add_mem _ hf hj - | smul p j _ hj => rw [map_smul]; exact Submodule.smul_mem _ _ hj - | mem x hx => - obtain ⟨s,hs,rfl⟩ := hx - induction s using Finset.induction_on generalizing d with - | empty => - have hi : spoil p (poly1 ∅)=0 := by funext; simp [spoil,poly1] - rw [hi]; exact Submodule.zero_mem _ - | insert i s hi ih => - rw [card_insert_of_notMem hi] at hs - have he : poly1 s∈ Stocks A d := subset_span ⟨_,by omega,rfl⟩ - let u := poly1 s - let v := fun x : Vec A => x i+p i - have hh : - spoil p (poly1 (insert i s))=p i • u + v*spoil p u := by - funext x; simp only [v,u,spoil,LinearMap.coe_mk,AddHom.coe_mk, - poly1,Finset.prod_insert hi,Pi.smul_apply,Pi.add_apply,smul_eq_mul,Pi.mul_apply]; ring - rw [hh] - refine Submodule.add_mem _ (Submodule.smul_mem _ _ he) ?_ - cases d - next => - obtain rfl : s=∅ := Finset.card_eq_zero.mp (by omega) - have hi : spoil p u=0 := by funext; simp [spoil,u,poly1] - rw [hi]; simp - next d => - have hS : spoil p u∈ Stocks A d := ih (by omega) - have hf : v∈ Stocks A 1 := Submodule.add_mem (Stocks A 1) - (stock_var i) (stocks_one A 1 (p i)) - have hm := stock_prod hf hS - rwa [Nat.add_comm 1] at hm - -omit [Fintype A] [DecidableEq A] in -theorem stock_initial {f} (x y : Vec A) (h : f∈ Stocks A 0) : f x=f y := by - unfold Stocks at h - induction h using Submodule.span_induction with - | zero => rfl - | add f j _ _ hf hj => simp only [Pi.add_apply,hf,hj] - | smul p j _ hj => simp only [Pi.smul_apply,hj] - | mem x hx => - obtain ⟨s,hs,rfl⟩ := hx - obtain rfl : s=∅ := Finset.card_eq_zero.mp (by omega) - simp [poly1] - -theorem stocks_bound (A : Type) [Fintype A] [DecidableEq A] (d : ℕ) (f : Vec (Vec A)) - (h : f∈ Stocks A d) (he : ∃ x, f x≠0) : - bp (-(d:ℝ))≤ pr unif (fun x => f x≠0) := by - classical - induction d generalizing f with - | zero => - obtain ⟨x,hx⟩ := he - have he (y:Vec A) : f y≠0 := (stock_initial y x h).trans_ne hx - simp only [pr,ind_one (he _), Nat.cast_zero, neg_zero,bp_zero,unif_law.avg_const,le_refl] - | succ d ih => - by_cases hh : ∃ y, f y=0 - · obtain ⟨x,hx⟩ := he; obtain ⟨y,hy⟩ := hh - let p := x-y - have hZ : bp (-(d:ℝ))≤ pr unif (fun x=>spoil p f x≠0) := ih _ (stock_decay p h) - ⟨y,by change f (y+p)-f y≠0; unfold p; rw [add_sub_cancel,hy,sub_zero]; exact hx⟩ - let P x := f x≠0 - have hg : - pr unif (fun x=>spoil p f x≠0)≤2*pr unif P := by - have he x (h : spoil p f x≠0) : - P (x+p)∨P x := by - by_contra! hh; unfold spoil at h; apply h - unfold P at hh; simp [not_ne_iff.mp hh.1,not_ne_iff.mp hh.2] - apply ((pr_mono unif_law.nz he).trans (pr_or_le unif_law.nz)).trans_eq - rw [show pr unif (fun x=>P (x+p))=pr unif P from phase_trans p (fun x=>ind (P x)),two_mul] - have hx' := hZ.trans hg - push_cast - rw [neg_add,bp_add,bp_neg 1,bp_one] - linarith only [hx'] - have hz (x:Vec A) : f x≠0 := fun he=>hh ⟨x,he⟩ - simp only [pr,ind_one (hz _),unif_law.avg_const] - rw [←bp_zero]; exact bp_le (by apply neg_nonpos.mpr; positivity) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.QuadraticFourier + +namespace OAI + +/-! # Polynomial Zero Tests -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module LinearMap Submodule Function +open scoped BigOperators +variable {A I J : Type} [Fintype A] [DecidableEq A] + +def poly1 (s : Finset A) (x : Vec A) := ∏ i∈s,x i + +def Stocks (A : Type) (d : ℕ) : Space (Vec (Vec A)) := + open Classical in Submodule.span F {x | ∃ s : Finset A,s.card ≤ d ∧ x = poly1 s} + +theorem stocks_rise (A : Type) [Fintype A] [DecidableEq A] {d j : ℕ} (h : d≤j) : + Stocks A d≤ Stocks A j := span_mono (fun _ ⟨s,hx,h'⟩=> ⟨s,hx.trans h,h'⟩) +theorem stocks_one (A : Type) [Fintype A] [DecidableEq A] (d : ℕ) (b : F) : + (fun _ : Vec A=>b)∈ Stocks A d := by + have hh : poly1 (∅:Finset A)∈ Stocks A d := subset_span ⟨_,by simp,rfl⟩ + have he : b • poly1 (∅:Finset A)=(fun _ : Vec A=>b) := by ext; simp [poly1] + rw [←he]; exact Submodule.smul_mem _ _ hh +omit [Fintype A] [DecidableEq A] in +theorem stock_var (i : A) : (fun x : Vec A => x i)∈Stocks A 1 := + subset_span ⟨{i},by simp,by funext; simp [poly1]⟩ + +omit [Fintype A] in +theorem poly1_union (x : Vec A) (s t : Finset A) : + poly1 (s∪t) x=poly1 s x*poly1 t x := by + have he (x : Vec A) (s : Finset A) (i : A) : + poly1 (insert i s) x=x i*poly1 s x := by + by_cases h : i∈s + · rw [insert_eq_of_mem h] + unfold poly1; rw [← Finset.mul_prod_erase _ _ h,←mul_assoc,bit_sq] + simp [poly1,h] + induction s using Finset.induction_on with + | empty => simp [poly1] + | insert i s hi ih => rw [insert_union,he,he,ih,mul_assoc] + +omit [Fintype A] in +set_option maxHeartbeats 600000 in +theorem stock_prod {f g : Vec (Vec A)} {d j : ℕ} (hf : f∈ Stocks A d) (hg : g∈Stocks A j) : + f*g∈Stocks A (d+j) := by + classical + unfold Stocks at hf + induction hf using Submodule.span_induction with + | zero => simp + | add f j _ _ hf hj => rw [add_mul]; exact Submodule.add_mem _ hf hj + | smul p j _ hj => + rw [smul_mul_assoc]; exact Submodule.smul_mem _ _ hj + | mem x hx => + obtain ⟨s,hs,rfl⟩ := hx + unfold Stocks at hg + induction hg using Submodule.span_induction with + | mem x hx => + obtain ⟨t,ht,rfl⟩ := hx + exact subset_span ⟨s∪t,(Finset.card_union_le ..).trans (add_le_add hs ht), + funext fun x=>(poly1_union x s t).symm⟩ + | zero => simp + | add f j _ _ hf hj => rw [mul_add]; exact Submodule.add_mem _ hf hj + | smul p j _ hj => rw [mul_smul_comm]; exact Submodule.smul_mem _ _ hj + +def spoil (p : Vec A) : Vec (Vec A) →ₗ[F] Vec (Vec A) where + toFun f := fun i => f (i+p)-f i + map_add' a b := funext fun i=>by simp only [Pi.add_apply]; ring + map_smul' a b := funext fun i=>by + simp only [Pi.smul_apply,smul_eq_mul,RingHom.id_apply]; ring + +set_option maxHeartbeats 600000 in +theorem stock_decay (p : Vec A) {d : ℕ} {f} (h : f∈ Stocks A (d+1)) : + spoil p f ∈ Stocks A d := by + classical + unfold Stocks at h + induction h using Submodule.span_induction with + | zero => simp + | add f j _ _ hf hj => rw [map_add]; exact Submodule.add_mem _ hf hj + | smul p j _ hj => rw [map_smul]; exact Submodule.smul_mem _ _ hj + | mem x hx => + obtain ⟨s,hs,rfl⟩ := hx + induction s using Finset.induction_on generalizing d with + | empty => + have hi : spoil p (poly1 ∅)=0 := by funext; simp [spoil,poly1] + rw [hi]; exact Submodule.zero_mem _ + | insert i s hi ih => + rw [card_insert_of_notMem hi] at hs + have he : poly1 s∈ Stocks A d := subset_span ⟨_,by omega,rfl⟩ + let u := poly1 s + let v := fun x : Vec A => x i+p i + have hh : + spoil p (poly1 (insert i s))=p i • u + v*spoil p u := by + funext x; simp only [v,u,spoil,LinearMap.coe_mk,AddHom.coe_mk, + poly1,Finset.prod_insert hi,Pi.smul_apply,Pi.add_apply,smul_eq_mul,Pi.mul_apply]; ring + rw [hh] + refine Submodule.add_mem _ (Submodule.smul_mem _ _ he) ?_ + cases d + next => + obtain rfl : s=∅ := Finset.card_eq_zero.mp (by omega) + have hi : spoil p u=0 := by funext; simp [spoil,u,poly1] + rw [hi]; simp + next d => + have hS : spoil p u∈ Stocks A d := ih (by omega) + have hf : v∈ Stocks A 1 := Submodule.add_mem (Stocks A 1) + (stock_var i) (stocks_one A 1 (p i)) + have hm := stock_prod hf hS + rwa [Nat.add_comm 1] at hm + +omit [Fintype A] [DecidableEq A] in +theorem stock_initial {f} (x y : Vec A) (h : f∈ Stocks A 0) : f x=f y := by + unfold Stocks at h + induction h using Submodule.span_induction with + | zero => rfl + | add f j _ _ hf hj => simp only [Pi.add_apply,hf,hj] + | smul p j _ hj => simp only [Pi.smul_apply,hj] + | mem x hx => + obtain ⟨s,hs,rfl⟩ := hx + obtain rfl : s=∅ := Finset.card_eq_zero.mp (by omega) + simp [poly1] + +theorem stocks_bound (A : Type) [Fintype A] [DecidableEq A] (d : ℕ) (f : Vec (Vec A)) + (h : f∈ Stocks A d) (he : ∃ x, f x≠0) : + bp (-(d:ℝ))≤ pr unif (fun x => f x≠0) := by + classical + induction d generalizing f with + | zero => + obtain ⟨x,hx⟩ := he + have he (y:Vec A) : f y≠0 := (stock_initial y x h).trans_ne hx + simp only [pr,ind_one (he _), Nat.cast_zero, neg_zero,bp_zero,unif_law.avg_const,le_refl] + | succ d ih => + by_cases hh : ∃ y, f y=0 + · obtain ⟨x,hx⟩ := he; obtain ⟨y,hy⟩ := hh + let p := x-y + have hZ : bp (-(d:ℝ))≤ pr unif (fun x=>spoil p f x≠0) := ih _ (stock_decay p h) + ⟨y,by change f (y+p)-f y≠0; unfold p; rw [add_sub_cancel,hy,sub_zero]; exact hx⟩ + let P x := f x≠0 + have hg : + pr unif (fun x=>spoil p f x≠0)≤2*pr unif P := by + have he x (h : spoil p f x≠0) : + P (x+p)∨P x := by + by_contra! hh; unfold spoil at h; apply h + unfold P at hh; simp [not_ne_iff.mp hh.1,not_ne_iff.mp hh.2] + apply ((pr_mono unif_law.nz he).trans (pr_or_le unif_law.nz)).trans_eq + rw [show pr unif (fun x=>P (x+p))=pr unif P from phase_trans p (fun x=>ind (P x)),two_mul] + have hx' := hZ.trans hg + push_cast + rw [neg_add,bp_add,bp_neg 1,bp_one] + linarith only [hx'] + have hz (x:Vec A) : f x≠0 := fun he=>hh ⟨x,he⟩ + simp only [pr,ind_one (hz _),unif_law.avg_const] + rw [←bp_zero]; exact bp_le (by apply neg_nonpos.mpr; positivity) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PositiveTestMass.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PositiveTestMass.lean index 9d97f2b374df392757c810d5f38a3fbbe9f18e6f..c97ad06655ec14e461089374cdc147c995397c63 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PositiveTestMass.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PositiveTestMass.lean @@ -1,126 +1,126 @@ -import OAI.Combinatorics.HadwigerCounterexample.PredictionExtraction - -namespace OAI - -/-! # Positive Test Mass -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Function Filter Finset LinearMap Module -open scoped BigOperators Topology -open Template -variable {p:Shape} {n N K M s0 r :ℕ} -namespace StatusAnalysis -open PreparationParameters Station PredictionClass Club Guild DualAnalysis -variable {q:PreparationParameters} {w:LeafMixture p n N} - -abbrev Aspect (p:Shape) (n N :ℕ) (w:LeafMixture p n N) := w.T × UnitType p n N -abbrev ViewPair (p:Shape) (n N :ℕ) (w:LeafMixture p n N) := Aspect p n N w × Aspect p n N w - -def troupe (w:LeafMixture p n N) (U:Wgt (UnitType p n N)) := - semi (portionW U w.T) (fun i=>partW U i.val) -def cirque (w:LeafMixture p n N) (U:Wgt (UnitType p n N)) := - pairW (troupe w U) (troupe w U) -def eligiblePair (v:Station p n N K w) (m:Mixer p n) (i j:Aspect p n N w) - (Y:Silhouette p N r) (a:ℝ) := - ∃ k:Scrip p K, k.2.2.permission ∧ a ≤ v.twilight k.2.2 m k.2.1 Y i.1 j.1 (i.2,j.2) - -def supportBudget (p:Shape) (K:ℕ) (η a:ℝ) := - 0 exact ⟨1,zero_lt_one,fun i=>(h.false i).elim⟩ - next h => - let g:=univ.image F - have he:g.Nonempty:=image_nonempty.mpr univ_nonempty - refine ⟨g.min' he, ?_,fun i=> min'_le _ _ (mem_image_of_mem _ (mem_univ _))⟩ - obtain ⟨i,hi,h⟩:=mem_image.mp (min'_mem _ he) - exact h ▸ hf i - -set_option maxHeartbeats 1400000 in -theorem inform (w:LeafMixture p n N) (v:Station p n N K w) - (m:Mixer p n) (Y:Silhouette p N r) (i j:Aspect p n N w) - (hc:PreparationParameters.frameSide p m i.2) (he:PreparationParameters.frameSide p m j.2) - (ha:(w.pin i.1.val).agree i.2) (hb:(w.pin j.1.val).agree j.2) - (d e:Stakes K) - (h1:charted (v.cAxes i.1 (toRates d)) (w.pin i.1.val).sp) - (h2:charted (v.cAxes j.1 (toRates e)) (w.pin j.1.val).sp) - {η a:ℝ} (h : supportBudget p K η a) - (x y:Stalls p) (hx:booths p K (w.pin i.1.val).sp x) - (hy:booths p K (w.pin j.1.val).sp y) - (P Q:Stalls p) (hF:x≤P)(hG:y≤Q) - (hg:3≤p.g)(hp:1≤p.J)(hη:0<η) - (k:Fin (2^deckMax p K)) - (hk:berthTicket (w.pin i.1.val) (w.pin j.1.val) (v.mails i.1 j.1 k) (i.2,j.2)) - (S:Straps (Label p.b)) : - let X:= v.cAxes i.1 (toRates d); let W:=v.cAxes j.1 (toRates e) - let C:=stellar (wisp p Y) (wake p Y m i.2 X) (wake p Y m j.2 W) η P Q - (∀ i:Grid,(C i).travels S 100 (view _ _) (chapter C S i)) → - scorecard (chapter C S) (hailing p X W (v.mails i.1 j.1 k)) → - eligiblePair v m i j Y a := by - classical - intro X W C hA hB - obtain ⟨q,g,F,G,hT,hU⟩:=processions p K P Q _ _ X W (v.mails i.1 j.1 k) h1 h2 hk.1 hk.2.1 x y hx hy - hF hG (by omega) hp S hA hB - let z:=g.binding p F G - let I:Scrip p K:=⟨(q,d,e),k,z⟩ - refine ⟨I,hT.1,?_⟩ - obtain ⟨hL,hR⟩:= berth_flags _ _ _ hk ha hb - have hC : - v.frontPage z m i.1 j.1 k i.2∧v.backPage z m i.1 j.1 k j.2 := - ⟨⟨hT,ha,hc,hL⟩,⟨hT,hb,he,hR⟩⟩ - change _≤ ind _ * z.constellation i.2 j.2 X W m Y - rw [ind_one hC,one_mul] - refine (h.2 I).trans (mul_le_mul_of_nonneg_left ?_ - (mul_nonneg (kappa_pos _).le (kappa_pos _).le)) - let J:=Messenger (toFormat q) - have hi (x:J):η ≤ z.chimera i.2 j.2 X W m Y x := (hU x).trans_eq - (Engagement.solicit ..).symm - exact le_trans (le_of_eq (show η^Fintype.card J=∏ _:J,η by simp)) (Finset.prod_le_prod₀ - (fun i _=> hη.le) fun i _=> hi i) - -variable {U : Wgt (UnitType p n N)} {m : Mixer p n} - -structure Lead (U: Wgt (UnitType p n N)) (w : LeafMixture p n N) (m:Mixer p n) (q:PreparationParameters) : Prop where - strength : w.strength U (usual p m N) q.leafNew (2*q.ζ) q.pins - amount : 0(h.strength.leaf _ hi).pos) h.amount - have hk i:IsLaw (partW U (Subtype.val (show w.T from i))):=on_law h.law.nz (h.strength.leaf _ - i.property).pos - constructor - · constructor - · intro x; exact mul_nonneg (h1.nz _) ((hk _).nz _) - unfold troupe; rw [semi_total]; simp_rw [(hk _).total]; exact h1.avg_const _ - change _=allW U w.T; rw [h2]; funext i - unfold mapW mixW pr troupe; rw [semi_avg] - simp_rw [show ∀ w':↥w.T,avg (partW U w'.val) (fun x=> ind (x=i))=partW U w'.val i from - (fun w=> pr_point' ..)] - -theorem troupe_home (h:Lead U w m q) (x: Aspect p n N w) (hx:troupe w U x≠0): - x.2∈x.1.val∧w.rooting x.2=(w.pin x.1.val).sp∧frameSide p m x.2∧ (w.pin x.1.val).agree x.2 := by - have he : x.2∈x.1.val := (onW_ne (right_ne_zero_of_mul hx)).1 - exact ⟨he, congrArg Pin.sp (LeafMixture.poller_eq w h.strength.part x.1.property he),h.coverC _ - x.1.property x.2 he,(h.strength.leaf _ x.1.property).fixpin x.2 he⟩ -theorem cirque_unit (w:LeafMixture p n N) (h: Lead U w m q) : - mapW (cirque w U) (fun i=>(i.1.2,i.2.2)) = pairW (w.sap U) (w.sap U) := by - classical - have hk:=map_pair_law (troupe w U) (troupe w U) Prod.snd Prod.snd - rw [(troupe_bill h).2] at hk; exact hk -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PredictionExtraction + +namespace OAI + +/-! # Positive Test Mass -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Function Filter Finset LinearMap Module +open scoped BigOperators Topology +open Template +variable {p:Shape} {n N K M s0 r :ℕ} +namespace StatusAnalysis +open PreparationParameters Station PredictionClass Club Guild DualAnalysis +variable {q:PreparationParameters} {w:LeafMixture p n N} + +abbrev Aspect (p:Shape) (n N :ℕ) (w:LeafMixture p n N) := w.T × UnitType p n N +abbrev ViewPair (p:Shape) (n N :ℕ) (w:LeafMixture p n N) := Aspect p n N w × Aspect p n N w + +def troupe (w:LeafMixture p n N) (U:Wgt (UnitType p n N)) := + semi (portionW U w.T) (fun i=>partW U i.val) +def cirque (w:LeafMixture p n N) (U:Wgt (UnitType p n N)) := + pairW (troupe w U) (troupe w U) +def eligiblePair (v:Station p n N K w) (m:Mixer p n) (i j:Aspect p n N w) + (Y:Silhouette p N r) (a:ℝ) := + ∃ k:Scrip p K, k.2.2.permission ∧ a ≤ v.twilight k.2.2 m k.2.1 Y i.1 j.1 (i.2,j.2) + +def supportBudget (p:Shape) (K:ℕ) (η a:ℝ) := + 0 exact ⟨1,zero_lt_one,fun i=>(h.false i).elim⟩ + next h => + let g:=univ.image F + have he:g.Nonempty:=image_nonempty.mpr univ_nonempty + refine ⟨g.min' he, ?_,fun i=> min'_le _ _ (mem_image_of_mem _ (mem_univ _))⟩ + obtain ⟨i,hi,h⟩:=mem_image.mp (min'_mem _ he) + exact h ▸ hf i + +set_option maxHeartbeats 1400000 in +theorem inform (w:LeafMixture p n N) (v:Station p n N K w) + (m:Mixer p n) (Y:Silhouette p N r) (i j:Aspect p n N w) + (hc:PreparationParameters.frameSide p m i.2) (he:PreparationParameters.frameSide p m j.2) + (ha:(w.pin i.1.val).agree i.2) (hb:(w.pin j.1.val).agree j.2) + (d e:Stakes K) + (h1:charted (v.cAxes i.1 (toRates d)) (w.pin i.1.val).sp) + (h2:charted (v.cAxes j.1 (toRates e)) (w.pin j.1.val).sp) + {η a:ℝ} (h : supportBudget p K η a) + (x y:Stalls p) (hx:booths p K (w.pin i.1.val).sp x) + (hy:booths p K (w.pin j.1.val).sp y) + (P Q:Stalls p) (hF:x≤P)(hG:y≤Q) + (hg:3≤p.g)(hp:1≤p.J)(hη:0<η) + (k:Fin (2^deckMax p K)) + (hk:berthTicket (w.pin i.1.val) (w.pin j.1.val) (v.mails i.1 j.1 k) (i.2,j.2)) + (S:Straps (Label p.b)) : + let X:= v.cAxes i.1 (toRates d); let W:=v.cAxes j.1 (toRates e) + let C:=stellar (wisp p Y) (wake p Y m i.2 X) (wake p Y m j.2 W) η P Q + (∀ i:Grid,(C i).travels S 100 (view _ _) (chapter C S i)) → + scorecard (chapter C S) (hailing p X W (v.mails i.1 j.1 k)) → + eligiblePair v m i j Y a := by + classical + intro X W C hA hB + obtain ⟨q,g,F,G,hT,hU⟩:=processions p K P Q _ _ X W (v.mails i.1 j.1 k) h1 h2 hk.1 hk.2.1 x y hx hy + hF hG (by omega) hp S hA hB + let z:=g.binding p F G + let I:Scrip p K:=⟨(q,d,e),k,z⟩ + refine ⟨I,hT.1,?_⟩ + obtain ⟨hL,hR⟩:= berth_flags _ _ _ hk ha hb + have hC : + v.frontPage z m i.1 j.1 k i.2∧v.backPage z m i.1 j.1 k j.2 := + ⟨⟨hT,ha,hc,hL⟩,⟨hT,hb,he,hR⟩⟩ + change _≤ ind _ * z.constellation i.2 j.2 X W m Y + rw [ind_one hC,one_mul] + refine (h.2 I).trans (mul_le_mul_of_nonneg_left ?_ + (mul_nonneg (kappa_pos _).le (kappa_pos _).le)) + let J:=Messenger (toFormat q) + have hi (x:J):η ≤ z.chimera i.2 j.2 X W m Y x := (hU x).trans_eq + (Engagement.solicit ..).symm + exact le_trans (le_of_eq (show η^Fintype.card J=∏ _:J,η by simp)) (Finset.prod_le_prod₀ + (fun i _=> hη.le) fun i _=> hi i) + +variable {U : Wgt (UnitType p n N)} {m : Mixer p n} + +structure Lead (U: Wgt (UnitType p n N)) (w : LeafMixture p n N) (m:Mixer p n) (q:PreparationParameters) : Prop where + strength : w.strength U (usual p m N) q.leafNew (2*q.ζ) q.pins + amount : 0(h.strength.leaf _ hi).pos) h.amount + have hk i:IsLaw (partW U (Subtype.val (show w.T from i))):=on_law h.law.nz (h.strength.leaf _ + i.property).pos + constructor + · constructor + · intro x; exact mul_nonneg (h1.nz _) ((hk _).nz _) + unfold troupe; rw [semi_total]; simp_rw [(hk _).total]; exact h1.avg_const _ + change _=allW U w.T; rw [h2]; funext i + unfold mapW mixW pr troupe; rw [semi_avg] + simp_rw [show ∀ w':↥w.T,avg (partW U w'.val) (fun x=> ind (x=i))=partW U w'.val i from + (fun w=> pr_point' ..)] + +theorem troupe_home (h:Lead U w m q) (x: Aspect p n N w) (hx:troupe w U x≠0): + x.2∈x.1.val∧w.rooting x.2=(w.pin x.1.val).sp∧frameSide p m x.2∧ (w.pin x.1.val).agree x.2 := by + have he : x.2∈x.1.val := (onW_ne (right_ne_zero_of_mul hx)).1 + exact ⟨he, congrArg Pin.sp (LeafMixture.poller_eq w h.strength.part x.1.property he),h.coverC _ + x.1.property x.2 he,(h.strength.leaf _ x.1.property).fixpin x.2 he⟩ +theorem cirque_unit (w:LeafMixture p n N) (h: Lead U w m q) : + mapW (cirque w U) (fun i=>(i.1.2,i.2.2)) = pairW (w.sap U) (w.sap U) := by + classical + have hk:=map_pair_law (troupe w U) (troupe w U) Prod.snd Prod.snd + rw [(troupe_bill h).2] at hk; exact hk +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PredictedDualCoefficients.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PredictedDualCoefficients.lean index 1d9a7875ccb70303837fe3e54180ca40af35302f..d31ced8645a9dc1bd70b632611523bba75ea23d8 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PredictedDualCoefficients.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PredictedDualCoefficients.lean @@ -1,101 +1,101 @@ -import OAI.Combinatorics.HadwigerCounterexample.FinitePredictions - -namespace OAI - -/-! # Predicted Dual Coefficients -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix Module LinearMap -open scoped BigOperators Topology -variable {p:Shape} {r n:ℕ} -namespace StatusAnalysis -namespace DualAnalysis - -variable {d e:Rates} {u:Terrain p r} {s:Gazette p r d} {t:Gazette p r e} - -open PredictionClass - -private def scaled (a:F) (w:RhymeSet n):RhymeSet n := - ⟨a*w.bit,a • w.coal,a*w.headBit,a*w.gamma⟩ -def Pulsar.mult (g:Pulsar p r)(a:F) : Pulsar p r := fun i j k=>a*g i j k - -private theorem scaleShot (i:Nodes) (z:RhymeSet (d i)) (A:Finset (Label p.b)) (f:Pulsar p r) - {ε:ℝ}(hc:0≤ε)(h:praise u s i A z f ε) (k:F) : - praise u s i A (scaled k z) (f.mult k) ε := by - classical - rcases bit_cases k with ht|ht - · subst k; intro x hx ha - unfold shot Pulsar.mult RhymeSet.soot RhymeSet.read scaled - simp only [zero_mul,zero_smul,zero_dotProduct,add_zero, ne_eq,not_true_eq_false,pr_false,avg_const, - mul_zero]; exact hc - subst k; rw [show f.mult 1=f from (by unfold Pulsar.mult; simp only [one_mul]), show scaled 1 z=z from (by unfold scaled; simp)] ; exact h - -private theorem center_tri (w:Wgt (Fin r)) (k:F) - (f g h:Fin r→ F) (b:F) (hw:IsLaw w) - (x y:ℝ) - (hx:pr w (fun i=>h i≠f i)≤x) (hy:pr w (fun i=>h i+b*k≠g i)≤y): - pr w (fun i=> f i+g i≠ b*k)≤ x+y := by - classical - let P i:= h i≠f i; let Q i:=h i+b*k≠g i - have hi i (h': f i+g i≠b*k):P i∨Q i:= by - by_contra! hh - apply h' - rw [← not_not.mp hh.1,← not_not.mp hh.2,←add_assoc,char_two,zero_add] - exact ((pr_mono hw.nz hi).trans (pr_or_le hw.nz)).trans (add_le_add hx hy) - -abbrev styles (d:Rates) := ∀ i:Nodes, Cell (d i) - -structure PredictionData (p:Shape) (d e:Rates) (r:ℕ) where - α : Party - g : Nodes→ Pulsar p r - X : styles d - Y : styles e - -def PredictionData.colored (v:PredictionData p d e r) (u:Terrain p r) (s:Gazette p r d) (t:Gazette p r e) - (A B:Stalls p) (ε:ℝ) := - (∀ i,praise u s i (A i) (yokeSet (v.X i) (v.α i)) (v.g i) ε) ∧ - (∀ i,praise u t i (B i) (yokeSet (v.Y i) (v.α i)) (v.g i) ε) - -def ChorusCost (w:PredictionData p d e r) (v:DualCoefficients d e) (i:Grid) (u:Terrain p r) - (l:Tag p.g) (q:F) := - pr (u l q) (fun k=>v.left i.2*w.g i.1 l q k+v.right i.1*w.g i.2 l q k≠v.gam i*q) - -set_option maxHeartbeats 900000 in -theorem duet_edge {δ β a ε:ℝ} - (v:PredictionData p d e r) (z:DualCoefficients d e) (i:Grid) - (hp:3≤p.g) (hu:origami p r u δ) (hs:reports p r u s β δ) (ht:reports p r u t β δ) - (A B:Stalls p) - (hv:v.colored u s t A B a) (hA:(A i.1).card?_⟩ - unfold ChorusCost - rw [two_mul] - apply center_tri (w:=u l q) (k:=q) (h:=P l q) _ _ (b:=z.gam i) (hu.1 l q) - (3*ε+a) (3*ε+a) - · have ht:=hE l q - simpa only [leftChime,scaled,yokeSet,mul_zero,zero_mul,add_zero,Pulsar.mult] using ht - have ht:=hH l q - simpa only [rightChime,scaled,yokeSet,mul_zero,zero_mul,add_zero,Pulsar.mult] using ht -end DualAnalysis -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FinitePredictions + +namespace OAI + +/-! # Predicted Dual Coefficients -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix Module LinearMap +open scoped BigOperators Topology +variable {p:Shape} {r n:ℕ} +namespace StatusAnalysis +namespace DualAnalysis + +variable {d e:Rates} {u:Terrain p r} {s:Gazette p r d} {t:Gazette p r e} + +open PredictionClass + +private def scaled (a:F) (w:RhymeSet n):RhymeSet n := + ⟨a*w.bit,a • w.coal,a*w.headBit,a*w.gamma⟩ +def Pulsar.mult (g:Pulsar p r)(a:F) : Pulsar p r := fun i j k=>a*g i j k + +private theorem scaleShot (i:Nodes) (z:RhymeSet (d i)) (A:Finset (Label p.b)) (f:Pulsar p r) + {ε:ℝ}(hc:0≤ε)(h:praise u s i A z f ε) (k:F) : + praise u s i A (scaled k z) (f.mult k) ε := by + classical + rcases bit_cases k with ht|ht + · subst k; intro x hx ha + unfold shot Pulsar.mult RhymeSet.soot RhymeSet.read scaled + simp only [zero_mul,zero_smul,zero_dotProduct,add_zero, ne_eq,not_true_eq_false,pr_false,avg_const, + mul_zero]; exact hc + subst k; rw [show f.mult 1=f from (by unfold Pulsar.mult; simp only [one_mul]), show scaled 1 z=z from (by unfold scaled; simp)] ; exact h + +private theorem center_tri (w:Wgt (Fin r)) (k:F) + (f g h:Fin r→ F) (b:F) (hw:IsLaw w) + (x y:ℝ) + (hx:pr w (fun i=>h i≠f i)≤x) (hy:pr w (fun i=>h i+b*k≠g i)≤y): + pr w (fun i=> f i+g i≠ b*k)≤ x+y := by + classical + let P i:= h i≠f i; let Q i:=h i+b*k≠g i + have hi i (h': f i+g i≠b*k):P i∨Q i:= by + by_contra! hh + apply h' + rw [← not_not.mp hh.1,← not_not.mp hh.2,←add_assoc,char_two,zero_add] + exact ((pr_mono hw.nz hi).trans (pr_or_le hw.nz)).trans (add_le_add hx hy) + +abbrev styles (d:Rates) := ∀ i:Nodes, Cell (d i) + +structure PredictionData (p:Shape) (d e:Rates) (r:ℕ) where + α : Party + g : Nodes→ Pulsar p r + X : styles d + Y : styles e + +def PredictionData.colored (v:PredictionData p d e r) (u:Terrain p r) (s:Gazette p r d) (t:Gazette p r e) + (A B:Stalls p) (ε:ℝ) := + (∀ i,praise u s i (A i) (yokeSet (v.X i) (v.α i)) (v.g i) ε) ∧ + (∀ i,praise u t i (B i) (yokeSet (v.Y i) (v.α i)) (v.g i) ε) + +def ChorusCost (w:PredictionData p d e r) (v:DualCoefficients d e) (i:Grid) (u:Terrain p r) + (l:Tag p.g) (q:F) := + pr (u l q) (fun k=>v.left i.2*w.g i.1 l q k+v.right i.1*w.g i.2 l q k≠v.gam i*q) + +set_option maxHeartbeats 900000 in +theorem duet_edge {δ β a ε:ℝ} + (v:PredictionData p d e r) (z:DualCoefficients d e) (i:Grid) + (hp:3≤p.g) (hu:origami p r u δ) (hs:reports p r u s β δ) (ht:reports p r u t β δ) + (A B:Stalls p) + (hv:v.colored u s t A B a) (hA:(A i.1).card?_⟩ + unfold ChorusCost + rw [two_mul] + apply center_tri (w:=u l q) (k:=q) (h:=P l q) _ _ (b:=z.gam i) (hu.1 l q) + (3*ε+a) (3*ε+a) + · have ht:=hE l q + simpa only [leftChime,scaled,yokeSet,mul_zero,zero_mul,add_zero,Pulsar.mult] using ht + have ht:=hH l q + simpa only [rightChime,scaled,yokeSet,mul_zero,zero_mul,add_zero,Pulsar.mult] using ht +end DualAnalysis +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PredictedDualEvaluation.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PredictedDualEvaluation.lean index 7b04692e6738c7abb5b6cb3822da44082226dfec..ce76dd537cd21b5c88d529ac6eade9f4ee7dbdad 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PredictedDualEvaluation.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PredictedDualEvaluation.lean @@ -1,185 +1,185 @@ -import OAI.Combinatorics.HadwigerCounterexample.PredictedDualCoefficients - -namespace OAI - -/-! # Predicted Dual Evaluation -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Finset Function LinearMap Module -open scoped BigOperators -namespace StatusAnalysis -namespace DualAnalysis -open PredictionClass -variable {p:Shape} {n N r :ℕ} {A B:Rates} - -private theorem echo_pattern (c:PredictionClass) (z:DualCoefficients A B) - (h:∀ i j,echoes c i j (z.left j) (z.right i)) - (hn:c≠dusk) (he:z.left ≠0∨ z.right≠0): - z.left=z.right ∧ - ((∃ i, c=dawn i∧ z.left=unary i) ∨ (c=twinned∧ z.left=allSide)) := by - classical - have hh (i) : c.active i→ z.left i=z.right i := by - intro ht; have hk:=(h i i).1 - rcases bit_cases (z.left i) with hi|hi <;> rcases bit_cases (z.right i) with hx|hx <;> simp_all - cases c - · exact (hn rfl).elim - · rename_i i - have ht : (dawn i).active i:= rfl - have hact := hh i ht - have hx j (hij:i≠j): z.left j=0 ∧ z.right j=0 := by - have hf : ¬(dawn i).active j:=hij - have h1:=(h i j).1; have h2:=(h j i).1 - constructor - · exact (bit_cases _).resolve_right fun h'=> hf (h1.mp ⟨h',ht⟩).2 - exact (bit_cases _).resolve_right fun h'=> hf (h2.mpr ⟨h',ht⟩).2 - have hm : z.left=z.right := funext fun j=>by - by_cases hij : i=j - · exact hij ▸ hact - exact (hx j hij).1.trans (hx j hij).2.symm - have hz:=show z.left≠0 from he.elim id (fun h=>hm.symm ▸ h) - refine ⟨hm,Or.inl ⟨i,rfl, funext fun j=>?_⟩⟩ - by_cases hij:i=j - · subst j - have hv : z.left i=1:= (bit_cases _).resolve_left (fun h=> hz (funext fun j=> by - by_cases hi : i = j - · exact hi ▸ h - exact (hx j hi).1)) - simp [unary,hv] - rw [(hx j hij).1]; simp [unary,Ne.symm hij] - · have heq : z.left=z.right:= funext (fun i=> hh i trivial) - have hz:=show z.left≠0 from he.elim id (fun h=>heq.symm ▸ h) - refine ⟨heq,Or.inr ⟨rfl,funext fun j=>?_⟩⟩ - change z.left j=1; refine (bit_cases _).resolve_left (fun ht=>?_); apply hz - apply funext; intro i - have hx:= (h i j).1 - change z.left i=0; apply (hh i trivial).trans - exact (bit_cases _).resolve_right (fun h=> zero_ne_one (ht.symm.trans (hx.mpr ⟨h,trivial⟩).1)) - have heq : z.left=z.right:=funext fun i=>hh i trivial - exfalso - have hz : z.left ≠0 := he.elim id (heq.symm ▸ id) - apply hz - apply funext; intro i; change z.left i=0 - refine (bit_cases _).resolve_right fun hx=>?_ - have ht:= (h (!i) i).2 ⟨hx,trivial⟩ - cases i <;> simp at ht - -private theorem gamma_unique {u:Wgt (Fin r)} (w:Fin r→F) (a b:F) - (hu:IsLaw u) {ε:ℝ} (h:2*ε<1) - (ha:pr u (fun x=>w x≠a)≤ ε) (hb:pr u (fun x=>w x≠b)≤ ε): - a=b := by - classical - by_contra hf - have hi (i) (h:True): w i≠a∨w i≠b:=by - by_cases hh:w i=a - · exact Or.inr (hh ▸ hf) - exact Or.inl hh - have hp:=((pr_mono hu.nz hi).trans (pr_or_le hu.nz)).trans (add_le_add ha hb) - rw [pr_true,hu.total,←two_mul] at hp - linarith only [hp,h] - -def chorusClass (p:Shape) (v:PredictionData p A B r) (u:Terrain p r) (c:PredictionClass) (τ :ℝ) := - c.lit v.α ∧ - (c=dusk→∀ i l q k,v.g i l q k=0) ∧ - ∀ (z:DualCoefficients A B), c≠dusk → - (∀ i,z.hed i=z.left i.2 * firstBit v.α i.1 ∧ z.hed i=z.right i.1*firstBit v.α i.2) → - (∀ i l q, ChorusCost v z i u l q≤τ) → - ∀ i j,c.echoes i j (z.left j) (z.right i) - -set_option maxHeartbeats 1400000 in -theorem harmony (v:PredictionData p A B r) (u:Terrain p r) (c:PredictionClass) (τ :ℝ) - (m:BMark p n N) (x y:UnitType p n N) - (T:Cross p n) (s:Charts p n A) (t:Charts p n B) - (hx:coordSpec m x s v.X) (hy:coordSpec m y t v.Y) - (hg:3≤p.g) - (h:chorusClass p v u c τ) - (hq:∀ l q,IsLaw (u l q)) - (he:glint p (m x)=glint p (m y)) - (hf:c.compatible v.α (glint p (m x)) (cardTone m x T,cardTone m y (reciprocal p T))) - (z:DualCoefficients A B) (hτ:0≤τ) (ht:2*τ<1) (hz:z.left≠0∨z.right≠0) - (ha:∀ i,z.north i=z.left i.2 • v.X i.1 ∧ z.south i=z.right i.1 •v.Y i.2) - (hb:∀ i,z.hed i=z.left i.2*firstBit v.α i.1∧z.hed i=z.right i.1*firstBit v.α i.2) - (hl:∀ i l q,ChorusCost v z i u l q≤τ): - ∑ i,z.bet i (hailing p s t T i)=0 := by - classical - let G:= z.left; let H:=z.right - let L i j:= contract p T i j (m x i)+role p n (m x i) - let R i j:= contract p (reciprocal p T) j i (m y j)+role p n (m y j) - let P:=cardTone m x T; let Q:=cardTone m y (reciprocal p T) - let D:=glint p (m x) - have h1 (i j): z.bet (i,j) (hailing p s t T (i,j)) = - z.gam (i,j) + z.hed (i,j) + (G j * L i j + H i * R i j) := by - unfold DualCoefficients.bet - rw [(ha _).1,(ha _).2]; dsimp only [hailing] - rw [smul_dotProduct,smul_dotProduct,mul_one,mul_one,dotProduct_comm (v.X _),dotProduct_comm (v.Y _)] - unfold targetMark; rw [←roll_project, ←roll_project,hx _,hy _]; rfl - let E:=∑ i:Grid,z.gam i - let F' :=∑ i:Grid,z.hed i - let g i:=G i*(P i+D); let h' i:=H i*(Q i+D) - have hZ :∑ i,z.bet i (hailing p s t T i)=E+F'+((∑ i,g i)+(∑ j,h' j)):= by - have h2 j : ∑ i:Nodes,G j*L i j=g j:= by - unfold g P L; rw [←Finset.mul_sum,Finset.sum_add_distrib]; rfl - have h3 i:∑ j:Nodes,H i*R i j=h' i:= by - unfold h' Q R D; rw [←Finset.mul_sum,Finset.sum_add_distrib,he]; rfl - unfold E F'; rw [Fintype.sum_prod_type, Fintype.sum_prod_type,Fintype.sum_prod_type] - simp_rw [h1,Finset.sum_add_distrib,h3] - congr 2 - rw [Finset.sum_comm]; simp_rw [h2] - let l : Tag p.g:=⟨0,by omega⟩; let w:= u l 1 - have hh i: pr w (fun k=>G i.2 *v.g i.1 l 1 k+H i.1*v.g i.2 l 1 k ≠ z.gam i)≤τ :=by - simpa only [w,ChorusCost,G,H,mul_one] using hl i l 1 - rw [hZ] - by_cases hC : c=dusk - · subst c - have hg i : z.gam i=0:= by - apply gamma_unique (w:=fun k=>_) _ _ (hq l 1) ht (hh i) - simp only [h.2.1 rfl,mul_zero,add_zero, ne_eq,not_true_eq_false,pr_false] - exact hτ - have hf' i : z.hed i=0:= by - rw [(hb i).1,h.1.1 i.1 not_false,mul_zero] - have hx : P=fun _=> D:= congrArg Prod.fst hf - have hy : Q=fun _=> D:= congrArg Prod.snd hf - simp only [E,F',hg,hf',g,h',hx,hy,char_two,mul_zero,sum_const_zero] - have hi := h.2.2 z hC hb hl - obtain ⟨hr,hG⟩:=echo_pattern c z hi hC hz - have hm : G=H :=hr - have hf0 i: z.gam (i,i)=0:= by - apply gamma_unique (w:=fun k=>_) _ _ (hq l 1) ht (hh (i,i)) - simp only [hm,char_two,ne_eq,not_true_eq_false,pr_false] - exact hτ - have hg1 i j : z.gam (i,j)=z.gam (j,i):= by - apply gamma_unique (w:=fun k=>_) _ _ (hq l 1) ht (hh (i,j)) - simpa only [hm,add_comm] using hh (j,i) - have hE : E=0 := by unfold E; rw [Fintype.sum_prod_type] - ; simp only [Fintype.sum_bool,hf0,hg1 false true,add_zero,zero_add,char_two] - rw [hE,zero_add] - obtain ⟨i,hc,hx⟩|⟨hc,hx⟩:=hG - · subst c - have hy : H=unary i:=hm ▸ hx - change P i+Q i=firstBit v.α i at hf - unfold F' - rw [Fintype.sum_prod_type]; simp_rw [(hb _).1] - have hi : firstBit v.α (!i)=0:= h.1.1 _ (by cases i <;> simp [active]) - cases i - · change firstBit v.α true=0 at hi - simp [hx,g,h',G,hy,unary,hi] - rw [add_add_add_comm,char_two,add_zero,hf,char_two] - · change firstBit v.α false=0 at hi - simp [hx,g,h',G,hy,unary,hi] - rw [add_add_add_comm,char_two,add_zero,hf,char_two] - · subst c - have hy : H=allSide:=hm ▸ hx - change dotProduct allSide P + dotProduct allSide Q=0 at hf - simp only [dotProduct,Fintype.sum_bool,allSide,one_mul] at hf - unfold F' - rw [Fintype.sum_prod_type]; simp_rw [(hb _).1] - simp only [hx,g,h',G,hy,Fintype.sum_bool,allSide,one_mul,char_two,zero_add] - rw [add_add_add_comm (P true) D,add_add_add_comm (Q true) D,char_two] - simpa using hf -end DualAnalysis -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PredictedDualCoefficients + +namespace OAI + +/-! # Predicted Dual Evaluation -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Finset Function LinearMap Module +open scoped BigOperators +namespace StatusAnalysis +namespace DualAnalysis +open PredictionClass +variable {p:Shape} {n N r :ℕ} {A B:Rates} + +private theorem echo_pattern (c:PredictionClass) (z:DualCoefficients A B) + (h:∀ i j,echoes c i j (z.left j) (z.right i)) + (hn:c≠dusk) (he:z.left ≠0∨ z.right≠0): + z.left=z.right ∧ + ((∃ i, c=dawn i∧ z.left=unary i) ∨ (c=twinned∧ z.left=allSide)) := by + classical + have hh (i) : c.active i→ z.left i=z.right i := by + intro ht; have hk:=(h i i).1 + rcases bit_cases (z.left i) with hi|hi <;> rcases bit_cases (z.right i) with hx|hx <;> simp_all + cases c + · exact (hn rfl).elim + · rename_i i + have ht : (dawn i).active i:= rfl + have hact := hh i ht + have hx j (hij:i≠j): z.left j=0 ∧ z.right j=0 := by + have hf : ¬(dawn i).active j:=hij + have h1:=(h i j).1; have h2:=(h j i).1 + constructor + · exact (bit_cases _).resolve_right fun h'=> hf (h1.mp ⟨h',ht⟩).2 + exact (bit_cases _).resolve_right fun h'=> hf (h2.mpr ⟨h',ht⟩).2 + have hm : z.left=z.right := funext fun j=>by + by_cases hij : i=j + · exact hij ▸ hact + exact (hx j hij).1.trans (hx j hij).2.symm + have hz:=show z.left≠0 from he.elim id (fun h=>hm.symm ▸ h) + refine ⟨hm,Or.inl ⟨i,rfl, funext fun j=>?_⟩⟩ + by_cases hij:i=j + · subst j + have hv : z.left i=1:= (bit_cases _).resolve_left (fun h=> hz (funext fun j=> by + by_cases hi : i = j + · exact hi ▸ h + exact (hx j hi).1)) + simp [unary,hv] + rw [(hx j hij).1]; simp [unary,Ne.symm hij] + · have heq : z.left=z.right:= funext (fun i=> hh i trivial) + have hz:=show z.left≠0 from he.elim id (fun h=>heq.symm ▸ h) + refine ⟨heq,Or.inr ⟨rfl,funext fun j=>?_⟩⟩ + change z.left j=1; refine (bit_cases _).resolve_left (fun ht=>?_); apply hz + apply funext; intro i + have hx:= (h i j).1 + change z.left i=0; apply (hh i trivial).trans + exact (bit_cases _).resolve_right (fun h=> zero_ne_one (ht.symm.trans (hx.mpr ⟨h,trivial⟩).1)) + have heq : z.left=z.right:=funext fun i=>hh i trivial + exfalso + have hz : z.left ≠0 := he.elim id (heq.symm ▸ id) + apply hz + apply funext; intro i; change z.left i=0 + refine (bit_cases _).resolve_right fun hx=>?_ + have ht:= (h (!i) i).2 ⟨hx,trivial⟩ + cases i <;> simp at ht + +private theorem gamma_unique {u:Wgt (Fin r)} (w:Fin r→F) (a b:F) + (hu:IsLaw u) {ε:ℝ} (h:2*ε<1) + (ha:pr u (fun x=>w x≠a)≤ ε) (hb:pr u (fun x=>w x≠b)≤ ε): + a=b := by + classical + by_contra hf + have hi (i) (h:True): w i≠a∨w i≠b:=by + by_cases hh:w i=a + · exact Or.inr (hh ▸ hf) + exact Or.inl hh + have hp:=((pr_mono hu.nz hi).trans (pr_or_le hu.nz)).trans (add_le_add ha hb) + rw [pr_true,hu.total,←two_mul] at hp + linarith only [hp,h] + +def chorusClass (p:Shape) (v:PredictionData p A B r) (u:Terrain p r) (c:PredictionClass) (τ :ℝ) := + c.lit v.α ∧ + (c=dusk→∀ i l q k,v.g i l q k=0) ∧ + ∀ (z:DualCoefficients A B), c≠dusk → + (∀ i,z.hed i=z.left i.2 * firstBit v.α i.1 ∧ z.hed i=z.right i.1*firstBit v.α i.2) → + (∀ i l q, ChorusCost v z i u l q≤τ) → + ∀ i j,c.echoes i j (z.left j) (z.right i) + +set_option maxHeartbeats 1400000 in +theorem harmony (v:PredictionData p A B r) (u:Terrain p r) (c:PredictionClass) (τ :ℝ) + (m:BMark p n N) (x y:UnitType p n N) + (T:Cross p n) (s:Charts p n A) (t:Charts p n B) + (hx:coordSpec m x s v.X) (hy:coordSpec m y t v.Y) + (hg:3≤p.g) + (h:chorusClass p v u c τ) + (hq:∀ l q,IsLaw (u l q)) + (he:glint p (m x)=glint p (m y)) + (hf:c.compatible v.α (glint p (m x)) (cardTone m x T,cardTone m y (reciprocal p T))) + (z:DualCoefficients A B) (hτ:0≤τ) (ht:2*τ<1) (hz:z.left≠0∨z.right≠0) + (ha:∀ i,z.north i=z.left i.2 • v.X i.1 ∧ z.south i=z.right i.1 •v.Y i.2) + (hb:∀ i,z.hed i=z.left i.2*firstBit v.α i.1∧z.hed i=z.right i.1*firstBit v.α i.2) + (hl:∀ i l q,ChorusCost v z i u l q≤τ): + ∑ i,z.bet i (hailing p s t T i)=0 := by + classical + let G:= z.left; let H:=z.right + let L i j:= contract p T i j (m x i)+role p n (m x i) + let R i j:= contract p (reciprocal p T) j i (m y j)+role p n (m y j) + let P:=cardTone m x T; let Q:=cardTone m y (reciprocal p T) + let D:=glint p (m x) + have h1 (i j): z.bet (i,j) (hailing p s t T (i,j)) = + z.gam (i,j) + z.hed (i,j) + (G j * L i j + H i * R i j) := by + unfold DualCoefficients.bet + rw [(ha _).1,(ha _).2]; dsimp only [hailing] + rw [smul_dotProduct,smul_dotProduct,mul_one,mul_one,dotProduct_comm (v.X _),dotProduct_comm (v.Y _)] + unfold targetMark; rw [←roll_project, ←roll_project,hx _,hy _]; rfl + let E:=∑ i:Grid,z.gam i + let F' :=∑ i:Grid,z.hed i + let g i:=G i*(P i+D); let h' i:=H i*(Q i+D) + have hZ :∑ i,z.bet i (hailing p s t T i)=E+F'+((∑ i,g i)+(∑ j,h' j)):= by + have h2 j : ∑ i:Nodes,G j*L i j=g j:= by + unfold g P L; rw [←Finset.mul_sum,Finset.sum_add_distrib]; rfl + have h3 i:∑ j:Nodes,H i*R i j=h' i:= by + unfold h' Q R D; rw [←Finset.mul_sum,Finset.sum_add_distrib,he]; rfl + unfold E F'; rw [Fintype.sum_prod_type, Fintype.sum_prod_type,Fintype.sum_prod_type] + simp_rw [h1,Finset.sum_add_distrib,h3] + congr 2 + rw [Finset.sum_comm]; simp_rw [h2] + let l : Tag p.g:=⟨0,by omega⟩; let w:= u l 1 + have hh i: pr w (fun k=>G i.2 *v.g i.1 l 1 k+H i.1*v.g i.2 l 1 k ≠ z.gam i)≤τ :=by + simpa only [w,ChorusCost,G,H,mul_one] using hl i l 1 + rw [hZ] + by_cases hC : c=dusk + · subst c + have hg i : z.gam i=0:= by + apply gamma_unique (w:=fun k=>_) _ _ (hq l 1) ht (hh i) + simp only [h.2.1 rfl,mul_zero,add_zero, ne_eq,not_true_eq_false,pr_false] + exact hτ + have hf' i : z.hed i=0:= by + rw [(hb i).1,h.1.1 i.1 not_false,mul_zero] + have hx : P=fun _=> D:= congrArg Prod.fst hf + have hy : Q=fun _=> D:= congrArg Prod.snd hf + simp only [E,F',hg,hf',g,h',hx,hy,char_two,mul_zero,sum_const_zero] + have hi := h.2.2 z hC hb hl + obtain ⟨hr,hG⟩:=echo_pattern c z hi hC hz + have hm : G=H :=hr + have hf0 i: z.gam (i,i)=0:= by + apply gamma_unique (w:=fun k=>_) _ _ (hq l 1) ht (hh (i,i)) + simp only [hm,char_two,ne_eq,not_true_eq_false,pr_false] + exact hτ + have hg1 i j : z.gam (i,j)=z.gam (j,i):= by + apply gamma_unique (w:=fun k=>_) _ _ (hq l 1) ht (hh (i,j)) + simpa only [hm,add_comm] using hh (j,i) + have hE : E=0 := by unfold E; rw [Fintype.sum_prod_type] + ; simp only [Fintype.sum_bool,hf0,hg1 false true,add_zero,zero_add,char_two] + rw [hE,zero_add] + obtain ⟨i,hc,hx⟩|⟨hc,hx⟩:=hG + · subst c + have hy : H=unary i:=hm ▸ hx + change P i+Q i=firstBit v.α i at hf + unfold F' + rw [Fintype.sum_prod_type]; simp_rw [(hb _).1] + have hi : firstBit v.α (!i)=0:= h.1.1 _ (by cases i <;> simp [active]) + cases i + · change firstBit v.α true=0 at hi + simp [hx,g,h',G,hy,unary,hi] + rw [add_add_add_comm,char_two,add_zero,hf,char_two] + · change firstBit v.α false=0 at hi + simp [hx,g,h',G,hy,unary,hi] + rw [add_add_add_comm,char_two,add_zero,hf,char_two] + · subst c + have hy : H=allSide:=hm ▸ hx + change dotProduct allSide P + dotProduct allSide Q=0 at hf + simp only [dotProduct,Fintype.sum_bool,allSide,one_mul] at hf + unfold F' + rw [Fintype.sum_prod_type]; simp_rw [(hb _).1] + simp only [hx,g,h',G,hy,Fintype.sum_bool,allSide,one_mul,char_two,zero_add] + rw [add_add_add_comm (P true) D,add_add_add_comm (Q true) D,char_two] + simpa using hf +end DualAnalysis +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionClassBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionClassBounds.lean index 949e2b8ba52f9674e6c95f7b9c1f648ce5b50aa0..4f3acc1cbbd013a86c71481755ceca9d94b633b0 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionClassBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionClassBounds.lean @@ -1,120 +1,120 @@ -import OAI.Combinatorics.HadwigerCounterexample.ForbiddenPredictions - -namespace OAI - -/-! # Prediction Class Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Function Module LinearMap Matrix -open scoped BigOperators Topology -open Template -variable {p:Shape} {n N r M K s0:ℕ} -namespace StatusAnalysis -open PreparationParameters Station PredictionClass DualAnalysis Club Guild -variable {w:LeafMixture p n N} {b:PreparationParameters} {B:Sketch p M} -variable {d e: Rates} - -set_option maxHeartbeats 1200000 in -theorem laysScore (p:Shape) (K:ℕ) - (Y: Silhouette p N r) (m: Mixer p n) (U:Terrain p r) - (x y:UnitType p n N) (z:BMark p n N) - (d e:Rates) - (X:Charts p n d) (V:Charts p n e) - (c:PredictionClass) (g:PredictionData p d e r) - (A B:Stalls p) - (S:Straps (Label p.b)) (η ε β δ τ:ℝ) - (hx:coordSpec z x X g.X)(hy:coordSpec z y V g.Y) - (h:chorusClass p g U c τ)(hτ:0≤τ)(hl:2*τ<1) - (ht:countStory p K η δ ε β U) - (ha:reports p r U (wake p Y m x X) β δ) - (hb:reports p r U (wake p Y m y V) β δ) - (hs:g.colored U (wake p Y m x X) (wake p Y m y V) A B (2*ε)) - (hk:∀ i,d i≤K^2)(hq:∀ i,e i≤K^2) - (hg:3≤p.g)(hμ:10*ε≤τ) - (hA:seeking p A)(hB:seeking p B) - (he:sizeB S 800) - (T:Cross p n) - (hF:glint p (z x)=glint p (z y)) - (hQ:c.compatible g.α (glint p (z x)) - (cardTone z x T,cardTone z y (reciprocal p T))) : - let C:=stellar U (wake p Y m x X) (wake p Y m y V) η A B - Guild.rich C→scorecard (chapter C S) (hailing p X V T) := by - classical - intro C hC - by_contra hc - obtain ⟨j,h1,h2,h3⟩:= jargon_score _ _ hc (rich_covers C hC S (fun i=>(he i).trans (by norm_num))) - let L:= wake p Y m x X; let R:=wake p Y m y V - let A':=outstraps A S true; let B':=outstraps B S false - have hS:g.colored U L R A' B' (2*ε):= by - exact ⟨fun i z hz=> hs.1 i z (mt (Finset.mem_union_left _) hz), - fun i z hz=> hs.2 i z (mt (Finset.mem_union_left _) hz)⟩ - have hh i:= duet_edge g j i hg ht.h ha hb A' B' hS (outcard p A S hA he _ _) - (outcard p B S hB he _ _) (counter_bill j ht ha hb _ _ S i h2 (hk _) (hq _)) ht.he - (show 0 ≤ 2*ε from by linarith only [ht.he]) ht.hb (show 3*ε+2*ε<1/2*β from - by linarith only [ht.high,ht.he]) - apply h3 - refine harmony g U c τ z x y T X V hx hy hg h ht.h.1 hF hQ j hτ hl h1 - (fun i=>⟨(hh i).1,(hh i).2.1⟩) (fun i=>⟨(hh i).2.2.1,(hh i).2.2.2.1⟩) - (fun i l q=>((hh i).2.2.2.2 l q).trans (by linarith only [hμ])) - -structure pilot (p:Shape) (d: Rates) (r:ℕ) where - m : Bool→ Pulsar p r - -structure hue (c:PredictionClass) (Y:Silhouette p N r) (f:Bool→ Pulsar p r) - (u:Bool→Augur p N) (α:Party) (τ:ℝ) :Prop where - consistent : c.lit α - pulse_eq : c≠dusk → ∀ i,fromPulse Y (f i)=u i - atDawn : c=dusk→∀ i,f i=0 - recording : c.recital p u α τ - -theorem paintChorus (c:PredictionClass) (Y:Silhouette p N r) (f:Bool→ Pulsar p r) - (u:Bool→Augur p N) (α:Party) (τ:ℝ) - (h:hue c Y f u α τ) (A:styles d) (B:styles e) : - chorusClass p (⟨α,f,A,B⟩:PredictionData p d e r) (wisp p Y) c τ := by - classical - refine ⟨h.consistent,?_,?_⟩ - · intro hg i j l k; change f i j l k=0; rw [h.atDawn hg]; rfl - intro j hc ha hb x y - obtain ⟨he,hf⟩:= ha (x,y) - apply h.recording.2 x y (j.left y) (j.right x) (j.gam (x,y)) (he.symm.trans hf) - intro l q - specialize hb (x,y) l q - unfold tabRef assembly; rw [← h.pulse_eq hc x,← h.pulse_eq hc y] - unfold ChorusCost wisp at hb; rw [mapW_pr] at hb; exact hb - -set_option maxHeartbeats 900000 in -theorem crew_praise (p:Shape) {q: PreparationParameters} (c:PredictionClass) (Y:Silhouette p N r) - (f:Bool→ Pulsar p r) (u:Bool→Augur p N) (α:Party) (τ:ℝ) (h:hue c Y f u α τ) - (m:Mixer p n)(A:Charts p n d)(g:styles d)(w:BMark p n N) - (x:UnitType p n N) (H S : Stalls p) (hS:H ≤ S)(hp:coordSpec w x A g) - {δ ε:ℝ} (he:0≤ε)(hd:δ≤ε) (ht:AnalyticParameters p M q s0)(hn:2*p.r≤n) - (hf:claimed p x u m (w x) α H (scanPrice p*ε)) - (hg:c=dusk → exactInk p m w x) (hG:gauze p δ δ Y m q.pins x): - ∀ i,praise (wisp p Y) (wake p Y m x A) i (S i) (yokeSet (g i) (α i)) (f i) (2*ε) := by - classical - intro i a ha hz - let L:=S i - have hk : postulates p (onSide x i) (fromPulse Y (f i)) (compass i x A m (g i) (α i)) - (H i) (scanPrice p*ε) := by - unfold compass; rw [hp i] - by_cases hC:c=dusk - · have heq:= dusk_lit α (hC ▸ h.consistent) - rw [heq,h.atDawn hC i] - intro s hs z v - have hj (y:Knobs p.g n): ¬mismatch p (fromPulse Y 0) (yoke p m x i (w x i) 1) z s v - (onSide x i) y := by - exact fun hk=>hk (show _= (0:F) from hg hC i _ (mem_useAtom ..)) - simp_rw [eq_false (hj _),pr_false]; exact mul_nonneg (scanPrice_pos _).le he - rw [h.pulse_eq hC]; exact hf i - have hi:= ht.enter.first - exact (predict_praise A Y i x m (g i) (α i) (f i) (H i) he hi.hR hn - (fun a h=> (hG i a).1 h) hk a (fun hx=>ha (hS i hx)) hz).trans - (show ε+δ ≤ 2*ε from by linarith only [hd]) - -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ForbiddenPredictions + +namespace OAI + +/-! # Prediction Class Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Function Module LinearMap Matrix +open scoped BigOperators Topology +open Template +variable {p:Shape} {n N r M K s0:ℕ} +namespace StatusAnalysis +open PreparationParameters Station PredictionClass DualAnalysis Club Guild +variable {w:LeafMixture p n N} {b:PreparationParameters} {B:Sketch p M} +variable {d e: Rates} + +set_option maxHeartbeats 1200000 in +theorem laysScore (p:Shape) (K:ℕ) + (Y: Silhouette p N r) (m: Mixer p n) (U:Terrain p r) + (x y:UnitType p n N) (z:BMark p n N) + (d e:Rates) + (X:Charts p n d) (V:Charts p n e) + (c:PredictionClass) (g:PredictionData p d e r) + (A B:Stalls p) + (S:Straps (Label p.b)) (η ε β δ τ:ℝ) + (hx:coordSpec z x X g.X)(hy:coordSpec z y V g.Y) + (h:chorusClass p g U c τ)(hτ:0≤τ)(hl:2*τ<1) + (ht:countStory p K η δ ε β U) + (ha:reports p r U (wake p Y m x X) β δ) + (hb:reports p r U (wake p Y m y V) β δ) + (hs:g.colored U (wake p Y m x X) (wake p Y m y V) A B (2*ε)) + (hk:∀ i,d i≤K^2)(hq:∀ i,e i≤K^2) + (hg:3≤p.g)(hμ:10*ε≤τ) + (hA:seeking p A)(hB:seeking p B) + (he:sizeB S 800) + (T:Cross p n) + (hF:glint p (z x)=glint p (z y)) + (hQ:c.compatible g.α (glint p (z x)) + (cardTone z x T,cardTone z y (reciprocal p T))) : + let C:=stellar U (wake p Y m x X) (wake p Y m y V) η A B + Guild.rich C→scorecard (chapter C S) (hailing p X V T) := by + classical + intro C hC + by_contra hc + obtain ⟨j,h1,h2,h3⟩:= jargon_score _ _ hc (rich_covers C hC S (fun i=>(he i).trans (by norm_num))) + let L:= wake p Y m x X; let R:=wake p Y m y V + let A':=outstraps A S true; let B':=outstraps B S false + have hS:g.colored U L R A' B' (2*ε):= by + exact ⟨fun i z hz=> hs.1 i z (mt (Finset.mem_union_left _) hz), + fun i z hz=> hs.2 i z (mt (Finset.mem_union_left _) hz)⟩ + have hh i:= duet_edge g j i hg ht.h ha hb A' B' hS (outcard p A S hA he _ _) + (outcard p B S hB he _ _) (counter_bill j ht ha hb _ _ S i h2 (hk _) (hq _)) ht.he + (show 0 ≤ 2*ε from by linarith only [ht.he]) ht.hb (show 3*ε+2*ε<1/2*β from + by linarith only [ht.high,ht.he]) + apply h3 + refine harmony g U c τ z x y T X V hx hy hg h ht.h.1 hF hQ j hτ hl h1 + (fun i=>⟨(hh i).1,(hh i).2.1⟩) (fun i=>⟨(hh i).2.2.1,(hh i).2.2.2.1⟩) + (fun i l q=>((hh i).2.2.2.2 l q).trans (by linarith only [hμ])) + +structure pilot (p:Shape) (d: Rates) (r:ℕ) where + m : Bool→ Pulsar p r + +structure hue (c:PredictionClass) (Y:Silhouette p N r) (f:Bool→ Pulsar p r) + (u:Bool→Augur p N) (α:Party) (τ:ℝ) :Prop where + consistent : c.lit α + pulse_eq : c≠dusk → ∀ i,fromPulse Y (f i)=u i + atDawn : c=dusk→∀ i,f i=0 + recording : c.recital p u α τ + +theorem paintChorus (c:PredictionClass) (Y:Silhouette p N r) (f:Bool→ Pulsar p r) + (u:Bool→Augur p N) (α:Party) (τ:ℝ) + (h:hue c Y f u α τ) (A:styles d) (B:styles e) : + chorusClass p (⟨α,f,A,B⟩:PredictionData p d e r) (wisp p Y) c τ := by + classical + refine ⟨h.consistent,?_,?_⟩ + · intro hg i j l k; change f i j l k=0; rw [h.atDawn hg]; rfl + intro j hc ha hb x y + obtain ⟨he,hf⟩:= ha (x,y) + apply h.recording.2 x y (j.left y) (j.right x) (j.gam (x,y)) (he.symm.trans hf) + intro l q + specialize hb (x,y) l q + unfold tabRef assembly; rw [← h.pulse_eq hc x,← h.pulse_eq hc y] + unfold ChorusCost wisp at hb; rw [mapW_pr] at hb; exact hb + +set_option maxHeartbeats 900000 in +theorem crew_praise (p:Shape) {q: PreparationParameters} (c:PredictionClass) (Y:Silhouette p N r) + (f:Bool→ Pulsar p r) (u:Bool→Augur p N) (α:Party) (τ:ℝ) (h:hue c Y f u α τ) + (m:Mixer p n)(A:Charts p n d)(g:styles d)(w:BMark p n N) + (x:UnitType p n N) (H S : Stalls p) (hS:H ≤ S)(hp:coordSpec w x A g) + {δ ε:ℝ} (he:0≤ε)(hd:δ≤ε) (ht:AnalyticParameters p M q s0)(hn:2*p.r≤n) + (hf:claimed p x u m (w x) α H (scanPrice p*ε)) + (hg:c=dusk → exactInk p m w x) (hG:gauze p δ δ Y m q.pins x): + ∀ i,praise (wisp p Y) (wake p Y m x A) i (S i) (yokeSet (g i) (α i)) (f i) (2*ε) := by + classical + intro i a ha hz + let L:=S i + have hk : postulates p (onSide x i) (fromPulse Y (f i)) (compass i x A m (g i) (α i)) + (H i) (scanPrice p*ε) := by + unfold compass; rw [hp i] + by_cases hC:c=dusk + · have heq:= dusk_lit α (hC ▸ h.consistent) + rw [heq,h.atDawn hC i] + intro s hs z v + have hj (y:Knobs p.g n): ¬mismatch p (fromPulse Y 0) (yoke p m x i (w x i) 1) z s v + (onSide x i) y := by + exact fun hk=>hk (show _= (0:F) from hg hC i _ (mem_useAtom ..)) + simp_rw [eq_false (hj _),pr_false]; exact mul_nonneg (scanPrice_pos _).le he + rw [h.pulse_eq hC]; exact hf i + have hi:= ht.enter.first + exact (predict_praise A Y i x m (g i) (α i) (f i) (H i) he hi.hR hn + (fun a h=> (hG i a).1 h) hk a (fun hx=>ha (hS i hx)) hz).trans + (show ε+δ ≤ 2*ε from by linarith only [hd]) + +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionClasses.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionClasses.lean index 4731933850f2ae2b03059b95ded6e20a2742e019..2128f92707d9427bcfdb6d9996a190d4211ad104 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionClasses.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionClasses.lean @@ -1,199 +1,199 @@ -import OAI.Combinatorics.HadwigerCounterexample.PredictionExactification -import OAI.Combinatorics.HadwigerCounterexample.UltrafilterRates -import OAI.Combinatorics.HadwigerCounterexample.RefinedPinImages - -namespace OAI - -/-! # Prediction Classes -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Matrix Finset -open scoped BigOperators Topology - -inductive PredictionClass -| dusk -| dawn (i : Bool) -| twinned -| noon -deriving Inhabited, DecidableEq - -variable {p : Shape} -namespace PredictionClass - -def active : PredictionClass→Bool→ Prop -| dusk,_=>False -| dawn i,j=>i=j -| twinned,_=>True -| noon,_=>True - -def echoes (c : PredictionClass) (i j : Bool) (s r : F) := - ((s=1 ∧ c.active i) ↔ (r=1 ∧ c.active j)) ∧ - ((s=1 ∧ c.active i) → (i=j ∨ c=twinned)) - -def firstBit (α : Party) (i : Bool) := 1+α i - -def lit (c : PredictionClass) (α : Party) := - (∀ i,¬c.active i → firstBit α i=0) ∧ - (c=twinned → α true=α false) - -def assembly {N} (g : Bool→Augur p N) (i j : Bool) (s t : F) : Augur p N := - fun l q x => s*g i l q x+t*g j l q x - -/-- Enough to test against dual relations. -/ -def recital (c : PredictionClass) (p : Shape) {N} - (g : Bool→Augur p N) (α : Party) (τ : ℝ) := - c.lit α ∧ ∀ (i j : Bool) (s t r : F), s*firstBit α i=t*firstBit α j → - (∀ l q,tabRef p l q (assembly g i j s t) r ≤ τ) → c.echoes i j s t -abbrev season (p : Shape) (M : ℕ) := (n : ℕ)→Augur p (M*n) -def disappearing (U : Ultrafilter ℕ) {M} (g : season p M) (s : F) := - ∀ l q, slight (U:Filter ℕ) (fun i=>tabRef p l q (g i) s) - -private def modest (U : Ultrafilter ℕ) {M} - (g : Bool→season p M) (α : Party) (i : Bool) := - firstBit α i=0 ∧ ∃ s,g i |> fun x=> disappearing U x s - -private def accords (U : Ultrafilter ℕ) {M} - (g : Bool→season p M) (α : Party) := - α true=α false ∧ ∃ s, disappearing U - (fun n : ℕ=>fun l q x => g true n l q x+g false n l q x) s - -private def census (U : Ultrafilter ℕ) {M} - (g : Bool→season p M) (α : Party) := - open scoped Classical in - if modest U g α true then if modest U g α false then dusk else dawn false - else if modest U g α false then dawn true - else if accords U g α then twinned else noon - -variable {U : Ultrafilter ℕ} {M : ℕ} - {g : Bool → season p M} {α : Party} - -private theorem census_active (i : Bool) : - active (census U g α) i ↔ ¬modest U g α i := by - classical - unfold census - cases i <;> split_ifs <;> simp_all [active] - -private theorem census_lit : - (census U g α).lit α := by - classical - constructor - · intro i hi; exact (show modest U g α i from not_not.mp (fun h=> hi ((census_active i).mpr h))).1 - unfold census - intro h; split_ifs at h; try contradiction - exact ‹accords U g α›.1 - -theorem disappearing_add {x y : season p M} {r s : F} - (h : disappearing U x r) (hh : disappearing U y s) : - disappearing U (fun i => fun l q j=> x i l q j+y i l q j) (r+s) := by - intro l q ε he - filter_upwards [h l q _ (half_pos he),hh l q _ (half_pos he)] with i hi hj - let v := lawOmega p (M*i) l q - have hv (j : AtomKey (p:=p) l (M*i)) : 0≤ v j := by - exact (unifOn_sub _).nz _ - let P j := x i l q j≠r*q - let Q j := y i l q j≠s*q - have hh (j) (h : x i l q j+y i l q j≠ (r+s)*q) : P j∨ Q j := by - unfold P Q - rw [add_mul] at h; contrapose h - push Not at * - simp [h] - have hf : pr v P ≤ ε/2 := hi; have hg : pr v Q ≤ ε/2 := hj - exact ((pr_mono hv hh).trans (pr_or_le hv)).trans (by linarith only [hf,hg]) - -private theorem census_match (h : accords U g α) : - modest U g α true ↔ modest U g α false := by - classical - let x : season p M := fun n l q i=>g true n l q i+g false n l q i - obtain ⟨hd,s,hs⟩:=h - have hs : disappearing U x s := hs - refine ⟨fun ⟨h,r,hg⟩=>⟨by simpa only [firstBit,←hd] using h,r+s,?_⟩, - fun ⟨h,r,hg⟩=>⟨by simpa only [firstBit,hd] using h,r+s,?_⟩⟩ - · have he : (fun n l q j=>g true n l q j+x n l q j)=g false := by - funext n l q j; change _+(_+_)=_; rw [←add_assoc,char_two,zero_add] - rw [←he]; exact disappearing_add hg hs - have he : (fun n l q j=>g false n l q j+x n l q j)=g true := by - funext n l q j; change _+(_+_)=_; rw [add_left_comm,char_two,add_zero] - rw [←he]; exact disappearing_add hg hs - -set_option maxHeartbeats 1000000 in -private theorem census_echoes (i j : Bool) (s t r : F) (h : s*firstBit α i=t*firstBit α j) - (hg : disappearing U (fun n=>assembly (fun i=>g i n) i j s t) r) : - (census U g α).echoes i j s t := by - classical - unfold echoes; simp_rw [census_active] - rcases bit_cases s with hs|hs <;> rcases bit_cases t with ht|ht <;> subst s t - · simp - · have hi : firstBit α j=0 := by simpa only [zero_mul,one_mul] using h.symm - have hh : (fun n : ℕ=> assembly (fun i=>g i n) i j 0 1)=g j := by - funext n l q x; change (0:F)*g i n l q x+ (1:F)*g j n l q x=g j n l q x; rw [one_mul,zero_mul,zero_add] - have he : modest U g α j := ⟨hi,r,hh ▸ hg⟩ - simp [he] - · have hi : firstBit α i=0 := by simpa only [zero_mul,one_mul] using h - have hh : (fun n : ℕ=> assembly (fun i=>g i n) i j 1 0)=g i := by - funext n l q x; change (1:F)*g i n l q x+ (0:F)*g j n l q x=g i n l q x; rw [one_mul,zero_mul,add_zero] - have he : modest U g α i := ⟨hi,r,hh ▸ hg⟩ - simp [he] - simp only [true_and] - by_cases hv : i=j - · subst j; simp - have ht : accords U g α := by - have hh : 1+α i=1+α j := by simpa only [one_mul,firstBit] using h - have h : α i=α j := add_left_cancel hh - let x1 (i j: Bool) := fun n=>assembly (fun i=>g i n) i j 1 1 - let x2 : season p M := fun n l q v=> g true n l q v+g false n l q v - have hv' : x1 i j=x2 := by - funext n l q v - unfold x1 assembly x2 - simp only [one_mul] - cases i <;> cases j <;> first | rfl | contradiction | exact add_comm _ _ - refine ⟨?_,r,show disappearing U x2 r from hv' ▸ (show disappearing U (x1 i j) r from hg)⟩ - cases i <;> cases j <;> first | contradiction | exact h | exact h.symm - have hm := census_match ht - by_cases he : modest U g α true - · have hh (i : Bool) : modest U g α i := by cases i; exact hm.mp he; exact he - simp [hh] - have hh (i: Bool) : ¬modest U g α i := by cases i; exact mt hm.mpr he; exact he - simp only [census, ite_eq_right (hh _), ite_eq_left ht]; simp [hh] - -private theorem eventual_echoes (i j : Bool) (s t r : F) : - ∃ τ:ℝ,0<τ ∧ ∀ᶠ n in U, - s*firstBit α i=t*firstBit α j → - ((∀ l q,tabRef p l q (assembly (fun i=> g i n) i j s t) r ≤ τ) → - (census U g α).echoes i j s t) := by - classical - by_cases hf : disappearing U (fun n=>assembly (fun i=>g i n) i j s t) r - · exact ⟨1,zero_lt_one,.of_forall (fun _ h _=> census_echoes i j s t r h hf)⟩ - unfold disappearing slight at hf - push Not at hf - obtain ⟨l,q,τ,hτ,h⟩:=hf - exact ⟨τ,hτ,h.mono fun i hi _ H=>(hi.not_ge (H l q)).elim⟩ - -theorem examine (U : Ultrafilter ℕ) (p : Shape) (M : ℕ) (g : Bool→ season p M) (α : Party) : - ∃ (c : PredictionClass) (τ : ℝ),0 < τ ∧ - (∀ᶠ n in U,c.recital p (fun i=>g i n) α τ) ∧ c.lit α ∧ - (c=dusk → ∀ i, ∃ r,disappearing U (g i) r) := by - classical - let A:=Bool × Bool × (F×F×F) - let c:= census U g α - choose τ hτ hg using fun x : A=> @eventual_echoes p U M g α - x.1 x.2.1 x.2.2.1 x.2.2.2.1 x.2.2.2.2 - have hh : ∃ δ:ℝ,0<δ∧∀ x,δ≤τ x := by - let S := univ.image τ - have hn : S.Nonempty := Finset.image_nonempty.mpr Finset.univ_nonempty - refine ⟨S.min' hn, ?_, fun x=> Finset.min'_le _ _ (mem_image_of_mem _ (mem_univ _))⟩ - obtain ⟨x,hx,hx'⟩:= mem_image.mp (Finset.min'_mem _ hn) - exact hx' ▸ hτ x - obtain ⟨δ,hδ,hT⟩:=hh - refine ⟨c,δ,hδ,?_,census_lit,fun h i=>?_⟩ - · filter_upwards [eventually_all.mpr hg] with n h - refine ⟨census_lit,fun i j s t r he hh=>?_⟩ - exact h (i,j,s,t,r) he (fun l q=>(hh l q).trans (hT _)) - have he : ¬ c.active i := by rw [h]; exact not_false - exact (show modest U g α i from not_not.mp (fun h=>he ((census_active i).mpr h))).2 -end PredictionClass -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PredictionExactification +import OAI.Combinatorics.HadwigerCounterexample.UltrafilterRates +import OAI.Combinatorics.HadwigerCounterexample.RefinedPinImages + +namespace OAI + +/-! # Prediction Classes -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Matrix Finset +open scoped BigOperators Topology + +inductive PredictionClass +| dusk +| dawn (i : Bool) +| twinned +| noon +deriving Inhabited, DecidableEq + +variable {p : Shape} +namespace PredictionClass + +def active : PredictionClass→Bool→ Prop +| dusk,_=>False +| dawn i,j=>i=j +| twinned,_=>True +| noon,_=>True + +def echoes (c : PredictionClass) (i j : Bool) (s r : F) := + ((s=1 ∧ c.active i) ↔ (r=1 ∧ c.active j)) ∧ + ((s=1 ∧ c.active i) → (i=j ∨ c=twinned)) + +def firstBit (α : Party) (i : Bool) := 1+α i + +def lit (c : PredictionClass) (α : Party) := + (∀ i,¬c.active i → firstBit α i=0) ∧ + (c=twinned → α true=α false) + +def assembly {N} (g : Bool→Augur p N) (i j : Bool) (s t : F) : Augur p N := + fun l q x => s*g i l q x+t*g j l q x + +/-- Enough to test against dual relations. -/ +def recital (c : PredictionClass) (p : Shape) {N} + (g : Bool→Augur p N) (α : Party) (τ : ℝ) := + c.lit α ∧ ∀ (i j : Bool) (s t r : F), s*firstBit α i=t*firstBit α j → + (∀ l q,tabRef p l q (assembly g i j s t) r ≤ τ) → c.echoes i j s t +abbrev season (p : Shape) (M : ℕ) := (n : ℕ)→Augur p (M*n) +def disappearing (U : Ultrafilter ℕ) {M} (g : season p M) (s : F) := + ∀ l q, slight (U:Filter ℕ) (fun i=>tabRef p l q (g i) s) + +private def modest (U : Ultrafilter ℕ) {M} + (g : Bool→season p M) (α : Party) (i : Bool) := + firstBit α i=0 ∧ ∃ s,g i |> fun x=> disappearing U x s + +private def accords (U : Ultrafilter ℕ) {M} + (g : Bool→season p M) (α : Party) := + α true=α false ∧ ∃ s, disappearing U + (fun n : ℕ=>fun l q x => g true n l q x+g false n l q x) s + +private def census (U : Ultrafilter ℕ) {M} + (g : Bool→season p M) (α : Party) := + open scoped Classical in + if modest U g α true then if modest U g α false then dusk else dawn false + else if modest U g α false then dawn true + else if accords U g α then twinned else noon + +variable {U : Ultrafilter ℕ} {M : ℕ} + {g : Bool → season p M} {α : Party} + +private theorem census_active (i : Bool) : + active (census U g α) i ↔ ¬modest U g α i := by + classical + unfold census + cases i <;> split_ifs <;> simp_all [active] + +private theorem census_lit : + (census U g α).lit α := by + classical + constructor + · intro i hi; exact (show modest U g α i from not_not.mp (fun h=> hi ((census_active i).mpr h))).1 + unfold census + intro h; split_ifs at h; try contradiction + exact ‹accords U g α›.1 + +theorem disappearing_add {x y : season p M} {r s : F} + (h : disappearing U x r) (hh : disappearing U y s) : + disappearing U (fun i => fun l q j=> x i l q j+y i l q j) (r+s) := by + intro l q ε he + filter_upwards [h l q _ (half_pos he),hh l q _ (half_pos he)] with i hi hj + let v := lawOmega p (M*i) l q + have hv (j : AtomKey (p:=p) l (M*i)) : 0≤ v j := by + exact (unifOn_sub _).nz _ + let P j := x i l q j≠r*q + let Q j := y i l q j≠s*q + have hh (j) (h : x i l q j+y i l q j≠ (r+s)*q) : P j∨ Q j := by + unfold P Q + rw [add_mul] at h; contrapose h + push Not at * + simp [h] + have hf : pr v P ≤ ε/2 := hi; have hg : pr v Q ≤ ε/2 := hj + exact ((pr_mono hv hh).trans (pr_or_le hv)).trans (by linarith only [hf,hg]) + +private theorem census_match (h : accords U g α) : + modest U g α true ↔ modest U g α false := by + classical + let x : season p M := fun n l q i=>g true n l q i+g false n l q i + obtain ⟨hd,s,hs⟩:=h + have hs : disappearing U x s := hs + refine ⟨fun ⟨h,r,hg⟩=>⟨by simpa only [firstBit,←hd] using h,r+s,?_⟩, + fun ⟨h,r,hg⟩=>⟨by simpa only [firstBit,hd] using h,r+s,?_⟩⟩ + · have he : (fun n l q j=>g true n l q j+x n l q j)=g false := by + funext n l q j; change _+(_+_)=_; rw [←add_assoc,char_two,zero_add] + rw [←he]; exact disappearing_add hg hs + have he : (fun n l q j=>g false n l q j+x n l q j)=g true := by + funext n l q j; change _+(_+_)=_; rw [add_left_comm,char_two,add_zero] + rw [←he]; exact disappearing_add hg hs + +set_option maxHeartbeats 1000000 in +private theorem census_echoes (i j : Bool) (s t r : F) (h : s*firstBit α i=t*firstBit α j) + (hg : disappearing U (fun n=>assembly (fun i=>g i n) i j s t) r) : + (census U g α).echoes i j s t := by + classical + unfold echoes; simp_rw [census_active] + rcases bit_cases s with hs|hs <;> rcases bit_cases t with ht|ht <;> subst s t + · simp + · have hi : firstBit α j=0 := by simpa only [zero_mul,one_mul] using h.symm + have hh : (fun n : ℕ=> assembly (fun i=>g i n) i j 0 1)=g j := by + funext n l q x; change (0:F)*g i n l q x+ (1:F)*g j n l q x=g j n l q x; rw [one_mul,zero_mul,zero_add] + have he : modest U g α j := ⟨hi,r,hh ▸ hg⟩ + simp [he] + · have hi : firstBit α i=0 := by simpa only [zero_mul,one_mul] using h + have hh : (fun n : ℕ=> assembly (fun i=>g i n) i j 1 0)=g i := by + funext n l q x; change (1:F)*g i n l q x+ (0:F)*g j n l q x=g i n l q x; rw [one_mul,zero_mul,add_zero] + have he : modest U g α i := ⟨hi,r,hh ▸ hg⟩ + simp [he] + simp only [true_and] + by_cases hv : i=j + · subst j; simp + have ht : accords U g α := by + have hh : 1+α i=1+α j := by simpa only [one_mul,firstBit] using h + have h : α i=α j := add_left_cancel hh + let x1 (i j: Bool) := fun n=>assembly (fun i=>g i n) i j 1 1 + let x2 : season p M := fun n l q v=> g true n l q v+g false n l q v + have hv' : x1 i j=x2 := by + funext n l q v + unfold x1 assembly x2 + simp only [one_mul] + cases i <;> cases j <;> first | rfl | contradiction | exact add_comm _ _ + refine ⟨?_,r,show disappearing U x2 r from hv' ▸ (show disappearing U (x1 i j) r from hg)⟩ + cases i <;> cases j <;> first | contradiction | exact h | exact h.symm + have hm := census_match ht + by_cases he : modest U g α true + · have hh (i : Bool) : modest U g α i := by cases i; exact hm.mp he; exact he + simp [hh] + have hh (i: Bool) : ¬modest U g α i := by cases i; exact mt hm.mpr he; exact he + simp only [census, ite_eq_right (hh _), ite_eq_left ht]; simp [hh] + +private theorem eventual_echoes (i j : Bool) (s t r : F) : + ∃ τ:ℝ,0<τ ∧ ∀ᶠ n in U, + s*firstBit α i=t*firstBit α j → + ((∀ l q,tabRef p l q (assembly (fun i=> g i n) i j s t) r ≤ τ) → + (census U g α).echoes i j s t) := by + classical + by_cases hf : disappearing U (fun n=>assembly (fun i=>g i n) i j s t) r + · exact ⟨1,zero_lt_one,.of_forall (fun _ h _=> census_echoes i j s t r h hf)⟩ + unfold disappearing slight at hf + push Not at hf + obtain ⟨l,q,τ,hτ,h⟩:=hf + exact ⟨τ,hτ,h.mono fun i hi _ H=>(hi.not_ge (H l q)).elim⟩ + +theorem examine (U : Ultrafilter ℕ) (p : Shape) (M : ℕ) (g : Bool→ season p M) (α : Party) : + ∃ (c : PredictionClass) (τ : ℝ),0 < τ ∧ + (∀ᶠ n in U,c.recital p (fun i=>g i n) α τ) ∧ c.lit α ∧ + (c=dusk → ∀ i, ∃ r,disappearing U (g i) r) := by + classical + let A:=Bool × Bool × (F×F×F) + let c:= census U g α + choose τ hτ hg using fun x : A=> @eventual_echoes p U M g α + x.1 x.2.1 x.2.2.1 x.2.2.2.1 x.2.2.2.2 + have hh : ∃ δ:ℝ,0<δ∧∀ x,δ≤τ x := by + let S := univ.image τ + have hn : S.Nonempty := Finset.image_nonempty.mpr Finset.univ_nonempty + refine ⟨S.min' hn, ?_, fun x=> Finset.min'_le _ _ (mem_image_of_mem _ (mem_univ _))⟩ + obtain ⟨x,hx,hx'⟩:= mem_image.mp (Finset.min'_mem _ hn) + exact hx' ▸ hτ x + obtain ⟨δ,hδ,hT⟩:=hh + refine ⟨c,δ,hδ,?_,census_lit,fun h i=>?_⟩ + · filter_upwards [eventually_all.mpr hg] with n h + refine ⟨census_lit,fun i j s t r he hh=>?_⟩ + exact h (i,j,s,t,r) he (fun l q=>(hh l q).trans (hT _)) + have he : ¬ c.active i := by rw [h]; exact not_false + exact (show modest U g α i from not_not.mp (fun h=>he ((census_active i).mpr h))).2 +end PredictionClass +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionDichotomy.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionDichotomy.lean index 981d52acb65bb8989b508aac9e2b2cfc919e7b98..79f81030ae3d37a784f2c54dd492373b260d8fbc 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionDichotomy.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionDichotomy.lean @@ -1,226 +1,226 @@ -import OAI.Combinatorics.HadwigerCounterexample.PreliminaryRestrictions - -namespace OAI - -/-! # Prediction Dichotomy -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix -open scoped BigOperators Topology -open PredictionClass - -namespace PreparationParameters - -variable {l : Filter ℕ} {p : Shape} {M n N : ℕ} {q : PreparationParameters} {m : cycleM p} - {s : rhythms p M} {w : tale p M} {b : Sketch p M} {U : Ultrafilter ℕ} {P : Campaign p M} - -def outlook (q : PreparationParameters) (l : Filter ℕ) (p : Shape) (M : ℕ) - (m : cycleM p) (w : tale p M) (s : rhythms p M) := - ∃ ε:ℕ→ℝ, slight l ε ∧ ∀ᶠ n in l,q.predicts p (M*n) (m n) (s n) (w n) (ε n) - -theorem eclipse (hl : (U:Filter ℕ)≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in U,q.nascent p (M*n) (w n) (m n)) - (hx : ∀ᶠ n in U,q.entered p (M*n) (m n) (w n) (s n)) : - q.silenceOutcome (U:Filter ℕ) p M m w s ∨ q.outlook (U:Filter ℕ) p M m w s := by - classical - let P (n : ℕ) ε := q.predicts p (M*n) (m n) (s n) (w n) ε - let c (i:ℕ) := ((i:ℝ)+1)⁻¹ - by_cases he : ∀ k : ℕ,∀ᶠ n in U,P n (c k) - · obtain ⟨k,h1,h2⟩:= diagonal_gains (U:Filter ℕ) hl (fun i j=>P i (c j)) he - exact Or.inr ⟨fun i=>c (k i),slight_inv_stage h1,h2⟩ - push Not at he - obtain ⟨k,hk⟩:=he - exact Or.inl ⟨c k, by unfold c; positivity, - hk.and (((retainInitial hl hq hx).unconditional hl hq hw).mono fun i hi=>hi.2)⟩ - -structure Sage (p : Shape) (n N : ℕ) where - g : Bool→Augur p N - m : BMark p n N - L : UnitType p n N → Bool→ Finset (Label p.b) - -instance : Inhabited (Sage p n N) := ⟨⟨fun _ _ _ _=>0,fun _=>0,fun _ _=>∅⟩⟩ - -abbrev Banners := Party × F × Bool - -def tender {p : Shape} {n N} (i : Sage p n N) (q : PreparationParameters) (m : Mixer p n) - (s : LeafMixture p n N) (z : Banners) (ε : ℝ) (x : UnitType p n N) := - q.seems p m s x i.g (i.m x) (i.L x) z.1 ε ∧ glint p (i.m x)=z.2.1 ∧ - ((z.2.2=true) ↔ delta i.m x=0) - -def crowdSeed : ℝ := 2*pollen -theorem crowdSeed_pos : 0 (by change ind (v x≠0∧P x)=ind (P x); rw [show (v x≠0∧P x)=(P x) from propext (and_iff_right h)]) - choose f hf using show - ∀ x : UnitType p n N,∃ (z : Bool→Profile p n) (L : Bool→Finset (Label p.b)) - (α : Party), (∀ j,totalRank (z j)≤ q.e) ∧ (Q x → q.seems p m s x g z L α ε) from by - intro x; by_cases h : Q x - · obtain ⟨z,L,a,hv⟩:=h.2 - refine ⟨z,L,a,fun i=>?_,fun _=>hv⟩ - exact (effective_rank (hv.1 i).2).trans (LeafMixture.root_bound hs.strength _) - refine ⟨0,fun _=>∅,0,fun i=>?_,fun he=>(h he).elim⟩ - unfold totalRank - have hh (j:Comp p.g) : - ((0:Profile p n) j).rank=0 := Matrix.rank_zero - exact le_trans (Finset.sum_eq_zero (fun i _=>hh i)).le (Nat.zero_le _) - choose L a hA hh using hf - let i:= (⟨g,f,L⟩: Sage p n N) - have he x (h : Q x) : ∃ z : Banners,tender i q m s z ε x := by - refine ⟨(a x,glint p (i.m x),decide (delta i.m x=0)),hh x h,rfl,?_⟩ - simp - have ht' : (0.000001:ℝ) ≤ ∑ j : Banners,pr v (tender i q m s j ε) := - hg.trans ((ht.symm ▸ pr_mono hv.nz he).trans (pr_exists_le hv.nz _)) - have hz : ∃ j : Banners,crowdSeed ≤ pr v (tender i q m s j ε) := by - by_contra! h - have hx : 0.000001≤∑ _j : Banners,crowdSeed := - ht'.trans (Finset.sum_le_sum fun j _=>(h j).le) - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] at hx - simp [Banners,Party,F,Vec,ZMod.card] at hx - norm_num [crowdSeed,pollen] at hx - obtain ⟨j,hj⟩:=hz - exact ⟨j,i,hA,hj⟩ - -set_option maxHeartbeats 1800000 in -theorem pruneWhisper (hl : (U:Filter ℕ)≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in U,q.nascent p (M*n) (w n) (m n)) - (hx : ∀ᶠ n in U,q.entered p (M*n) (m n) (w n) (s n)) - (hc : b.c=dusk) - (hf : ledger b (U:Filter ℕ)) - (hg : ∀ i,∃ r, disappearing U (b.g i) r) - (h : ∀ᶠ n in U, crowdSeed ≤ pr ((s n).sap (w n)) (P n) ∧ - ∀ x,P n x → q.seems p (m n) (s n) x (fun i=>b.g i n) (b.m n x) (b.L n x) b.α (b.ε n)) : - ∃ Q:Campaign p M,∀ᶠ n in U, pollen ≤ pr ((s n).sap (w n)) (Q n) ∧ - ∀ x,Q n x→P n x∧exactInk p (m n) (b.m n) x := by - classical - have ha : ∀ i,b.α i=1 := dusk_lit _ (hc ▸ hf.light) - choose g hG using hg - let Y (n) (x : UnitType p n (M*n)) i := whisper p (b.g i n) (g i) (onSide x i) - let Q : Campaign p M := fun n x=>P n x∧∀ i,Y n x i - have he : - ∀ᶠ n in U,∀ (i : Bool) (l : Tag p.g) (b':F),tabRef p l b' (b.g i n) (g i) ≤1/100 := - eventually_all.mpr fun i=> eventually_all.mpr fun l=> eventually_all.mpr fun b'=> hG i l b' - _ (by norm_num) - have hz : - ∀ᶠ n : ℕ in atTop, (2:ℝ)*(2*q.L*bp (-(1/16:ℝ)*n))≤pollen := by - have hh : Tendsto (fun n:ℕ=>(2:ℝ)*(2*q.L*bp (-(1/16:ℝ)*n))) atTop (𝓝 0) := by - have h := ((bp_nat_vanish (by norm_num : 0<(1/16:ℝ))).const_mul (2*q.L)).const_mul 2 - simpa using h - exact (hh.eventually (gt_mem_nhds pollen_pos)).mono (fun _ hi=>hi.le) - refine ⟨Q,?_⟩ - filter_upwards [hw,hx,h,hq.wrap.filter_mono hl,he,hf.small (1/16) (by norm_num), - (hushCalendar p M hq.hM hq.hG hq.hR hq.hJ).filter_mono hl,hz.filter_mono hl, - (eventually_ge_atTop (2*p.r)).filter_mono hl] with n hn ht hs hq' hG hε hh hz hN - let s':=s n; let w':=w n - let v:=s'.sap w' - have hv : IsLaw v:= LeafMixture.sapLaw (lt_of_lt_of_le (by norm_num) ht.weight) hn.law - have hS : bySide p v (m n) (2*q.L) := by - refine LeafMixture.upperSide hn.border (K':=2) (fun x=>?_) (by norm_num) le_rfl - exact (on_mon hn.law.nz (by norm_num) ht.weight x).trans_eq (by norm_num) - constructor - · let V (x : UnitType p n (M*n)) := ∀ i,Y n x i - have hT := pr_shield hv.nz (P n) V - let δ := 2*q.L*bp (-(1/16:ℝ)*n) - have hi (i:Bool) : pr v (fun x=>¬Y n x i) ≤ δ := by - let T (o:Orient p n (M*n)) := ¬ whisper p (b.g i n) (g i) o - let f x:= onSide (x:UnitType p n (M*n)) i - change pr v (fun x=>T (f x)) ≤ _ - rw [←mapW_pr] - apply (pr_cap (hS i) T).trans - exact mul_le_mul_of_nonneg_left (hh (m n) hq'.1 _ _ (hG i)) - (mul_nonneg (by norm_num) hq.early.hL) - have hf : pr v (fun x=>¬V x)≤pollen := by - refine le_trans ?_ hz - calc pr v (fun x=>¬V x) - _ ≤ ∑ i:Bool,pr v (fun x=>¬Y n x i) := - (pr_mono hv.nz (p:=fun x=>¬V x) (fun x h => show ∃ i:Bool,¬Y n x i from not_forall.mp h)).trans - (pr_exists_le hv.nz _) - _ ≤ 2*δ := by rw [Fintype.sum_bool,two_mul]; exact add_le_add (hi _) (hi _) - have hh : 2*pollen ≤ pr v (P n) := hs.1 - exact le_trans (by linarith only [hh,hf]) hT - · intro x hh - have hs := hs.2 x hh.1 - refine ⟨hh.1,fun i=>?_⟩ - have hi : - postulates p (onSide x i) (b.g i n) (yoke p (m n) x i (b.m n x i) 1) (b.L n x i) (1/16) := by - rw [←ha i] - exact fun z hz j k=>(hs.2 i z hz j k).trans hε - have he : (↑(b.L n x i).card:ℝ) (i n).g j - obtain ⟨c,τ,hτ,hG,hL,hB⟩:= examine U p M g z.1 - let b:= (⟨c,z.1,z.2.1,fun n=>(i n).m,fun n=>(i n).L,g,ε⟩: Sketch p M) - let P : Campaign p M := fun n => tender (i n) q (m n) (s n) z (ε n) - have hT : ledger b (U:Filter ℕ):= ⟨hε,⟨τ,hτ,hG⟩,hL⟩ - have hk : - ∃ Q : Campaign p M,∀ᶠ n in U, pollen ≤ pr ((s n).sap (w n)) (Q n) ∧ - ∀ x,Q n x→ P n x∧ (b.c=dusk→exactInk p (m n) (b.m n) x) := by - by_cases hC : c=dusk - · obtain ⟨Q,hQ⟩:= pruneWhisper hl hq hw hx (show b.c=dusk from hC) hT (hB hC) - (P:=P) (hi.mono fun n hn=>⟨hn.2,fun x h=>h.1⟩) - exact ⟨Q,hQ.mono (fun n hn=>⟨hn.1,fun i h=>⟨(hn.2 i h).1,fun _=>(hn.2 i h).2⟩⟩)⟩ - exact ⟨P,hi.mono (fun n hn=>⟨le_trans (show pollen≤crowdSeed from - by unfold crowdSeed; linarith only [pollen_pos]) hn.2,fun x h=>⟨h,fun hh=>(hC hh).elim⟩⟩)⟩ - obtain ⟨Q,hQ⟩:=hk - have hB : ∀ᶠ n in U,pollen ≤ pr ((s n).sap (w n)) (Q n) := hQ.mono fun i hi=>hi.1 - have hc : q.citable (U:Filter ℕ) p M m w s b Q := by - refine ⟨(warm.const (trend_sizes (U:Filter ℕ) hl hq.hM).2 pollen_pos).mono hB,hT,?_⟩ - filter_upwards [hQ] with n hn - intro i hi x hx hp - obtain ⟨⟨hr,hv,_⟩,hs⟩:= hn.2 x hp - exact ⟨hr,hv,hs⟩ - refine ⟨b,Q,z.2.2,⟨hc,hB,hi.mono (fun i hi=>hi.1)⟩, hQ.mono fun i hi x hx=>?_⟩ - exact ((hi.2 x hx).1).2.2 - -set_option maxHeartbeats 1000000 in -theorem prepare (U : Ultrafilter ℕ) (hl : (U:Filter ℕ) ≤ atTop) (hq : q.planted p M) - {s : rhythms p M} (hw : ∀ᶠ n in U,q.nascent p (M*n) (w n) (m n)) - (hx : ∀ᶠ n in U,q.entered p (M*n) (m n) (w n) (s n)) : - satisfied q (U:Filter ℕ) p M m w := by - classical - rcases eclipse hl hq hw hx with hn|hn - · exact ⟨s,retainInitial hl hq hx,Or.inl hn⟩ - obtain ⟨b,P,i,hQ,hz⟩:= outlook_to_dose hl hq hw hx hn - cases i - · obtain ⟨R,hR,hT⟩:= phaseSplit hl hq hw hx hQ - (hz.mono fun n hn i hi x h hh ht=> Bool.false_ne_true ((hn x hh).mpr ht)) - rcases Ultrafilter.eventually_or.mp hT with hF|hF - · exact outByMix hl hq hw hx hR hF - exact outByCover hl hq hw hx hR hF - exact phaseAbsent hl hq hw hx hQ (hz.mono fun n hn i hi x h hh=>(hn x hh).mp rfl) -end PreparationParameters -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PreliminaryRestrictions + +namespace OAI + +/-! # Prediction Dichotomy -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix +open scoped BigOperators Topology +open PredictionClass + +namespace PreparationParameters + +variable {l : Filter ℕ} {p : Shape} {M n N : ℕ} {q : PreparationParameters} {m : cycleM p} + {s : rhythms p M} {w : tale p M} {b : Sketch p M} {U : Ultrafilter ℕ} {P : Campaign p M} + +def outlook (q : PreparationParameters) (l : Filter ℕ) (p : Shape) (M : ℕ) + (m : cycleM p) (w : tale p M) (s : rhythms p M) := + ∃ ε:ℕ→ℝ, slight l ε ∧ ∀ᶠ n in l,q.predicts p (M*n) (m n) (s n) (w n) (ε n) + +theorem eclipse (hl : (U:Filter ℕ)≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in U,q.nascent p (M*n) (w n) (m n)) + (hx : ∀ᶠ n in U,q.entered p (M*n) (m n) (w n) (s n)) : + q.silenceOutcome (U:Filter ℕ) p M m w s ∨ q.outlook (U:Filter ℕ) p M m w s := by + classical + let P (n : ℕ) ε := q.predicts p (M*n) (m n) (s n) (w n) ε + let c (i:ℕ) := ((i:ℝ)+1)⁻¹ + by_cases he : ∀ k : ℕ,∀ᶠ n in U,P n (c k) + · obtain ⟨k,h1,h2⟩:= diagonal_gains (U:Filter ℕ) hl (fun i j=>P i (c j)) he + exact Or.inr ⟨fun i=>c (k i),slight_inv_stage h1,h2⟩ + push Not at he + obtain ⟨k,hk⟩:=he + exact Or.inl ⟨c k, by unfold c; positivity, + hk.and (((retainInitial hl hq hx).unconditional hl hq hw).mono fun i hi=>hi.2)⟩ + +structure Sage (p : Shape) (n N : ℕ) where + g : Bool→Augur p N + m : BMark p n N + L : UnitType p n N → Bool→ Finset (Label p.b) + +instance : Inhabited (Sage p n N) := ⟨⟨fun _ _ _ _=>0,fun _=>0,fun _ _=>∅⟩⟩ + +abbrev Banners := Party × F × Bool + +def tender {p : Shape} {n N} (i : Sage p n N) (q : PreparationParameters) (m : Mixer p n) + (s : LeafMixture p n N) (z : Banners) (ε : ℝ) (x : UnitType p n N) := + q.seems p m s x i.g (i.m x) (i.L x) z.1 ε ∧ glint p (i.m x)=z.2.1 ∧ + ((z.2.2=true) ↔ delta i.m x=0) + +def crowdSeed : ℝ := 2*pollen +theorem crowdSeed_pos : 0 (by change ind (v x≠0∧P x)=ind (P x); rw [show (v x≠0∧P x)=(P x) from propext (and_iff_right h)]) + choose f hf using show + ∀ x : UnitType p n N,∃ (z : Bool→Profile p n) (L : Bool→Finset (Label p.b)) + (α : Party), (∀ j,totalRank (z j)≤ q.e) ∧ (Q x → q.seems p m s x g z L α ε) from by + intro x; by_cases h : Q x + · obtain ⟨z,L,a,hv⟩:=h.2 + refine ⟨z,L,a,fun i=>?_,fun _=>hv⟩ + exact (effective_rank (hv.1 i).2).trans (LeafMixture.root_bound hs.strength _) + refine ⟨0,fun _=>∅,0,fun i=>?_,fun he=>(h he).elim⟩ + unfold totalRank + have hh (j:Comp p.g) : + ((0:Profile p n) j).rank=0 := Matrix.rank_zero + exact le_trans (Finset.sum_eq_zero (fun i _=>hh i)).le (Nat.zero_le _) + choose L a hA hh using hf + let i:= (⟨g,f,L⟩: Sage p n N) + have he x (h : Q x) : ∃ z : Banners,tender i q m s z ε x := by + refine ⟨(a x,glint p (i.m x),decide (delta i.m x=0)),hh x h,rfl,?_⟩ + simp + have ht' : (0.000001:ℝ) ≤ ∑ j : Banners,pr v (tender i q m s j ε) := + hg.trans ((ht.symm ▸ pr_mono hv.nz he).trans (pr_exists_le hv.nz _)) + have hz : ∃ j : Banners,crowdSeed ≤ pr v (tender i q m s j ε) := by + by_contra! h + have hx : 0.000001≤∑ _j : Banners,crowdSeed := + ht'.trans (Finset.sum_le_sum fun j _=>(h j).le) + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] at hx + simp [Banners,Party,F,Vec,ZMod.card] at hx + norm_num [crowdSeed,pollen] at hx + obtain ⟨j,hj⟩:=hz + exact ⟨j,i,hA,hj⟩ + +set_option maxHeartbeats 1800000 in +theorem pruneWhisper (hl : (U:Filter ℕ)≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in U,q.nascent p (M*n) (w n) (m n)) + (hx : ∀ᶠ n in U,q.entered p (M*n) (m n) (w n) (s n)) + (hc : b.c=dusk) + (hf : ledger b (U:Filter ℕ)) + (hg : ∀ i,∃ r, disappearing U (b.g i) r) + (h : ∀ᶠ n in U, crowdSeed ≤ pr ((s n).sap (w n)) (P n) ∧ + ∀ x,P n x → q.seems p (m n) (s n) x (fun i=>b.g i n) (b.m n x) (b.L n x) b.α (b.ε n)) : + ∃ Q:Campaign p M,∀ᶠ n in U, pollen ≤ pr ((s n).sap (w n)) (Q n) ∧ + ∀ x,Q n x→P n x∧exactInk p (m n) (b.m n) x := by + classical + have ha : ∀ i,b.α i=1 := dusk_lit _ (hc ▸ hf.light) + choose g hG using hg + let Y (n) (x : UnitType p n (M*n)) i := whisper p (b.g i n) (g i) (onSide x i) + let Q : Campaign p M := fun n x=>P n x∧∀ i,Y n x i + have he : + ∀ᶠ n in U,∀ (i : Bool) (l : Tag p.g) (b':F),tabRef p l b' (b.g i n) (g i) ≤1/100 := + eventually_all.mpr fun i=> eventually_all.mpr fun l=> eventually_all.mpr fun b'=> hG i l b' + _ (by norm_num) + have hz : + ∀ᶠ n : ℕ in atTop, (2:ℝ)*(2*q.L*bp (-(1/16:ℝ)*n))≤pollen := by + have hh : Tendsto (fun n:ℕ=>(2:ℝ)*(2*q.L*bp (-(1/16:ℝ)*n))) atTop (𝓝 0) := by + have h := ((bp_nat_vanish (by norm_num : 0<(1/16:ℝ))).const_mul (2*q.L)).const_mul 2 + simpa using h + exact (hh.eventually (gt_mem_nhds pollen_pos)).mono (fun _ hi=>hi.le) + refine ⟨Q,?_⟩ + filter_upwards [hw,hx,h,hq.wrap.filter_mono hl,he,hf.small (1/16) (by norm_num), + (hushCalendar p M hq.hM hq.hG hq.hR hq.hJ).filter_mono hl,hz.filter_mono hl, + (eventually_ge_atTop (2*p.r)).filter_mono hl] with n hn ht hs hq' hG hε hh hz hN + let s':=s n; let w':=w n + let v:=s'.sap w' + have hv : IsLaw v:= LeafMixture.sapLaw (lt_of_lt_of_le (by norm_num) ht.weight) hn.law + have hS : bySide p v (m n) (2*q.L) := by + refine LeafMixture.upperSide hn.border (K':=2) (fun x=>?_) (by norm_num) le_rfl + exact (on_mon hn.law.nz (by norm_num) ht.weight x).trans_eq (by norm_num) + constructor + · let V (x : UnitType p n (M*n)) := ∀ i,Y n x i + have hT := pr_shield hv.nz (P n) V + let δ := 2*q.L*bp (-(1/16:ℝ)*n) + have hi (i:Bool) : pr v (fun x=>¬Y n x i) ≤ δ := by + let T (o:Orient p n (M*n)) := ¬ whisper p (b.g i n) (g i) o + let f x:= onSide (x:UnitType p n (M*n)) i + change pr v (fun x=>T (f x)) ≤ _ + rw [←mapW_pr] + apply (pr_cap (hS i) T).trans + exact mul_le_mul_of_nonneg_left (hh (m n) hq'.1 _ _ (hG i)) + (mul_nonneg (by norm_num) hq.early.hL) + have hf : pr v (fun x=>¬V x)≤pollen := by + refine le_trans ?_ hz + calc pr v (fun x=>¬V x) + _ ≤ ∑ i:Bool,pr v (fun x=>¬Y n x i) := + (pr_mono hv.nz (p:=fun x=>¬V x) (fun x h => show ∃ i:Bool,¬Y n x i from not_forall.mp h)).trans + (pr_exists_le hv.nz _) + _ ≤ 2*δ := by rw [Fintype.sum_bool,two_mul]; exact add_le_add (hi _) (hi _) + have hh : 2*pollen ≤ pr v (P n) := hs.1 + exact le_trans (by linarith only [hh,hf]) hT + · intro x hh + have hs := hs.2 x hh.1 + refine ⟨hh.1,fun i=>?_⟩ + have hi : + postulates p (onSide x i) (b.g i n) (yoke p (m n) x i (b.m n x i) 1) (b.L n x i) (1/16) := by + rw [←ha i] + exact fun z hz j k=>(hs.2 i z hz j k).trans hε + have he : (↑(b.L n x i).card:ℝ) (i n).g j + obtain ⟨c,τ,hτ,hG,hL,hB⟩:= examine U p M g z.1 + let b:= (⟨c,z.1,z.2.1,fun n=>(i n).m,fun n=>(i n).L,g,ε⟩: Sketch p M) + let P : Campaign p M := fun n => tender (i n) q (m n) (s n) z (ε n) + have hT : ledger b (U:Filter ℕ):= ⟨hε,⟨τ,hτ,hG⟩,hL⟩ + have hk : + ∃ Q : Campaign p M,∀ᶠ n in U, pollen ≤ pr ((s n).sap (w n)) (Q n) ∧ + ∀ x,Q n x→ P n x∧ (b.c=dusk→exactInk p (m n) (b.m n) x) := by + by_cases hC : c=dusk + · obtain ⟨Q,hQ⟩:= pruneWhisper hl hq hw hx (show b.c=dusk from hC) hT (hB hC) + (P:=P) (hi.mono fun n hn=>⟨hn.2,fun x h=>h.1⟩) + exact ⟨Q,hQ.mono (fun n hn=>⟨hn.1,fun i h=>⟨(hn.2 i h).1,fun _=>(hn.2 i h).2⟩⟩)⟩ + exact ⟨P,hi.mono (fun n hn=>⟨le_trans (show pollen≤crowdSeed from + by unfold crowdSeed; linarith only [pollen_pos]) hn.2,fun x h=>⟨h,fun hh=>(hC hh).elim⟩⟩)⟩ + obtain ⟨Q,hQ⟩:=hk + have hB : ∀ᶠ n in U,pollen ≤ pr ((s n).sap (w n)) (Q n) := hQ.mono fun i hi=>hi.1 + have hc : q.citable (U:Filter ℕ) p M m w s b Q := by + refine ⟨(warm.const (trend_sizes (U:Filter ℕ) hl hq.hM).2 pollen_pos).mono hB,hT,?_⟩ + filter_upwards [hQ] with n hn + intro i hi x hx hp + obtain ⟨⟨hr,hv,_⟩,hs⟩:= hn.2 x hp + exact ⟨hr,hv,hs⟩ + refine ⟨b,Q,z.2.2,⟨hc,hB,hi.mono (fun i hi=>hi.1)⟩, hQ.mono fun i hi x hx=>?_⟩ + exact ((hi.2 x hx).1).2.2 + +set_option maxHeartbeats 1000000 in +theorem prepare (U : Ultrafilter ℕ) (hl : (U:Filter ℕ) ≤ atTop) (hq : q.planted p M) + {s : rhythms p M} (hw : ∀ᶠ n in U,q.nascent p (M*n) (w n) (m n)) + (hx : ∀ᶠ n in U,q.entered p (M*n) (m n) (w n) (s n)) : + satisfied q (U:Filter ℕ) p M m w := by + classical + rcases eclipse hl hq hw hx with hn|hn + · exact ⟨s,retainInitial hl hq hx,Or.inl hn⟩ + obtain ⟨b,P,i,hQ,hz⟩:= outlook_to_dose hl hq hw hx hn + cases i + · obtain ⟨R,hR,hT⟩:= phaseSplit hl hq hw hx hQ + (hz.mono fun n hn i hi x h hh ht=> Bool.false_ne_true ((hn x hh).mpr ht)) + rcases Ultrafilter.eventually_or.mp hT with hF|hF + · exact outByMix hl hq hw hx hR hF + exact outByCover hl hq hw hx hR hF + exact phaseAbsent hl hq hw hx hQ (hz.mono fun n hn i hi x h hh=>(hn x hh).mp rfl) +end PreparationParameters +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionExactification.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionExactification.lean index 1c565cd8e1629fb41c3fba15505a18e14cf4b148..d6b685be0f6701ffa91cc8ce1bfeb0ec2f926054 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionExactification.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionExactification.lean @@ -1,100 +1,100 @@ -import OAI.Combinatorics.HadwigerCounterexample.CommonPredictions - -namespace OAI - -/-! # Prediction Exactification -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix LinearMap Function Filter Real -open scoped BigOperators -variable {p : Shape} {n N : ℕ} - -def tabErr (p : Shape) (l : Tag p.g) (s : Label p.b) (o : Orient p n N) - (x : F) (g : Augur p N) (f : F) := - let v := Template.solo p l s Flavor.full - let u:= scopedBit p n l Flavor.full x - pr u (fun i=> g l x (v.desc i o)≠ f*x) -def tabRef (p : Shape) (l : Tag p.g) (x : F) (g : Augur p N) (f : F) := - pr (lawOmega p N l x) (fun i=> g l x i≠f*x) - -theorem tabCalendar (p : Shape) (M : ℕ) (hM : 1≤M) (hg : 3≤ p.g) (hr : 1≤p.r) (hj : 1≤p.j) - (l : Tag p.g) (s : Label p.b) : - ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ (m : Mixer p n), 2*num (Full p n) 1/32dialed p l Flavor.full i=x)) - let T (i : AtomKey (p:=p) l N) := ind (g l x i≠ f*x) - have ht (i) : |T i|≤1 := by unfold T; rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ - have hh := hn m w x hw hy (scopedZ_bit p n _ _ _ hw) hN T ht - refine (pr_mono (raw_law m hN).nz (fun i hi => ?_)).trans hh - change 1/100≤ |tabErr p l s i x g f-tabRef p l x g f| - exact le_trans (by linarith only [he,hi]) (le_abs_self _) - -def whisper (p : Shape) (g : Augur p N) (x : F) (i : Orient p n N) := - ∀ l s b,tabErr p l s i b g x ≤1/32 - -theorem hushCalendar (p : Shape) (M : ℕ) (hM : 1≤M) (hg : 3≤p.g) - (hr : 1≤p.r) (hj : 1≤p.j) : - ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ (m : Mixer p n),2*num (Full p n)¬ whisper p g x i)≤bp (-(1/16:ℝ)*n) := by - classical - let A:= Tag p.g × Label p.b × F - filter_upwards [eventually_all.mpr (fun i:A => tabCalendar p M hM hg hr hj i.1 i.2.1), - pay_nat (a:=1/8) (b:=1/16) (num A) (by norm_num)] - with n hn hd N m hN g f hw - let T (i:A) (o:Orient p n N) := 1/32ht i)).trans_eq (by simp [num])).trans hd) - -set_option maxHeartbeats 800000 in -theorem hush_vat (w : Pdual p n) (E : Finset (Label p.b)) (i : Orient p n N) (g : Augur p N) (f : F) - (hE : (E.card:ℝ)< bp ((p.b:ℝ)-2*p.j)) (h : postulates p i g w E (1/16)) - (hz : whisper p g f i) (hg : Odd p.g) (hr : 1≤p.r) (hn : 2*p.r≤n) : - f=0∧silent w := by - classical - refine exact_vat w E f hE hg hn hr (fun l s hs=>?_) - let v := Template.solo p l s Flavor.full; let μ:= spins p n - let q (x: Knobs p.g n) := dialed p l Flavor.full x - let Q (b:F) (x) := q x=b - let S (b:F) x := g l b (v.desc x i) ≠ f*b - let P x:= S (q x) x - have hμ:= spins_law p n - have hp : - pr μ P ≤ 2*(1/32) := by - have ht b : pr μ (fun x=>Q b x∧S b x) ≤ 1/32 := by - rw [pr_of_on hμ.nz] - have hh : pr (onW μ (Q b)) (S b) ≤1/32 := hz _ _ _ - exact (mul_le_mul ((pr_le_tot hμ.nz).trans hμ.total.le) hh - (pr_nonneg (normW_subLaw (subW_nonneg hμ.nz _)).nz) zero_le_one).trans_eq (one_mul _) - calc _ - _ ≤ ∑ b:F,pr μ (fun i=>Q b i ∧ S b i) := - (pr_mono hμ.nz (fun i h=>show ∃ b,Q b i∧S b i from ⟨q i,rfl,h⟩)).trans - (pr_exists_le hμ.nz _) - _ ≤ _ := (Finset.sum_le_sum fun i _=>ht i).trans_eq (by simp [F,ZMod.card]) - let T x:= mismatch p g w l s Flavor.full i x - have ht : pr μ T≤ 1/16 := h _ hs _ _ - have he x (h : w (useAtom p l s Flavor.full x)≠ f*q x) : T x∨P x := by - by_contra! hh - exact h ((not_ne_iff.mp hh.1).trans (not_ne_iff.mp hh.2)) - exact lt_of_le_of_lt ((pr_mono hμ.nz he).trans (pr_or_le hμ.nz)) (by linarith only [ht,hp]) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CommonPredictions + +namespace OAI + +/-! # Prediction Exactification -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix LinearMap Function Filter Real +open scoped BigOperators +variable {p : Shape} {n N : ℕ} + +def tabErr (p : Shape) (l : Tag p.g) (s : Label p.b) (o : Orient p n N) + (x : F) (g : Augur p N) (f : F) := + let v := Template.solo p l s Flavor.full + let u:= scopedBit p n l Flavor.full x + pr u (fun i=> g l x (v.desc i o)≠ f*x) +def tabRef (p : Shape) (l : Tag p.g) (x : F) (g : Augur p N) (f : F) := + pr (lawOmega p N l x) (fun i=> g l x i≠f*x) + +theorem tabCalendar (p : Shape) (M : ℕ) (hM : 1≤M) (hg : 3≤ p.g) (hr : 1≤p.r) (hj : 1≤p.j) + (l : Tag p.g) (s : Label p.b) : + ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ (m : Mixer p n), 2*num (Full p n) 1/32dialed p l Flavor.full i=x)) + let T (i : AtomKey (p:=p) l N) := ind (g l x i≠ f*x) + have ht (i) : |T i|≤1 := by unfold T; rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ + have hh := hn m w x hw hy (scopedZ_bit p n _ _ _ hw) hN T ht + refine (pr_mono (raw_law m hN).nz (fun i hi => ?_)).trans hh + change 1/100≤ |tabErr p l s i x g f-tabRef p l x g f| + exact le_trans (by linarith only [he,hi]) (le_abs_self _) + +def whisper (p : Shape) (g : Augur p N) (x : F) (i : Orient p n N) := + ∀ l s b,tabErr p l s i b g x ≤1/32 + +theorem hushCalendar (p : Shape) (M : ℕ) (hM : 1≤M) (hg : 3≤p.g) + (hr : 1≤p.r) (hj : 1≤p.j) : + ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ (m : Mixer p n),2*num (Full p n)¬ whisper p g x i)≤bp (-(1/16:ℝ)*n) := by + classical + let A:= Tag p.g × Label p.b × F + filter_upwards [eventually_all.mpr (fun i:A => tabCalendar p M hM hg hr hj i.1 i.2.1), + pay_nat (a:=1/8) (b:=1/16) (num A) (by norm_num)] + with n hn hd N m hN g f hw + let T (i:A) (o:Orient p n N) := 1/32ht i)).trans_eq (by simp [num])).trans hd) + +set_option maxHeartbeats 800000 in +theorem hush_vat (w : Pdual p n) (E : Finset (Label p.b)) (i : Orient p n N) (g : Augur p N) (f : F) + (hE : (E.card:ℝ)< bp ((p.b:ℝ)-2*p.j)) (h : postulates p i g w E (1/16)) + (hz : whisper p g f i) (hg : Odd p.g) (hr : 1≤p.r) (hn : 2*p.r≤n) : + f=0∧silent w := by + classical + refine exact_vat w E f hE hg hn hr (fun l s hs=>?_) + let v := Template.solo p l s Flavor.full; let μ:= spins p n + let q (x: Knobs p.g n) := dialed p l Flavor.full x + let Q (b:F) (x) := q x=b + let S (b:F) x := g l b (v.desc x i) ≠ f*b + let P x:= S (q x) x + have hμ:= spins_law p n + have hp : + pr μ P ≤ 2*(1/32) := by + have ht b : pr μ (fun x=>Q b x∧S b x) ≤ 1/32 := by + rw [pr_of_on hμ.nz] + have hh : pr (onW μ (Q b)) (S b) ≤1/32 := hz _ _ _ + exact (mul_le_mul ((pr_le_tot hμ.nz).trans hμ.total.le) hh + (pr_nonneg (normW_subLaw (subW_nonneg hμ.nz _)).nz) zero_le_one).trans_eq (one_mul _) + calc _ + _ ≤ ∑ b:F,pr μ (fun i=>Q b i ∧ S b i) := + (pr_mono hμ.nz (fun i h=>show ∃ b,Q b i∧S b i from ⟨q i,rfl,h⟩)).trans + (pr_exists_le hμ.nz _) + _ ≤ _ := (Finset.sum_le_sum fun i _=>ht i).trans_eq (by simp [F,ZMod.card]) + let T x:= mismatch p g w l s Flavor.full i x + have ht : pr μ T≤ 1/16 := h _ hs _ _ + have he x (h : w (useAtom p l s Flavor.full x)≠ f*q x) : T x∨P x := by + by_contra! hh + exact h ((not_ne_iff.mp hh.1).trans (not_ne_iff.mp hh.2)) + exact lt_of_le_of_lt ((pr_mono hμ.nz he).trans (pr_or_le hμ.nz)) (by linarith only [ht,hp]) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionExtraction.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionExtraction.lean index b228e395b6d1fa8100e3dddd782c3c37a2e8a7a9..e68438146d71aea9f1b8f3282f8da248644ff8ee 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionExtraction.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PredictionExtraction.lean @@ -1,163 +1,163 @@ -import OAI.Combinatorics.HadwigerCounterexample.PredictedDualEvaluation - -namespace OAI - -/-! # Prediction Extraction -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Matrix Function Submodule LinearMap Module Finset -open scoped BigOperators -namespace StatusAnalysis -namespace DualAnalysis -variable {p:Shape} {r n:ℕ} {A B: Rates} - {u:Terrain p r} {s:Gazette p r A} {t:Gazette p r B} -open PredictionClass Club Guild - -structure countStory (p:Shape) (K:ℕ) (η δ ε β :ℝ) (u:Terrain p r) : Prop where - h : origami p r u δ - hb : 0≤β - he : 0≤ ε - ht : 0≤η - bill : playbook p K * η ≤ ε - high : 6*ε < 1/2*β - -structure Stirrings (p:Shape) (r:ℕ) (u:Terrain p r) (s:Gazette p r A) (t:Gazette p r B) - (p0:DualCoefficients A B) (S T:Stalls p) (ε:ℝ) : Prop where - - recollect (i:Grid): ∃ f:Pulsar p r,praise u s i.1 (S i.1) (leftChime p0 i) f (3*ε) ∧ - praise u t i.2 (T i.2) (rightChime p0 i) f (3*ε) -theorem counter_bill {δ ε β η:ℝ} (q: DualCoefficients A B) - {K:ℕ} (h:countStory p K η δ ε β u) - (hs:reports p r u s β δ) (ht:reports p r u t β δ) - (P Q:Stalls p) (S:Straps (Label p.b)) (i:Grid) - (he:q.law (chapter (stellar u s t η P Q) S)) - (ha:A i.1≤K^2) (hb:B i.2≤K^2): - counsel u s t i (outstraps P S true i.1) (outstraps Q S false i.2) - (leftChime q i) (rightChime q i) ε := by - intro x hx hp hq - apply (charge_counter h.h hs ht P Q S q he h.ht x i hx hp hq).trans - exact (mul_le_mul_of_nonneg_right (booklet_cap p K _ _ ha hb) h.ht).trans h.bill - -theorem tells {δ ε β η:ℝ} (q: DualCoefficients A B) {K:ℕ} - (h:countStory p K η δ ε β u) - (hs:reports p r u s β δ) (ht:reports p r u t β δ) - (P Q:Stalls p) (S:Straps (Label p.b)) - (he:q.law (chapter (stellar u s t η P Q) S)) - (ha:∀ i,A i≤K^2) (hb:∀ i,B i≤K^2) - (h1 : ∀ i, (outstraps P S true i).card f l q x ≠ d i a.bit a.gamma l q x) ≤ 2*ε - -set_option maxHeartbeats 800000 in -theorem build_anthology {δ ε β:ℝ} (P : Terrain p r) (s : Gazette p r A) - (hp:origami p r P δ) (hs:reports p r P s β δ) - (he:ε+ε<1/2*β) (hβ:0≤β) (hg:3≤p.g) - (L:ℕ) (hL:2*L v l q x≠ f l q x) ≤2*ε from by - intro i b k; let Q (v : Pulsar p r) := - ∃ (A' : Finset (Label p.b)) (a:RhymeSet (A i)), - A'.card≤ L ∧ a.bit=b ∧ a.gamma=k ∧ praise P s i A' a v ε - by_cases h:∃ v,Q v - · obtain ⟨x,S,a0,hx,hy,hk,h⟩:= h - refine ⟨x,fun v T a hc ha ht hz l q=>?_⟩ - obtain ⟨_,_,hg⟩:=unison hg hp hs i a a0 v x T S - ((card_union_le ..).trans_lt (by rw [two_mul] at hL; linarith only [hL,hc,hx])) - hz h (ha.trans hy.symm) he hβ - specialize hg l q - rw [ht,hk] at hg - simpa only [ne_eq,add_left_inj,two_mul] using hg - exact ⟨0,fun v t a h1 h2 h3 h4=>(h ⟨v,t,a,h1,h2,h3,h4⟩).elim⟩ - exact ⟨f,fun B i hi w a h=> hf i _ _ w (B i) a hi rfl rfl h⟩ - -def Pulsar.shift (g:Pulsar p r) (a:F): Pulsar p r := fun l q x => g l q x+a*q - -abbrev Snip := F×F×F -abbrev Memo := Nodes × (Nodes→Snip) -theorem memo_card : Fintype.card Memo=128 := by simp [Memo,Nodes,Snip,F]; - -def Memo.words (d:Dict p r) (i:Memo) : Nodes→ Pulsar p r := - fun j=> let h:=i.2 j; (d i.1 h.1 h.2.1).shift h.2.2 - -private theorem praise_tidy (d : Dict p r) (u:Terrain p r) (s:Gazette p r A) - (t:Gazette p r B) - {ε β δ:ℝ} (hs:reports p r u s β δ) (h:origami p r u δ) (L:ℕ) - (S T:Stalls p) (i j:Nodes) (a:RhymeSet (A i)) (b:RhymeSet (B j)) - (f:Pulsar p r) (ha:a.bit=1) (hq:anthology p r u t d L ε) - (hh:(T j).card ≤ L) - (hA:praise u s i (S i) a f ε) (hB:praise u t j (T j) b f ε): - praise u s i (S i) (yokeSet a.coal (1+a.headBit)) ((d j b.bit b.gamma).shift a.gamma) (3*ε) := by - intro x hx hg - let g:= d j b.bit b.gamma - have hz : shot u s i x a g ≤ 3*ε := - ((shot_switch u s i x a f g (h.1 _ _) (hs.law _ _ hg)).trans (add_le_add (hA x hx hg) - (hq T j hh f b hB _ _))).trans_eq (by ring) - let y := yokeSet a.coal (1+a.headBit) - have he (j k) : - y.soot x k≠ g.shift a.gamma x.l x.q j ↔ a.soot x k≠g x.l x.q j := by - have hh : a.soot x k=y.soot x k+a.gamma*x.q := by - unfold y RhymeSet.soot RhymeSet.read yokeSet; rw [ha] - simp only [zero_mul,add_zero,←add_assoc,char_two,zero_add] - rw [hh] - unfold Pulsar.shift - have hx : g x.l x.q j=(g x.l x.q j+a.gamma*x.q)+a.gamma*x.q := - Eq.symm (by rw [add_assoc,char_two,add_zero]) - apply not_congr - constructor - · intro h; rw [h,←hx] - intro h; exact add_right_cancel (h.trans hx) - change shot u s i x y (g.shift a.gamma) ≤_ - unfold shot; simp_rw [he]; exact hz - -def announced (u:Terrain p r) (s:Gazette p r A) (d:Dict p r) (L:ℕ) (ε:ℝ) := - ∃ i:Memo,∃ (v:styles A) (a:Party) (S:Stalls p),∀ j, - (S j).card≤L ∧ praise u s j (S j) (yokeSet (v j) (a j)) (Memo.words d i j) ε - -set_option maxHeartbeats 900000 in -theorem quotes (d e:Dict p r) - {ε β δ:ℝ} (hs:reports p r u s β δ) (ht:reports p r u t β δ) (h:origami p r u δ) - (z:DualCoefficients A B) (hh:z.left ≠0 ∨ z.right≠0) - (P Q:Stalls p) (hc:Stirrings p r u s t z P Q ε) - (L:ℕ) (hA:anthology p r u s d L (3*ε)) (hB:anthology p r u t e L (3*ε)) - (hp:∀ i,(P i).card≤L)(hq:∀ i,(Q i).card≤L): - announced u s e L (3*(3*ε)) ∨ announced u t d L (3*(3*ε)) := by - classical - choose f ha hb using hc.recollect - have he (s: Quota) (h:s≠0): ∃ i:Nodes,s i=1 := by - by_contra! hf; exact h (funext (fun i=> (bit_cases _).resolve_right (hf i))) - rcases hh with h1|h1 - · obtain ⟨i,hi⟩:= he z.left h1 - let S j:= leftChime z (j,i); let T j:= rightChime z (j,i) - let m : Memo:=(i,fun j=>((T j).bit,(T j).gamma,(S j).gamma)) - refine Or.inl ⟨m,fun j=>(S j).coal, fun j=>1+(S j).headBit,P, fun j=>⟨hp j,?_⟩⟩ - exact praise_tidy e u s t hs h L P Q j i (S j) (T j) (f (j,i)) hi hB (hq i) - (ha (j,i)) (hb (j,i)) - obtain ⟨i,hi⟩:= he z.right h1 - let S j:= rightChime z (i,j); let T j:=leftChime z (i,j) - let m : Memo:=(i,fun j=> ((T j).bit,(T j).gamma,(S j).gamma)) - refine Or.inr ⟨m,fun j=>(S j).coal,fun j=>1+(S j).headBit,Q,fun j=>⟨hq j,?_⟩⟩ - exact praise_tidy d u t s ht h L Q P j i (S j) (T j) (f (i,j)) hi hA (hp i) (hb (i,j)) (ha (i,j)) - -end DualAnalysis -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PredictedDualEvaluation + +namespace OAI + +/-! # Prediction Extraction -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Matrix Function Submodule LinearMap Module Finset +open scoped BigOperators +namespace StatusAnalysis +namespace DualAnalysis +variable {p:Shape} {r n:ℕ} {A B: Rates} + {u:Terrain p r} {s:Gazette p r A} {t:Gazette p r B} +open PredictionClass Club Guild + +structure countStory (p:Shape) (K:ℕ) (η δ ε β :ℝ) (u:Terrain p r) : Prop where + h : origami p r u δ + hb : 0≤β + he : 0≤ ε + ht : 0≤η + bill : playbook p K * η ≤ ε + high : 6*ε < 1/2*β + +structure Stirrings (p:Shape) (r:ℕ) (u:Terrain p r) (s:Gazette p r A) (t:Gazette p r B) + (p0:DualCoefficients A B) (S T:Stalls p) (ε:ℝ) : Prop where + + recollect (i:Grid): ∃ f:Pulsar p r,praise u s i.1 (S i.1) (leftChime p0 i) f (3*ε) ∧ + praise u t i.2 (T i.2) (rightChime p0 i) f (3*ε) +theorem counter_bill {δ ε β η:ℝ} (q: DualCoefficients A B) + {K:ℕ} (h:countStory p K η δ ε β u) + (hs:reports p r u s β δ) (ht:reports p r u t β δ) + (P Q:Stalls p) (S:Straps (Label p.b)) (i:Grid) + (he:q.law (chapter (stellar u s t η P Q) S)) + (ha:A i.1≤K^2) (hb:B i.2≤K^2): + counsel u s t i (outstraps P S true i.1) (outstraps Q S false i.2) + (leftChime q i) (rightChime q i) ε := by + intro x hx hp hq + apply (charge_counter h.h hs ht P Q S q he h.ht x i hx hp hq).trans + exact (mul_le_mul_of_nonneg_right (booklet_cap p K _ _ ha hb) h.ht).trans h.bill + +theorem tells {δ ε β η:ℝ} (q: DualCoefficients A B) {K:ℕ} + (h:countStory p K η δ ε β u) + (hs:reports p r u s β δ) (ht:reports p r u t β δ) + (P Q:Stalls p) (S:Straps (Label p.b)) + (he:q.law (chapter (stellar u s t η P Q) S)) + (ha:∀ i,A i≤K^2) (hb:∀ i,B i≤K^2) + (h1 : ∀ i, (outstraps P S true i).card f l q x ≠ d i a.bit a.gamma l q x) ≤ 2*ε + +set_option maxHeartbeats 800000 in +theorem build_anthology {δ ε β:ℝ} (P : Terrain p r) (s : Gazette p r A) + (hp:origami p r P δ) (hs:reports p r P s β δ) + (he:ε+ε<1/2*β) (hβ:0≤β) (hg:3≤p.g) + (L:ℕ) (hL:2*L v l q x≠ f l q x) ≤2*ε from by + intro i b k; let Q (v : Pulsar p r) := + ∃ (A' : Finset (Label p.b)) (a:RhymeSet (A i)), + A'.card≤ L ∧ a.bit=b ∧ a.gamma=k ∧ praise P s i A' a v ε + by_cases h:∃ v,Q v + · obtain ⟨x,S,a0,hx,hy,hk,h⟩:= h + refine ⟨x,fun v T a hc ha ht hz l q=>?_⟩ + obtain ⟨_,_,hg⟩:=unison hg hp hs i a a0 v x T S + ((card_union_le ..).trans_lt (by rw [two_mul] at hL; linarith only [hL,hc,hx])) + hz h (ha.trans hy.symm) he hβ + specialize hg l q + rw [ht,hk] at hg + simpa only [ne_eq,add_left_inj,two_mul] using hg + exact ⟨0,fun v t a h1 h2 h3 h4=>(h ⟨v,t,a,h1,h2,h3,h4⟩).elim⟩ + exact ⟨f,fun B i hi w a h=> hf i _ _ w (B i) a hi rfl rfl h⟩ + +def Pulsar.shift (g:Pulsar p r) (a:F): Pulsar p r := fun l q x => g l q x+a*q + +abbrev Snip := F×F×F +abbrev Memo := Nodes × (Nodes→Snip) +theorem memo_card : Fintype.card Memo=128 := by simp [Memo,Nodes,Snip,F]; + +def Memo.words (d:Dict p r) (i:Memo) : Nodes→ Pulsar p r := + fun j=> let h:=i.2 j; (d i.1 h.1 h.2.1).shift h.2.2 + +private theorem praise_tidy (d : Dict p r) (u:Terrain p r) (s:Gazette p r A) + (t:Gazette p r B) + {ε β δ:ℝ} (hs:reports p r u s β δ) (h:origami p r u δ) (L:ℕ) + (S T:Stalls p) (i j:Nodes) (a:RhymeSet (A i)) (b:RhymeSet (B j)) + (f:Pulsar p r) (ha:a.bit=1) (hq:anthology p r u t d L ε) + (hh:(T j).card ≤ L) + (hA:praise u s i (S i) a f ε) (hB:praise u t j (T j) b f ε): + praise u s i (S i) (yokeSet a.coal (1+a.headBit)) ((d j b.bit b.gamma).shift a.gamma) (3*ε) := by + intro x hx hg + let g:= d j b.bit b.gamma + have hz : shot u s i x a g ≤ 3*ε := + ((shot_switch u s i x a f g (h.1 _ _) (hs.law _ _ hg)).trans (add_le_add (hA x hx hg) + (hq T j hh f b hB _ _))).trans_eq (by ring) + let y := yokeSet a.coal (1+a.headBit) + have he (j k) : + y.soot x k≠ g.shift a.gamma x.l x.q j ↔ a.soot x k≠g x.l x.q j := by + have hh : a.soot x k=y.soot x k+a.gamma*x.q := by + unfold y RhymeSet.soot RhymeSet.read yokeSet; rw [ha] + simp only [zero_mul,add_zero,←add_assoc,char_two,zero_add] + rw [hh] + unfold Pulsar.shift + have hx : g x.l x.q j=(g x.l x.q j+a.gamma*x.q)+a.gamma*x.q := + Eq.symm (by rw [add_assoc,char_two,add_zero]) + apply not_congr + constructor + · intro h; rw [h,←hx] + intro h; exact add_right_cancel (h.trans hx) + change shot u s i x y (g.shift a.gamma) ≤_ + unfold shot; simp_rw [he]; exact hz + +def announced (u:Terrain p r) (s:Gazette p r A) (d:Dict p r) (L:ℕ) (ε:ℝ) := + ∃ i:Memo,∃ (v:styles A) (a:Party) (S:Stalls p),∀ j, + (S j).card≤L ∧ praise u s j (S j) (yokeSet (v j) (a j)) (Memo.words d i j) ε + +set_option maxHeartbeats 900000 in +theorem quotes (d e:Dict p r) + {ε β δ:ℝ} (hs:reports p r u s β δ) (ht:reports p r u t β δ) (h:origami p r u δ) + (z:DualCoefficients A B) (hh:z.left ≠0 ∨ z.right≠0) + (P Q:Stalls p) (hc:Stirrings p r u s t z P Q ε) + (L:ℕ) (hA:anthology p r u s d L (3*ε)) (hB:anthology p r u t e L (3*ε)) + (hp:∀ i,(P i).card≤L)(hq:∀ i,(Q i).card≤L): + announced u s e L (3*(3*ε)) ∨ announced u t d L (3*(3*ε)) := by + classical + choose f ha hb using hc.recollect + have he (s: Quota) (h:s≠0): ∃ i:Nodes,s i=1 := by + by_contra! hf; exact h (funext (fun i=> (bit_cases _).resolve_right (hf i))) + rcases hh with h1|h1 + · obtain ⟨i,hi⟩:= he z.left h1 + let S j:= leftChime z (j,i); let T j:= rightChime z (j,i) + let m : Memo:=(i,fun j=>((T j).bit,(T j).gamma,(S j).gamma)) + refine Or.inl ⟨m,fun j=>(S j).coal, fun j=>1+(S j).headBit,P, fun j=>⟨hp j,?_⟩⟩ + exact praise_tidy e u s t hs h L P Q j i (S j) (T j) (f (j,i)) hi hB (hq i) + (ha (j,i)) (hb (j,i)) + obtain ⟨i,hi⟩:= he z.right h1 + let S j:= rightChime z (i,j); let T j:=leftChime z (i,j) + let m : Memo:=(i,fun j=> ((T j).bit,(T j).gamma,(S j).gamma)) + refine Or.inr ⟨m,fun j=>(S j).coal,fun j=>1+(S j).headBit,Q,fun j=>⟨hq j,?_⟩⟩ + exact praise_tidy d u t s ht h L Q P j i (S j) (T j) (f (i,j)) hi hA (hp i) (hb (i,j)) (ha (i,j)) + +end DualAnalysis +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PreliminaryRestrictions.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PreliminaryRestrictions.lean index 43718dca4fae7a30da90cfbcf0d07edc60743cf7..eca5ecc0c2e48b1159d6d123acf7c173f30bf5fe 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PreliminaryRestrictions.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PreliminaryRestrictions.lean @@ -1,164 +1,164 @@ -import OAI.Combinatorics.HadwigerCounterexample.PhasePreparedOutcomes - -namespace OAI - -/-! # Preliminary Restrictions -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix -open scoped BigOperators Topology -open PredictionClass -namespace PreparationParameters - -variable {l : Filter ℕ} {p : Shape} {M n N : ℕ} {q : PreparationParameters} {m : cycleM p} - {s : rhythms p M} {w : tale p M} {b : Sketch p M} {P : Campaign p M} - -def pollen : ℝ := 10^(-9:ℤ) -theorem pollen_pos : 0?_⟩ - apply (hh x).trans - apply (mul_le_mul_of_nonneg_left (hw.total x) (bp_pos _).le).trans - rw [←mul_assoc, ←bp_add] - refine mul_le_mul_of_nonneg_right (bp_le ?_) (show 0≤usual p (m n) (M*n) x from - mul_nonneg (raw_nonneg ..) (raw_nonneg ..)) - unfold spJoint; linarith only [hN] - -private theorem epic_bounds (p : Shape) (z : BMark p n N) (x : UnitType p n N) - (h : ∀ i,totalRank (z x i)≤q.e) : - epoch p (delta z x) ≤ q.rank ∧ ∀ i,epoch p (mrAmbient z x i)≤ q.rank := by - classical - have hm i : epoch p (mrAmbient z x i) ≤ q.e := - (Finset.sum_le_sum (s:=Finset.univ) (g:=fun j:Comp p.g=>(z x i j).rank) - (fun j _=> rank_lift_le _ _ _)).trans (h i) - have hh : epoch p (delta z x) ≤ - epoch p (mrAmbient z x true)+epoch p (mrAmbient z x false) := by - unfold epoch; rw [←Finset.sum_add_distrib] - exact Finset.sum_le_sum fun j _ => mrk_add_le .. - have hi : q.e+q.e≤q.rank := by unfold rank; omega - exact ⟨hh.trans ((add_le_add (hm _) (hm _)).trans hi),fun i=>(hm i).trans (by unfold rank; omega)⟩ - -set_option maxHeartbeats 900000 in -theorem phaseSplit (hl : l≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) - (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) - (hb : q.dosed l p M m w s b P) - (he : ∀ᶠ n in l, (s n).within - (fun x=> P n x → delta (b.m n) x ≠ 0)) : - ∃ R : Campaign p M, q.citable l p M m w s b R ∧ ∀ᶠ n in l, - let v:=potion s w R n - tonalMix p (delta (b.m n)) v ∨ tonalTiny p (delta (b.m n)) v q.d := by - classical - let c:=(tinyPhase p.g q.rank q.spJoint / 2)*(coin/2) - have hc : 0 ?_) - (fun x=>(hh x).1) - obtain ⟨hp,hx⟩:= onW_ne hx - exact ⟨LeafMixture.in_parent hv (LeafMixture.present hx).1 hp,(hh x).2 _⟩ - have hx' : warm l (fun i=> ((M*i:ℕ):ℝ)) (fun i=>pr (v i) (A i)) := - (warm.const (trend_sizes l hl hq.hM).2 hc).mono (hA.mono fun i hi=>hi.1) - obtain ⟨h1,h2⟩:= citable_interpose hw hx hb.cite hx' - refine ⟨_,h1,?_⟩ - filter_upwards [h2,hA] with n hn ht - dsimp only; rw [hn] - exact ht.2 - -set_option maxHeartbeats 1200000 in -theorem phaseAbsent (hl : l≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) - (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) - (hb : q.dosed l p M m w s b P) - (he : ∀ᶠ n in l,(s n).within - (fun x=> P n x → delta (b.m n) x=0)) : - satisfied q l p M m w := by - classical - obtain ⟨d,h1,h2⟩:=hq.room - have hB : q.Bb.g i n) hn.1 hn.2.1 (fun x hc=>?_) - obtain ⟨_,h2,h3,h4,⟨h5,h6⟩,_,_⟩:=heq x hc - refine ⟨h2,b.m n x,b.L n x,fun i=> ⟨(h5 i).1,(effective_mem.mp (h5 i).2).1, - hz x i,h3 i⟩, zero_delta (b.m n) x h4,?_⟩ - exact fun i z h l g => (h6 i z h l g).trans hδ - have hm (x) (h : pairW v v x≠0) : - matchProg b n x := by - have hx := heq x.1 (left_ne_zero_of_mul h) - have hy := heq x.2 (right_ne_zero_of_mul h) - refine fade b.c b.α b.r hb.cite.forecast.light hi (fun HD => ?_) _ x hx.2.2.2.1 hy.2.2.2.1 - obtain ⟨he,_,hF,hD,⟨hg,_⟩,hh,hx⟩:=hx - exact hh.symm.trans (delta_dusk (m n) (b.m n) _ (fun i=>(effective_mem.mp (hg i).2).1) - (hx HD) hD he hF) - have hi : charm s w P b n=pr (pairW v v) (fun _=>True) := avg_congr (fun i hi=> - (ind_one (hm i hi)).trans ind_true.symm) - have hv : IsLaw v:=hn.1 - rw [hi,pr_true,(pairW_law hv hv).total]; norm_num - -end PreparationParameters -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PhasePreparedOutcomes + +namespace OAI + +/-! # Preliminary Restrictions -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix +open scoped BigOperators Topology +open PredictionClass +namespace PreparationParameters + +variable {l : Filter ℕ} {p : Shape} {M n N : ℕ} {q : PreparationParameters} {m : cycleM p} + {s : rhythms p M} {w : tale p M} {b : Sketch p M} {P : Campaign p M} + +def pollen : ℝ := 10^(-9:ℤ) +theorem pollen_pos : 0?_⟩ + apply (hh x).trans + apply (mul_le_mul_of_nonneg_left (hw.total x) (bp_pos _).le).trans + rw [←mul_assoc, ←bp_add] + refine mul_le_mul_of_nonneg_right (bp_le ?_) (show 0≤usual p (m n) (M*n) x from + mul_nonneg (raw_nonneg ..) (raw_nonneg ..)) + unfold spJoint; linarith only [hN] + +private theorem epic_bounds (p : Shape) (z : BMark p n N) (x : UnitType p n N) + (h : ∀ i,totalRank (z x i)≤q.e) : + epoch p (delta z x) ≤ q.rank ∧ ∀ i,epoch p (mrAmbient z x i)≤ q.rank := by + classical + have hm i : epoch p (mrAmbient z x i) ≤ q.e := + (Finset.sum_le_sum (s:=Finset.univ) (g:=fun j:Comp p.g=>(z x i j).rank) + (fun j _=> rank_lift_le _ _ _)).trans (h i) + have hh : epoch p (delta z x) ≤ + epoch p (mrAmbient z x true)+epoch p (mrAmbient z x false) := by + unfold epoch; rw [←Finset.sum_add_distrib] + exact Finset.sum_le_sum fun j _ => mrk_add_le .. + have hi : q.e+q.e≤q.rank := by unfold rank; omega + exact ⟨hh.trans ((add_le_add (hm _) (hm _)).trans hi),fun i=>(hm i).trans (by unfold rank; omega)⟩ + +set_option maxHeartbeats 900000 in +theorem phaseSplit (hl : l≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) + (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) + (hb : q.dosed l p M m w s b P) + (he : ∀ᶠ n in l, (s n).within + (fun x=> P n x → delta (b.m n) x ≠ 0)) : + ∃ R : Campaign p M, q.citable l p M m w s b R ∧ ∀ᶠ n in l, + let v:=potion s w R n + tonalMix p (delta (b.m n)) v ∨ tonalTiny p (delta (b.m n)) v q.d := by + classical + let c:=(tinyPhase p.g q.rank q.spJoint / 2)*(coin/2) + have hc : 0 ?_) + (fun x=>(hh x).1) + obtain ⟨hp,hx⟩:= onW_ne hx + exact ⟨LeafMixture.in_parent hv (LeafMixture.present hx).1 hp,(hh x).2 _⟩ + have hx' : warm l (fun i=> ((M*i:ℕ):ℝ)) (fun i=>pr (v i) (A i)) := + (warm.const (trend_sizes l hl hq.hM).2 hc).mono (hA.mono fun i hi=>hi.1) + obtain ⟨h1,h2⟩:= citable_interpose hw hx hb.cite hx' + refine ⟨_,h1,?_⟩ + filter_upwards [h2,hA] with n hn ht + dsimp only; rw [hn] + exact ht.2 + +set_option maxHeartbeats 1200000 in +theorem phaseAbsent (hl : l≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) + (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) + (hb : q.dosed l p M m w s b P) + (he : ∀ᶠ n in l,(s n).within + (fun x=> P n x → delta (b.m n) x=0)) : + satisfied q l p M m w := by + classical + obtain ⟨d,h1,h2⟩:=hq.room + have hB : q.Bb.g i n) hn.1 hn.2.1 (fun x hc=>?_) + obtain ⟨_,h2,h3,h4,⟨h5,h6⟩,_,_⟩:=heq x hc + refine ⟨h2,b.m n x,b.L n x,fun i=> ⟨(h5 i).1,(effective_mem.mp (h5 i).2).1, + hz x i,h3 i⟩, zero_delta (b.m n) x h4,?_⟩ + exact fun i z h l g => (h6 i z h l g).trans hδ + have hm (x) (h : pairW v v x≠0) : + matchProg b n x := by + have hx := heq x.1 (left_ne_zero_of_mul h) + have hy := heq x.2 (right_ne_zero_of_mul h) + refine fade b.c b.α b.r hb.cite.forecast.light hi (fun HD => ?_) _ x hx.2.2.2.1 hy.2.2.2.1 + obtain ⟨he,_,hF,hD,⟨hg,_⟩,hh,hx⟩:=hx + exact hh.symm.trans (delta_dusk (m n) (b.m n) _ (fun i=>(effective_mem.mp (hg i).2).1) + (hx HD) hD he hF) + have hi : charm s w P b n=pr (pairW v v) (fun _=>True) := avg_congr (fun i hi=> + (ind_one (hm i hi)).trans ind_true.symm) + have hv : IsLaw v:=hn.1 + rw [hi,pr_true,(pairW_law hv hv).total]; norm_num + +end PreparationParameters +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PreparationConditions.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PreparationConditions.lean index 2d301cb7852c98e96e0f74030f25f7b895b8fe8e..6d3615ea401a27c4dfacc4c0971861fcac6bb0d1 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PreparationConditions.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PreparationConditions.lean @@ -1,183 +1,183 @@ -import OAI.Combinatorics.HadwigerCounterexample.LeafMixtures -import OAI.Combinatorics.HadwigerCounterexample.CoverAlternatives -import OAI.Combinatorics.HadwigerCounterexample.ZeroDiscrepancyLemma - -namespace OAI - -/-! # Preparation Conditions -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset -open scoped BigOperators Topology -open PredictionClass - -structure PreparationParameters where - D : ℕ - L : ℝ - d : ℕ - e : ℕ - s : ℕ - u : ℕ - k : ℕ - ζ : ℝ - B : ℕ - -namespace PreparationParameters -def pins (q : PreparationParameters) := 3*q.e+q.s -def rank (q : PreparationParameters) := 2*q.e + 2 - -def leafOld (q : PreparationParameters) : ℝ := ↑q.D+q.e+2 -def leafNew (q : PreparationParameters) : ℝ := q.leafOld+q.u+q.s+2 -def spJoint (q : PreparationParameters) : ℝ := (q.D:ℝ)+1 - -def spear (q : PreparationParameters) := bp (100)*q.L - -structure allows (q : PreparationParameters) : Prop where - pos : 0< q.ζ - small : q.ζ < 1 - hL : 0≤q.L - bigS : q.leafOld+q.u+q.ζ ≤ (q.ζ-q.ζ/4) * q.s - -variable {p : Shape} {M n N : ℕ} -abbrev tale (p : Shape) (M : ℕ) := ∀ n,Wgt (UnitType p n (M*n)) -abbrev rhythms (p : Shape) (M : ℕ) := ∀ n,LeafMixture p n (M*n) -abbrev cycleM (p : Shape) := ∀ n,Mixer p n - -def frameSide (p : Shape) (m : Mixer p n) (x : UnitType p n N) := - ∀ i,frameLaw m (onSide x i) -def usual (p : Shape) (m : Mixer p n) (N : ℕ) := - pairW (raw m N) (raw m N) - -structure nascent (q : PreparationParameters) (p : Shape) (N : ℕ) {n} - (w : Wgt (UnitType p n N)) (m : Mixer p n) : Prop where - law : IsLaw w - border : bySide p w m q.L - total : ∀ x,w x≤bp ((q.D:ℝ)*N)*usual p m N x - -structure entered (q : PreparationParameters) (p : Shape) (N : ℕ) {n} (m : Mixer p n) - (w : Wgt (UnitType p n N)) (s : LeafMixture p n N) : Prop where - weight : (1/2:ℝ) ≤ s.amount w - strength : s.strength w (usual p m N) q.leafOld q.ζ q.e - onTile : s.within (fun x=>w x≠0 ∧ (rawHoles m).unit x ∧ joins x≤2*q.D ∧ frameSide p m x) - -structure durable (q : PreparationParameters) (l : Filter ℕ) (p : Shape) (M : ℕ) (m : cycleM p) - (w : tale p M) (s : rhythms p M) : Prop where - mass : warm l (fun i=> ((M*i:ℕ):ℝ)) (fun i=>(s i).amount (w i)) - shape : ∀ᶠ n in l,(s n).strength (w n) (usual p (m n) (M*n)) q.leafNew (2*q.ζ) q.pins ∧ - (s n).within (frameSide p (m n)) - -def seems (q : PreparationParameters) (p : Shape) (m : Mixer p n) - (s : LeafMixture p n N) - (x : UnitType p n N) (g : Bool → Augur p N) (z : Bool → Profile p n) - (L : Bool→Finset (Label p.b)) (α : Party) (ε : ℝ) := - (∀ i : Bool,(L i).card≤ q.B ∧ z i∈ effective (s.rooting x) i) ∧ - claimed p x g m z α L ε - -def predicts (q : PreparationParameters) (p : Shape) (N : ℕ) {n} (m : Mixer p n) - (s : LeafMixture p n N) (w : Wgt (UnitType p n N)) (ε : ℝ) := - ∃ g : Bool → Augur p N, (0.000001 : ℝ) ≤ pr (s.sap w) (fun x => ∃ z L α, q.seems p m s x g z L α ε) - -def silenceOutcome (q : PreparationParameters) (l : Filter ℕ) (p : Shape) (M : ℕ) (m : cycleM p) - (w : tale p M) (s : rhythms p M) := - ∃ ε:ℝ,0<ε∧∀ᶠ n in l, ¬q.predicts p (M*n) (m n) (s n) (w n) ε ∧ - let v:=(s n).sap (w n) - 0.99 < pr (pairW v v) (secureAt p (s n).rooting) - -structure Sketch (p : Shape) (M : ℕ) where - c : PredictionClass - α : Party - r : F - m : ∀ n,BMark p n (M*n) - L : ∀ n,UnitType p n (M*n) → Bool → Finset (Label p.b) - g : Bool → PredictionClass.season p M - ε : ℕ→ℝ - -def engrave (b : Sketch p M) (q : PreparationParameters) (m : cycleM p) (s : rhythms p M) (n : ℕ) := - fun x : UnitType p n (M*n) => - q.seems p (m n) (s n) x (fun i=> b.g i n) (b.m n x) (b.L n x) b.α (b.ε n) ∧ - glint p (b.m n x) = b.r ∧ (b.c=dusk → exactInk p (m n) (b.m n) x) - -structure ledger (b : Sketch p M) (l : Filter ℕ) : Prop where - small : slight l b.ε - classes : ∃ τ:ℝ, 0<τ∧∀ᶠ n in l,b.c.recital p (fun i=>b.g i n) b.α τ - light : b.c.lit b.α - -structure bright (q : PreparationParameters) (l : Filter ℕ) (p : Shape) (M : ℕ) (m : cycleM p) - (s : rhythms p M) (b : Sketch p M) : Prop where - forecasts : ledger b l - engraved : ∀ᶠ n in l,(s n).within (engrave b q m s n) - -def matchProg (b : Sketch p M) (n : ℕ) := - matchUp (delta (b.m n)) b.α b.r b.c -def glow (s : rhythms p M) (w : tale p M) (b : Sketch p M) (n : ℕ) := - pr (pairW ((s n).sap (w n)) ((s n).sap (w n))) (matchProg b n) -def gleam (s : rhythms p M) (w : tale p M) (b : Sketch p M) (n : ℕ) := - pr (pairW ((s n).sap (w n)) ((s n).sap (w n))) - (fun x=>matchProg b n x∧¬secureAt p (s n).rooting x) -def gilded (s : rhythms p M) (w : tale p M) (b : Sketch p M) (n : ℕ) := - pr (pairW ((s n).sap (w n)) ((s n).sap (w n))) - (fun x=>matchProg b n x∧secureAt p (s n).rooting x) - -theorem gilding (s : rhythms p M) (w : tale p M) (b : Sketch p M) (n : ℕ) - (h : IsLaw ((s n).sap (w n))) : - glow s w b n-gleam s w b n≤gilded s w b n := by - let G:= matchProg b n - let Q := secureAt p (s n).rooting - have ht (x) : G x → (G x∧ Q x) ∨ (G x ∧¬Q x) := by tauto - have hv := pairW_law h h - have hx : glow s w b n ≤ gilded s w b n+gleam s w b n := - (pr_mono hv.nz ht).trans (pr_or_le hv.nz) - linarith only [hx] - -def glowOutcome (l : Filter ℕ) (p : Shape) (M : ℕ) - (w : tale p M) (s : rhythms p M) (b : Sketch p M) := - ∃ e:ℝ,0 covered p T (delta z x))) ∧ - ∀ i∈s.T,∃ a,specialLeaf T z a i (s.pin i) ∧ - ∀ x∈i,∀ j,z x j ∈ effective a.sp j - -def glimmer (q : PreparationParameters) (l : Filter ℕ) (p : Shape) (M : ℕ) - (w : tale p M) (s : rhythms p M) (b : Sketch p M) := - b.c=dusk ∧ ∃ e:ℝ,0P x ∧ ¬secureAt p b x) ≤ 0.0005*pr (pairW w w) P+edgeError N -structure planted (q : PreparationParameters) (p : Shape) (M : ℕ) : Prop where - early : q.allows - hM : 1≤M - hg : Odd p.g - hG : 3≤p.g - hJ : 1≤p.j - hR : 1≤p.r - hB : (q.B:ℝ)w x≠0 ∧ (rawHoles m).unit x ∧ joins x≤2*q.D ∧ frameSide p m x) + +structure durable (q : PreparationParameters) (l : Filter ℕ) (p : Shape) (M : ℕ) (m : cycleM p) + (w : tale p M) (s : rhythms p M) : Prop where + mass : warm l (fun i=> ((M*i:ℕ):ℝ)) (fun i=>(s i).amount (w i)) + shape : ∀ᶠ n in l,(s n).strength (w n) (usual p (m n) (M*n)) q.leafNew (2*q.ζ) q.pins ∧ + (s n).within (frameSide p (m n)) + +def seems (q : PreparationParameters) (p : Shape) (m : Mixer p n) + (s : LeafMixture p n N) + (x : UnitType p n N) (g : Bool → Augur p N) (z : Bool → Profile p n) + (L : Bool→Finset (Label p.b)) (α : Party) (ε : ℝ) := + (∀ i : Bool,(L i).card≤ q.B ∧ z i∈ effective (s.rooting x) i) ∧ + claimed p x g m z α L ε + +def predicts (q : PreparationParameters) (p : Shape) (N : ℕ) {n} (m : Mixer p n) + (s : LeafMixture p n N) (w : Wgt (UnitType p n N)) (ε : ℝ) := + ∃ g : Bool → Augur p N, (0.000001 : ℝ) ≤ pr (s.sap w) (fun x => ∃ z L α, q.seems p m s x g z L α ε) + +def silenceOutcome (q : PreparationParameters) (l : Filter ℕ) (p : Shape) (M : ℕ) (m : cycleM p) + (w : tale p M) (s : rhythms p M) := + ∃ ε:ℝ,0<ε∧∀ᶠ n in l, ¬q.predicts p (M*n) (m n) (s n) (w n) ε ∧ + let v:=(s n).sap (w n) + 0.99 < pr (pairW v v) (secureAt p (s n).rooting) + +structure Sketch (p : Shape) (M : ℕ) where + c : PredictionClass + α : Party + r : F + m : ∀ n,BMark p n (M*n) + L : ∀ n,UnitType p n (M*n) → Bool → Finset (Label p.b) + g : Bool → PredictionClass.season p M + ε : ℕ→ℝ + +def engrave (b : Sketch p M) (q : PreparationParameters) (m : cycleM p) (s : rhythms p M) (n : ℕ) := + fun x : UnitType p n (M*n) => + q.seems p (m n) (s n) x (fun i=> b.g i n) (b.m n x) (b.L n x) b.α (b.ε n) ∧ + glint p (b.m n x) = b.r ∧ (b.c=dusk → exactInk p (m n) (b.m n) x) + +structure ledger (b : Sketch p M) (l : Filter ℕ) : Prop where + small : slight l b.ε + classes : ∃ τ:ℝ, 0<τ∧∀ᶠ n in l,b.c.recital p (fun i=>b.g i n) b.α τ + light : b.c.lit b.α + +structure bright (q : PreparationParameters) (l : Filter ℕ) (p : Shape) (M : ℕ) (m : cycleM p) + (s : rhythms p M) (b : Sketch p M) : Prop where + forecasts : ledger b l + engraved : ∀ᶠ n in l,(s n).within (engrave b q m s n) + +def matchProg (b : Sketch p M) (n : ℕ) := + matchUp (delta (b.m n)) b.α b.r b.c +def glow (s : rhythms p M) (w : tale p M) (b : Sketch p M) (n : ℕ) := + pr (pairW ((s n).sap (w n)) ((s n).sap (w n))) (matchProg b n) +def gleam (s : rhythms p M) (w : tale p M) (b : Sketch p M) (n : ℕ) := + pr (pairW ((s n).sap (w n)) ((s n).sap (w n))) + (fun x=>matchProg b n x∧¬secureAt p (s n).rooting x) +def gilded (s : rhythms p M) (w : tale p M) (b : Sketch p M) (n : ℕ) := + pr (pairW ((s n).sap (w n)) ((s n).sap (w n))) + (fun x=>matchProg b n x∧secureAt p (s n).rooting x) + +theorem gilding (s : rhythms p M) (w : tale p M) (b : Sketch p M) (n : ℕ) + (h : IsLaw ((s n).sap (w n))) : + glow s w b n-gleam s w b n≤gilded s w b n := by + let G:= matchProg b n + let Q := secureAt p (s n).rooting + have ht (x) : G x → (G x∧ Q x) ∨ (G x ∧¬Q x) := by tauto + have hv := pairW_law h h + have hx : glow s w b n ≤ gilded s w b n+gleam s w b n := + (pr_mono hv.nz ht).trans (pr_or_le hv.nz) + linarith only [hx] + +def glowOutcome (l : Filter ℕ) (p : Shape) (M : ℕ) + (w : tale p M) (s : rhythms p M) (b : Sketch p M) := + ∃ e:ℝ,0 covered p T (delta z x))) ∧ + ∀ i∈s.T,∃ a,specialLeaf T z a i (s.pin i) ∧ + ∀ x∈i,∀ j,z x j ∈ effective a.sp j + +def glimmer (q : PreparationParameters) (l : Filter ℕ) (p : Shape) (M : ℕ) + (w : tale p M) (s : rhythms p M) (b : Sketch p M) := + b.c=dusk ∧ ∃ e:ℝ,0P x ∧ ¬secureAt p b x) ≤ 0.0005*pr (pairW w w) P+edgeError N +structure planted (q : PreparationParameters) (p : Shape) (M : ℕ) : Prop where + early : q.allows + hM : 1≤M + hg : Odd p.g + hG : 3≤p.g + hJ : 1≤p.j + hR : 1≤p.r + hB : (q.B:ℝ)P y∧¬secureAt p x y) ≤ - 0.0005* pr (pairW v v) P +edgeError N := by - let N (n:ℕ):=M*n - let z (i:ℕ):=((N i):ℝ) - have hz := (trend_sizes l hl hq.hM).2 - let a := (0.005:ℝ) - have ha : 0 hB.2.2.2.2 P hp hP v (s n).rooting (m n) - (LeafMixture.root_bound h) hm hg (fun x hx => ?_)⟩ - exact LeafMixture.in_parent hF (LeafMixture.present hx).1 - -theorem durable.unconditional (h : durable q l p M m w s) (hl : l≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) : - ∀ᶠ n in l,let v:=(s n).sap (w n); - pr (pairW v v) (fun x=>¬secureAt p (s n).rooting x) <0.01 ∧ - 0.99 < pr (pairW v v) (secureAt p (s n).rooting) := by - have he : - ∀ᶠ n in l,edgeError (M*n)<0.0005 := - (((bp_tendsto_zero (by norm_num : 0 < (0.005:ℝ))).comp - (trend_sizes l hl hq.hM).2).eventually (gt_mem_nhds (by norm_num))) - filter_upwards [h.gripped hl hq hw,he] with n hn ht - obtain ⟨hm,hg⟩:=hn - let v:=(s n).sap (w n) - let P := secureAt p (s n).rooting - have hp : 1≤bp (3*q.d*((M*n:ℕ):ℝ)) := by - rw [←bp_zero]; exact bp_le (by positivity) - have hx := hg (fun _=>True) (named_true hp) (named_true hp) - have hv : IsLaw (pairW v v):=pairW_law hm hm - change pr (pairW v v) (fun x=>True∧¬P x) ≤ 0.0005*pr (pairW v v) (fun _=>True)+ _ at hx - simp only [true_and,pr_true,hv.total,mul_one] at hx - have hh : pr (pairW v v) (fun x=>¬P x)<0.01 := by linarith only [hx,ht] - refine ⟨hh,?_⟩; rw [pr_not,hv.total] at hh - linarith only [hh] - -variable {b : Sketch p M} - -theorem durable.kindles (h : durable q l p M m w s) (hl : l≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) - (hf : ∀ᶠ n in l,0.04 ≤ glow s w b n) : - glowOutcome l p M w s b := by - refine ⟨0.02, by norm_num,?_⟩ - filter_upwards [h.gripped hl hq hw,h.unconditional hl hq hw,hf] with n hn ht hv - obtain ⟨hm,_⟩:=hn - have hi : gleam s w b n <0.01 := - lt_of_le_of_lt (pr_mono (pairW_law hm hm).nz (fun i hi=>hi.2)) ht.1 - have hg := gilding s w b n hm - linarith only [hi,hg,hv] - -def domed (q : PreparationParameters) (l : Filter ℕ) (s : rhythms p M) (b : Sketch p M) := - ∀ᶠ n in l, ∃ T : Cov p (M*n), cdim p T≤q.d ∧ - (s n).within (fun x=>covered p T (delta (b.m n) x)) - -theorem durable.domeLight (h : durable q l p M m w s) (hl : l≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) (hd : q.domed l s b) : - ∀ᶠ n in l,gleam s w b n≤0.0005*glow s w b n+edgeError (M*n) := by - classical - filter_upwards [h.gripped hl hq hw,hd] with n hn hd - obtain ⟨T,hT,hC⟩:= hd - let v:=(s n).sap (w n) - let P := matchProg b n - obtain ⟨Q,h1,h2,h3⟩:= longStory T q.d hT b.c b.α b.r (delta (b.m n)) v - (fun x hx=>LeafMixture.in_parent hC (LeafMixture.present hx).1) - have hi : pr (pairW v v) Q=glow s w b n := avg_congr - (fun x hx=> congrArg ind (propext (h3 x hx))) - have hf : gleam s w b n=pr (pairW v v) (fun y=> Q y∧¬secureAt p (s n).rooting y) := - avg_congr (fun x hx=> congrArg ind (propext (and_congr_left fun _=>(h3 x hx).symm))) - rw [hf,←hi]; exact hn.2 _ h1 h2 - -theorem durable.domeGlow (h : durable q l p M m w s) (hl : l≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) (hd : q.domed l s b) - {δ : ℝ} (hδ : 0<δ) (hg : ∀ᶠ n in l,δ ≤ glow s w b n) : - glowOutcome l p M w s b := by - have he : ∀ᶠ n in l,edgeError (M*n)<δ/4 := (((bp_tendsto_zero - (by norm_num : 0<(0.005:ℝ))).comp - (trend_sizes l hl hq.hM).2).eventually (gt_mem_nhds (by positivity))) - refine ⟨δ/2,half_pos hδ,?_⟩ - filter_upwards [h.gripped hl hq hw,h.domeLight hl hq hw hd,he,hg] with n hn ht he hg - have hh := gilding s w b n hn.1 - linarith only [hh,he,hg,hδ,ht] - -theorem durable.domeSpark (h : durable q l p M m w s) (hl : l≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) - (hd : b.c=dusk) - (hb : ∀ᶠ n in l,q.hardened p (M*n) (s n) (b.m n)) - {δ : ℝ} (hδ : 0<δ) (hg : ∀ᶠ n in l,δ/((M*n:ℕ):ℝ)^4 ≤ glow s w b n) : - q.glimmer l p M w s b := by - have hB := show q.domed l s b from hb.mono (fun i h => by - obtain ⟨T,hT,hC,_⟩:=h; exact ⟨T,hT,hC⟩) - let z n:=((M*n:ℕ):ℝ) - have hz : Tendsto z l atTop := (trend_sizes l hl hq.hM).2 - have hi : ExpSmall l z (fun n=>edgeError (M*n)*(z n)^4) := - (ExpSmall.bp_n (by norm_num)).poly hz 4 - refine ⟨hd,δ,hδ,?_⟩ - filter_upwards [h.domeLight hl hq hw hB,hb,hg,hz.eventually (eventually_gt_atTop 0), - (hi.lim hz).eventually (gt_mem_nhds (show 0<0.0005*δ from mul_pos (by norm_num) hδ))] - with n h hb hg he hi - refine ⟨hb,hg,h.trans ?_⟩ - have hz : edgeError (M*n) ≤ 0.0005*glow s w b n := calc - _ ≤ 0.0005*δ/(z n)^4 := (le_div_iff₀ (by positivity)).mpr hi.le - _ ≤ _ := by rw [mul_div_assoc]; exact mul_le_mul_of_nonneg_left hg (by norm_num) - linarith only [hz] - -end PreparationParameters -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PreparationConditions + +namespace OAI + +/-! # Prepared Outcomes -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset +open scoped BigOperators Topology +open PredictionClass + +namespace PreparationParameters +variable {l : Filter ℕ} {p : Shape} {M n N : ℕ} {q : PreparationParameters} + {m : cycleM p} {s : rhythms p M} {w : tale p M} + +theorem durable.gripped (h : durable q l p M m w s) (hl : l≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) : + ∀ᶠ n in l,let N:=M*n; let v:=(s n).sap (w n); let x:=(s n).rooting; + IsLaw v ∧ ∀ P:UnitType p n N×UnitType p n N→Prop, named P (bp (3*q.d*(N:ℝ))) → + named (P ∘ Prod.swap) (bp (3*q.d*(N:ℝ))) → + pr (pairW v v) (fun y=>P y∧¬secureAt p x y) ≤ + 0.0005* pr (pairW v v) P +edgeError N := by + let N (n:ℕ):=M*n + let z (i:ℕ):=((N i):ℝ) + have hz := (trend_sizes l hl hq.hM).2 + let a := (0.005:ℝ) + have ha : 0 hB.2.2.2.2 P hp hP v (s n).rooting (m n) + (LeafMixture.root_bound h) hm hg (fun x hx => ?_)⟩ + exact LeafMixture.in_parent hF (LeafMixture.present hx).1 + +theorem durable.unconditional (h : durable q l p M m w s) (hl : l≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) : + ∀ᶠ n in l,let v:=(s n).sap (w n); + pr (pairW v v) (fun x=>¬secureAt p (s n).rooting x) <0.01 ∧ + 0.99 < pr (pairW v v) (secureAt p (s n).rooting) := by + have he : + ∀ᶠ n in l,edgeError (M*n)<0.0005 := + (((bp_tendsto_zero (by norm_num : 0 < (0.005:ℝ))).comp + (trend_sizes l hl hq.hM).2).eventually (gt_mem_nhds (by norm_num))) + filter_upwards [h.gripped hl hq hw,he] with n hn ht + obtain ⟨hm,hg⟩:=hn + let v:=(s n).sap (w n) + let P := secureAt p (s n).rooting + have hp : 1≤bp (3*q.d*((M*n:ℕ):ℝ)) := by + rw [←bp_zero]; exact bp_le (by positivity) + have hx := hg (fun _=>True) (named_true hp) (named_true hp) + have hv : IsLaw (pairW v v):=pairW_law hm hm + change pr (pairW v v) (fun x=>True∧¬P x) ≤ 0.0005*pr (pairW v v) (fun _=>True)+ _ at hx + simp only [true_and,pr_true,hv.total,mul_one] at hx + have hh : pr (pairW v v) (fun x=>¬P x)<0.01 := by linarith only [hx,ht] + refine ⟨hh,?_⟩; rw [pr_not,hv.total] at hh + linarith only [hh] + +variable {b : Sketch p M} + +theorem durable.kindles (h : durable q l p M m w s) (hl : l≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) + (hf : ∀ᶠ n in l,0.04 ≤ glow s w b n) : + glowOutcome l p M w s b := by + refine ⟨0.02, by norm_num,?_⟩ + filter_upwards [h.gripped hl hq hw,h.unconditional hl hq hw,hf] with n hn ht hv + obtain ⟨hm,_⟩:=hn + have hi : gleam s w b n <0.01 := + lt_of_le_of_lt (pr_mono (pairW_law hm hm).nz (fun i hi=>hi.2)) ht.1 + have hg := gilding s w b n hm + linarith only [hi,hg,hv] + +def domed (q : PreparationParameters) (l : Filter ℕ) (s : rhythms p M) (b : Sketch p M) := + ∀ᶠ n in l, ∃ T : Cov p (M*n), cdim p T≤q.d ∧ + (s n).within (fun x=>covered p T (delta (b.m n) x)) + +theorem durable.domeLight (h : durable q l p M m w s) (hl : l≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) (hd : q.domed l s b) : + ∀ᶠ n in l,gleam s w b n≤0.0005*glow s w b n+edgeError (M*n) := by + classical + filter_upwards [h.gripped hl hq hw,hd] with n hn hd + obtain ⟨T,hT,hC⟩:= hd + let v:=(s n).sap (w n) + let P := matchProg b n + obtain ⟨Q,h1,h2,h3⟩:= longStory T q.d hT b.c b.α b.r (delta (b.m n)) v + (fun x hx=>LeafMixture.in_parent hC (LeafMixture.present hx).1) + have hi : pr (pairW v v) Q=glow s w b n := avg_congr + (fun x hx=> congrArg ind (propext (h3 x hx))) + have hf : gleam s w b n=pr (pairW v v) (fun y=> Q y∧¬secureAt p (s n).rooting y) := + avg_congr (fun x hx=> congrArg ind (propext (and_congr_left fun _=>(h3 x hx).symm))) + rw [hf,←hi]; exact hn.2 _ h1 h2 + +theorem durable.domeGlow (h : durable q l p M m w s) (hl : l≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) (hd : q.domed l s b) + {δ : ℝ} (hδ : 0<δ) (hg : ∀ᶠ n in l,δ ≤ glow s w b n) : + glowOutcome l p M w s b := by + have he : ∀ᶠ n in l,edgeError (M*n)<δ/4 := (((bp_tendsto_zero + (by norm_num : 0<(0.005:ℝ))).comp + (trend_sizes l hl hq.hM).2).eventually (gt_mem_nhds (by positivity))) + refine ⟨δ/2,half_pos hδ,?_⟩ + filter_upwards [h.gripped hl hq hw,h.domeLight hl hq hw hd,he,hg] with n hn ht he hg + have hh := gilding s w b n hn.1 + linarith only [hh,he,hg,hδ,ht] + +theorem durable.domeSpark (h : durable q l p M m w s) (hl : l≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) + (hd : b.c=dusk) + (hb : ∀ᶠ n in l,q.hardened p (M*n) (s n) (b.m n)) + {δ : ℝ} (hδ : 0<δ) (hg : ∀ᶠ n in l,δ/((M*n:ℕ):ℝ)^4 ≤ glow s w b n) : + q.glimmer l p M w s b := by + have hB := show q.domed l s b from hb.mono (fun i h => by + obtain ⟨T,hT,hC,_⟩:=h; exact ⟨T,hT,hC⟩) + let z n:=((M*n:ℕ):ℝ) + have hz : Tendsto z l atTop := (trend_sizes l hl hq.hM).2 + have hi : ExpSmall l z (fun n=>edgeError (M*n)*(z n)^4) := + (ExpSmall.bp_n (by norm_num)).poly hz 4 + refine ⟨hd,δ,hδ,?_⟩ + filter_upwards [h.domeLight hl hq hw hB,hb,hg,hz.eventually (eventually_gt_atTop 0), + (hi.lim hz).eventually (gt_mem_nhds (show 0<0.0005*δ from mul_pos (by norm_num) hδ))] + with n h hb hg he hi + refine ⟨hb,hg,h.trans ?_⟩ + have hz : edgeError (M*n) ≤ 0.0005*glow s w b n := calc + _ ≤ 0.0005*δ/(z n)^4 := (le_div_iff₀ (by positivity)).mpr hi.le + _ ≤ _ := by rw [mul_div_assoc]; exact mul_le_mul_of_nonneg_left hg (by norm_num) + linarith only [hz] + +end PreparationParameters +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PreparedPopulationTrimming.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PreparedPopulationTrimming.lean index 68832251881df42b513a3e7108b119fa60d32494..54ea3621dc2147dc2aefc7d8526ed5911564579e 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PreparedPopulationTrimming.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PreparedPopulationTrimming.lean @@ -1,211 +1,211 @@ -import OAI.Combinatorics.HadwigerCounterexample.PreparedOutcomes - -namespace OAI - -/-! # Prepared Population Trimming -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset -open scoped BigOperators Topology -open PredictionClass - -namespace PreparationParameters -variable {l : Filter ℕ} {p : Shape} {M : ℕ} {q : PreparationParameters} - {m : cycleM p} {s : rhythms p M} {w : tale p M} {b : Sketch p M} - -theorem retainInitial (hl : l≤atTop) (hq : q.planted p M) - (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) : - durable q l p M m w s := by - refine ⟨((warm.const (trend_sizes l hl hq.hM).2 (by norm_num : 0<(1/2:ℝ))).mono - (hx.mono fun i hi=> hi.weight)),?_⟩ - filter_upwards [hx] with n hn - have hh := hq.early - refine ⟨hn.strength.slide ?_ ?_ ?_ (fun x=> mul_nonneg (raw_nonneg _ _) (raw_nonneg _ _)), - fun i hi x hx => (hn.onTile i hi x hx).2.2.2⟩ - · unfold leafNew; linarith [(Nat.cast_nonneg q.u : 0≤(q.u:ℝ)),(Nat.cast_nonneg q.s : - 0≤(q.s:ℝ))] - · linarith only [hh.pos] - unfold pins; omega - -abbrev Campaign (p : Shape) (M : ℕ) := ∀ n,UnitType p n (M*n) → Prop -variable {P : Campaign p M} -structure citable (q : PreparationParameters) (l : Filter ℕ) (p : Shape) (M : ℕ) - (m : cycleM p) (w : tale p M) (s : rhythms p M) (b : Sketch p M) (P : Campaign p M) : Prop where - mass : warm l (fun i=> ((M*i:ℕ):ℝ)) (fun i=>pr ((s i).sap (w i)) (P i)) - forecast : ledger b l - mark : ∀ᶠ i in l, (s i).within (fun x => P i x → engrave b q m s i x) - -def potion (s : rhythms p M) (w : tale p M) (P : Campaign p M) : tale p M := - fun n => onW ((s n).sap (w n)) (P n) -def charm (s : rhythms p M) (w : tale p M) (P : Campaign p M) (b : Sketch p M) := - fun n => pr (pairW (potion s w P n) (potion s w P n)) (matchProg b n) - -theorem citable.on_law (h : citable q l p M m w s b P) - (hl : l ≤ atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) - (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) : - ∀ᶠ n in l, IsLaw (potion s w P n) := by - filter_upwards [h.mass.positive,hw,(retainInitial hl hq hx).mass.positive] with n hn ht hv - exact HadwigerCounterexample.on_law (LeafMixture.sapLaw hv ht.law).nz hn - -set_option maxHeartbeats 1400000 in -theorem dropHarvest (hl : l≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) - (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) - (hb : q.citable l p M m w s b P) : - ∃ t : rhythms p M, durable q l p M m w t ∧ - q.bright l p M m t b ∧ - (∀ᶠ n in l,(t n).within (fun x=>inTiles (s n).T x∧P n x)) ∧ - ∃ d,ExpSmall l (fun n=> ((M*n:ℕ):ℝ)) d ∧ - ∀ᶠ n in l,charm s w P b n-d n ≤ glow t w b n := by - classical - let N (n:ℕ) := M*n; let z n:=((N n):ℝ) - let Y : Campaign p M := fun n=> inTiles (s n).T - let E :=fun i=> bp (-q.ζ*z i) - let R n (t : LeafMixture p n (M*n)) := t.strength (w n) (usual p (m n) (M*n)) (q.leafOld+q.ζ) (2*q.ζ) q.e ∧ - LeafMixture.elder (s n) t (P n) (fun i j=> t.pin i=(s n).pin j) ∧ - pr (w n) (fun x=> Y n x ∧ P n x∧¬inTiles t.T x)≤ E n - obtain ⟨t,ht⟩ : ∃ t: rhythms p M,∀ᶠ n in l,R n (t n) := by - refine taking ?_ - filter_upwards [hw,hx] with n hn h - exact LeafMixture.elder_trim h.strength hq.early.pos.le hn.law _ - have hz := (trend_sizes l hl hq.hM).2 - let Q : Campaign p M := fun n=> inTiles (t n).T - have ht' (i) : R i (t i) → (∀ x, Q i x → Y i x∧P i x) ∧ - pr (w i) (fun x=>Y i x∧P i x∧¬Q i x)≤E i := fun h=>⟨fun x hx=>LeafMixture.ancestral h.2.1 hx,h.2.2⟩ - obtain ⟨hW,d,hd,hZ⟩:= vigor_trim z hz w (hw.mono fun i h=>h.law.nz) - Y Q P (ExpSmall.bp_n hq.early.pos) (retainInitial hl hq hx).mass hb.mass - (ht.mono (fun i h=> ht' i h)) - have h1 : durable q l p M m w t := by - refine ⟨hW,?_⟩ - filter_upwards [ht,hx] with n hn h - refine ⟨hn.1.slide ?_ le_rfl (by unfold pins; omega) - (fun x=> mul_nonneg (raw_nonneg _ _) (raw_nonneg _ _)),fun i hi x hx=>?_⟩ - · unfold leafNew - linarith [hq.early.small,(Nat.cast_nonneg q.u : 0≤(q.u:ℝ)),(Nat.cast_nonneg q.s : 0≤(q.s:ℝ))] - obtain ⟨j,hj,hs,_⟩:=hn.2.1 i hi - exact (h.onTile j hj x (hs hx)).2.2.2 - refine ⟨t,h1,⟨hb.forecast,?_⟩,ht.mono fun i h j hj x hx=> (ht' i h).1 x ⟨j,hj,hx⟩, - d,hd,hZ.mono (fun i h => h _)⟩ - filter_upwards [ht,hx,hb.mark] with n hn he hm - intro i hi x hx - obtain ⟨j,hj,hs,hc,hh⟩:=hn.2.1 i hi - have hz : (t n).rooting x=(s n).rooting x := by - unfold LeafMixture.rooting - rw [LeafMixture.poller_eq (t n) hn.1.part hi hx,LeafMixture.poller_eq (s n) he.strength.part hj (hs hx), - hh] - have hH := hm j hj x (hs hx) (hc x hx) - unfold engrave seems at hH ⊢; rwa [hz] - -/-- Tiny cover exists after preparing retained mass, seen on -its support. Requires each old tile contain only original support. -/ -def nebulous (q : PreparationParameters) (l : Filter ℕ) (s : rhythms p M) (w : tale p M) (P : Campaign p M) - (b : Sketch p M) := - ∀ᶠ n in l,∃ T : Cov p (M*n),cdim p T≤q.d∧ - ∀ x,potion s w P n x≠0 → covered p T (delta (b.m n) x) - -theorem hideOn (h : nebulous q l s w P b) (hb : q.citable l p M m w s b P) - (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) : - ∀ᶠ n in l,∃ T : Cov p (M*n),cdim p T≤q.d∧∀ i ∈ (s n).T, - ∀ x∈i,P n x→covered p T (delta (b.m n) x) := by - classical - filter_upwards [hb.mass.positive,hx,h] with n hn h ht - obtain ⟨T,hT,hc⟩:=ht - refine ⟨T,hT,fun i hi x hx hp=> hc _ ?_⟩ - have hh := (h.onTile i hi x hx).1 - unfold potion - have hm : 0< (s n).amount (w n) := lt_of_lt_of_le (by norm_num) h.weight - have hv : (s n).sap (w n) x≠0 := by - unfold LeafMixture.sap allW - rw [onW_val,ind_one (show inTiles (s n).T x from ⟨i,hi,hx⟩),mul_one] - exact div_ne_zero hh hm.ne' - rw [onW_val,ind_one hp,mul_one]; exact div_ne_zero hv hn.ne' - -set_option maxHeartbeats 1800000 in -theorem pressHarvest (hl : l≤atTop) (hq : q.planted p M) - (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) - (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) - (hb : q.citable l p M m w s b P) - (hc : q.nebulous l s w P b) : - ∃ t : rhythms p M, durable q l p M m w t ∧ - q.bright l p M m t b ∧ - (∀ᶠ n in l,q.hardened p (M*n) (t n) (b.m n)) ∧ - ∃ d,ExpSmall l (fun n=> ((M*n:ℕ):ℝ)) d ∧ - ∀ᶠ n in l,charm s w P b n-d n ≤ glow t w b n := by - classical - let N (n:ℕ) := M*n; let z (n:ℕ):=((N n):ℝ) - let Y : Campaign p M := fun n=> inTiles (s n).T - let E := fun i => bp (-(z i)) + bp (-q.ζ*z i) - let R n (t : LeafMixture p n (M*n)) := t.strength (w n) (usual p (m n) (M*n)) - (q.leafOld+q.u+q.s+1) q.ζ q.pins ∧ pr (w n) (fun x=> Y n x ∧ P n x∧¬inTiles t.T x)≤ E n ∧ - ∃ T:Cov p (M*n), cdim p T ≤q.d ∧ - (∀ i∈(s n).T,∀ x∈i,P n x → covered p T (delta (b.m n) x)) ∧ - LeafMixture.elder (s n) t (P n) - (fun i j=> specialLeaf T (b.m n) ((s n).pin j) i (t.pin i)) - obtain ⟨t,ht⟩ : ∃ t: rhythms p M,∀ᶠ n in l,R n (t n) := by - refine taking ?_ - filter_upwards [hw,hx,hideOn hc hb hx,hq.wrap.filter_mono hl, - ((trend_sizes l hl hq.hM).1.eventually (eventually_gt_atTop 0)),hb.mark] - with n hn h ht hZ hN hh - obtain ⟨T,hT,hL⟩:=ht - have he := hq.early - have hf (i) (hi:i∈(s n).T) (x) (hx:x∈i) (hp:P n x) j : - b.m n x j∈effective ((s n).pin i).sp j := by - have hz : (s n).rooting x=((s n).pin i).sp := - congrArg Pin.sp (LeafMixture.poller_eq (s n) h.strength.part hi hx) - rw [←hz]; exact (((hh i hi x hx hp).1.1 j).2) - obtain ⟨t,h1,h2,h3⟩ := LeafMixture.elder_weave h.strength he.pos hn.law (P n) (b.m n) T - he.small hN (hZ.2.2.1 _) hT (fun i hi x hx hp=> ⟨hL i hi x hx hp,hf i hi x hx hp⟩) - he.bigS hZ.2.1 - exact ⟨t,h1,h3,T,hT,hL,h2⟩ - have hz : Tendsto z l atTop := (trend_sizes l hl hq.hM).2 - let Q : Campaign p M := fun n=> inTiles (t n).T - have ht' (i) : R i (t i) → (∀ x, Q i x → Y i x∧P i x) ∧ - pr (w i) (fun x=>Y i x∧P i x∧¬Q i x)≤E i := by - rintro ⟨h,h',T,hi,hz,hg⟩; exact ⟨fun x hx=> LeafMixture.ancestral hg hx,h'⟩ - have hE : ExpSmall l z E := by - unfold E - convert ((ExpSmall.bp_n zero_lt_one).add hz (ExpSmall.bp_n hq.early.pos)) using 1 - simp - obtain ⟨hW,d,hd,hZ⟩:= vigor_trim z hz w (hw.mono fun i h=>h.law.nz) - Y Q P hE (retainInitial hl hq hx).mass hb.mass - (ht.mono (fun i h=> ht' i h)) - have h1 : durable q l p M m w t := by - refine ⟨hW,?_⟩ - filter_upwards [ht,hx] with n hn h - obtain ⟨hi,_,T,hT,hC,hL⟩:=hn - refine ⟨hi.slide ?_ ?_ le_rfl - (fun x=> mul_nonneg (raw_nonneg _ _) (raw_nonneg _ _)),fun i hi x hx=>?_⟩ - · unfold leafNew; linarith - · linarith only [hq.early.pos] - obtain ⟨j,hj,hs,_⟩:=hL i hi - exact (h.onTile j hj x (hs hx)).2.2.2 - have he (i : ℕ) (h : q.entered p (M*i) (m i) (w i) (s i)) (j) (hj:j∈(s i).T) - (x) (hx:x∈j) : (s i).rooting x=((s i).pin j).sp := - congrArg Pin.sp (LeafMixture.poller_eq (s i) h.strength.part hj hx) - refine ⟨t,h1,⟨hb.forecast,?_⟩,?_,d,hd,hZ.mono (fun i h=>h _)⟩ - · filter_upwards [ht,hx,hb.mark] with n hn he' hm - intro i hi x hx - obtain ⟨hT,_,T,_,_,hL⟩:=hn - obtain ⟨j,hj,hs,hc,hV⟩:=hL i hi - have hz : (s n).rooting x≤(t n).rooting x := by - rw [he n he' j hj x (hs hx),LeafMixture.rooting,LeafMixture.poller_eq (t n) hT.part hi hx] - exact hV.1 - obtain ⟨⟨hE,hA⟩,he,hy⟩:=hm j hj x (hs hx) (hc x hx) - exact ⟨⟨fun i=>⟨(hE i).1,plan_inc_eff _ _ hz _ ((hE i).2)⟩,hA⟩,he,hy⟩ - · filter_upwards [ht,hx,hb.mark] with n hn he' hm - obtain ⟨hT,_,T,hC,hD,hL⟩:=hn - refine ⟨T,hC,fun i hi x hx=>?_,fun i hi=>?_⟩ - · obtain ⟨j,hj,hS,hE,_⟩:= hL i hi; exact hD j hj x (hS hx) (hE x hx) - obtain ⟨j,hj,hS,hE,hH⟩:= hL i hi - refine ⟨(s n).pin j,hH,fun x hx k=> ?_⟩ - rw [←he n he' j hj x (hS hx)] - exact (((hm j hj x (hS hx) (hE x hx)).1.1 k).2) - -end PreparationParameters -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PreparedOutcomes + +namespace OAI + +/-! # Prepared Population Trimming -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset +open scoped BigOperators Topology +open PredictionClass + +namespace PreparationParameters +variable {l : Filter ℕ} {p : Shape} {M : ℕ} {q : PreparationParameters} + {m : cycleM p} {s : rhythms p M} {w : tale p M} {b : Sketch p M} + +theorem retainInitial (hl : l≤atTop) (hq : q.planted p M) + (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) : + durable q l p M m w s := by + refine ⟨((warm.const (trend_sizes l hl hq.hM).2 (by norm_num : 0<(1/2:ℝ))).mono + (hx.mono fun i hi=> hi.weight)),?_⟩ + filter_upwards [hx] with n hn + have hh := hq.early + refine ⟨hn.strength.slide ?_ ?_ ?_ (fun x=> mul_nonneg (raw_nonneg _ _) (raw_nonneg _ _)), + fun i hi x hx => (hn.onTile i hi x hx).2.2.2⟩ + · unfold leafNew; linarith [(Nat.cast_nonneg q.u : 0≤(q.u:ℝ)),(Nat.cast_nonneg q.s : + 0≤(q.s:ℝ))] + · linarith only [hh.pos] + unfold pins; omega + +abbrev Campaign (p : Shape) (M : ℕ) := ∀ n,UnitType p n (M*n) → Prop +variable {P : Campaign p M} +structure citable (q : PreparationParameters) (l : Filter ℕ) (p : Shape) (M : ℕ) + (m : cycleM p) (w : tale p M) (s : rhythms p M) (b : Sketch p M) (P : Campaign p M) : Prop where + mass : warm l (fun i=> ((M*i:ℕ):ℝ)) (fun i=>pr ((s i).sap (w i)) (P i)) + forecast : ledger b l + mark : ∀ᶠ i in l, (s i).within (fun x => P i x → engrave b q m s i x) + +def potion (s : rhythms p M) (w : tale p M) (P : Campaign p M) : tale p M := + fun n => onW ((s n).sap (w n)) (P n) +def charm (s : rhythms p M) (w : tale p M) (P : Campaign p M) (b : Sketch p M) := + fun n => pr (pairW (potion s w P n) (potion s w P n)) (matchProg b n) + +theorem citable.on_law (h : citable q l p M m w s b P) + (hl : l ≤ atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) + (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) : + ∀ᶠ n in l, IsLaw (potion s w P n) := by + filter_upwards [h.mass.positive,hw,(retainInitial hl hq hx).mass.positive] with n hn ht hv + exact HadwigerCounterexample.on_law (LeafMixture.sapLaw hv ht.law).nz hn + +set_option maxHeartbeats 1400000 in +theorem dropHarvest (hl : l≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) + (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) + (hb : q.citable l p M m w s b P) : + ∃ t : rhythms p M, durable q l p M m w t ∧ + q.bright l p M m t b ∧ + (∀ᶠ n in l,(t n).within (fun x=>inTiles (s n).T x∧P n x)) ∧ + ∃ d,ExpSmall l (fun n=> ((M*n:ℕ):ℝ)) d ∧ + ∀ᶠ n in l,charm s w P b n-d n ≤ glow t w b n := by + classical + let N (n:ℕ) := M*n; let z n:=((N n):ℝ) + let Y : Campaign p M := fun n=> inTiles (s n).T + let E :=fun i=> bp (-q.ζ*z i) + let R n (t : LeafMixture p n (M*n)) := t.strength (w n) (usual p (m n) (M*n)) (q.leafOld+q.ζ) (2*q.ζ) q.e ∧ + LeafMixture.elder (s n) t (P n) (fun i j=> t.pin i=(s n).pin j) ∧ + pr (w n) (fun x=> Y n x ∧ P n x∧¬inTiles t.T x)≤ E n + obtain ⟨t,ht⟩ : ∃ t: rhythms p M,∀ᶠ n in l,R n (t n) := by + refine taking ?_ + filter_upwards [hw,hx] with n hn h + exact LeafMixture.elder_trim h.strength hq.early.pos.le hn.law _ + have hz := (trend_sizes l hl hq.hM).2 + let Q : Campaign p M := fun n=> inTiles (t n).T + have ht' (i) : R i (t i) → (∀ x, Q i x → Y i x∧P i x) ∧ + pr (w i) (fun x=>Y i x∧P i x∧¬Q i x)≤E i := fun h=>⟨fun x hx=>LeafMixture.ancestral h.2.1 hx,h.2.2⟩ + obtain ⟨hW,d,hd,hZ⟩:= vigor_trim z hz w (hw.mono fun i h=>h.law.nz) + Y Q P (ExpSmall.bp_n hq.early.pos) (retainInitial hl hq hx).mass hb.mass + (ht.mono (fun i h=> ht' i h)) + have h1 : durable q l p M m w t := by + refine ⟨hW,?_⟩ + filter_upwards [ht,hx] with n hn h + refine ⟨hn.1.slide ?_ le_rfl (by unfold pins; omega) + (fun x=> mul_nonneg (raw_nonneg _ _) (raw_nonneg _ _)),fun i hi x hx=>?_⟩ + · unfold leafNew + linarith [hq.early.small,(Nat.cast_nonneg q.u : 0≤(q.u:ℝ)),(Nat.cast_nonneg q.s : 0≤(q.s:ℝ))] + obtain ⟨j,hj,hs,_⟩:=hn.2.1 i hi + exact (h.onTile j hj x (hs hx)).2.2.2 + refine ⟨t,h1,⟨hb.forecast,?_⟩,ht.mono fun i h j hj x hx=> (ht' i h).1 x ⟨j,hj,hx⟩, + d,hd,hZ.mono (fun i h => h _)⟩ + filter_upwards [ht,hx,hb.mark] with n hn he hm + intro i hi x hx + obtain ⟨j,hj,hs,hc,hh⟩:=hn.2.1 i hi + have hz : (t n).rooting x=(s n).rooting x := by + unfold LeafMixture.rooting + rw [LeafMixture.poller_eq (t n) hn.1.part hi hx,LeafMixture.poller_eq (s n) he.strength.part hj (hs hx), + hh] + have hH := hm j hj x (hs hx) (hc x hx) + unfold engrave seems at hH ⊢; rwa [hz] + +/-- Tiny cover exists after preparing retained mass, seen on +its support. Requires each old tile contain only original support. -/ +def nebulous (q : PreparationParameters) (l : Filter ℕ) (s : rhythms p M) (w : tale p M) (P : Campaign p M) + (b : Sketch p M) := + ∀ᶠ n in l,∃ T : Cov p (M*n),cdim p T≤q.d∧ + ∀ x,potion s w P n x≠0 → covered p T (delta (b.m n) x) + +theorem hideOn (h : nebulous q l s w P b) (hb : q.citable l p M m w s b P) + (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) : + ∀ᶠ n in l,∃ T : Cov p (M*n),cdim p T≤q.d∧∀ i ∈ (s n).T, + ∀ x∈i,P n x→covered p T (delta (b.m n) x) := by + classical + filter_upwards [hb.mass.positive,hx,h] with n hn h ht + obtain ⟨T,hT,hc⟩:=ht + refine ⟨T,hT,fun i hi x hx hp=> hc _ ?_⟩ + have hh := (h.onTile i hi x hx).1 + unfold potion + have hm : 0< (s n).amount (w n) := lt_of_lt_of_le (by norm_num) h.weight + have hv : (s n).sap (w n) x≠0 := by + unfold LeafMixture.sap allW + rw [onW_val,ind_one (show inTiles (s n).T x from ⟨i,hi,hx⟩),mul_one] + exact div_ne_zero hh hm.ne' + rw [onW_val,ind_one hp,mul_one]; exact div_ne_zero hv hn.ne' + +set_option maxHeartbeats 1800000 in +theorem pressHarvest (hl : l≤atTop) (hq : q.planted p M) + (hw : ∀ᶠ n in l,q.nascent p (M*n) (w n) (m n)) + (hx : ∀ᶠ n in l,q.entered p (M*n) (m n) (w n) (s n)) + (hb : q.citable l p M m w s b P) + (hc : q.nebulous l s w P b) : + ∃ t : rhythms p M, durable q l p M m w t ∧ + q.bright l p M m t b ∧ + (∀ᶠ n in l,q.hardened p (M*n) (t n) (b.m n)) ∧ + ∃ d,ExpSmall l (fun n=> ((M*n:ℕ):ℝ)) d ∧ + ∀ᶠ n in l,charm s w P b n-d n ≤ glow t w b n := by + classical + let N (n:ℕ) := M*n; let z (n:ℕ):=((N n):ℝ) + let Y : Campaign p M := fun n=> inTiles (s n).T + let E := fun i => bp (-(z i)) + bp (-q.ζ*z i) + let R n (t : LeafMixture p n (M*n)) := t.strength (w n) (usual p (m n) (M*n)) + (q.leafOld+q.u+q.s+1) q.ζ q.pins ∧ pr (w n) (fun x=> Y n x ∧ P n x∧¬inTiles t.T x)≤ E n ∧ + ∃ T:Cov p (M*n), cdim p T ≤q.d ∧ + (∀ i∈(s n).T,∀ x∈i,P n x → covered p T (delta (b.m n) x)) ∧ + LeafMixture.elder (s n) t (P n) + (fun i j=> specialLeaf T (b.m n) ((s n).pin j) i (t.pin i)) + obtain ⟨t,ht⟩ : ∃ t: rhythms p M,∀ᶠ n in l,R n (t n) := by + refine taking ?_ + filter_upwards [hw,hx,hideOn hc hb hx,hq.wrap.filter_mono hl, + ((trend_sizes l hl hq.hM).1.eventually (eventually_gt_atTop 0)),hb.mark] + with n hn h ht hZ hN hh + obtain ⟨T,hT,hL⟩:=ht + have he := hq.early + have hf (i) (hi:i∈(s n).T) (x) (hx:x∈i) (hp:P n x) j : + b.m n x j∈effective ((s n).pin i).sp j := by + have hz : (s n).rooting x=((s n).pin i).sp := + congrArg Pin.sp (LeafMixture.poller_eq (s n) h.strength.part hi hx) + rw [←hz]; exact (((hh i hi x hx hp).1.1 j).2) + obtain ⟨t,h1,h2,h3⟩ := LeafMixture.elder_weave h.strength he.pos hn.law (P n) (b.m n) T + he.small hN (hZ.2.2.1 _) hT (fun i hi x hx hp=> ⟨hL i hi x hx hp,hf i hi x hx hp⟩) + he.bigS hZ.2.1 + exact ⟨t,h1,h3,T,hT,hL,h2⟩ + have hz : Tendsto z l atTop := (trend_sizes l hl hq.hM).2 + let Q : Campaign p M := fun n=> inTiles (t n).T + have ht' (i) : R i (t i) → (∀ x, Q i x → Y i x∧P i x) ∧ + pr (w i) (fun x=>Y i x∧P i x∧¬Q i x)≤E i := by + rintro ⟨h,h',T,hi,hz,hg⟩; exact ⟨fun x hx=> LeafMixture.ancestral hg hx,h'⟩ + have hE : ExpSmall l z E := by + unfold E + convert ((ExpSmall.bp_n zero_lt_one).add hz (ExpSmall.bp_n hq.early.pos)) using 1 + simp + obtain ⟨hW,d,hd,hZ⟩:= vigor_trim z hz w (hw.mono fun i h=>h.law.nz) + Y Q P hE (retainInitial hl hq hx).mass hb.mass + (ht.mono (fun i h=> ht' i h)) + have h1 : durable q l p M m w t := by + refine ⟨hW,?_⟩ + filter_upwards [ht,hx] with n hn h + obtain ⟨hi,_,T,hT,hC,hL⟩:=hn + refine ⟨hi.slide ?_ ?_ le_rfl + (fun x=> mul_nonneg (raw_nonneg _ _) (raw_nonneg _ _)),fun i hi x hx=>?_⟩ + · unfold leafNew; linarith + · linarith only [hq.early.pos] + obtain ⟨j,hj,hs,_⟩:=hL i hi + exact (h.onTile j hj x (hs hx)).2.2.2 + have he (i : ℕ) (h : q.entered p (M*i) (m i) (w i) (s i)) (j) (hj:j∈(s i).T) + (x) (hx:x∈j) : (s i).rooting x=((s i).pin j).sp := + congrArg Pin.sp (LeafMixture.poller_eq (s i) h.strength.part hj hx) + refine ⟨t,h1,⟨hb.forecast,?_⟩,?_,d,hd,hZ.mono (fun i h=>h _)⟩ + · filter_upwards [ht,hx,hb.mark] with n hn he' hm + intro i hi x hx + obtain ⟨hT,_,T,_,_,hL⟩:=hn + obtain ⟨j,hj,hs,hc,hV⟩:=hL i hi + have hz : (s n).rooting x≤(t n).rooting x := by + rw [he n he' j hj x (hs hx),LeafMixture.rooting,LeafMixture.poller_eq (t n) hT.part hi hx] + exact hV.1 + obtain ⟨⟨hE,hA⟩,he,hy⟩:=hm j hj x (hs hx) (hc x hx) + exact ⟨⟨fun i=>⟨(hE i).1,plan_inc_eff _ _ hz _ ((hE i).2)⟩,hA⟩,he,hy⟩ + · filter_upwards [ht,hx,hb.mark] with n hn he' hm + obtain ⟨hT,_,T,hC,hD,hL⟩:=hn + refine ⟨T,hC,fun i hi x hx=>?_,fun i hi=>?_⟩ + · obtain ⟨j,hj,hS,hE,_⟩:= hL i hi; exact hD j hj x (hS hx) (hE x hx) + obtain ⟨j,hj,hS,hE,hH⟩:= hL i hi + refine ⟨(s n).pin j,hH,fun x hx k=> ?_⟩ + rw [←he n he' j hj x (hS hx)] + exact (((hm j hj x (hS hx) (hE x hx)).1.1 k).2) + +end PreparationParameters +end HadwigerCounterexample + +end + +end OAI