diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PrimalChannelDecomposition.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PrimalChannelDecomposition.lean index b242d7ea44def76d44d81048fff0563fda72a3bf..99ea50abf53c34974dc3253a8b2d8e1b5cfa1f32 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PrimalChannelDecomposition.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PrimalChannelDecomposition.lean @@ -1,123 +1,123 @@ -import OAI.Combinatorics.HadwigerCounterexample.RealizationConditions - -namespace OAI - -/-! # Primal Channel Decomposition -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Submodule -variable {I : Type} [Fintype I] - -/-- Onto projection in coordinates, killing a specified disjoint subspace. -/ -structure ProjData (S T : Space (Vec I)) (A : Mat I I) : Prop where - onto (x) : A *ᵥ x ∈ S - fixes x : x ∈ S → A *ᵥ x=x - kills x : x∈T → A *ᵥ x=0 - -theorem proj_exists (S T : Space (Vec I)) (h : Disjoint S T) : - ∃ A, ProjData S T A := by - classical - obtain ⟨A,hA⟩ := mat_left_inv (inj_fromCols (pack_inj S) (pack_inj T) - (by rw [colSp_pack, colSp_pack]; exact h)) - let B := A.toRows₁ - let C := A.toRows₂ - have he : fromRows B C * fromCols (pack S) (pack T)=1 := by - rw [show fromRows B C=A from Matrix.fromRows_toRows A,hA] - rw [Matrix.fromRows_mul_fromCols, ← Matrix.fromBlocks_one] at he - have hb : B*pack S=1 := congrArg Matrix.toBlocks₁₁ he - have hg : B*pack T=0 := congrArg Matrix.toBlocks₁₂ he - refine ⟨pack S*B,fun x => ?_,fun x hx => ?_,fun x hx => ?_⟩ - · rw [←mulVec_mulVec] - exact (pack_mem_iff ..).mpr ⟨_,rfl⟩ - · obtain ⟨x,rfl⟩ := (pack_mem_iff ..).mp hx - rw [←mulVec_mulVec, mulVec_mulVec _ B, hb,one_mulVec] - · obtain ⟨x,rfl⟩ := (pack_mem_iff ..).mp hx - rw [←mulVec_mulVec,mulVec_mulVec _ B,hg,zero_mulVec,mulVec_zero] - -theorem rank_maps {J : Type} [Fintype J] {A : Mat I J} (S : Space (Vec I)) - (ha : ∀ x,A *ᵥ x∈ S) : A.rank ≤ dim S := - Submodule.finrank_mono (show colSp A ≤ S by - rintro x ⟨x,rfl⟩; exact ha x) - -theorem evmat_addM {J : Type} [Fintype J] (A B : Mat I J) (x y) : - evmat (A+B) x y = evmat A x y+evmat B x y := by rw [←mpair_outer,mpair_add, - mpair_outer,mpair_outer] - -theorem evmat_subM {J : Type} [Fintype J] (A B : Mat I J) (x y) : - evmat (A-B) x y = evmat A x y-evmat B x y := by - rw [ZModModule.sub_eq_add, ZModModule.sub_eq_add, evmat_addM] - -variable {p : Shape} {n : ℕ} - -/-- aggregate primal (resp. channel) directions in a unit. -/ -def primal (p : Shape) (n : ℕ) := colSp (IP p n true) ⊔ colSp (IP p n false) -def channels (p : Shape) (n : ℕ) := colSp (IH p n true) ⊔ colSp (IH p n false) - -theorem ip_le_primal (b : Bool) : colSp (IP p n b)≤primal p n := by - cases b; exact le_sup_right; exact le_sup_left - -theorem ih_le_channels (b : Bool) : colSp (IH p n b)≤channels p n := by - cases b; exact le_sup_right; exact le_sup_left - -theorem channels_proj (b : Bool) : channels p n ≤ LinearMap.ker (IP p n b)ᵀ.mulVecLin := by - have hi (i : Bool) : colSp (IH p n i) ≤ LinearMap.ker (IP p n b)ᵀ.mulVecLin := by - rintro x ⟨y,rfl⟩ - change (IP p n b)ᵀ *ᵥ (IH p n i *ᵥ y) = _ - rw [mulVec_mulVec, IP_IH, Matrix.zero_mulVec] - exact sup_le (hi _) (hi _) - -theorem primal_proj (b : Bool) : primal p n ≤ LinearMap.ker (IH p n b)ᵀ.mulVecLin := by - have hi (i : Bool) : colSp (IP p n i) ≤ LinearMap.ker (IH p n b)ᵀ.mulVecLin := by - rintro x ⟨y,rfl⟩ - change (IH p n b)ᵀ *ᵥ (IP p n i *ᵥ y) = _ - rw [mulVec_mulVec, IH_IP, Matrix.zero_mulVec] - exact sup_le (hi _) (hi _) - -theorem channels_disjoint : Disjoint (primal p n) (channels p n) := by - rw [disjoint_iff_inf_le] - rintro x ⟨hx,hy⟩ - have he (b : Bool) : (IP p n b)ᵀ *ᵥ x = 0 := channels_proj b hy - have hf (b : Bool) : (IH p n b)ᵀ *ᵥ x = 0 := primal_proj b hx - have hh := ip_decomp (show Dir p n from x) - simp_rw [he,hf,mulVec_zero,add_zero, Finset.sum_const_zero] at hh - rw [← hh] - exact Submodule.zero_mem _ - -/-- prSmall a z consists of the pure-primal coordinates kept by the small -table. -/ -def prSmall (a : Plan p n) (z : Place p) := - (sPin a z true).map (IP p n true).mulVecLin ⊔ - (sPin a z false).map (IP p n false).mulVecLin - -theorem prSmall_le (a : Plan p n) (z : Place p) : prSmall a z≤primal p n := by - apply sup_le_sup <;> rintro x ⟨x,h,rfl⟩ <;> exact ⟨x,rfl⟩ - -theorem prSmall_dim (a : Plan p n) (z : Place p) : - dim (prSmall a z)≤2 * planRank a := by - rw [two_mul] - have hh (i : Bool) : - dim ((sPin a z i).map (IP p n i).mulVecLin) ≤ planRank a := - (Submodule.finrank_map_le ..).trans ((sPin_dim ..).trans (dim_le_plan a z)) - exact (Submodule.finrank_add_le_finrank_add_finrank ..).trans (Nat.add_le_add (hh _) (hh _)) - -theorem prSmall_table (a : Plan p n) (z : Place p) : - tabSpace a z = prSmall a z ⊔ channels p n := by - unfold tabSpace halfTable prSmall channels - ac_rfl - -theorem keyPlane (v : Volley p n I) (t : Tagging p I) (z : Place p) : - v.keyPlan t z≤ primal p n := by - unfold Volley.keyPlan colSp - rw [range_mulVecLin] - apply Submodule.span_le.mpr - rintro x ⟨j,rfl⟩ - exact (show colSp (IP p n _) ≤ primal p n from ip_le_primal (v.obj j.val)) - (show v.rayLoc j.val∈colSp (IP p n _) from ⟨_,rfl⟩) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RealizationConditions + +namespace OAI + +/-! # Primal Channel Decomposition -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Submodule +variable {I : Type} [Fintype I] + +/-- Onto projection in coordinates, killing a specified disjoint subspace. -/ +structure ProjData (S T : Space (Vec I)) (A : Mat I I) : Prop where + onto (x) : A *ᵥ x ∈ S + fixes x : x ∈ S → A *ᵥ x=x + kills x : x∈T → A *ᵥ x=0 + +theorem proj_exists (S T : Space (Vec I)) (h : Disjoint S T) : + ∃ A, ProjData S T A := by + classical + obtain ⟨A,hA⟩ := mat_left_inv (inj_fromCols (pack_inj S) (pack_inj T) + (by rw [colSp_pack, colSp_pack]; exact h)) + let B := A.toRows₁ + let C := A.toRows₂ + have he : fromRows B C * fromCols (pack S) (pack T)=1 := by + rw [show fromRows B C=A from Matrix.fromRows_toRows A,hA] + rw [Matrix.fromRows_mul_fromCols, ← Matrix.fromBlocks_one] at he + have hb : B*pack S=1 := congrArg Matrix.toBlocks₁₁ he + have hg : B*pack T=0 := congrArg Matrix.toBlocks₁₂ he + refine ⟨pack S*B,fun x => ?_,fun x hx => ?_,fun x hx => ?_⟩ + · rw [←mulVec_mulVec] + exact (pack_mem_iff ..).mpr ⟨_,rfl⟩ + · obtain ⟨x,rfl⟩ := (pack_mem_iff ..).mp hx + rw [←mulVec_mulVec, mulVec_mulVec _ B, hb,one_mulVec] + · obtain ⟨x,rfl⟩ := (pack_mem_iff ..).mp hx + rw [←mulVec_mulVec,mulVec_mulVec _ B,hg,zero_mulVec,mulVec_zero] + +theorem rank_maps {J : Type} [Fintype J] {A : Mat I J} (S : Space (Vec I)) + (ha : ∀ x,A *ᵥ x∈ S) : A.rank ≤ dim S := + Submodule.finrank_mono (show colSp A ≤ S by + rintro x ⟨x,rfl⟩; exact ha x) + +theorem evmat_addM {J : Type} [Fintype J] (A B : Mat I J) (x y) : + evmat (A+B) x y = evmat A x y+evmat B x y := by rw [←mpair_outer,mpair_add, + mpair_outer,mpair_outer] + +theorem evmat_subM {J : Type} [Fintype J] (A B : Mat I J) (x y) : + evmat (A-B) x y = evmat A x y-evmat B x y := by + rw [ZModModule.sub_eq_add, ZModModule.sub_eq_add, evmat_addM] + +variable {p : Shape} {n : ℕ} + +/-- aggregate primal (resp. channel) directions in a unit. -/ +def primal (p : Shape) (n : ℕ) := colSp (IP p n true) ⊔ colSp (IP p n false) +def channels (p : Shape) (n : ℕ) := colSp (IH p n true) ⊔ colSp (IH p n false) + +theorem ip_le_primal (b : Bool) : colSp (IP p n b)≤primal p n := by + cases b; exact le_sup_right; exact le_sup_left + +theorem ih_le_channels (b : Bool) : colSp (IH p n b)≤channels p n := by + cases b; exact le_sup_right; exact le_sup_left + +theorem channels_proj (b : Bool) : channels p n ≤ LinearMap.ker (IP p n b)ᵀ.mulVecLin := by + have hi (i : Bool) : colSp (IH p n i) ≤ LinearMap.ker (IP p n b)ᵀ.mulVecLin := by + rintro x ⟨y,rfl⟩ + change (IP p n b)ᵀ *ᵥ (IH p n i *ᵥ y) = _ + rw [mulVec_mulVec, IP_IH, Matrix.zero_mulVec] + exact sup_le (hi _) (hi _) + +theorem primal_proj (b : Bool) : primal p n ≤ LinearMap.ker (IH p n b)ᵀ.mulVecLin := by + have hi (i : Bool) : colSp (IP p n i) ≤ LinearMap.ker (IH p n b)ᵀ.mulVecLin := by + rintro x ⟨y,rfl⟩ + change (IH p n b)ᵀ *ᵥ (IP p n i *ᵥ y) = _ + rw [mulVec_mulVec, IH_IP, Matrix.zero_mulVec] + exact sup_le (hi _) (hi _) + +theorem channels_disjoint : Disjoint (primal p n) (channels p n) := by + rw [disjoint_iff_inf_le] + rintro x ⟨hx,hy⟩ + have he (b : Bool) : (IP p n b)ᵀ *ᵥ x = 0 := channels_proj b hy + have hf (b : Bool) : (IH p n b)ᵀ *ᵥ x = 0 := primal_proj b hx + have hh := ip_decomp (show Dir p n from x) + simp_rw [he,hf,mulVec_zero,add_zero, Finset.sum_const_zero] at hh + rw [← hh] + exact Submodule.zero_mem _ + +/-- prSmall a z consists of the pure-primal coordinates kept by the small +table. -/ +def prSmall (a : Plan p n) (z : Place p) := + (sPin a z true).map (IP p n true).mulVecLin ⊔ + (sPin a z false).map (IP p n false).mulVecLin + +theorem prSmall_le (a : Plan p n) (z : Place p) : prSmall a z≤primal p n := by + apply sup_le_sup <;> rintro x ⟨x,h,rfl⟩ <;> exact ⟨x,rfl⟩ + +theorem prSmall_dim (a : Plan p n) (z : Place p) : + dim (prSmall a z)≤2 * planRank a := by + rw [two_mul] + have hh (i : Bool) : + dim ((sPin a z i).map (IP p n i).mulVecLin) ≤ planRank a := + (Submodule.finrank_map_le ..).trans ((sPin_dim ..).trans (dim_le_plan a z)) + exact (Submodule.finrank_add_le_finrank_add_finrank ..).trans (Nat.add_le_add (hh _) (hh _)) + +theorem prSmall_table (a : Plan p n) (z : Place p) : + tabSpace a z = prSmall a z ⊔ channels p n := by + unfold tabSpace halfTable prSmall channels + ac_rfl + +theorem keyPlane (v : Volley p n I) (t : Tagging p I) (z : Place p) : + v.keyPlan t z≤ primal p n := by + unfold Volley.keyPlan colSp + rw [range_mulVecLin] + apply Submodule.span_le.mpr + rintro x ⟨j,rfl⟩ + exact (show colSp (IP p n _) ≤ primal p n from ip_le_primal (v.obj j.val)) + (show v.rayLoc j.val∈colSp (IP p n _) from ⟨_,rfl⟩) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PrimalChannelTests.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PrimalChannelTests.lean index eb72d1f85c618651a504f5a4a45c38d167bd530f..18372c6f5b5e2778f0eef130f0276c7595c6e4d7 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PrimalChannelTests.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PrimalChannelTests.lean @@ -1,158 +1,158 @@ -import OAI.Combinatorics.HadwigerCounterexample.GramCharacterQuotients - -namespace OAI - -/-! # Primal Channel Tests -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Finset -open scoped BigOperators -variable {p : Shape} {n N : ℕ} - -private theorem cp_rep (f : Module.Dual F (Cross p n)) : - ∃ M : Cross p n,cpDual p M=f := by - classical - let B : Cross p n →ₗ[F] Module.Dual F (Cross p n) := { - toFun := cpDual p - map_add' := by - intro x y - refine LinearMap.ext fun w => ?_ - rw [LinearMap.add_apply] - simp only [cpDual_val,Pi.add_apply,mpair_add, Finset.sum_add_distrib] - map_smul' := by - intro a x - refine LinearMap.ext fun w => ?_ - rw [LinearMap.smul_apply] - simp only [cpDual_val,Pi.smul_apply,mpair_smul,RingHom.id_apply,smul_eq_mul,Finset.mul_sum] } - have hb : Function.Injective B := by - rw [← LinearMap.ker_eq_bot] - refine le_bot_iff.mp (fun x hx => ?_) - have h1 : x = 0 := by - funext i - apply mpair_nondeg - refine LinearMap.ext fun y => ?_ - change cpDual p x=0 at hx - have h := LinearMap.congr_fun hx (Pi.single i y) - rw [cpDual_val,Finset.sum_eq_single i] at h - · rwa [Pi.single_eq_same] at h - · intro j _ hj; simp [hj] - simp - rw [h1]; exact Submodule.zero_mem _ - exact rk_surj.mpr ((rk_inj.mp hb).trans Subspace.dual_finrank_eq.symm) f - -abbrev CheckOne (p : Shape) (n : ℕ) := - Place p → Bool → Bool → Mat (Chan p) (Row p n) -abbrev CheckGram (p : Shape) (n : ℕ) := - CheckOne p n × CheckOne p n -instance cgOneFin (p : Shape) (n : ℕ) : Fintype (CheckOne p n) := by - classical - letI : Fintype (Mat (Chan p) (Row p n)) := inferInstance - letI : Fintype (Bool → Bool → Mat (Chan p) (Row p n)) := inferInstance - exact inferInstance -instance cgFin (p : Shape) (n : ℕ) : Fintype (CheckGram p n) := inferInstance - -def testgram (p : Shape) {n} : Cross p n →ₗ[F] CheckGram p n where - toFun A := (scalarBlocks p A, scalarBlocks p (reciprocal p A)) - map_add' A B := by - apply Prod.ext <;> - · ext; simp only [Pi.add_apply,Prod.fst_add,Prod.snd_add, - scalarBlocks,channelOut,reciprocal,Matrix.add_apply,Matrix.add_mul,Matrix.transpose_add] - map_smul' a A := by - apply Prod.ext <;> - · ext; simp only [Pi.smul_apply,Prod.smul_fst,Prod.smul_snd, - scalarBlocks,channelOut,reciprocal,Matrix.smul_apply,Matrix.smul_mul,Matrix.transpose_smul, - RingHom.id_apply] - -theorem checkgram_dim : - dim (CheckGram p n)=16*ncComp p*p.h*Fintype.card (Row p n) := by - classical - let r := p.h*Fintype.card (Row p n) - let T := Mat (Chan p) (Row p n) - have hf : finrank F T=r := (dim_mat _ _).trans (by simp [r,Chan]) - have hg {I V : Type} [Fintype I] [AddCommGroup V] [Module F V] [FiniteDimensional F V] : - finrank F (I→V) = Fintype.card I * finrank F V := by - rw [finrank_pi_fintype]; simp - have h : finrank F (CheckOne p n)=8*ncComp p*r := by - unfold CheckOne - rw [hg,hg,hg,hf] - simp [ncComp,Place] - ring - unfold CheckGram dim - rw [Module.finrank_prod,h] - unfold r; ring - -theorem indicator_test {V A : Type} [Fintype A] [AddCommGroup V] [Module F V] - [Fintype V] (s : A → V) (w : Wgt A) (hw : IsLaw w) (ε : ℝ) (he : 0≤ε) - (hc : ∀ f : Module.Dual F V, let Y := avg w (fun x => wsign (f (s x))); Y=1 ∨ |Y|≤ε) : - bp (-(dim V:ℝ))- ε ≤ pr w (fun x => s x=0) := by - classical - let T := Module.Dual F V - have : Finite T := Finite.of_injective _ DFunLike.coe_injective - let : Fintype T := Fintype.ofFinite T - have h (v : V) : ind (v=0) = avg unif (fun f : T => wsign (f v)) := by - have h := wsign_lin (Module.evalEquiv F V v) - rw [map_eq_zero_iff _ (Module.evalEquiv F V).injective] at h - exact h.symm - unfold pr - simp_rw [h] - rw [avg_avg] - let E (v : T) := ind (v=0) - have hE : avg unif E = bp (-(dim V:ℝ)) := by - change pr unif (fun v : T => v=0)=_ - rw [pr_point',unif_apply,card_space, - show dim T=dim V from Subspace.dual_finrank_eq,bp_neg] - rw [← hE,show avg unif E - ε= avg unif (fun v : T => E v-ε) from (by - rw [avg_sub,unif_law.avg_const])] - refine avg_mono unif_law.nz fun x => ?_ - by_cases hh : x=0 - · subst x - change ind (0= (0:T))-ε ≤ avg w (fun _ => wsign 0) - rw [ind_one rfl,hw.avg_const,wsign_zero]; linarith - unfold E - rw [ind_zero hh,zero_sub] - rcases hc x with hi|hi - · rw [hi]; linarith - exact (abs_le.mp hi).1 - -theorem gram_hit (Q : 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)) - (hN : 100 ≤ N) (hT : (dim (CheckGram p n) : ℝ)≤0.01*N) : - hit N ≤ pr (pairW u w) (fun x => - testgram p (actual p x.1 x.2)=testgram p Q) := by - classical - let v := pairW u w - let s (x : UnitType p n N × UnitType p n N) := testgram p (actual p x.1 x.2 - Q) - have hh (g : Module.Dual F (CheckGram p n)) : - let Y := avg v (fun x => wsign (g (s x))) - Y=1 ∨ |Y|≤bp (-0.45*N) := by - obtain ⟨M,hM⟩ := cp_rep (g ∘ₗ testgram p) - have hf x := LinearMap.congr_fun hM x - have he x : g (s x) = cpDual p M _ := (hf (actual p x.1 x.2-Q)).symm - dsimp only - simp_rw [he] - exact gramCharacter Q M hu hw hc hd h - have hg := indicator_test s v (pairW_law hu hw) (bp (-0.45*N)) (bp_pos _).le hh - have he : pr v (fun x => s x=0)=pr v (fun x => testgram p (actual p x.1 x.2)=testgram p Q) := by - apply congrArg (pr v) - funext x; apply propext - unfold s - have he (A : Cross p n) : testgram p (A+Q) = testgram p A+testgram p Q := (testgram p).map_add' _ _ - rw [show actual p x.1 x.2-Q=actual p x.1 x.2+Q from ZModModule.sub_eq_add ..,he, ← ZModModule.sub_eq_add,sub_eq_zero] - rw [he] at hg - refine le_trans ?_ hg - have hn : 100≤(N:ℝ) := by exact_mod_cast hN - unfold hit - have heq := bp_le (show -0.45*N≤-0.02*(N:ℝ) by linarith only [hn]) - have heq' : 2*bp (-0.02*N) ≤ bp (-(dim (CheckGram p n):ℝ)) := by - rw [← bp_one,← bp_add]; apply bp_le; linarith only [hn,hT] - linarith only [heq,heq'] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.GramCharacterQuotients + +namespace OAI + +/-! # Primal Channel Tests -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} + +private theorem cp_rep (f : Module.Dual F (Cross p n)) : + ∃ M : Cross p n,cpDual p M=f := by + classical + let B : Cross p n →ₗ[F] Module.Dual F (Cross p n) := { + toFun := cpDual p + map_add' := by + intro x y + refine LinearMap.ext fun w => ?_ + rw [LinearMap.add_apply] + simp only [cpDual_val,Pi.add_apply,mpair_add, Finset.sum_add_distrib] + map_smul' := by + intro a x + refine LinearMap.ext fun w => ?_ + rw [LinearMap.smul_apply] + simp only [cpDual_val,Pi.smul_apply,mpair_smul,RingHom.id_apply,smul_eq_mul,Finset.mul_sum] } + have hb : Function.Injective B := by + rw [← LinearMap.ker_eq_bot] + refine le_bot_iff.mp (fun x hx => ?_) + have h1 : x = 0 := by + funext i + apply mpair_nondeg + refine LinearMap.ext fun y => ?_ + change cpDual p x=0 at hx + have h := LinearMap.congr_fun hx (Pi.single i y) + rw [cpDual_val,Finset.sum_eq_single i] at h + · rwa [Pi.single_eq_same] at h + · intro j _ hj; simp [hj] + simp + rw [h1]; exact Submodule.zero_mem _ + exact rk_surj.mpr ((rk_inj.mp hb).trans Subspace.dual_finrank_eq.symm) f + +abbrev CheckOne (p : Shape) (n : ℕ) := + Place p → Bool → Bool → Mat (Chan p) (Row p n) +abbrev CheckGram (p : Shape) (n : ℕ) := + CheckOne p n × CheckOne p n +instance cgOneFin (p : Shape) (n : ℕ) : Fintype (CheckOne p n) := by + classical + letI : Fintype (Mat (Chan p) (Row p n)) := inferInstance + letI : Fintype (Bool → Bool → Mat (Chan p) (Row p n)) := inferInstance + exact inferInstance +instance cgFin (p : Shape) (n : ℕ) : Fintype (CheckGram p n) := inferInstance + +def testgram (p : Shape) {n} : Cross p n →ₗ[F] CheckGram p n where + toFun A := (scalarBlocks p A, scalarBlocks p (reciprocal p A)) + map_add' A B := by + apply Prod.ext <;> + · ext; simp only [Pi.add_apply,Prod.fst_add,Prod.snd_add, + scalarBlocks,channelOut,reciprocal,Matrix.add_apply,Matrix.add_mul,Matrix.transpose_add] + map_smul' a A := by + apply Prod.ext <;> + · ext; simp only [Pi.smul_apply,Prod.smul_fst,Prod.smul_snd, + scalarBlocks,channelOut,reciprocal,Matrix.smul_apply,Matrix.smul_mul,Matrix.transpose_smul, + RingHom.id_apply] + +theorem checkgram_dim : + dim (CheckGram p n)=16*ncComp p*p.h*Fintype.card (Row p n) := by + classical + let r := p.h*Fintype.card (Row p n) + let T := Mat (Chan p) (Row p n) + have hf : finrank F T=r := (dim_mat _ _).trans (by simp [r,Chan]) + have hg {I V : Type} [Fintype I] [AddCommGroup V] [Module F V] [FiniteDimensional F V] : + finrank F (I→V) = Fintype.card I * finrank F V := by + rw [finrank_pi_fintype]; simp + have h : finrank F (CheckOne p n)=8*ncComp p*r := by + unfold CheckOne + rw [hg,hg,hg,hf] + simp [ncComp,Place] + ring + unfold CheckGram dim + rw [Module.finrank_prod,h] + unfold r; ring + +theorem indicator_test {V A : Type} [Fintype A] [AddCommGroup V] [Module F V] + [Fintype V] (s : A → V) (w : Wgt A) (hw : IsLaw w) (ε : ℝ) (he : 0≤ε) + (hc : ∀ f : Module.Dual F V, let Y := avg w (fun x => wsign (f (s x))); Y=1 ∨ |Y|≤ε) : + bp (-(dim V:ℝ))- ε ≤ pr w (fun x => s x=0) := by + classical + let T := Module.Dual F V + have : Finite T := Finite.of_injective _ DFunLike.coe_injective + let : Fintype T := Fintype.ofFinite T + have h (v : V) : ind (v=0) = avg unif (fun f : T => wsign (f v)) := by + have h := wsign_lin (Module.evalEquiv F V v) + rw [map_eq_zero_iff _ (Module.evalEquiv F V).injective] at h + exact h.symm + unfold pr + simp_rw [h] + rw [avg_avg] + let E (v : T) := ind (v=0) + have hE : avg unif E = bp (-(dim V:ℝ)) := by + change pr unif (fun v : T => v=0)=_ + rw [pr_point',unif_apply,card_space, + show dim T=dim V from Subspace.dual_finrank_eq,bp_neg] + rw [← hE,show avg unif E - ε= avg unif (fun v : T => E v-ε) from (by + rw [avg_sub,unif_law.avg_const])] + refine avg_mono unif_law.nz fun x => ?_ + by_cases hh : x=0 + · subst x + change ind (0= (0:T))-ε ≤ avg w (fun _ => wsign 0) + rw [ind_one rfl,hw.avg_const,wsign_zero]; linarith + unfold E + rw [ind_zero hh,zero_sub] + rcases hc x with hi|hi + · rw [hi]; linarith + exact (abs_le.mp hi).1 + +theorem gram_hit (Q : 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)) + (hN : 100 ≤ N) (hT : (dim (CheckGram p n) : ℝ)≤0.01*N) : + hit N ≤ pr (pairW u w) (fun x => + testgram p (actual p x.1 x.2)=testgram p Q) := by + classical + let v := pairW u w + let s (x : UnitType p n N × UnitType p n N) := testgram p (actual p x.1 x.2 - Q) + have hh (g : Module.Dual F (CheckGram p n)) : + let Y := avg v (fun x => wsign (g (s x))) + Y=1 ∨ |Y|≤bp (-0.45*N) := by + obtain ⟨M,hM⟩ := cp_rep (g ∘ₗ testgram p) + have hf x := LinearMap.congr_fun hM x + have he x : g (s x) = cpDual p M _ := (hf (actual p x.1 x.2-Q)).symm + dsimp only + simp_rw [he] + exact gramCharacter Q M hu hw hc hd h + have hg := indicator_test s v (pairW_law hu hw) (bp (-0.45*N)) (bp_pos _).le hh + have he : pr v (fun x => s x=0)=pr v (fun x => testgram p (actual p x.1 x.2)=testgram p Q) := by + apply congrArg (pr v) + funext x; apply propext + unfold s + have he (A : Cross p n) : testgram p (A+Q) = testgram p A+testgram p Q := (testgram p).map_add' _ _ + rw [show actual p x.1 x.2-Q=actual p x.1 x.2+Q from ZModModule.sub_eq_add ..,he, ← ZModModule.sub_eq_add,sub_eq_zero] + rw [he] at hg + refine le_trans ?_ hg + have hn : 100≤(N:ℝ) := by exact_mod_cast hN + unfold hit + have heq := bp_le (show -0.45*N≤-0.02*(N:ℝ) by linarith only [hn]) + have heq' : 2*bp (-0.02*N) ≤ bp (-(dim (CheckGram p n):ℝ)) := by + rw [← bp_one,← bp_add]; apply bp_le; linarith only [hn,hT] + linarith only [heq,heq'] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/PrimalSpaceCompression.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/PrimalSpaceCompression.lean index b95b0bfb658118736499ceec04ad757f97b3c92d..c6a7f3b18d818c8d30af88f0d10564355143ff70 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/PrimalSpaceCompression.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/PrimalSpaceCompression.lean @@ -1,199 +1,199 @@ -import OAI.Combinatorics.HadwigerCounterexample.RankEfficientDecomposition - -namespace OAI - -/-! # Primal Space Compression -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Finset -open scoped BigOperators -variable {p : Shape} {n : ℕ} {I J : Type} [Fintype I] [Fintype J] - -private theorem exists_cover (S : J→Space (Vec I)) (D : ℕ) (h : ∀ j,dim (S j)≤D) : - ∃ A : Space (Vec I),(∀ j,S j ≤ A) ∧ dim A≤Fintype.card J*D := by - classical - have hh (s : Finset J) : - ∃ A : Space (Vec I),(∀ j∈s,S j≤A) ∧ dim A≤s.card*D := by - induction s using Finset.induction with - | empty => exact ⟨⊥,by simp, by simp [dim]⟩ - | insert a s ha ih => - obtain ⟨A,hA,hD⟩ := ih - refine ⟨S a⊔A,fun j hj => ?_,?_⟩ - · rcases Finset.mem_insert.mp hj with rfl|g - · exact le_sup_left - exact (hA _ g).trans le_sup_right - simpa only [Finset.card_insert_of_notMem ha,Nat.add_mul,one_mul,add_comm D] using - ((Submodule.finrank_add_le_finrank_add_finrank (S a) A).trans (add_le_add (h a) hD)) - simpa only [Finset.mem_univ,true_imp_iff,card_univ] using hh Finset.univ - -theorem compact_endo (S T : Space (Vec I)) : - ∃ A : Mat I I,(∀ x∈S,A *ᵥ x=x) ∧ (∀ x∈T,Aᵀ *ᵥ x=x) ∧ A.rank≤dim S+dim T := by - classical - obtain ⟨A,hA⟩ := proj_exists S ⊥ disjoint_bot_right - obtain ⟨B,hB⟩ := proj_exists T ⊥ disjoint_bot_right - refine ⟨A+Bᵀ * (1-A),fun x hx => ?_,fun x hx => ?_,?_⟩ - · rw [Matrix.add_mulVec,←Matrix.mulVec_mulVec,Matrix.sub_mulVec,hA.fixes x hx, - Matrix.one_mulVec,sub_self,Matrix.mulVec_zero,add_zero] - · rw [Matrix.transpose_add,Matrix.add_mulVec,Matrix.transpose_mul,Matrix.transpose_transpose, - ← mulVec_mulVec,hB.fixes x hx,Matrix.transpose_sub,Matrix.sub_mulVec,Matrix.transpose_one, - Matrix.one_mulVec,add_sub_cancel] - exact (mrk_add_le ..).trans (add_le_add (rank_maps S hA.onto) ((Matrix.rank_mul_le_left ..).trans - (by rw [Matrix.rank_transpose]; exact rank_maps T hB.onto))) - -abbrev Sel (p : Shape) := SelIdx p.b p.j -abbrev Nendo (p : Shape) (n : ℕ) := Block p.g→ Mat (Fin n) (Fin n) -def iFix (p : Shape) (n : ℕ) : Mat (Row p n) (Sel p) := embedMat (fun s => (s,none)) -def iCoeff (p : Shape) (n : ℕ) (s : Sel p) (d : Block p.g) : - Mat (Row p n) (Fin n) := embedMat (fun i => (s,some (d,i))) - -/-- induced row vector transform. -/ -def rowShrink (p : Shape) {n} (A : Nendo p n) : Mat (Row p n) (Row p n) := - iFix p n*(iFix p n)ᵀ + - ∑ i : Sel p,∑ d : Block p.g,iCoeff p n i d*A d*(iCoeff p n i d)ᵀ - -def readCoeff (p : Shape) {n} (s : Sel p) (d : Block p.g) (v : Ray p n) := - fun i => v (s,some (d,i)) - -theorem readCoeff_val (s : Sel p) (d : Block p.g) (v : Ray p n) : - (iCoeff p n s d)ᵀ *ᵥ v=readCoeff p s d v := embedMatT _ _ - -theorem shrink_transpose (A : Nendo p n) : - (rowShrink p A)ᵀ=rowShrink p (fun i => (A i)ᵀ) := by - simp only [rowShrink,Matrix.transpose_add,Matrix.transpose_mul, - Matrix.transpose_sum,Matrix.transpose_transpose,Matrix.mul_assoc] - -private theorem coeff_none (A : Nendo p n) (v : Ray p n) (s : Sel p) : - (rowShrink p A *ᵥ v) (s,none)=v (s,none) := by - classical - simp only [rowShrink,Matrix.add_mulVec, Matrix.sum_mulVec,←Matrix.mulVec_mulVec,readCoeff_val] - unfold iFix iCoeff - rw [embedMatT] - simp [embedMat,Matrix.mulVec,dotProduct,Finset.sum_apply,Matrix.mul_apply] - -set_option maxHeartbeats 600000 in -private theorem coeff_some (A : Nendo p n) (v : Ray p n) (s : Sel p) - (d : Block p.g) (i : Fin n) : - (rowShrink p A *ᵥ v) (s,some (d,i))=(A d *ᵥ (readCoeff p s d v)) i := by - classical - simp only [rowShrink,Matrix.add_mulVec, Matrix.sum_mulVec,←Matrix.mulVec_mulVec,readCoeff_val] - simp only [Pi.add_apply,Finset.sum_apply] - have hz (x) : (iFix p n *ᵥ x) (s,some (d,i))=0 := by - simp [iFix,embedMat,Matrix.mulVec,dotProduct] - rw [hz,zero_add] - have hh (t : Sel p) (a : Block p.g) (x : Vec (Fin n)) : - (iCoeff p n t a *ᵥ x) (s,some (d,i)) = - if s=t then (if d=a then x i else 0) else 0 := by - by_cases e : s=t <;> by_cases g : d=a <;> simp [iCoeff,embedMat,Matrix.mulVec,dotProduct,e,g] - simp_rw [hh] - rw [Finset.sum_eq_single s] - · simp only [ite_true,Finset.sum_ite_eq,mem_univ] - · intro a _ ha; simp only [ite_eq_right (Ne.symm ha),Finset.sum_const_zero] - simp - -private theorem coeff_fixes (A : Nendo p n) (v : Ray p n) - (h : ∀ d s, A d *ᵥ (readCoeff p s d v) = readCoeff p s d v) : - rowShrink p A *ᵥ v=v := by - funext i - rcases i with ⟨s, _|⟨d,i⟩⟩ - · rw [coeff_none] - rw [coeff_some,h] - rfl - -def nbBlock (p : Shape) := Fintype.card (Block p.g) -def ncComp (p : Shape) := Fintype.card (Comp p.g) - -theorem shrink_rank (A : Nendo p n) (D : ℕ) (h : ∀ i,(A i).rank ≤ D) : - (rowShrink p A).rank≤ psize p+ psize p* (nbBlock p*D) := by - apply le_trans (mrk_add_le ..) - apply add_le_add - · exact (Matrix.rank_mul_le_left ..).trans (iFix p n).rank_le_card_width - refine (mrk_sum_le ..).trans ((Finset.sum_le_sum (g:=fun _ => nbBlock p*D) (fun i _ => ?_)).trans_eq - (by simp [psize,Sel])) - refine (mrk_sum_le ..).trans ((Finset.sum_le_sum (g:=fun _ => D) (fun i _ => ?_)).trans_eq - (by simp [nbBlock])) - exact ((Matrix.rank_mul_le_left ..).trans (Matrix.rank_mul_le_right ..)).trans (h i) - -def dbits (p : Shape) (T R : ℕ) := ncComp p*2* psize p*(T+R) -def drow (p : Shape) (T R : ℕ) := psize p+psize p*(nbBlock p*dbits p T R) - -theorem shrink_both (S T : Place p → Space (Ray p n)) (K R : ℕ) - (hk : ∀ z,dim (S z) ≤K) (hr : ∀ z,dim (T z)≤R) : - ∃ A : Nendo p n, - (∀ z,∀ x∈S z,rowShrink p A *ᵥ x=x) ∧ - (∀ z,∀ x∈T z,(rowShrink p A)ᵀ *ᵥ x=x) ∧ - (rowShrink p A).rank ≤ drow p K R := by - classical - let W := Place p×Sel p - have hp : Fintype.card (Place p×Sel p)=ncComp p*2*psize p := by - simp only [Place,Fintype.card_prod,ncComp,Fintype.card_bool,psize,Sel] - let G d (S : Place p → Space (Ray p n)) (z : Place p×Sel p) := - (S z.1).map (iCoeff p n z.2 d)ᵀ.mulVecLin - obtain ⟨A,hA,hT,hL⟩ : - ∃ A : Nendo p n, - (∀ d z,∀ x∈G d S z,A d *ᵥ x=x) ∧ - (∀ d z,∀ x∈G d T z,(A d)ᵀ *ᵥ x=x) ∧ ∀ i,(A i).rank≤dbits p K R := by - have he (d : Block p.g) : - ∃ A : Mat (Fin n) (Fin n), (∀ z,∀ x∈G d S z,A *ᵥ x=x) ∧ - (∀ z,∀ x∈G d T z,Aᵀ *ᵥ x=x) ∧ A.rank≤dbits p K R := by - obtain ⟨X,hX,hD⟩ := exists_cover (G d S) K (fun j => (Submodule.finrank_map_le ..).trans - (hk j.1)) - obtain ⟨Y,hY,hD'⟩ := exists_cover (G d T) R (fun j => (Submodule.finrank_map_le ..).trans - (hr j.1)) - obtain ⟨A,hA,hZ,hL⟩ := compact_endo X Y - refine ⟨A,(fun z x hx => hA x (hX z hx)),(fun z x hx => hZ x (hY z hx)),?_⟩ - rw [hp] at hD hD' - exact hL.trans ((add_le_add hD hD').trans_eq (Nat.mul_add ..).symm) - choose A hA hZ hL using he - exact ⟨A,hA,hZ,hL⟩ - have he (X : Place p → Space (Ray p n)) (z) - (x : Ray p n) (hx : x∈X z) (d s) : readCoeff p s d x∈ G d X (z,s) := - ⟨x,hx,readCoeff_val ..⟩ - refine ⟨A,fun z x hx => ?_,fun z x hx => ?_,shrink_rank A _ hL⟩ - · exact coeff_fixes A x (fun d s => hA _ (z,s) _ (he S z x hx d s)) - rw [shrink_transpose] - exact coeff_fixes _ _ (fun d s => hT _ (z,s) _ (he T z x hx d s)) - -private def shrinkBase (A : Nendo p n) (v : Base p.g n) : Base p.g n := - fun x => (A x.1 *ᵥ (fun j => v (x.1,j))) x.2 - -private theorem shrink_point (A : Nendo p n) (s : Label p.b) (z : Base p.g n) : - rowShrink p A *ᵥ point p s z=point p s (shrinkBase (p:=p) A z) := by - classical - funext i - rcases i with ⟨r,_|⟨d,i⟩⟩ - · rw [coeff_none]; rfl - rw [coeff_some] - simp only [point_eval,readCoeff,shrinkBase,Matrix.mulVec,dotProduct, - baseV,Option.elim',Finset.mul_sum] - exact Finset.sum_congr rfl fun i _ => mul_left_comm .. - -private theorem shrink_tag (A : Nendo p n) (l : Tag p.g) (M : Moment p n) (h : M∈Wtag p n l) : - liftM (rowShrink p A) (rowShrink p A) M∈Wtag p n l := by - classical - unfold Wtag at h - induction h using Submodule.span_induction with - | mem m hm => - obtain ⟨s,z,hz,rfl⟩ := hm - simp only [mom,liftM_outer,shrink_point] - apply Submodule.subset_span - refine ⟨s,shrinkBase (p:=p) A z,?_,rfl⟩ - intro d t hd i - change (A (Block.O d t) *ᵥ _) i = _ - simp only [Matrix.mulVec,dotProduct,hz _ _ hd,mul_zero,Finset.sum_const_zero] - | zero => rw [map_zero]; exact Submodule.zero_mem _ - | add x y hx hy ih ih' => rw [map_add]; exact Submodule.add_mem _ ih ih' - | smul a x hx ih => rw [map_smul]; exact Submodule.smul_mem _ _ ih - -theorem shrink_X (A : Nendo p n) (M : Profile p n) (h : M∈Xspace p n) : - (fun e : Comp p.g => liftM (rowShrink p A) (rowShrink p A) (M e))∈Xspace p n := by - obtain ⟨w,hw,rfl⟩ := mem_X.mp h - refine mem_X.mpr ⟨_,(fun l => shrink_tag A l _ (hw l)),?_⟩ - funext i - exact (map_add (liftM (rowShrink p A) (rowShrink p A)) _ _).symm - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RankEfficientDecomposition + +namespace OAI + +/-! # Primal Space Compression -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Finset +open scoped BigOperators +variable {p : Shape} {n : ℕ} {I J : Type} [Fintype I] [Fintype J] + +private theorem exists_cover (S : J→Space (Vec I)) (D : ℕ) (h : ∀ j,dim (S j)≤D) : + ∃ A : Space (Vec I),(∀ j,S j ≤ A) ∧ dim A≤Fintype.card J*D := by + classical + have hh (s : Finset J) : + ∃ A : Space (Vec I),(∀ j∈s,S j≤A) ∧ dim A≤s.card*D := by + induction s using Finset.induction with + | empty => exact ⟨⊥,by simp, by simp [dim]⟩ + | insert a s ha ih => + obtain ⟨A,hA,hD⟩ := ih + refine ⟨S a⊔A,fun j hj => ?_,?_⟩ + · rcases Finset.mem_insert.mp hj with rfl|g + · exact le_sup_left + exact (hA _ g).trans le_sup_right + simpa only [Finset.card_insert_of_notMem ha,Nat.add_mul,one_mul,add_comm D] using + ((Submodule.finrank_add_le_finrank_add_finrank (S a) A).trans (add_le_add (h a) hD)) + simpa only [Finset.mem_univ,true_imp_iff,card_univ] using hh Finset.univ + +theorem compact_endo (S T : Space (Vec I)) : + ∃ A : Mat I I,(∀ x∈S,A *ᵥ x=x) ∧ (∀ x∈T,Aᵀ *ᵥ x=x) ∧ A.rank≤dim S+dim T := by + classical + obtain ⟨A,hA⟩ := proj_exists S ⊥ disjoint_bot_right + obtain ⟨B,hB⟩ := proj_exists T ⊥ disjoint_bot_right + refine ⟨A+Bᵀ * (1-A),fun x hx => ?_,fun x hx => ?_,?_⟩ + · rw [Matrix.add_mulVec,←Matrix.mulVec_mulVec,Matrix.sub_mulVec,hA.fixes x hx, + Matrix.one_mulVec,sub_self,Matrix.mulVec_zero,add_zero] + · rw [Matrix.transpose_add,Matrix.add_mulVec,Matrix.transpose_mul,Matrix.transpose_transpose, + ← mulVec_mulVec,hB.fixes x hx,Matrix.transpose_sub,Matrix.sub_mulVec,Matrix.transpose_one, + Matrix.one_mulVec,add_sub_cancel] + exact (mrk_add_le ..).trans (add_le_add (rank_maps S hA.onto) ((Matrix.rank_mul_le_left ..).trans + (by rw [Matrix.rank_transpose]; exact rank_maps T hB.onto))) + +abbrev Sel (p : Shape) := SelIdx p.b p.j +abbrev Nendo (p : Shape) (n : ℕ) := Block p.g→ Mat (Fin n) (Fin n) +def iFix (p : Shape) (n : ℕ) : Mat (Row p n) (Sel p) := embedMat (fun s => (s,none)) +def iCoeff (p : Shape) (n : ℕ) (s : Sel p) (d : Block p.g) : + Mat (Row p n) (Fin n) := embedMat (fun i => (s,some (d,i))) + +/-- induced row vector transform. -/ +def rowShrink (p : Shape) {n} (A : Nendo p n) : Mat (Row p n) (Row p n) := + iFix p n*(iFix p n)ᵀ + + ∑ i : Sel p,∑ d : Block p.g,iCoeff p n i d*A d*(iCoeff p n i d)ᵀ + +def readCoeff (p : Shape) {n} (s : Sel p) (d : Block p.g) (v : Ray p n) := + fun i => v (s,some (d,i)) + +theorem readCoeff_val (s : Sel p) (d : Block p.g) (v : Ray p n) : + (iCoeff p n s d)ᵀ *ᵥ v=readCoeff p s d v := embedMatT _ _ + +theorem shrink_transpose (A : Nendo p n) : + (rowShrink p A)ᵀ=rowShrink p (fun i => (A i)ᵀ) := by + simp only [rowShrink,Matrix.transpose_add,Matrix.transpose_mul, + Matrix.transpose_sum,Matrix.transpose_transpose,Matrix.mul_assoc] + +private theorem coeff_none (A : Nendo p n) (v : Ray p n) (s : Sel p) : + (rowShrink p A *ᵥ v) (s,none)=v (s,none) := by + classical + simp only [rowShrink,Matrix.add_mulVec, Matrix.sum_mulVec,←Matrix.mulVec_mulVec,readCoeff_val] + unfold iFix iCoeff + rw [embedMatT] + simp [embedMat,Matrix.mulVec,dotProduct,Finset.sum_apply,Matrix.mul_apply] + +set_option maxHeartbeats 600000 in +private theorem coeff_some (A : Nendo p n) (v : Ray p n) (s : Sel p) + (d : Block p.g) (i : Fin n) : + (rowShrink p A *ᵥ v) (s,some (d,i))=(A d *ᵥ (readCoeff p s d v)) i := by + classical + simp only [rowShrink,Matrix.add_mulVec, Matrix.sum_mulVec,←Matrix.mulVec_mulVec,readCoeff_val] + simp only [Pi.add_apply,Finset.sum_apply] + have hz (x) : (iFix p n *ᵥ x) (s,some (d,i))=0 := by + simp [iFix,embedMat,Matrix.mulVec,dotProduct] + rw [hz,zero_add] + have hh (t : Sel p) (a : Block p.g) (x : Vec (Fin n)) : + (iCoeff p n t a *ᵥ x) (s,some (d,i)) = + if s=t then (if d=a then x i else 0) else 0 := by + by_cases e : s=t <;> by_cases g : d=a <;> simp [iCoeff,embedMat,Matrix.mulVec,dotProduct,e,g] + simp_rw [hh] + rw [Finset.sum_eq_single s] + · simp only [ite_true,Finset.sum_ite_eq,mem_univ] + · intro a _ ha; simp only [ite_eq_right (Ne.symm ha),Finset.sum_const_zero] + simp + +private theorem coeff_fixes (A : Nendo p n) (v : Ray p n) + (h : ∀ d s, A d *ᵥ (readCoeff p s d v) = readCoeff p s d v) : + rowShrink p A *ᵥ v=v := by + funext i + rcases i with ⟨s, _|⟨d,i⟩⟩ + · rw [coeff_none] + rw [coeff_some,h] + rfl + +def nbBlock (p : Shape) := Fintype.card (Block p.g) +def ncComp (p : Shape) := Fintype.card (Comp p.g) + +theorem shrink_rank (A : Nendo p n) (D : ℕ) (h : ∀ i,(A i).rank ≤ D) : + (rowShrink p A).rank≤ psize p+ psize p* (nbBlock p*D) := by + apply le_trans (mrk_add_le ..) + apply add_le_add + · exact (Matrix.rank_mul_le_left ..).trans (iFix p n).rank_le_card_width + refine (mrk_sum_le ..).trans ((Finset.sum_le_sum (g:=fun _ => nbBlock p*D) (fun i _ => ?_)).trans_eq + (by simp [psize,Sel])) + refine (mrk_sum_le ..).trans ((Finset.sum_le_sum (g:=fun _ => D) (fun i _ => ?_)).trans_eq + (by simp [nbBlock])) + exact ((Matrix.rank_mul_le_left ..).trans (Matrix.rank_mul_le_right ..)).trans (h i) + +def dbits (p : Shape) (T R : ℕ) := ncComp p*2* psize p*(T+R) +def drow (p : Shape) (T R : ℕ) := psize p+psize p*(nbBlock p*dbits p T R) + +theorem shrink_both (S T : Place p → Space (Ray p n)) (K R : ℕ) + (hk : ∀ z,dim (S z) ≤K) (hr : ∀ z,dim (T z)≤R) : + ∃ A : Nendo p n, + (∀ z,∀ x∈S z,rowShrink p A *ᵥ x=x) ∧ + (∀ z,∀ x∈T z,(rowShrink p A)ᵀ *ᵥ x=x) ∧ + (rowShrink p A).rank ≤ drow p K R := by + classical + let W := Place p×Sel p + have hp : Fintype.card (Place p×Sel p)=ncComp p*2*psize p := by + simp only [Place,Fintype.card_prod,ncComp,Fintype.card_bool,psize,Sel] + let G d (S : Place p → Space (Ray p n)) (z : Place p×Sel p) := + (S z.1).map (iCoeff p n z.2 d)ᵀ.mulVecLin + obtain ⟨A,hA,hT,hL⟩ : + ∃ A : Nendo p n, + (∀ d z,∀ x∈G d S z,A d *ᵥ x=x) ∧ + (∀ d z,∀ x∈G d T z,(A d)ᵀ *ᵥ x=x) ∧ ∀ i,(A i).rank≤dbits p K R := by + have he (d : Block p.g) : + ∃ A : Mat (Fin n) (Fin n), (∀ z,∀ x∈G d S z,A *ᵥ x=x) ∧ + (∀ z,∀ x∈G d T z,Aᵀ *ᵥ x=x) ∧ A.rank≤dbits p K R := by + obtain ⟨X,hX,hD⟩ := exists_cover (G d S) K (fun j => (Submodule.finrank_map_le ..).trans + (hk j.1)) + obtain ⟨Y,hY,hD'⟩ := exists_cover (G d T) R (fun j => (Submodule.finrank_map_le ..).trans + (hr j.1)) + obtain ⟨A,hA,hZ,hL⟩ := compact_endo X Y + refine ⟨A,(fun z x hx => hA x (hX z hx)),(fun z x hx => hZ x (hY z hx)),?_⟩ + rw [hp] at hD hD' + exact hL.trans ((add_le_add hD hD').trans_eq (Nat.mul_add ..).symm) + choose A hA hZ hL using he + exact ⟨A,hA,hZ,hL⟩ + have he (X : Place p → Space (Ray p n)) (z) + (x : Ray p n) (hx : x∈X z) (d s) : readCoeff p s d x∈ G d X (z,s) := + ⟨x,hx,readCoeff_val ..⟩ + refine ⟨A,fun z x hx => ?_,fun z x hx => ?_,shrink_rank A _ hL⟩ + · exact coeff_fixes A x (fun d s => hA _ (z,s) _ (he S z x hx d s)) + rw [shrink_transpose] + exact coeff_fixes _ _ (fun d s => hT _ (z,s) _ (he T z x hx d s)) + +private def shrinkBase (A : Nendo p n) (v : Base p.g n) : Base p.g n := + fun x => (A x.1 *ᵥ (fun j => v (x.1,j))) x.2 + +private theorem shrink_point (A : Nendo p n) (s : Label p.b) (z : Base p.g n) : + rowShrink p A *ᵥ point p s z=point p s (shrinkBase (p:=p) A z) := by + classical + funext i + rcases i with ⟨r,_|⟨d,i⟩⟩ + · rw [coeff_none]; rfl + rw [coeff_some] + simp only [point_eval,readCoeff,shrinkBase,Matrix.mulVec,dotProduct, + baseV,Option.elim',Finset.mul_sum] + exact Finset.sum_congr rfl fun i _ => mul_left_comm .. + +private theorem shrink_tag (A : Nendo p n) (l : Tag p.g) (M : Moment p n) (h : M∈Wtag p n l) : + liftM (rowShrink p A) (rowShrink p A) M∈Wtag p n l := by + classical + unfold Wtag at h + induction h using Submodule.span_induction with + | mem m hm => + obtain ⟨s,z,hz,rfl⟩ := hm + simp only [mom,liftM_outer,shrink_point] + apply Submodule.subset_span + refine ⟨s,shrinkBase (p:=p) A z,?_,rfl⟩ + intro d t hd i + change (A (Block.O d t) *ᵥ _) i = _ + simp only [Matrix.mulVec,dotProduct,hz _ _ hd,mul_zero,Finset.sum_const_zero] + | zero => rw [map_zero]; exact Submodule.zero_mem _ + | add x y hx hy ih ih' => rw [map_add]; exact Submodule.add_mem _ ih ih' + | smul a x hx ih => rw [map_smul]; exact Submodule.smul_mem _ _ ih + +theorem shrink_X (A : Nendo p n) (M : Profile p n) (h : M∈Xspace p n) : + (fun e : Comp p.g => liftM (rowShrink p A) (rowShrink p A) (M e))∈Xspace p n := by + obtain ⟨w,hw,rfl⟩ := mem_X.mp h + refine mem_X.mpr ⟨_,(fun l => shrink_tag A l _ (hw l)),?_⟩ + funext i + exact (map_add (liftM (rowShrink p A) (rowShrink p A)) _ _).symm + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ProbePointMasses.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ProbePointMasses.lean index 6855b2fdb67e8533097bc1ef759168cf8d70e1c9..a1e84e5bb7d41bad7baf500b0df14ba386c5d422 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ProbePointMasses.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ProbePointMasses.lean @@ -1,208 +1,208 @@ -import OAI.Combinatorics.HadwigerCounterexample.OffsetEnergy - -namespace OAI - -/-! # Probe Point Masses -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Module Submodule LinearMap Finset Function -variable {p : Shape} {n N : ℕ} {q t : Place p→ℕ} - -def initCap (p : Shape) {n} (N : ℕ) (m : Mixer p n) (ε : ℝ) := - ∀ a : Pin p n N,pr (pairW (raw m N) (raw m N)) a.agree ≤ fee N ε (planRank a.sp) - -def bySide (p : Shape) {n N} (w : Wgt (UnitType p n N)) - (m : Mixer p n) (c : ℝ) := - ∀ i x, mapW w (fun y => onSide y i) x ≤ c*raw m N x - -theorem side_same {A : Type} [Fintype A] (i : Bool) (w : Wgt A) (hw : IsLaw w) - (v : Wgt (A × A)) {H : ℝ} - (h : ∀ x,mapW v (fun x => onSide x i) x≤H * w x) - (P : A×A→Prop) (he : ∀ x y,onSide x i=onSide y i → (P x↔P y)) : - pr v P ≤ H * pr (pairW w w) P := by - classical - let Q := fun x => P (x,x) - have hq : P=fun x => Q (onSide x i) := by - funext x; exact propext (he x _ (by cases i <;> rfl)) - rw [hq,←mapW_pr v (fun x => onSide x i) Q] - refine (pr_cap h Q).trans_eq ?_ - have hh : pr (pairW w w) (fun x => Q (onSide x i)) = pr w Q := by - cases i - · change pr (pairW w w) (fun x => Q x.2)=pr w Q - simpa only [true_and, pr_true,hw.total,one_mul] using pairW_pr w w (fun _ => True) Q - change pr (pairW w w) (fun x => Q x.1)=pr w Q - simpa only [and_true,pr_true,hw.total,mul_one] using pairW_pr w w Q (fun _ => True) - rw [hh] - -def basisFrom (p : Shape) {n N} (x : UnitType p n N) (i : Bool) - {q : Place p→ℕ} (Z : DTuple (p:=p) q N) := - ∀ z,Injective (Z z).mulVec ∧ colSp (Z z) ≤ imageP p x i (flipZ p z) - -def ctot (p : Shape) (r : Place p→ℕ) := ∑ i,r i -abbrev Among (p : Shape) (n : ℕ) (q : Place p→ℕ) := - ∀ z, Mat (Row p n) (Fin (q z)) -def csignal (p : Shape) {n} (i : Bool) {q : Place p → ℕ} - (S : Among p n q) : WTuple (p:=p) q n := - fun z => IP p n i * S z - -def poke (p : Shape) {n N} {q t : Place p → ℕ} - (B : WTuple (p:=p) q n) (C : WTuple (p:=p) t n) - (Z : DTuple (p:=p) q N) (A : DTuple (p:=p) t N) - (x : UnitType p n N) := - ∀ z, images x (flipZ p z) * B z=Z z ∧ images x z * C z = A z - -set_option maxHeartbeats 600000 in -theorem poke_cap (B : WTuple (p:=p) q n) (C : WTuple (p:=p) t n) - (Z : DTuple (p:=p) q N) (A : DTuple (p:=p) t N) - (m : Mixer p n) {ε : ℝ} (he : initCap p N m ε) - (hB : ∀ z, Injective (B z).mulVec) - (hC : ∀ z, Injective (C z).mulVec) - (hD : ∀ z, Disjoint (colSp (B z)) (colSp (C (flipZ p z)))) : - pr (pairW (raw m N) (raw m N)) (poke p B C Z A) ≤ - fee N ε (ctot p q+ctot p t) := by - classical - let μ := raw m N - let w := pairW μ μ - have hw (x) : 0 ≤ w x := mul_nonneg (raw_nonneg m _) (raw_nonneg m _) - by_cases h : 0 < pr w (poke p B C Z A) - · obtain ⟨x,hx,_⟩ := exists_of_pr_pos hw h - let U : Plan p n := fun z => colSp (B (flipZ p z)) ⊔ colSp (C z) - let V := Pin.make U x - refine (pr_mono hw (q:=V.agree) fun y hy => ?_).trans ((he V).trans ?_) - · intro z v hv - change images y z *ᵥ v=images x z *ᵥ v - obtain ⟨l,⟨t,rfl⟩,r,⟨u,rfl⟩,rfl⟩ := Submodule.mem_sup.mp - (show v∈colSp (B (flipZ p z))⊔colSp (C z) from hv) - have h1 := (hx (flipZ p z)).1.trans (hy (flipZ p z)).1.symm - simp only [flipZ_flip] at h1 - simp only [mulVecLin_apply, Matrix.mulVec_add, Matrix.mulVec_mulVec,h1, - (hx z).2,(hy z).2] - · have hF (z) : dim (U z)=q (flipZ p z)+t z := by - have hi := Submodule.finrank_sup_add_finrank_inf_eq (colSp (B (flipZ p z))) (colSp (C z)) - have hy := hD (flipZ p z) - rw [flipZ_flip] at hy - rw [hy.eq_bot,finrank_bot,add_zero] at hi - exact hi.trans (congrArg₂ (·+·) ((mrk_inj.mp (hB (flipZ p z))).trans (Fintype.card_fin _)) - ((mrk_inj.mp (hC z)).trans (Fintype.card_fin _))) - have ht : planRank V.sp=ctot p q+ctot p t := by - unfold planRank ctot - change ∑ z,dim (U z)= _ - simp_rw [hF,Finset.sum_add_distrib] - exact congrArg (fun x => x + ∑ z,t z) (Equiv.sum_comp (flipEquiv p) q) - rw [ht] - exact (not_lt.mp h).trans (bp_pos _).le - -def heatRate (p : Shape) (n N : ℕ) (ε : ℝ) (x y : ℕ) := - bp (num (Row p n)* x+ 2*p.h*y)*fee N ε (x+y) - -instance amongFintype (p : Shape) (n : ℕ) (r : Place p→ℕ) : Fintype (Among p n r) := by - classical exact inferInstanceAs (Fintype (Among p n r)) - -private theorem format_size : - num (Among p n q × (Bool → DTuple (p:=p) t p.h)) = - bp (num (Row p n)*ctot p q+2*p.h*ctot p t) := by - classical - unfold num - rw [card_space,dim,Module.finrank_prod, Nat.cast_add] - have he : finrank F (Among p n q)=Fintype.card (Row p n)*ctot p q := by - unfold Among - rw [finrank_pi_fintype] - unfold ctot; rw [Finset.mul_sum] - refine Finset.sum_congr rfl fun i _ => (dim_mat ..).trans (by rw [Fintype.card_fin]) - have hf : - finrank F (Bool → DTuple (p:=p) t p.h)=2*p.h*ctot p t := by - rw [finrank_pi_fintype,Fintype.sum_bool] - change dim (DTuple ..)+dim (DTuple ..)=_ - rw [tuple_dim] - unfold ctot; ring - rw [he,hf] - push_cast; rfl - -set_option maxHeartbeats 800000 in -theorem heat_rate (i : Bool) (S : Party) (hi : S i=1) - (A : DTuple (p:=p) t N) - (B : DTuple (p:=p) t N) (Z : DTuple (p:=p) q N) - (m : Mixer p n) {ε : ℝ} (he : initCap p N m ε) : - pr (pairW (raw m N) (raw m N)) (fun x => - basisFrom p x i Z ∧ glimpse p x i A ∧ thermal p x S A=B) - ≤ heatRate p n N ε (ctot p q) (ctot p t) := by - classical - let M := Among p n q × (Bool → DTuple (p:=p) t p.h) - let P (v : M) (x : UnitType p n N) := - let X := csignal p i v.1 - let Y := hfused p n _ v.2 - (∀ z, Injective (X z).mulVec ∧ Injective (Y z).mulVec) ∧ poke p X Y Z B x - let w := pairW (raw m N) (raw m N) - have hw x : 0 ≤ w x := mul_nonneg (raw_nonneg m _) (raw_nonneg m _) - have h : ∀ x : UnitType p n N,basisFrom p x i Z ∧ glimpse p x i A ∧ thermal p x S A=B → - ∃ v, P v x := by - rintro x ⟨hF,hT,hU⟩ - choose A' hA using fun z => pull_cols (fpAt p (onSide x i) (flipZ p z)) (Z z) (hF z).2 - let C := sparks p x S A - let Y := hfused p n _ C - let X := csignal p i A' - have hh z : images x (flipZ p z)*X z=Z z := by - unfold X csignal - rw [← Matrix.mul_assoc, images_ip] - exact hA z - refine ⟨(A',C),fun z => ⟨?_,hotfused x S A i hi hT z⟩, fun z => ?_⟩ - · have hg := (hF z).1 - rw [← hh z] at hg - intro p' q he - apply hg - change X z *ᵥ p' = X z*ᵥ q at he - rw [← Matrix.mulVec_mulVec,← Matrix.mulVec_mulVec,he] - exact ⟨hh z,(fuse_val x S A z).trans (congr_fun hU z)⟩ - have hg (v : M) : - pr w (P v) ≤ fee N ε (ctot p q+ctot p t) := by - let X := csignal p i v.1 - let Y := hfused p n _ v.2 - by_cases hh : ∀ z, Injective (X z).mulVec ∧ Injective (Y z).mulVec - · refine (pr_mono hw (p:=P v) (q:=poke p X Y Z B) fun x h => h.2).trans - (poke_cap X Y _ _ m he (fun z => (hh z).1) (fun z => (hh z).2) ?_) - intro z - exact (channels_disjoint (p:=p) (n:=n)).mono - ((col_follow ..).trans (ip_le_primal i)) (fused_support v.2 _) - have heq : P v=(fun _ => False) := funext fun x => propext (iff_false_intro (fun h => hh h.1)) - rw [heq,pr_false]; exact (bp_pos _).le - refine ((pr_mono hw h).trans (pr_exists_le hw P)).trans ?_ - refine (Finset.sum_le_sum fun i _ => hg i).trans_eq ?_ - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - change num (Among p n q × _) *_= _ - rw [format_size]; rfl - -theorem heat_one (i : Bool) - (A : DTuple (p:=p) t N) (B : DTuple (p:=p) t N) - (Z : DTuple (p:=p) q N) - {w : Wgt (UnitType p n N)} {H : ℝ} (hH : 0 ≤ H) - (m : Mixer p n) {ε : ℝ} (hm : IsLaw (raw m N)) (he : initCap p N m ε) - (hw : bySide p w m H) : - pr w (fun x => basisFrom p x i Z ∧ glimpse p x i A ∧ thermal p x (unary i) A=B) ≤ - H*heatRate p n N ε (ctot p q) (ctot p t) := by - refine (side_same i _ hm w (hw i) _ ?_).trans - (mul_le_mul_of_nonneg_left (heat_rate i (unary i) (by simp [unary]) A B Z m he) hH) - intro x y h - unfold basisFrom glimpse thermal imageP - simp_rw [heat_unary,h] - -theorem heat_none (i : Bool) (Z : DTuple (p:=p) q N) - {w : Wgt (UnitType p n N)} {H : ℝ} (hH : 0 ≤ H) - (m : Mixer p n) {ε : ℝ} (hm : IsLaw (raw m N)) (he : initCap p N m ε) - (hw : bySide p w m H) : - pr w (fun x => basisFrom p x i Z) ≤ H*heatRate p n N ε (ctot p q) 0 := by - classical - let t : Place p→ℕ := fun _ => 0 - let B : DTuple (p:=p) t N := 0 - have hh := heat_one i B B Z hH m hm he hw - have h1 (x : UnitType p n N) : glimpse p x i B := fun z v v' h => Subsingleton.elim v v' - have h2 (x : UnitType p n N) : thermal p x (unary i) B=B := Subsingleton.elim _ _ - simp_rw [h1,h2,and_true] at hh - simpa only [ctot,t,Finset.sum_const_zero] using hh - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.OffsetEnergy + +namespace OAI + +/-! # Probe Point Masses -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Module Submodule LinearMap Finset Function +variable {p : Shape} {n N : ℕ} {q t : Place p→ℕ} + +def initCap (p : Shape) {n} (N : ℕ) (m : Mixer p n) (ε : ℝ) := + ∀ a : Pin p n N,pr (pairW (raw m N) (raw m N)) a.agree ≤ fee N ε (planRank a.sp) + +def bySide (p : Shape) {n N} (w : Wgt (UnitType p n N)) + (m : Mixer p n) (c : ℝ) := + ∀ i x, mapW w (fun y => onSide y i) x ≤ c*raw m N x + +theorem side_same {A : Type} [Fintype A] (i : Bool) (w : Wgt A) (hw : IsLaw w) + (v : Wgt (A × A)) {H : ℝ} + (h : ∀ x,mapW v (fun x => onSide x i) x≤H * w x) + (P : A×A→Prop) (he : ∀ x y,onSide x i=onSide y i → (P x↔P y)) : + pr v P ≤ H * pr (pairW w w) P := by + classical + let Q := fun x => P (x,x) + have hq : P=fun x => Q (onSide x i) := by + funext x; exact propext (he x _ (by cases i <;> rfl)) + rw [hq,←mapW_pr v (fun x => onSide x i) Q] + refine (pr_cap h Q).trans_eq ?_ + have hh : pr (pairW w w) (fun x => Q (onSide x i)) = pr w Q := by + cases i + · change pr (pairW w w) (fun x => Q x.2)=pr w Q + simpa only [true_and, pr_true,hw.total,one_mul] using pairW_pr w w (fun _ => True) Q + change pr (pairW w w) (fun x => Q x.1)=pr w Q + simpa only [and_true,pr_true,hw.total,mul_one] using pairW_pr w w Q (fun _ => True) + rw [hh] + +def basisFrom (p : Shape) {n N} (x : UnitType p n N) (i : Bool) + {q : Place p→ℕ} (Z : DTuple (p:=p) q N) := + ∀ z,Injective (Z z).mulVec ∧ colSp (Z z) ≤ imageP p x i (flipZ p z) + +def ctot (p : Shape) (r : Place p→ℕ) := ∑ i,r i +abbrev Among (p : Shape) (n : ℕ) (q : Place p→ℕ) := + ∀ z, Mat (Row p n) (Fin (q z)) +def csignal (p : Shape) {n} (i : Bool) {q : Place p → ℕ} + (S : Among p n q) : WTuple (p:=p) q n := + fun z => IP p n i * S z + +def poke (p : Shape) {n N} {q t : Place p → ℕ} + (B : WTuple (p:=p) q n) (C : WTuple (p:=p) t n) + (Z : DTuple (p:=p) q N) (A : DTuple (p:=p) t N) + (x : UnitType p n N) := + ∀ z, images x (flipZ p z) * B z=Z z ∧ images x z * C z = A z + +set_option maxHeartbeats 600000 in +theorem poke_cap (B : WTuple (p:=p) q n) (C : WTuple (p:=p) t n) + (Z : DTuple (p:=p) q N) (A : DTuple (p:=p) t N) + (m : Mixer p n) {ε : ℝ} (he : initCap p N m ε) + (hB : ∀ z, Injective (B z).mulVec) + (hC : ∀ z, Injective (C z).mulVec) + (hD : ∀ z, Disjoint (colSp (B z)) (colSp (C (flipZ p z)))) : + pr (pairW (raw m N) (raw m N)) (poke p B C Z A) ≤ + fee N ε (ctot p q+ctot p t) := by + classical + let μ := raw m N + let w := pairW μ μ + have hw (x) : 0 ≤ w x := mul_nonneg (raw_nonneg m _) (raw_nonneg m _) + by_cases h : 0 < pr w (poke p B C Z A) + · obtain ⟨x,hx,_⟩ := exists_of_pr_pos hw h + let U : Plan p n := fun z => colSp (B (flipZ p z)) ⊔ colSp (C z) + let V := Pin.make U x + refine (pr_mono hw (q:=V.agree) fun y hy => ?_).trans ((he V).trans ?_) + · intro z v hv + change images y z *ᵥ v=images x z *ᵥ v + obtain ⟨l,⟨t,rfl⟩,r,⟨u,rfl⟩,rfl⟩ := Submodule.mem_sup.mp + (show v∈colSp (B (flipZ p z))⊔colSp (C z) from hv) + have h1 := (hx (flipZ p z)).1.trans (hy (flipZ p z)).1.symm + simp only [flipZ_flip] at h1 + simp only [mulVecLin_apply, Matrix.mulVec_add, Matrix.mulVec_mulVec,h1, + (hx z).2,(hy z).2] + · have hF (z) : dim (U z)=q (flipZ p z)+t z := by + have hi := Submodule.finrank_sup_add_finrank_inf_eq (colSp (B (flipZ p z))) (colSp (C z)) + have hy := hD (flipZ p z) + rw [flipZ_flip] at hy + rw [hy.eq_bot,finrank_bot,add_zero] at hi + exact hi.trans (congrArg₂ (·+·) ((mrk_inj.mp (hB (flipZ p z))).trans (Fintype.card_fin _)) + ((mrk_inj.mp (hC z)).trans (Fintype.card_fin _))) + have ht : planRank V.sp=ctot p q+ctot p t := by + unfold planRank ctot + change ∑ z,dim (U z)= _ + simp_rw [hF,Finset.sum_add_distrib] + exact congrArg (fun x => x + ∑ z,t z) (Equiv.sum_comp (flipEquiv p) q) + rw [ht] + exact (not_lt.mp h).trans (bp_pos _).le + +def heatRate (p : Shape) (n N : ℕ) (ε : ℝ) (x y : ℕ) := + bp (num (Row p n)* x+ 2*p.h*y)*fee N ε (x+y) + +instance amongFintype (p : Shape) (n : ℕ) (r : Place p→ℕ) : Fintype (Among p n r) := by + classical exact inferInstanceAs (Fintype (Among p n r)) + +private theorem format_size : + num (Among p n q × (Bool → DTuple (p:=p) t p.h)) = + bp (num (Row p n)*ctot p q+2*p.h*ctot p t) := by + classical + unfold num + rw [card_space,dim,Module.finrank_prod, Nat.cast_add] + have he : finrank F (Among p n q)=Fintype.card (Row p n)*ctot p q := by + unfold Among + rw [finrank_pi_fintype] + unfold ctot; rw [Finset.mul_sum] + refine Finset.sum_congr rfl fun i _ => (dim_mat ..).trans (by rw [Fintype.card_fin]) + have hf : + finrank F (Bool → DTuple (p:=p) t p.h)=2*p.h*ctot p t := by + rw [finrank_pi_fintype,Fintype.sum_bool] + change dim (DTuple ..)+dim (DTuple ..)=_ + rw [tuple_dim] + unfold ctot; ring + rw [he,hf] + push_cast; rfl + +set_option maxHeartbeats 800000 in +theorem heat_rate (i : Bool) (S : Party) (hi : S i=1) + (A : DTuple (p:=p) t N) + (B : DTuple (p:=p) t N) (Z : DTuple (p:=p) q N) + (m : Mixer p n) {ε : ℝ} (he : initCap p N m ε) : + pr (pairW (raw m N) (raw m N)) (fun x => + basisFrom p x i Z ∧ glimpse p x i A ∧ thermal p x S A=B) + ≤ heatRate p n N ε (ctot p q) (ctot p t) := by + classical + let M := Among p n q × (Bool → DTuple (p:=p) t p.h) + let P (v : M) (x : UnitType p n N) := + let X := csignal p i v.1 + let Y := hfused p n _ v.2 + (∀ z, Injective (X z).mulVec ∧ Injective (Y z).mulVec) ∧ poke p X Y Z B x + let w := pairW (raw m N) (raw m N) + have hw x : 0 ≤ w x := mul_nonneg (raw_nonneg m _) (raw_nonneg m _) + have h : ∀ x : UnitType p n N,basisFrom p x i Z ∧ glimpse p x i A ∧ thermal p x S A=B → + ∃ v, P v x := by + rintro x ⟨hF,hT,hU⟩ + choose A' hA using fun z => pull_cols (fpAt p (onSide x i) (flipZ p z)) (Z z) (hF z).2 + let C := sparks p x S A + let Y := hfused p n _ C + let X := csignal p i A' + have hh z : images x (flipZ p z)*X z=Z z := by + unfold X csignal + rw [← Matrix.mul_assoc, images_ip] + exact hA z + refine ⟨(A',C),fun z => ⟨?_,hotfused x S A i hi hT z⟩, fun z => ?_⟩ + · have hg := (hF z).1 + rw [← hh z] at hg + intro p' q he + apply hg + change X z *ᵥ p' = X z*ᵥ q at he + rw [← Matrix.mulVec_mulVec,← Matrix.mulVec_mulVec,he] + exact ⟨hh z,(fuse_val x S A z).trans (congr_fun hU z)⟩ + have hg (v : M) : + pr w (P v) ≤ fee N ε (ctot p q+ctot p t) := by + let X := csignal p i v.1 + let Y := hfused p n _ v.2 + by_cases hh : ∀ z, Injective (X z).mulVec ∧ Injective (Y z).mulVec + · refine (pr_mono hw (p:=P v) (q:=poke p X Y Z B) fun x h => h.2).trans + (poke_cap X Y _ _ m he (fun z => (hh z).1) (fun z => (hh z).2) ?_) + intro z + exact (channels_disjoint (p:=p) (n:=n)).mono + ((col_follow ..).trans (ip_le_primal i)) (fused_support v.2 _) + have heq : P v=(fun _ => False) := funext fun x => propext (iff_false_intro (fun h => hh h.1)) + rw [heq,pr_false]; exact (bp_pos _).le + refine ((pr_mono hw h).trans (pr_exists_le hw P)).trans ?_ + refine (Finset.sum_le_sum fun i _ => hg i).trans_eq ?_ + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + change num (Among p n q × _) *_= _ + rw [format_size]; rfl + +theorem heat_one (i : Bool) + (A : DTuple (p:=p) t N) (B : DTuple (p:=p) t N) + (Z : DTuple (p:=p) q N) + {w : Wgt (UnitType p n N)} {H : ℝ} (hH : 0 ≤ H) + (m : Mixer p n) {ε : ℝ} (hm : IsLaw (raw m N)) (he : initCap p N m ε) + (hw : bySide p w m H) : + pr w (fun x => basisFrom p x i Z ∧ glimpse p x i A ∧ thermal p x (unary i) A=B) ≤ + H*heatRate p n N ε (ctot p q) (ctot p t) := by + refine (side_same i _ hm w (hw i) _ ?_).trans + (mul_le_mul_of_nonneg_left (heat_rate i (unary i) (by simp [unary]) A B Z m he) hH) + intro x y h + unfold basisFrom glimpse thermal imageP + simp_rw [heat_unary,h] + +theorem heat_none (i : Bool) (Z : DTuple (p:=p) q N) + {w : Wgt (UnitType p n N)} {H : ℝ} (hH : 0 ≤ H) + (m : Mixer p n) {ε : ℝ} (hm : IsLaw (raw m N)) (he : initCap p N m ε) + (hw : bySide p w m H) : + pr w (fun x => basisFrom p x i Z) ≤ H*heatRate p n N ε (ctot p q) 0 := by + classical + let t : Place p→ℕ := fun _ => 0 + let B : DTuple (p:=p) t N := 0 + have hh := heat_one i B B Z hH m hm he hw + have h1 (x : UnitType p n N) : glimpse p x i B := fun z v v' h => Subsingleton.elim v v' + have h2 (x : UnitType p n N) : thermal p x (unary i) B=B := Subsingleton.elim _ _ + simp_rw [h1,h2,and_true] at hh + simpa only [ctot,t,Finset.sum_const_zero] using hh + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ProductCharacterTests.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ProductCharacterTests.lean index c2b4827097b055e3dc504de3112cbf43a323f4e1..222f266260678e8d67f6d5d681b8bb7d247b4b17 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ProductCharacterTests.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ProductCharacterTests.lean @@ -1,135 +1,135 @@ -import OAI.Combinatorics.HadwigerCounterexample.ConditionedCorrelations - -namespace OAI - -/-! # Product Character Tests -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Filter Function -open scoped BigOperators -variable {I J A Z D : Type} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] -variable [Fintype A] - -def Pipe (P : A→Z→ ℝ) := - ∃ (f : A→ℝ) (g : Z→ℝ),(∀ i, |f i|≤1) ∧ (∀ i, |g i|≤1) ∧ ∀ x y,P x y=f x*g y - -omit [Fintype I] [Fintype A] in -private theorem pipe_prod (s : Finset I) (P : I → A→Z→ℝ) - (h : ∀ i∈s,Pipe (P i)) : - Pipe (fun x y => ∏ i∈s,P i x y) := by - classical - induction s using Finset.induction_on with - | empty => - exact ⟨fun _ =>1,fun _=>1,(by simp),(by simp),fun _ _=>by simp⟩ - | @insert i s hi ih => - obtain ⟨f,g,hf,hg,hH⟩ := h i (by simp) - obtain ⟨u,v,hu,hv,hU⟩ := ih (fun j hj => h j (mem_insert_of_mem hj)) - have he (f g : ℝ) (hf : |f|≤1) (hg : |g|≤1) : - |f*g|≤1 := by rw [abs_mul]; exact (mul_le_mul hf hg (abs_nonneg _) zero_le_one).trans_eq - (by ring) - exact ⟨fun x => f x*u x,fun x => g x*v x,(fun x=>he _ _ (hf x) (hu x)), - (fun x => he _ _ (hg x) (hv x)),fun x y => by dsimp only at *; rw [prod_insert hi,hH,hU]; ring⟩ - -structure Stage (I J : Type) where - first : J→I - nextP : J→I - diff k : first k ≠ nextP k - once k j : first k=first j → nextP k=nextP j → k=j - anti k j : first k=nextP j → nextP k≠first j - -variable (s : Stage I J) - -set_option maxHeartbeats 600000 in -theorem far_avg (w : I→Wgt A) (hw : ∀ i,IsLaw (w i)) (F : Wgt (I→A)) (i j : I) - (_ : i ≠ j) : - let U := prodW w - avg U F = avg U (fun x => avg (pairW (w i) (w j)) (fun y => F (update (update x i y.1) j y.2))) := by - classical - intro U - rw [update_avg w j F (hw j),update_avg w i _ (hw i)] - simp only [U,pairW_avg] -private def moveInputs (i j : I) (x : I→A) (p q : A) := update (update x i p) j q - -set_option maxHeartbeats 800000 in -theorem band_res (w : I→ Wgt A) (hw : ∀ i,IsLaw (w i)) - (f : I→ Wgt A) (hf : ∀ i x,|f i x|≤1) - (u : J→ A→ A→ℝ) (hu : ∀ k x y,|u k x y|≤1) - (k : J) (η : ℝ) - (h : ∀ p q : Wgt A,(∀ i, |p i|≤1)→(∀ i,|q i|≤1) → - |avg (pairW (w (s.first k)) (w (s.nextP k))) (fun x => - u k x.1 x.2 * (p x.1*q x.2))|≤η) : - |avg (prodW w) (fun x => (∏ j:J,u j (x (s.first j)) (x (s.nextP j)))*prodW f x)|≤η := by - classical - let i:=s.first k; let j:=s.nextP k - have hj : i≠ j := s.diff k - let W (x : I→ A) := (∏ j':J,u j' (x (s.first j')) (x (s.nextP j')))*prodW f x - have hi (z : I→A) : - |avg (pairW (w i) (w j)) (fun x => W (moveInputs i j z x.1 x.2))|≤ η := by - let C a b := moveInputs i j z a b - let g (v : J⊕I) (a b : A) := - match v with - | .inl t => if t=k then 1 else u t (C a b (s.first t)) (C a b (s.nextP t)) - | .inr t => f t (C a b t) - have he a b : - W (C a b)=u k a b * ∏ l:J ⊕ I,g l a b := by - unfold W prodW; rw [Fintype.prod_sum_type] - rw [← mul_prod_erase _ _ (mem_univ k),←mul_prod_erase _ - (fun t:J=>g (.inl t) a b) (mem_univ k)] - have he (t:J) (h : t∈univ.erase k) : - g (Sum.inl t) a b=u t (C a b (s.first t)) (C a b (s.nextP t)) := - ite_eq_right (mem_erase.mp h).1 - rw [Finset.prod_congr rfl (g:=fun t:J => u t (C a b (s.first t)) (C a b (s.nextP t))) he] - change (u k (C a b i) (C a b j)*_) *_=_ - rw [show C a b i=a from (by simp [C,moveInputs,hj]), - show C a b j=b from (by simp [C,moveInputs]),show g (.inl k) a b=1 from - (by simp [g]),one_mul,mul_assoc] - let d := z i - have hp : ∀ x:J ⊕ I,Pipe (g x) := by - have he (t : I) (h : t ≠ j) (a b : A) : C a b t=C a d t := by - unfold C moveInputs; rw [update_of_ne h,update_of_ne h] - have hu' (t : I) (h : t ≠ i) (a b : A) : C a b t=C d b t := by - unfold C moveInputs - by_cases hx : t=j <;> simp [hx,h] - have h1 (x:J⊕I) (h : ∀ a b,|g x a b|≤1) - (e : (∀ a b,g x a b=g x a d)∨(∀ a b,g x a b=g x d b)) : - Pipe (g x) := by - rcases e with e|e - · exact ⟨fun a=>g x a d,fun _=>1,fun i=>h _ _,(by simp),fun i j=> (e i j).trans - (by rw [mul_one])⟩ - exact ⟨fun _=>1,g x d,(by simp),h d,fun i j=> (e i j).trans (by rw [one_mul])⟩ - rintro (l|l) - · by_cases hh : l=k - · subst l; exact h1 (Sum.inl k) (by simp [g]) (Or.inl (by simp [g])) - apply h1 (Sum.inl l) (fun a b => by simp only [g,ite_eq_right hh]; exact hu _ _ _) - have hh1 : - (s.first l≠j∧s.nextP l≠j) ∨(s.first l≠i∧s.nextP l≠i) := by - by_contra! ha - by_cases hx : s.first l=j - · have hy : s.first l≠i := hx ▸ Ne.symm hj - exact s.anti l k hx (ha.2 hy) - have ht := ha.1 hx - have hs : s.first l=i := by_contra (fun h=>hj ((ha.2 h).symm.trans ht)) - exact hh (s.once l k hs ht) - simp only [g,ite_eq_right hh]; rcases hh1 with ⟨h,h'⟩|⟨h,h'⟩ - · left; intro a b; rw [he _ h,he _ h'] - right; intro a b; rw [hu' _ h,hu' _ h'] - apply h1 (Sum.inr l) (fun a b => hf _ _) - unfold g - by_cases h : l=i - · exact Or.inl fun a b => congrArg _ (he _ (h.symm ▸ hj) _ _) - exact Or.inr fun a b=> congrArg _ (hu' l h a b) - obtain ⟨p,q,hp,hq,ht⟩ := pipe_prod univ g (fun i _ => hp i) - have heq (x : A×A) : W (moveInputs i j z x.1 x.2)=u k x.1 x.2*(p x.1*q x.2) := by - change W (C _ _)=_ - rw [he]; exact congrArg (_ * ·) (ht x.1 x.2) - simp_rw [heq] - exact h p q hp hq - change |avg _ W|≤η - rw [far_avg w hw W i j hj] - exact (abs_avg_le (prodW_law hw).nz).trans ((prodW_law hw).avg_le hi) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ConditionedCorrelations + +namespace OAI + +/-! # Product Character Tests -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Filter Function +open scoped BigOperators +variable {I J A Z D : Type} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] +variable [Fintype A] + +def Pipe (P : A→Z→ ℝ) := + ∃ (f : A→ℝ) (g : Z→ℝ),(∀ i, |f i|≤1) ∧ (∀ i, |g i|≤1) ∧ ∀ x y,P x y=f x*g y + +omit [Fintype I] [Fintype A] in +private theorem pipe_prod (s : Finset I) (P : I → A→Z→ℝ) + (h : ∀ i∈s,Pipe (P i)) : + Pipe (fun x y => ∏ i∈s,P i x y) := by + classical + induction s using Finset.induction_on with + | empty => + exact ⟨fun _ =>1,fun _=>1,(by simp),(by simp),fun _ _=>by simp⟩ + | @insert i s hi ih => + obtain ⟨f,g,hf,hg,hH⟩ := h i (by simp) + obtain ⟨u,v,hu,hv,hU⟩ := ih (fun j hj => h j (mem_insert_of_mem hj)) + have he (f g : ℝ) (hf : |f|≤1) (hg : |g|≤1) : + |f*g|≤1 := by rw [abs_mul]; exact (mul_le_mul hf hg (abs_nonneg _) zero_le_one).trans_eq + (by ring) + exact ⟨fun x => f x*u x,fun x => g x*v x,(fun x=>he _ _ (hf x) (hu x)), + (fun x => he _ _ (hg x) (hv x)),fun x y => by dsimp only at *; rw [prod_insert hi,hH,hU]; ring⟩ + +structure Stage (I J : Type) where + first : J→I + nextP : J→I + diff k : first k ≠ nextP k + once k j : first k=first j → nextP k=nextP j → k=j + anti k j : first k=nextP j → nextP k≠first j + +variable (s : Stage I J) + +set_option maxHeartbeats 600000 in +theorem far_avg (w : I→Wgt A) (hw : ∀ i,IsLaw (w i)) (F : Wgt (I→A)) (i j : I) + (_ : i ≠ j) : + let U := prodW w + avg U F = avg U (fun x => avg (pairW (w i) (w j)) (fun y => F (update (update x i y.1) j y.2))) := by + classical + intro U + rw [update_avg w j F (hw j),update_avg w i _ (hw i)] + simp only [U,pairW_avg] +private def moveInputs (i j : I) (x : I→A) (p q : A) := update (update x i p) j q + +set_option maxHeartbeats 800000 in +theorem band_res (w : I→ Wgt A) (hw : ∀ i,IsLaw (w i)) + (f : I→ Wgt A) (hf : ∀ i x,|f i x|≤1) + (u : J→ A→ A→ℝ) (hu : ∀ k x y,|u k x y|≤1) + (k : J) (η : ℝ) + (h : ∀ p q : Wgt A,(∀ i, |p i|≤1)→(∀ i,|q i|≤1) → + |avg (pairW (w (s.first k)) (w (s.nextP k))) (fun x => + u k x.1 x.2 * (p x.1*q x.2))|≤η) : + |avg (prodW w) (fun x => (∏ j:J,u j (x (s.first j)) (x (s.nextP j)))*prodW f x)|≤η := by + classical + let i:=s.first k; let j:=s.nextP k + have hj : i≠ j := s.diff k + let W (x : I→ A) := (∏ j':J,u j' (x (s.first j')) (x (s.nextP j')))*prodW f x + have hi (z : I→A) : + |avg (pairW (w i) (w j)) (fun x => W (moveInputs i j z x.1 x.2))|≤ η := by + let C a b := moveInputs i j z a b + let g (v : J⊕I) (a b : A) := + match v with + | .inl t => if t=k then 1 else u t (C a b (s.first t)) (C a b (s.nextP t)) + | .inr t => f t (C a b t) + have he a b : + W (C a b)=u k a b * ∏ l:J ⊕ I,g l a b := by + unfold W prodW; rw [Fintype.prod_sum_type] + rw [← mul_prod_erase _ _ (mem_univ k),←mul_prod_erase _ + (fun t:J=>g (.inl t) a b) (mem_univ k)] + have he (t:J) (h : t∈univ.erase k) : + g (Sum.inl t) a b=u t (C a b (s.first t)) (C a b (s.nextP t)) := + ite_eq_right (mem_erase.mp h).1 + rw [Finset.prod_congr rfl (g:=fun t:J => u t (C a b (s.first t)) (C a b (s.nextP t))) he] + change (u k (C a b i) (C a b j)*_) *_=_ + rw [show C a b i=a from (by simp [C,moveInputs,hj]), + show C a b j=b from (by simp [C,moveInputs]),show g (.inl k) a b=1 from + (by simp [g]),one_mul,mul_assoc] + let d := z i + have hp : ∀ x:J ⊕ I,Pipe (g x) := by + have he (t : I) (h : t ≠ j) (a b : A) : C a b t=C a d t := by + unfold C moveInputs; rw [update_of_ne h,update_of_ne h] + have hu' (t : I) (h : t ≠ i) (a b : A) : C a b t=C d b t := by + unfold C moveInputs + by_cases hx : t=j <;> simp [hx,h] + have h1 (x:J⊕I) (h : ∀ a b,|g x a b|≤1) + (e : (∀ a b,g x a b=g x a d)∨(∀ a b,g x a b=g x d b)) : + Pipe (g x) := by + rcases e with e|e + · exact ⟨fun a=>g x a d,fun _=>1,fun i=>h _ _,(by simp),fun i j=> (e i j).trans + (by rw [mul_one])⟩ + exact ⟨fun _=>1,g x d,(by simp),h d,fun i j=> (e i j).trans (by rw [one_mul])⟩ + rintro (l|l) + · by_cases hh : l=k + · subst l; exact h1 (Sum.inl k) (by simp [g]) (Or.inl (by simp [g])) + apply h1 (Sum.inl l) (fun a b => by simp only [g,ite_eq_right hh]; exact hu _ _ _) + have hh1 : + (s.first l≠j∧s.nextP l≠j) ∨(s.first l≠i∧s.nextP l≠i) := by + by_contra! ha + by_cases hx : s.first l=j + · have hy : s.first l≠i := hx ▸ Ne.symm hj + exact s.anti l k hx (ha.2 hy) + have ht := ha.1 hx + have hs : s.first l=i := by_contra (fun h=>hj ((ha.2 h).symm.trans ht)) + exact hh (s.once l k hs ht) + simp only [g,ite_eq_right hh]; rcases hh1 with ⟨h,h'⟩|⟨h,h'⟩ + · left; intro a b; rw [he _ h,he _ h'] + right; intro a b; rw [hu' _ h,hu' _ h'] + apply h1 (Sum.inr l) (fun a b => hf _ _) + unfold g + by_cases h : l=i + · exact Or.inl fun a b => congrArg _ (he _ (h.symm ▸ hj) _ _) + exact Or.inr fun a b=> congrArg _ (hu' l h a b) + obtain ⟨p,q,hp,hq,ht⟩ := pipe_prod univ g (fun i _ => hp i) + have heq (x : A×A) : W (moveInputs i j z x.1 x.2)=u k x.1 x.2*(p x.1*q x.2) := by + change W (C _ _)=_ + rw [he]; exact congrArg (_ * ·) (ht x.1 x.2) + simp_rw [heq] + exact h p q hp hq + change |avg _ W|≤η + rw [far_avg w hw W i j hj] + exact (abs_avg_le (prodW_law hw).nz).trans ((prodW_law hw).avg_le hi) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ProductComparisonScales.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ProductComparisonScales.lean index 0a77b658b225e54032409a25c72385b95834df87..e1be7e7973527e420512e4850cd3407ff5695085 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ProductComparisonScales.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ProductComparisonScales.lean @@ -1,130 +1,130 @@ -import OAI.Combinatorics.HadwigerCounterexample.RecursiveComparisonErrors - -namespace OAI - -/-! # Product Comparison Scales -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module Function Finset Filter -open scoped BigOperators -variable {p : Shape} {n N M : ℕ} {I : Type} [Fintype I] [DecidableEq I] -namespace Template -variable (v : Template p I) - -def play (v : Template p I) (M : ℕ) (C b ε : ℝ) := - ∃ (r : ℕ) (c : ℝ),0 ?_)⟩ - intro N q U hU - let i : Keys (p:=p) v.t N := 0 - refine ⟨U, ⟨fun _ => ⟨U i,fun _ _=> True⟩,?_,fun _=>hU _⟩,fun f h=>?_, - fun m hN w hw s x h hh =>?_⟩ - · funext x - simp only [mural,Paint.cost,prodW,ind_true,prod_const_one,mul_one,sum_const, - card_univ,Fintype.card_fin,one_smul] - exact congrArg U (Subsingleton.elim x i) - · simp only [board,sub_self,curtain,Pi.zero_apply,mul_zero,zero_mul,avg_zero,abs_zero] - exact hε - · have ht o : ¬ exceeds v q (U-U) s m x ε o := by - rintro ⟨f,_,hh⟩ - simp only [scene,protean,curtain,sub_self,Pi.zero_apply,mul_zero,zero_mul,avg_zero, - abs_zero] at hh - exact (not_lt_of_ge hε) hh - rw [show exceeds _ _ _ _ _ _ _=(fun _=>False) from funext fun i=>propext ⟨ht i,False.elim⟩, - pr_false]; exact (bp_pos _).le - -set_option maxHeartbeats 1200000 in -theorem play_step (v : Template p I) (j : I) (M : ℕ) (hM : 1≤ M) (C b ε : ℝ) - (hb : 0≤b) (hε : 0<ε) - (h : play (v.beyond j) M C b (ε/2)) : - play v M C b ε := by - classical - let u:= ε/2; let L:=1+2*b; have hu : 0 h Q (B i) (hb' i) - let D := patched v j a g - have hT : shadowed v q W u := by - have he := chair_board v j q W L d hL hQ - have hm : d*L ≤ u := (le_div_iff₀ hL).mp (min_le_right ..) - exact fun i hi => (he i hi).trans hm - have hx : engaged v q W n C (bp (-(1/16:ℝ)*n)) u := by - intro m hN w hw s x hx hz - have he : chairCut v j R δ := - fun i hi k hk=> (hQ i hi k hk).trans (min_le_left ..) - have hg (x) : |propel v s m x|≤1 := by - unfold propel; rw [abs_of_nonneg (ind_nonneg _)] - exact ind_le_one _ - obtain ⟨hw,hv,h',hm'⟩ := hw - have h4 := hn q R (propel v s m) x hs he hW hg hx hz m hN w hw hv h' hm' - refine (pr_mono hw.nz (fun i hh => ?_)).trans h4 - obtain ⟨f,hf,hg⟩ := hh - refine ⟨f,hf,?_⟩ - unfold R - rw [put_back v q W L,abs_div,abs_of_pos hL] - exact div_lt_div_of_pos_right hg hL - have hg := gild_play v j q n N l a B g U C u _ _ hT hx h2 h3 - have heq : u+u=ε := by unfold u; ring - dsimp only at hg - rw [heq] at hg - refine ⟨D,design_mono v D b _ (s*r) hb (Nat.mul_le_mul_right r hl) - (design_patch v j l r a g b h1),hg.1,?_⟩ - intro m hN w hw s' x hx hz - apply (hg.2 m hN w hw s' x hx hz).trans - apply le_trans ?_ ha - let z := bp (-t*n) - have h1 : bp (-c*n)≤ z := bp_le (by gcongr; exact min_le_right ..) - have h2 : bp (-(1/16:ℝ)*n)≤ z := bp_le (by gcongr; exact min_le_left ..) - exact (add_le_add h2 (mul_le_mul (by exact_mod_cast hl) h1 (bp_pos _).le - (Nat.cast_nonneg s))).trans_eq (by ring) - -theorem plays_calendar (p : Shape) (M : ℕ) (hM : 1≤M) (C b : ℝ) (hb : 0 ≤ b) - (r : ℕ) : - ∀ (I : Type) [Fintype I] [DecidableEq I],Fintype.card I≤r → - ∀ v : Template p I,∀ ε : ℝ,0< ε→play v M C b ε := by - classical - induction r with - | zero => - intro I inst h hi v ε he - have : IsEmpty I := Fintype.card_eq_zero_iff.mp (Nat.eq_zero_of_le_zero hi) - exact play_empty v M C b ε he.le - | succ r ih => - intro I _ _ h v ε he - cases isEmpty_or_nonempty I - next => exact play_empty v M C b ε he.le - next hi => - obtain ⟨i⟩:=hi - apply play_step v i M hM C b ε hb he - refine ih _ ?_ _ _ (half_pos he) - have hh : Fintype.card (Aside i)+1=Fintype.card I := by - have hg := Fintype.card_congr (Equiv.optionSubtypeNe i) - simpa only [Aside,Fintype.card_option] using hg - omega -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RecursiveComparisonErrors + +namespace OAI + +/-! # Product Comparison Scales -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module Function Finset Filter +open scoped BigOperators +variable {p : Shape} {n N M : ℕ} {I : Type} [Fintype I] [DecidableEq I] +namespace Template +variable (v : Template p I) + +def play (v : Template p I) (M : ℕ) (C b ε : ℝ) := + ∃ (r : ℕ) (c : ℝ),0 ?_)⟩ + intro N q U hU + let i : Keys (p:=p) v.t N := 0 + refine ⟨U, ⟨fun _ => ⟨U i,fun _ _=> True⟩,?_,fun _=>hU _⟩,fun f h=>?_, + fun m hN w hw s x h hh =>?_⟩ + · funext x + simp only [mural,Paint.cost,prodW,ind_true,prod_const_one,mul_one,sum_const, + card_univ,Fintype.card_fin,one_smul] + exact congrArg U (Subsingleton.elim x i) + · simp only [board,sub_self,curtain,Pi.zero_apply,mul_zero,zero_mul,avg_zero,abs_zero] + exact hε + · have ht o : ¬ exceeds v q (U-U) s m x ε o := by + rintro ⟨f,_,hh⟩ + simp only [scene,protean,curtain,sub_self,Pi.zero_apply,mul_zero,zero_mul,avg_zero, + abs_zero] at hh + exact (not_lt_of_ge hε) hh + rw [show exceeds _ _ _ _ _ _ _=(fun _=>False) from funext fun i=>propext ⟨ht i,False.elim⟩, + pr_false]; exact (bp_pos _).le + +set_option maxHeartbeats 1200000 in +theorem play_step (v : Template p I) (j : I) (M : ℕ) (hM : 1≤ M) (C b ε : ℝ) + (hb : 0≤b) (hε : 0<ε) + (h : play (v.beyond j) M C b (ε/2)) : + play v M C b ε := by + classical + let u:= ε/2; let L:=1+2*b; have hu : 0 h Q (B i) (hb' i) + let D := patched v j a g + have hT : shadowed v q W u := by + have he := chair_board v j q W L d hL hQ + have hm : d*L ≤ u := (le_div_iff₀ hL).mp (min_le_right ..) + exact fun i hi => (he i hi).trans hm + have hx : engaged v q W n C (bp (-(1/16:ℝ)*n)) u := by + intro m hN w hw s x hx hz + have he : chairCut v j R δ := + fun i hi k hk=> (hQ i hi k hk).trans (min_le_left ..) + have hg (x) : |propel v s m x|≤1 := by + unfold propel; rw [abs_of_nonneg (ind_nonneg _)] + exact ind_le_one _ + obtain ⟨hw,hv,h',hm'⟩ := hw + have h4 := hn q R (propel v s m) x hs he hW hg hx hz m hN w hw hv h' hm' + refine (pr_mono hw.nz (fun i hh => ?_)).trans h4 + obtain ⟨f,hf,hg⟩ := hh + refine ⟨f,hf,?_⟩ + unfold R + rw [put_back v q W L,abs_div,abs_of_pos hL] + exact div_lt_div_of_pos_right hg hL + have hg := gild_play v j q n N l a B g U C u _ _ hT hx h2 h3 + have heq : u+u=ε := by unfold u; ring + dsimp only at hg + rw [heq] at hg + refine ⟨D,design_mono v D b _ (s*r) hb (Nat.mul_le_mul_right r hl) + (design_patch v j l r a g b h1),hg.1,?_⟩ + intro m hN w hw s' x hx hz + apply (hg.2 m hN w hw s' x hx hz).trans + apply le_trans ?_ ha + let z := bp (-t*n) + have h1 : bp (-c*n)≤ z := bp_le (by gcongr; exact min_le_right ..) + have h2 : bp (-(1/16:ℝ)*n)≤ z := bp_le (by gcongr; exact min_le_left ..) + exact (add_le_add h2 (mul_le_mul (by exact_mod_cast hl) h1 (bp_pos _).le + (Nat.cast_nonneg s))).trans_eq (by ring) + +theorem plays_calendar (p : Shape) (M : ℕ) (hM : 1≤M) (C b : ℝ) (hb : 0 ≤ b) + (r : ℕ) : + ∀ (I : Type) [Fintype I] [DecidableEq I],Fintype.card I≤r → + ∀ v : Template p I,∀ ε : ℝ,0< ε→play v M C b ε := by + classical + induction r with + | zero => + intro I inst h hi v ε he + have : IsEmpty I := Fintype.card_eq_zero_iff.mp (Nat.eq_zero_of_le_zero hi) + exact play_empty v M C b ε he.le + | succ r ih => + intro I _ _ h v ε he + cases isEmpty_or_nonempty I + next => exact play_empty v M C b ε he.le + next hi => + obtain ⟨i⟩:=hi + apply play_step v i M hM C b ε hb he + refine ih _ ?_ _ _ (half_pos he) + have hh : Fintype.card (Aside i)+1=Fintype.card I := by + have hg := Fintype.card_congr (Equiv.optionSubtypeNe i) + simpa only [Aside,Fintype.card_option] using hg + omega +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ProductCoordinateReplacement.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ProductCoordinateReplacement.lean index c35ec2505eecfd3f032e2a7ce6937bf0be797c2b..d9566c786656103e2f0f07f7a4c3c76d1ef0661a 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ProductCoordinateReplacement.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ProductCoordinateReplacement.lean @@ -1,58 +1,58 @@ -import OAI.Combinatorics.HadwigerCounterexample.PairedRankBounds - -namespace OAI - -/-! # Product Coordinate Replacement -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Function -open scoped BigOperators -variable {I J K : Type} {A : Type} [Fintype I] [DecidableEq I] [Fintype A] - -set_option maxHeartbeats 600000 in -theorem update_avg (p : I→ Wgt A) (i : I) (f : Wgt (I→A)) (hp : IsLaw (p i)) : - avg (prodW p) f = avg (prodW p) (fun x => avg (p i) (fun y => f (update x i y))) := by - classical - - let e : ((I→A)×A)≃ ((I→A)×A) := { - toFun x := (update x.1 i x.2,x.1 i) - invFun x := (update x.1 i x.2,x.1 i) - left_inv x := by simp - right_inv x := by simp } - let μ := pairW (prodW p) (p i) - have he (x : (I→A)×A) : μ (e x)=μ x := by - unfold μ pairW prodW - let s := Finset.univ.erase i - rw [←Finset.mul_prod_erase _ _ (mem_univ i),←Finset.mul_prod_erase _ - (fun i => p i (x.1 i)) (mem_univ i)] - have h : - ∏ j∈s,p j (update x.1 i x.2 j)=∏ j∈s,p j (x.1 j) := by - refine prod_congr rfl fun j hj => ?_ - rw [update_of_ne ((mem_erase.mp hj).1)] - change p i _ * (∏ j∈s,p j (update x.1 i x.2 j))*p i (x.1 i)=_ - rw [h] - change p i (Function.update x.1 i (x.2) i) * _ * _=_ - rw [Function.update_self]; ac_rfl - have ht := avg_bij e μ (fun x => f x.1) - simp_rw [he] at ht - unfold μ at ht; simp only [pairW_avg,hp.avg_const] at ht - exact ht.symm - -theorem update2_avg (p q : I→Wgt A) (i : I) (f : Wgt ((I→A)×(I→A))) (hp : IsLaw (p i)) - (hq : IsLaw (q i)) : - let u := pairW (prodW p) (prodW q) - avg u f = avg u (fun x => avg (pairW (p i) (q i)) - (fun y => f (update x.1 i y.1,update x.2 i y.2))) := by - intro u - simp only [u,pairW_avg] - conv_lhs => rw [update_avg p i _ hp] - apply avg_congr; intro x _ - - conv_rhs => rw [avg_avg] - exact avg_congr (fun _ _ => update_avg q i _ hq) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PairedRankBounds + +namespace OAI + +/-! # Product Coordinate Replacement -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Function +open scoped BigOperators +variable {I J K : Type} {A : Type} [Fintype I] [DecidableEq I] [Fintype A] + +set_option maxHeartbeats 600000 in +theorem update_avg (p : I→ Wgt A) (i : I) (f : Wgt (I→A)) (hp : IsLaw (p i)) : + avg (prodW p) f = avg (prodW p) (fun x => avg (p i) (fun y => f (update x i y))) := by + classical + + let e : ((I→A)×A)≃ ((I→A)×A) := { + toFun x := (update x.1 i x.2,x.1 i) + invFun x := (update x.1 i x.2,x.1 i) + left_inv x := by simp + right_inv x := by simp } + let μ := pairW (prodW p) (p i) + have he (x : (I→A)×A) : μ (e x)=μ x := by + unfold μ pairW prodW + let s := Finset.univ.erase i + rw [←Finset.mul_prod_erase _ _ (mem_univ i),←Finset.mul_prod_erase _ + (fun i => p i (x.1 i)) (mem_univ i)] + have h : + ∏ j∈s,p j (update x.1 i x.2 j)=∏ j∈s,p j (x.1 j) := by + refine prod_congr rfl fun j hj => ?_ + rw [update_of_ne ((mem_erase.mp hj).1)] + change p i _ * (∏ j∈s,p j (update x.1 i x.2 j))*p i (x.1 i)=_ + rw [h] + change p i (Function.update x.1 i (x.2) i) * _ * _=_ + rw [Function.update_self]; ac_rfl + have ht := avg_bij e μ (fun x => f x.1) + simp_rw [he] at ht + unfold μ at ht; simp only [pairW_avg,hp.avg_const] at ht + exact ht.symm + +theorem update2_avg (p q : I→Wgt A) (i : I) (f : Wgt ((I→A)×(I→A))) (hp : IsLaw (p i)) + (hq : IsLaw (q i)) : + let u := pairW (prodW p) (prodW q) + avg u f = avg u (fun x => avg (pairW (p i) (q i)) + (fun y => f (update x.1 i y.1,update x.2 i y.2))) := by + intro u + simp only [u,pairW_avg] + conv_lhs => rw [update_avg p i _ hp] + apply avg_congr; intro x _ + + conv_rhs => rw [avg_avg] + exact avg_congr (fun _ _ => update_avg q i _ hq) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ProductLaws.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ProductLaws.lean index fccdd02aa63d923e8203c31aafa65afb0ce77c37..d1e23ba6ad59d3017d2b026e76874287c43eecfb 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ProductLaws.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ProductLaws.lean @@ -1,119 +1,119 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteLaws -import Mathlib.Data.Fintype.Pi -import Mathlib.Algebra.BigOperators.GroupWithZero.Finset - -namespace OAI - -/-! # Product Laws -/ - -noncomputable section -open scoped BigOperators -namespace HadwigerCounterexample - -theorem ind_all {ι : Type*} [Fintype ι] (p : ι → Prop) : - ind (∀ i, p i) = ∏ i, ind (p i) := by - classical - simp [ind, Fintype.prod_ite_zero] - -variable {ι κ α : Type*} -variable {β : ι → Type*} - -def prodW [Fintype ι] (w : ∀ i, Wgt (β i)) : Wgt (∀ i, β i) := fun x => ∏ i, w i (x i) - -section -variable [Fintype ι] [DecidableEq ι] [∀ i, Fintype (β i)] - -theorem prodW_tot (w : ∀ i, Wgt (β i)) : tot (prodW w) = ∏ i, tot (w i) := - (Fintype.prod_sum w).symm - -theorem prodW_avg (w f : ∀ i, Wgt (β i)) : - avg (prodW w) (prodW f) = ∏ i, avg (w i) (f i) := by - simp only [avg, prodW] - rw [Fintype.prod_sum] - simp only [Finset.prod_mul_distrib] - -theorem prodW_pr (w : ∀ i, Wgt (β i)) (p : ∀ i, β i → Prop) : - pr (prodW w) (fun x => ∀ i, p i (x i)) = ∏ i, pr (w i) (p i) := by - simp_rw [pr, ind_all] - exact prodW_avg w (fun i x => ind (p i x)) - -omit [DecidableEq ι] [∀ i, Fintype (β i)] in -theorem prodW_nonneg {w : ∀ i, Wgt (β i)} (h : ∀ i x, 0 ≤ w i x) (x) : 0 ≤ prodW w x := - Finset.prod_nonneg (fun i _ => h i _) - -theorem prodW_law {w : ∀ i, Wgt (β i)} (hw : ∀ i, IsLaw (w i)) : IsLaw (prodW w) := by - refine ⟨prodW_nonneg (fun i => (hw i).nz), ?_⟩ - rw [prodW_tot] - simp_rw [(hw _).total] - simp - -end - -section -variable [Fintype ι] [Fintype κ] [Fintype α] [DecidableEq κ] -/-- Observe distinct coordinates of a (constant-type) product law. -/ -theorem prodW_pr_inj {e : ι → κ} (he : Function.Injective e) - {w : κ → Wgt α} (hw : ∀ k, IsLaw (w k)) (p : ι → α → Prop) : - pr (prodW (β:=fun _ => α) w) (fun x => ∀ i, p i (x (e i))) = - ∏ i, pr (w (e i)) (p i) := by - classical - let P (k : κ) (x : α) := ∀ i, e i = k → p i x - have h (x : κ → α) : (∀ i, p i (x (e i))) ↔ ∀ k, P k (x k) := - ⟨fun h k i hi => hi ▸ h i, fun h i => h (e i) i rfl⟩ - simp_rw [h] - rw [prodW_pr _ P] - let f (k : κ) (i : ι) := if e i = k then pr (w k) (p i) else 1 - have hf (k : κ) : pr (w k) (P k) = ∏ i, f k i := by - by_cases hk : ∃ i, e i = k - · obtain ⟨i, rfl⟩ := hk - have hP : P (e i) = p i := funext fun x => propext - ⟨fun h => h i rfl, fun h j hj => (he hj).symm ▸ h⟩ - rw [hP] - symm - rw [Finset.prod_eq_single i] - · simp [f] - · intro j _ hj - simp [f, show e j ≠ e i from he.ne hj] - · simp - · push Not at hk - have hP : P k = (fun _ => True) := funext fun _ => propext - ⟨fun _ => trivial, fun _ j hj => (hk j hj).elim⟩ - simp [hP, (hw k).total, f, hk] - simp_rw [hf] - rw [Finset.prod_comm] - simp [f] - -theorem prodW_map_inj {e : ι → κ} (he : Function.Injective e) - {w : κ → Wgt α} (hw : ∀ k, IsLaw (w k)) : - mapW (prodW (β := fun _ => α) w) (fun x : κ → α => fun i : ι => x (e i)) = - prodW (β := fun _ => α) (fun i => w (e i)) := by - funext x - unfold mapW - simp_rw [funext_iff] - have h := prodW_pr_inj he hw (fun i y => y = x i) - simp_rw [pr_point'] at h - exact h - -/-- Mapping to ordered pairs along a disjoint family of positions. -/ -theorem prodW_map_pairs (e : ι ⊕ ι → κ) (he : Function.Injective e) - {w : Wgt α} (hw : IsLaw w) : - mapW (prodW (fun _ : κ => w)) - (fun x i => (x (e (.inl i)), x (e (.inr i)))) = - prodW (fun _ : ι => pairW w w) := by - funext y - let p (j : ι ⊕ ι) (x : α) := j.elim (fun i => x = (y i).1) (fun i => x = (y i).2) - have heq (x : κ → α) : - ((fun i => (x (e (.inl i)), x (e (.inr i)))) = y) ↔ ∀ j, p j (x (e j)) := by - simp [funext_iff, Prod.ext_iff, p, Sum.forall, forall_and] - unfold mapW - simp_rw [heq] - have h := prodW_pr_inj he (w:=fun _ => w) (fun _ => hw) p - rw [h] - simp [Fintype.prod_sum_type, p, prodW, pairW, Finset.prod_mul_distrib] - -end -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteLaws +import Mathlib.Data.Fintype.Pi +import Mathlib.Algebra.BigOperators.GroupWithZero.Finset + +namespace OAI + +/-! # Product Laws -/ + +noncomputable section +open scoped BigOperators +namespace HadwigerCounterexample + +theorem ind_all {ι : Type*} [Fintype ι] (p : ι → Prop) : + ind (∀ i, p i) = ∏ i, ind (p i) := by + classical + simp [ind, Fintype.prod_ite_zero] + +variable {ι κ α : Type*} +variable {β : ι → Type*} + +def prodW [Fintype ι] (w : ∀ i, Wgt (β i)) : Wgt (∀ i, β i) := fun x => ∏ i, w i (x i) + +section +variable [Fintype ι] [DecidableEq ι] [∀ i, Fintype (β i)] + +theorem prodW_tot (w : ∀ i, Wgt (β i)) : tot (prodW w) = ∏ i, tot (w i) := + (Fintype.prod_sum w).symm + +theorem prodW_avg (w f : ∀ i, Wgt (β i)) : + avg (prodW w) (prodW f) = ∏ i, avg (w i) (f i) := by + simp only [avg, prodW] + rw [Fintype.prod_sum] + simp only [Finset.prod_mul_distrib] + +theorem prodW_pr (w : ∀ i, Wgt (β i)) (p : ∀ i, β i → Prop) : + pr (prodW w) (fun x => ∀ i, p i (x i)) = ∏ i, pr (w i) (p i) := by + simp_rw [pr, ind_all] + exact prodW_avg w (fun i x => ind (p i x)) + +omit [DecidableEq ι] [∀ i, Fintype (β i)] in +theorem prodW_nonneg {w : ∀ i, Wgt (β i)} (h : ∀ i x, 0 ≤ w i x) (x) : 0 ≤ prodW w x := + Finset.prod_nonneg (fun i _ => h i _) + +theorem prodW_law {w : ∀ i, Wgt (β i)} (hw : ∀ i, IsLaw (w i)) : IsLaw (prodW w) := by + refine ⟨prodW_nonneg (fun i => (hw i).nz), ?_⟩ + rw [prodW_tot] + simp_rw [(hw _).total] + simp + +end + +section +variable [Fintype ι] [Fintype κ] [Fintype α] [DecidableEq κ] +/-- Observe distinct coordinates of a (constant-type) product law. -/ +theorem prodW_pr_inj {e : ι → κ} (he : Function.Injective e) + {w : κ → Wgt α} (hw : ∀ k, IsLaw (w k)) (p : ι → α → Prop) : + pr (prodW (β:=fun _ => α) w) (fun x => ∀ i, p i (x (e i))) = + ∏ i, pr (w (e i)) (p i) := by + classical + let P (k : κ) (x : α) := ∀ i, e i = k → p i x + have h (x : κ → α) : (∀ i, p i (x (e i))) ↔ ∀ k, P k (x k) := + ⟨fun h k i hi => hi ▸ h i, fun h i => h (e i) i rfl⟩ + simp_rw [h] + rw [prodW_pr _ P] + let f (k : κ) (i : ι) := if e i = k then pr (w k) (p i) else 1 + have hf (k : κ) : pr (w k) (P k) = ∏ i, f k i := by + by_cases hk : ∃ i, e i = k + · obtain ⟨i, rfl⟩ := hk + have hP : P (e i) = p i := funext fun x => propext + ⟨fun h => h i rfl, fun h j hj => (he hj).symm ▸ h⟩ + rw [hP] + symm + rw [Finset.prod_eq_single i] + · simp [f] + · intro j _ hj + simp [f, show e j ≠ e i from he.ne hj] + · simp + · push Not at hk + have hP : P k = (fun _ => True) := funext fun _ => propext + ⟨fun _ => trivial, fun _ j hj => (hk j hj).elim⟩ + simp [hP, (hw k).total, f, hk] + simp_rw [hf] + rw [Finset.prod_comm] + simp [f] + +theorem prodW_map_inj {e : ι → κ} (he : Function.Injective e) + {w : κ → Wgt α} (hw : ∀ k, IsLaw (w k)) : + mapW (prodW (β := fun _ => α) w) (fun x : κ → α => fun i : ι => x (e i)) = + prodW (β := fun _ => α) (fun i => w (e i)) := by + funext x + unfold mapW + simp_rw [funext_iff] + have h := prodW_pr_inj he hw (fun i y => y = x i) + simp_rw [pr_point'] at h + exact h + +/-- Mapping to ordered pairs along a disjoint family of positions. -/ +theorem prodW_map_pairs (e : ι ⊕ ι → κ) (he : Function.Injective e) + {w : Wgt α} (hw : IsLaw w) : + mapW (prodW (fun _ : κ => w)) + (fun x i => (x (e (.inl i)), x (e (.inr i)))) = + prodW (fun _ : ι => pairW w w) := by + funext y + let p (j : ι ⊕ ι) (x : α) := j.elim (fun i => x = (y i).1) (fun i => x = (y i).2) + have heq (x : κ → α) : + ((fun i => (x (e (.inl i)), x (e (.inr i)))) = y) ↔ ∀ j, p j (x (e j)) := by + simp [funext_iff, Prod.ext_iff, p, Sum.forall, forall_and] + unfold mapW + simp_rw [heq] + have h := prodW_pr_inj he (w:=fun _ => w) (fun _ => hw) p + rw [h] + simp [Fintype.prod_sum_type, p, prodW, pairW, Finset.prod_mul_distrib] + +end +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectedSurrogates.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectedSurrogates.lean index 0ffaf8b6c8dfe835edcf0f4da5c3c7832ebe5593..8ce6bbc53498d77f200ac5da4dd2a6f4ba23828b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectedSurrogates.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectedSurrogates.lean @@ -1,159 +1,159 @@ -import OAI.Combinatorics.HadwigerCounterexample.CommonPartitions - -namespace OAI - -/-! # Projected Surrogates -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real Function -open scoped BigOperators -variable {A B I J : Type} [Fintype A] [Fintype B] [Fintype I] [Fintype J] - -def bower (f : Wgt A) := (∀ i,0≤ f i)∧ (∀ i,f i≤1) -omit [Fintype B] in -theorem book_order (w : Wgt A) (p : A→ B) (hw : IsLaw w) - (f g : Wgt A) (h : ∀ i, f i≤ g i) (x) : - cashbook w p f x ≤ cashbook w p g x := by - apply div_le_div_of_nonneg_right _ (map_nz hw.nz p x) - exact pr_mono_left (fun i=> mul_le_mul_of_nonneg_left (h i) (hw.nz i)) _ -omit [Fintype B] in -theorem book_nonneg (w : Wgt A) (p : A→B) (hw : IsLaw w) (f : Wgt A) (hf : ∀ i,0 ≤ f i) (x) : - 0 ≤ cashbook w p f x := div_nonneg (pr_nonneg (fun i=>mul_nonneg (hw.nz i) (hf i))) (map_nz hw.nz p x) -omit [Fintype B] in -theorem garden (w f : Wgt A) (p : A→B) (hw : IsLaw w) (hf : bower f) : - bower (banner w p f) := by - refine ⟨fun i=> book_nonneg w p hw f hf.1 _,fun i=>?_⟩ - exact (le_abs_self _).trans (cashbook_bound w hw.nz p f 1 zero_le_one (fun i=>by - rw [abs_of_nonneg (hf.1 _)]; exact hf.2 _) _) -theorem projected_min (w : Wgt A) (p : A→B) (hw : IsLaw w) (f g : Wgt A) - (hf : bower f) (hg : bower g) : - dip w f g ^2 ≤ dip w (banner w p f) (banner w p g) := by - let h i := f i*g i - let u := banner w p h - have hi : dip w f g=avg w u := by - have hh := cash_orth w hw.nz p h (fun _=>1) - simpa only [dip,u,Function.comp_apply,mul_one,h] using hh.symm - have hh (i) : - u i^2 ≤ banner w p f i*banner w p g i := by - have h0 : bower u := garden w h p hw ⟨fun i=>mul_nonneg (hf.1 _) (hg.1 _),fun i=> - (mul_le_mul (hf.2 _) (hg.2 _) (hg.1 _) zero_le_one).trans_eq (one_mul _)⟩ - have h1 (i) : h i≤ f i := - ((mul_le_mul_of_nonneg_left (hg.2 _) (hf.1 _)).trans_eq (mul_one _)) - have h2 (i) : h i≤g i := - ((mul_le_mul_of_nonneg_right (hf.2 _) (hg.1 _)).trans_eq (one_mul _)) - rw [pow_two]; exact mul_le_mul (book_order w p hw h f h1 _) (book_order w p hw h g h2 _) - (h0.1 i) ((garden w f p hw hf).1 i) - rw [hi]; exact (mean_sq w hw u).trans (avg_mono hw.nz hh) - -def trayLoss (R : ℝ) (u f : Wgt A) := pr f (fun i => R≤density u f i) -omit [Fintype A] in -theorem dresso (u f : Wgt A) (h : lsupp f u) : f = fun i => u i*density u f i := by - funext i; unfold density - by_cases he : f i=0 - · simp only [he,zero_div,mul_zero] - have hh := h i he - field_simp - -theorem density_error (w : Wgt A) (p : A→B) (hw : IsLaw w) (f g : Wgt A) (hz : lsupp g w) : - lcost w (banner w p f) (banner w p (density w g))≤ - varOne (mapW (fun i=>w i*f i) p) (mapW g p) := by - classical - let x i := |cashbook w p f i-cashbook w p (density w g) i| - have he : - lcost w (banner w p f) (banner w p (density w g))=avg (mapW w p) x := - (mapW_avg w p x).symm - rw [he]; unfold avg varOne - refine sum_le_sum fun i _=>?_ - let V:=mapW w p i; let A:= mapW (fun i=> w i*f i) p i; let B:= mapW g p i - have hh : x i= |A-B|/V := by - unfold x cashbook A B V - rw [← dresso w g hz,←sub_div,abs_div,abs_of_nonneg (map_nz hw.nz ..)] - rw [hh] - by_cases h : V=0 - · change V*_ ≤_ - rw [h,zero_mul]; exact abs_nonneg _ - change V*(|A-B|/V)≤ |A-B| - exact le_of_eq (by field_simp) - -theorem density_trim (u f : Wgt A) (h : ∀ i,0≤f i) (hu : IsLaw u) - (R : ℝ) (hR : 0≤R) : - (∀ i,mcut R u f i ≤ density u f i) ∧ lcost u (density u f) (mcut R u f)≤trayLoss R u f := by - have h1 (i:A) : 0≤density u f i := div_nonneg (h _) (hu.nz _) - have h2 (i) : - mcut R u f i=min (density u f i) R := congrArg (fun x=>min x R) (max_eq_left (h1 _)) - have h3 (i) := show mcut R u f i ≤ density u f i from le_trans (le_of_eq (h2 i)) (min_le_left ..) - refine ⟨h3,Finset.sum_le_sum (fun i _=>?_)⟩ - change u i*|density u f i-mcut R u f i| ≤ f i* ind _ - rw [abs_of_nonneg (sub_nonneg.mpr (h3 _)),h2] - by_cases hz : R≤density u f i - · rw [ind_one hz,mul_one,min_eq_right hz] - have hm := hu.nz i - by_cases hg : u i=0 - · rw [hg,zero_mul]; exact h _ - apply le_trans (mul_le_mul_of_nonneg_left (sub_le_self _ hR) hm) (le_of_eq ?_) - unfold density; field_simp - rw [ind_zero hz,mul_zero,min_eq_left (le_of_not_ge hz),sub_self,mul_zero] - -private theorem cost_gap (u : Wgt A) (p : A→B) (f g : Wgt A) (h : ∀ i,g i≤ f i) - (hu : IsLaw u) : - lcost u (banner u p f) (banner u p g)=lcost u f g := by - have hf (i : A) : |banner u p f i-banner u p g i|=banner u p f i-banner u p g i := - abs_of_nonneg (sub_nonneg.mpr (book_order u p hu g f h _)) - have hg (f : Wgt A) : avg u f = avg u (banner u p f) := by - have hh := cash_orth u hu.nz p f (fun _=>1); simpa only [dip,Function.comp_apply,mul_one] using hh.symm - unfold lcost; simp_rw [hf, abs_of_nonneg (sub_nonneg.mpr (h _)), avg_sub] - rw [← hg f, ← hg g] - -set_option maxHeartbeats 800000 in -theorem density_mend (u : Wgt A) (hu : IsLaw u) (p : A→B) (R : ℝ) (hR : 0≤ R) - (f g x y : Wgt A) (hf : bower f) (hg : bower g) (hx : SubLaw x) - (hy : SubLaw y) (h1 : lsupp x u) (h2 : lsupp y u) : - let V f g := varOne (mapW (fun i=>u i*f i) p) (mapW g p)+trayLoss R u g - dip u f g ^ 2 ≤ overlap u x y + |rebate u (mcut R u x) (mcut R u y) p|+ - (V f x+V g y) := by - classical - intro V - let F:=banner u p f; let G:=banner u p g - let X:=banner u p (mcut R u x); let Y:=banner u p (mcut R u y) - have he (f x : Wgt A) (hx : SubLaw x) (h : lsupp x u) : - lcost u (banner u p f) (banner u p (mcut R u x)) ≤ V f x := by - let F := banner u p f; let X:=banner u p (density u x); let Z:=banner u p (mcut R u x) - obtain ⟨h1,h2⟩:=density_trim u x hx.nz hu R hR - have hh : lcost u F Z≤lcost u F X+lcost u X Z := by - unfold lcost; rw [← avg_add]; exact avg_mono hu.nz fun i=>abs_sub_le _ _ _ - exact hh.trans (add_le_add (density_error u p hu f x h) - (le_trans (cost_gap u p (density u x) _ h1 hu).le h2)) - have hh i : F i*G i ≤ X i*Y i + (|F i-X i|+|G i-Y i|) := by - have hA := (garden u f p hu hf).2 i; have hB := (garden u g p hu hg).2 i - have ht : 0≤X i := book_nonneg u p hu _ (fun i=> (mcut_range _ _ _ hR i).1) _ - have hq : 0≤Y i := book_nonneg u p hu _ (fun i=> (mcut_range _ _ _ hR i).1) _ - have hp := (garden u f p hu hf).1 i - by_cases h : X i≤F i - · by_cases h' : Y i≤ G i - · nlinarith only [ht,hq,h,h',hA,hB, le_abs_self (F i-X i),le_abs_self (G i-Y i)] - have hz := le_of_not_ge h' - nlinarith only [h,hB,hz,le_abs_self (F i-X i),abs_nonneg (G i-Y i),ht] - have hz := le_of_not_ge h - by_cases h' : Y i≤ G i - · nlinarith only [hA,hq,h',hz,abs_nonneg (F i-X i),le_abs_self (G i-Y i)] - have hi := le_of_not_ge h' - nlinarith only [hz,hq,hi,hp,abs_nonneg (F i-X i), abs_nonneg (G i-Y i)] - let A:= mcut R u x; let B:=mcut R u y - have hz : dip u A B≤overlap u x y := - avg_mono hu.nz (fun i=>mul_le_mul ((density_trim u x hx.nz hu _ hR).1 _) - ((density_trim u y hy.nz hu _ hR).1 _) ((mcut_range R u y hR i).1) - (div_nonneg (hx.nz _) (hu.nz _))) - have h : - dip u X Y≤overlap u x y + |rebate u A B p| := by - have h : dip u X Y-dip u A B ≤|dip u A B-dip u X Y| := by rw [abs_sub_comm]; exact le_abs_self _ - change _≤ _+ |dip u A B - dip u X Y|; linarith only [h,hz] - have hp := avg_mono hu.nz hh - rw [avg_add,avg_add] at hp - exact (le_trans (projected_min u p hu f g hf hg) hp).trans - (add_le_add h (add_le_add (he f x hx h1) (he g y hy h2))) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CommonPartitions + +namespace OAI + +/-! # Projected Surrogates -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real Function +open scoped BigOperators +variable {A B I J : Type} [Fintype A] [Fintype B] [Fintype I] [Fintype J] + +def bower (f : Wgt A) := (∀ i,0≤ f i)∧ (∀ i,f i≤1) +omit [Fintype B] in +theorem book_order (w : Wgt A) (p : A→ B) (hw : IsLaw w) + (f g : Wgt A) (h : ∀ i, f i≤ g i) (x) : + cashbook w p f x ≤ cashbook w p g x := by + apply div_le_div_of_nonneg_right _ (map_nz hw.nz p x) + exact pr_mono_left (fun i=> mul_le_mul_of_nonneg_left (h i) (hw.nz i)) _ +omit [Fintype B] in +theorem book_nonneg (w : Wgt A) (p : A→B) (hw : IsLaw w) (f : Wgt A) (hf : ∀ i,0 ≤ f i) (x) : + 0 ≤ cashbook w p f x := div_nonneg (pr_nonneg (fun i=>mul_nonneg (hw.nz i) (hf i))) (map_nz hw.nz p x) +omit [Fintype B] in +theorem garden (w f : Wgt A) (p : A→B) (hw : IsLaw w) (hf : bower f) : + bower (banner w p f) := by + refine ⟨fun i=> book_nonneg w p hw f hf.1 _,fun i=>?_⟩ + exact (le_abs_self _).trans (cashbook_bound w hw.nz p f 1 zero_le_one (fun i=>by + rw [abs_of_nonneg (hf.1 _)]; exact hf.2 _) _) +theorem projected_min (w : Wgt A) (p : A→B) (hw : IsLaw w) (f g : Wgt A) + (hf : bower f) (hg : bower g) : + dip w f g ^2 ≤ dip w (banner w p f) (banner w p g) := by + let h i := f i*g i + let u := banner w p h + have hi : dip w f g=avg w u := by + have hh := cash_orth w hw.nz p h (fun _=>1) + simpa only [dip,u,Function.comp_apply,mul_one,h] using hh.symm + have hh (i) : + u i^2 ≤ banner w p f i*banner w p g i := by + have h0 : bower u := garden w h p hw ⟨fun i=>mul_nonneg (hf.1 _) (hg.1 _),fun i=> + (mul_le_mul (hf.2 _) (hg.2 _) (hg.1 _) zero_le_one).trans_eq (one_mul _)⟩ + have h1 (i) : h i≤ f i := + ((mul_le_mul_of_nonneg_left (hg.2 _) (hf.1 _)).trans_eq (mul_one _)) + have h2 (i) : h i≤g i := + ((mul_le_mul_of_nonneg_right (hf.2 _) (hg.1 _)).trans_eq (one_mul _)) + rw [pow_two]; exact mul_le_mul (book_order w p hw h f h1 _) (book_order w p hw h g h2 _) + (h0.1 i) ((garden w f p hw hf).1 i) + rw [hi]; exact (mean_sq w hw u).trans (avg_mono hw.nz hh) + +def trayLoss (R : ℝ) (u f : Wgt A) := pr f (fun i => R≤density u f i) +omit [Fintype A] in +theorem dresso (u f : Wgt A) (h : lsupp f u) : f = fun i => u i*density u f i := by + funext i; unfold density + by_cases he : f i=0 + · simp only [he,zero_div,mul_zero] + have hh := h i he + field_simp + +theorem density_error (w : Wgt A) (p : A→B) (hw : IsLaw w) (f g : Wgt A) (hz : lsupp g w) : + lcost w (banner w p f) (banner w p (density w g))≤ + varOne (mapW (fun i=>w i*f i) p) (mapW g p) := by + classical + let x i := |cashbook w p f i-cashbook w p (density w g) i| + have he : + lcost w (banner w p f) (banner w p (density w g))=avg (mapW w p) x := + (mapW_avg w p x).symm + rw [he]; unfold avg varOne + refine sum_le_sum fun i _=>?_ + let V:=mapW w p i; let A:= mapW (fun i=> w i*f i) p i; let B:= mapW g p i + have hh : x i= |A-B|/V := by + unfold x cashbook A B V + rw [← dresso w g hz,←sub_div,abs_div,abs_of_nonneg (map_nz hw.nz ..)] + rw [hh] + by_cases h : V=0 + · change V*_ ≤_ + rw [h,zero_mul]; exact abs_nonneg _ + change V*(|A-B|/V)≤ |A-B| + exact le_of_eq (by field_simp) + +theorem density_trim (u f : Wgt A) (h : ∀ i,0≤f i) (hu : IsLaw u) + (R : ℝ) (hR : 0≤R) : + (∀ i,mcut R u f i ≤ density u f i) ∧ lcost u (density u f) (mcut R u f)≤trayLoss R u f := by + have h1 (i:A) : 0≤density u f i := div_nonneg (h _) (hu.nz _) + have h2 (i) : + mcut R u f i=min (density u f i) R := congrArg (fun x=>min x R) (max_eq_left (h1 _)) + have h3 (i) := show mcut R u f i ≤ density u f i from le_trans (le_of_eq (h2 i)) (min_le_left ..) + refine ⟨h3,Finset.sum_le_sum (fun i _=>?_)⟩ + change u i*|density u f i-mcut R u f i| ≤ f i* ind _ + rw [abs_of_nonneg (sub_nonneg.mpr (h3 _)),h2] + by_cases hz : R≤density u f i + · rw [ind_one hz,mul_one,min_eq_right hz] + have hm := hu.nz i + by_cases hg : u i=0 + · rw [hg,zero_mul]; exact h _ + apply le_trans (mul_le_mul_of_nonneg_left (sub_le_self _ hR) hm) (le_of_eq ?_) + unfold density; field_simp + rw [ind_zero hz,mul_zero,min_eq_left (le_of_not_ge hz),sub_self,mul_zero] + +private theorem cost_gap (u : Wgt A) (p : A→B) (f g : Wgt A) (h : ∀ i,g i≤ f i) + (hu : IsLaw u) : + lcost u (banner u p f) (banner u p g)=lcost u f g := by + have hf (i : A) : |banner u p f i-banner u p g i|=banner u p f i-banner u p g i := + abs_of_nonneg (sub_nonneg.mpr (book_order u p hu g f h _)) + have hg (f : Wgt A) : avg u f = avg u (banner u p f) := by + have hh := cash_orth u hu.nz p f (fun _=>1); simpa only [dip,Function.comp_apply,mul_one] using hh.symm + unfold lcost; simp_rw [hf, abs_of_nonneg (sub_nonneg.mpr (h _)), avg_sub] + rw [← hg f, ← hg g] + +set_option maxHeartbeats 800000 in +theorem density_mend (u : Wgt A) (hu : IsLaw u) (p : A→B) (R : ℝ) (hR : 0≤ R) + (f g x y : Wgt A) (hf : bower f) (hg : bower g) (hx : SubLaw x) + (hy : SubLaw y) (h1 : lsupp x u) (h2 : lsupp y u) : + let V f g := varOne (mapW (fun i=>u i*f i) p) (mapW g p)+trayLoss R u g + dip u f g ^ 2 ≤ overlap u x y + |rebate u (mcut R u x) (mcut R u y) p|+ + (V f x+V g y) := by + classical + intro V + let F:=banner u p f; let G:=banner u p g + let X:=banner u p (mcut R u x); let Y:=banner u p (mcut R u y) + have he (f x : Wgt A) (hx : SubLaw x) (h : lsupp x u) : + lcost u (banner u p f) (banner u p (mcut R u x)) ≤ V f x := by + let F := banner u p f; let X:=banner u p (density u x); let Z:=banner u p (mcut R u x) + obtain ⟨h1,h2⟩:=density_trim u x hx.nz hu R hR + have hh : lcost u F Z≤lcost u F X+lcost u X Z := by + unfold lcost; rw [← avg_add]; exact avg_mono hu.nz fun i=>abs_sub_le _ _ _ + exact hh.trans (add_le_add (density_error u p hu f x h) + (le_trans (cost_gap u p (density u x) _ h1 hu).le h2)) + have hh i : F i*G i ≤ X i*Y i + (|F i-X i|+|G i-Y i|) := by + have hA := (garden u f p hu hf).2 i; have hB := (garden u g p hu hg).2 i + have ht : 0≤X i := book_nonneg u p hu _ (fun i=> (mcut_range _ _ _ hR i).1) _ + have hq : 0≤Y i := book_nonneg u p hu _ (fun i=> (mcut_range _ _ _ hR i).1) _ + have hp := (garden u f p hu hf).1 i + by_cases h : X i≤F i + · by_cases h' : Y i≤ G i + · nlinarith only [ht,hq,h,h',hA,hB, le_abs_self (F i-X i),le_abs_self (G i-Y i)] + have hz := le_of_not_ge h' + nlinarith only [h,hB,hz,le_abs_self (F i-X i),abs_nonneg (G i-Y i),ht] + have hz := le_of_not_ge h + by_cases h' : Y i≤ G i + · nlinarith only [hA,hq,h',hz,abs_nonneg (F i-X i),le_abs_self (G i-Y i)] + have hi := le_of_not_ge h' + nlinarith only [hz,hq,hi,hp,abs_nonneg (F i-X i), abs_nonneg (G i-Y i)] + let A:= mcut R u x; let B:=mcut R u y + have hz : dip u A B≤overlap u x y := + avg_mono hu.nz (fun i=>mul_le_mul ((density_trim u x hx.nz hu _ hR).1 _) + ((density_trim u y hy.nz hu _ hR).1 _) ((mcut_range R u y hR i).1) + (div_nonneg (hx.nz _) (hu.nz _))) + have h : + dip u X Y≤overlap u x y + |rebate u A B p| := by + have h : dip u X Y-dip u A B ≤|dip u A B-dip u X Y| := by rw [abs_sub_comm]; exact le_abs_self _ + change _≤ _+ |dip u A B - dip u X Y|; linarith only [h,hz] + have hp := avg_mono hu.nz hh + rw [avg_add,avg_add] at hp + exact (le_trans (projected_min u p hu f g hf hg) hp).trans + (add_le_add h (add_le_add (he f x hx h1) (he g y hy h2))) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectionEnergy.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectionEnergy.lean index 4d8e26e18d38deffc2e0c3843ab15f43a0ae18c2..fd728809c3d2161bfffd32eb4527161754c2ab4b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectionEnergy.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectionEnergy.lean @@ -1,129 +1,129 @@ -import OAI.Combinatorics.HadwigerCounterexample.RelativeEntropy - -namespace OAI - -/-! # Projection Energy -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real -open scoped BigOperators -variable {A B C : Type} [Fintype A] [Fintype B] [Fintype C] - -theorem map_mass (p : Wgt A) (f : A→B) : tot (mapW p f)=tot p := by - simpa only [avg_const,mul_one] using mapW_avg p f (fun _ => 1) -omit [Fintype B] in -theorem map_nz {p : Wgt A} (hp : ∀ i, 0 ≤ p i) (f : A→B) (i : B) : - 0 ≤ mapW p f i := pr_nonneg hp -omit [Fintype B] in -theorem lsupp_witness {p : Wgt A} {f : A→B} {i} - (h : mapW p f i≠0) : ∃ x,p x≠0 ∧ f x=i := by - classical - by_contra! hh - refine h (Finset.sum_eq_zero (fun x _ => ?_)) - by_cases h : p x=0 - · change p x * ind _=0 - rw [h,zero_mul] - exact (congrArg (p x * ·) (ind_zero (hh x h))).trans (mul_zero _) - -omit [Fintype B] in -theorem lsupp_hit {p : Wgt A} (hp : ∀ i,0 ≤ p i) (f : A→B) (x : A) (h : p x≠0) : - mapW p f (f x)≠0 := by - have h' := lt_of_le_of_ne (hp x) (Ne.symm h) - have he := weight_le_tot (fun y => mul_nonneg (hp y) (ind_nonneg (f y = f x))) x - simp only [ind_true,mul_one] at he - exact (h'.trans_le he).ne' - -omit [Fintype B] in -theorem lsupp.map {p q : Wgt A} (h : lsupp p q) (hq : ∀ i,0 ≤ q i) - (f : A→B) : lsupp (mapW p f) (mapW q f) := by - intro i hi - obtain ⟨x,hx,rfl⟩ := lsupp_witness hi - exact lsupp_hit hq f x (h x hx) - -omit [Fintype C] in -theorem map_nested {p : Wgt A} (f : A→B) (g : B→C) : - mapW (mapW p f) g = mapW p (g ∘ f) := funext fun _ => mapW_pr p f _ - -omit [Fintype C] in -theorem map_mix (w : Wgt A) (p : A→ Wgt B) (f : B→C) : - mapW (mixW w p) f = mixW w (fun i => mapW (p i) f) := funext fun _ => mixW_avg .. - -omit [Fintype B] in -theorem map_resize (p : Wgt A) (f : A→B) (u : Wgt B) : - mapW (fun i => p i*u (f i)) f = (fun i => mapW p f i * u i) := by - funext i - unfold mapW pr avg - rw [Finset.sum_mul] - apply sum_congr rfl - intro j _ - by_cases h : f j=i - · simp only [h,ind_true,mul_one] - simp only [ind_zero h,mul_zero,zero_mul] - -def pour (q : Wgt A) (f : A→B) (w : Wgt B) := - fun i => q i * (w (f i) / mapW q f (f i)) - -omit [Fintype B] in -theorem map_pour (q : Wgt A) (f : A → B) (w : Wgt B) (h : lsupp w (mapW q f)) : - mapW (pour q f w) f=w := by - unfold pour - rw [map_resize (u:=fun i => w i / mapW q f i)] - funext i - by_cases he : w i=0 - · simp only [he,zero_div,mul_zero] - have hm := h i he - field_simp - -def bucket (q : Wgt A) (f : A→B) (p : Wgt A) := pour q f (mapW p f) - -omit [Fintype B] in -theorem pour_nz {q : Wgt A} {u : Wgt B} (f : A→B) - (hq : ∀ i,0 ≤ q i) (hu : ∀ i,0 ≤ u i) (i) : 0 ≤ pour q f u i := - mul_nonneg (hq i) (div_nonneg (hu _) (map_nz hq f _)) - -omit [Fintype B] in -theorem bucket_scale (q p : Wgt A) (hq : ∀ i,0≤q i) (h : lsupp p q) (f : A→B) : - mapW (bucket q f p) f=mapW p f := map_pour q f _ (lsupp.map h hq f) - -theorem bucket_law {q p : Wgt A} (hp : IsLaw p) - (f : A→B) (hq : ∀ i,0≤q i) (h : lsupp p q) : - IsLaw (bucket q f p) := by - refine ⟨pour_nz f hq (map_nz hp.nz f),?_⟩ - rw [←map_mass _ f,bucket_scale q p hq h,map_mass,hp.total] - -omit [Fintype B] in -theorem lsupp_bucket {p q : Wgt A} (f : A → B) (hp : ∀ i, 0 ≤ p i) - (hq : ∀ i,0 ≤ q i) (h : lsupp p q) : lsupp p (bucket q f p) := - fun x hx => mul_ne_zero (h x hx) (div_ne_zero (lsupp_hit hp f x hx) (lsupp_hit hq f x (h x hx))) - -omit [Fintype C] in -theorem bucket_nested (q p : Wgt A) (f : A→B) (g : B→C) : - mapW (bucket q (g ∘ f) p) f=bucket (mapW q f) g (mapW p f) := by - unfold bucket pour - rw [map_nested,map_nested] - have h := map_resize q f (fun i=>mapW p (g∘f) (g i)/mapW q (g∘f) (g i)) - exact h - -omit [Fintype B] in -theorem bucket_mix (q : Wgt A) (f : A → B) (w : Wgt C) (p : C→ Wgt A) : - bucket q f (mixW w p)=mixW w (fun y => bucket q f (p y)) := by - unfold bucket pour - rw [map_mix] - funext i; simp only [mixW,avg_mul',avg_div] - -theorem tension_stage (p q : Wgt A) (hp : ∀ i,0 ≤ p i) (hq : ∀ i, 0≤ q i) - (h : lsupp p q) (f : A→B) : - tension p q=tension p (bucket q f p)+tension (mapW p f) (mapW q f) := by - unfold tension - rw [mapW_avg, ← avg_add] - refine avg_congr (fun i hi => ?_) - have hu := h i hi; have hw := lsupp_hit hp f i hi; have hv := lsupp_hit hq f i hu - dsimp only [bucket,pour] - rw [log_mul hu (div_ne_zero hw hv),log_div hw hv] - ring -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RelativeEntropy + +namespace OAI + +/-! # Projection Energy -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real +open scoped BigOperators +variable {A B C : Type} [Fintype A] [Fintype B] [Fintype C] + +theorem map_mass (p : Wgt A) (f : A→B) : tot (mapW p f)=tot p := by + simpa only [avg_const,mul_one] using mapW_avg p f (fun _ => 1) +omit [Fintype B] in +theorem map_nz {p : Wgt A} (hp : ∀ i, 0 ≤ p i) (f : A→B) (i : B) : + 0 ≤ mapW p f i := pr_nonneg hp +omit [Fintype B] in +theorem lsupp_witness {p : Wgt A} {f : A→B} {i} + (h : mapW p f i≠0) : ∃ x,p x≠0 ∧ f x=i := by + classical + by_contra! hh + refine h (Finset.sum_eq_zero (fun x _ => ?_)) + by_cases h : p x=0 + · change p x * ind _=0 + rw [h,zero_mul] + exact (congrArg (p x * ·) (ind_zero (hh x h))).trans (mul_zero _) + +omit [Fintype B] in +theorem lsupp_hit {p : Wgt A} (hp : ∀ i,0 ≤ p i) (f : A→B) (x : A) (h : p x≠0) : + mapW p f (f x)≠0 := by + have h' := lt_of_le_of_ne (hp x) (Ne.symm h) + have he := weight_le_tot (fun y => mul_nonneg (hp y) (ind_nonneg (f y = f x))) x + simp only [ind_true,mul_one] at he + exact (h'.trans_le he).ne' + +omit [Fintype B] in +theorem lsupp.map {p q : Wgt A} (h : lsupp p q) (hq : ∀ i,0 ≤ q i) + (f : A→B) : lsupp (mapW p f) (mapW q f) := by + intro i hi + obtain ⟨x,hx,rfl⟩ := lsupp_witness hi + exact lsupp_hit hq f x (h x hx) + +omit [Fintype C] in +theorem map_nested {p : Wgt A} (f : A→B) (g : B→C) : + mapW (mapW p f) g = mapW p (g ∘ f) := funext fun _ => mapW_pr p f _ + +omit [Fintype C] in +theorem map_mix (w : Wgt A) (p : A→ Wgt B) (f : B→C) : + mapW (mixW w p) f = mixW w (fun i => mapW (p i) f) := funext fun _ => mixW_avg .. + +omit [Fintype B] in +theorem map_resize (p : Wgt A) (f : A→B) (u : Wgt B) : + mapW (fun i => p i*u (f i)) f = (fun i => mapW p f i * u i) := by + funext i + unfold mapW pr avg + rw [Finset.sum_mul] + apply sum_congr rfl + intro j _ + by_cases h : f j=i + · simp only [h,ind_true,mul_one] + simp only [ind_zero h,mul_zero,zero_mul] + +def pour (q : Wgt A) (f : A→B) (w : Wgt B) := + fun i => q i * (w (f i) / mapW q f (f i)) + +omit [Fintype B] in +theorem map_pour (q : Wgt A) (f : A → B) (w : Wgt B) (h : lsupp w (mapW q f)) : + mapW (pour q f w) f=w := by + unfold pour + rw [map_resize (u:=fun i => w i / mapW q f i)] + funext i + by_cases he : w i=0 + · simp only [he,zero_div,mul_zero] + have hm := h i he + field_simp + +def bucket (q : Wgt A) (f : A→B) (p : Wgt A) := pour q f (mapW p f) + +omit [Fintype B] in +theorem pour_nz {q : Wgt A} {u : Wgt B} (f : A→B) + (hq : ∀ i,0 ≤ q i) (hu : ∀ i,0 ≤ u i) (i) : 0 ≤ pour q f u i := + mul_nonneg (hq i) (div_nonneg (hu _) (map_nz hq f _)) + +omit [Fintype B] in +theorem bucket_scale (q p : Wgt A) (hq : ∀ i,0≤q i) (h : lsupp p q) (f : A→B) : + mapW (bucket q f p) f=mapW p f := map_pour q f _ (lsupp.map h hq f) + +theorem bucket_law {q p : Wgt A} (hp : IsLaw p) + (f : A→B) (hq : ∀ i,0≤q i) (h : lsupp p q) : + IsLaw (bucket q f p) := by + refine ⟨pour_nz f hq (map_nz hp.nz f),?_⟩ + rw [←map_mass _ f,bucket_scale q p hq h,map_mass,hp.total] + +omit [Fintype B] in +theorem lsupp_bucket {p q : Wgt A} (f : A → B) (hp : ∀ i, 0 ≤ p i) + (hq : ∀ i,0 ≤ q i) (h : lsupp p q) : lsupp p (bucket q f p) := + fun x hx => mul_ne_zero (h x hx) (div_ne_zero (lsupp_hit hp f x hx) (lsupp_hit hq f x (h x hx))) + +omit [Fintype C] in +theorem bucket_nested (q p : Wgt A) (f : A→B) (g : B→C) : + mapW (bucket q (g ∘ f) p) f=bucket (mapW q f) g (mapW p f) := by + unfold bucket pour + rw [map_nested,map_nested] + have h := map_resize q f (fun i=>mapW p (g∘f) (g i)/mapW q (g∘f) (g i)) + exact h + +omit [Fintype B] in +theorem bucket_mix (q : Wgt A) (f : A → B) (w : Wgt C) (p : C→ Wgt A) : + bucket q f (mixW w p)=mixW w (fun y => bucket q f (p y)) := by + unfold bucket pour + rw [map_mix] + funext i; simp only [mixW,avg_mul',avg_div] + +theorem tension_stage (p q : Wgt A) (hp : ∀ i,0 ≤ p i) (hq : ∀ i, 0≤ q i) + (h : lsupp p q) (f : A→B) : + tension p q=tension p (bucket q f p)+tension (mapW p f) (mapW q f) := by + unfold tension + rw [mapW_avg, ← avg_add] + refine avg_congr (fun i hi => ?_) + have hu := h i hi; have hw := lsupp_hit hp f i hi; have hv := lsupp_hit hq f i hu + dsimp only [bucket,pour] + rw [log_mul hu (div_ne_zero hw hv),log_div hw hv] + ring +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectionError.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectionError.lean index 6b0fbe8b450d555e218e240214b151c083b0f0f7..ddd2da271c445df6837afb127a87aeafff1918f5 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectionError.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectionError.lean @@ -1,100 +1,100 @@ -import OAI.Combinatorics.HadwigerCounterexample.ResidualRegularity - -namespace OAI - -/-! # Projection Error -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix LinearMap Module Filter Function -open scoped BigOperators -variable {A B I : Type} [Fintype A] [Fintype B] [Fintype I] - -def rebate (u f g : Wgt A) (p : A→B) := - dip u f g - dip u (banner u p f) (banner u p g) -omit [Fintype B] in -theorem rebate_sym (u f g : Wgt A) (p : A→B) : - rebate u f g p=rebate u g f p := by unfold rebate; rw [dip_sym u f,dip_sym u (banner u p f)] -theorem rebate_calc (u f g : Wgt A) (p : A→B) (hu : ∀ i,0≤u i) : - rebate u f g p=dip u (fun i=>f i-banner u p f i) g := by - unfold rebate - rw [dip_sub,dip_sym u (banner u p f) (banner u p g)] - exact congrArg (dip u f g - ·) ((show dip u (banner u p g) (banner u p f)=dip u g (banner u p f) from - cash_orth u hu p g (cashbook u p f)).trans (dip_sym ..)) -def lcost (u f g : Wgt A) := avg u (fun i=>|f i-g i|) - -theorem rebate_cost (u f g f' : Wgt A) (p : A→B) (hu : ∀ i,0≤u i) - (r : ℝ) (hr : 0 ≤ r) (h : ∀ i,|g i|≤r) : - |rebate u f g p-rebate u f' g p| ≤ lcost u f f' * (2*r) := by - rw [rebate_sym u f g,rebate_sym u f' g,rebate_calc u g f p hu,rebate_calc u g f' p hu] - unfold dip; rw [←avg_sub] - apply (abs_avg_le hu).trans - have hz i : |g i-banner u p g i|≤2*r := - ((abs_sub ..).trans (add_le_add (h i) (cashbook_bound u hu p g r hr h (p i)))).trans_eq - (two_mul _).symm - unfold lcost; rw [←avg_mul]; apply avg_mono hu - intro i - dsimp only - rw [←mul_sub,abs_mul,mul_comm] - exact mul_le_mul_of_nonneg_left (hz _) (abs_nonneg _) - -def syrup (r : ℝ) (x : ℝ) := min (max x 0) r -def mcut (r : ℝ) (u : Wgt A) (f : Wgt A) := syrup r ∘ density u f -theorem syrup_range (r x : ℝ) (h : 0≤r) : - 0≤ syrup r x∧ syrup r x ≤ r := ⟨le_min (le_max_right ..) h,min_le_right ..⟩ -omit [Fintype A] in -theorem mcut_range (r : ℝ) (u f : Wgt A) (h : 0≤r) (x) : - 0≤mcut r u f x∧mcut r u f x ≤ r := syrup_range _ _ h - -private theorem jelly (r x y : ℝ) : - |syrup r x-syrup r y| ≤ |x-y| := by - wlog hh : x≤y generalizing x y - · rw [abs_sub_comm,abs_sub_comm x y]; exact this y x (le_of_not_ge hh) - have hr : syrup r x ≤ syrup r y := min_le_min (max_le_max hh le_rfl) le_rfl - rw [abs_of_nonpos (sub_nonpos.mpr hh),abs_of_nonpos (sub_nonpos.mpr hr)] - unfold syrup - rcases le_total x 0 with h|h <;> rcases le_total y 0 with he|he - · rw [max_eq_right h,max_eq_right he]; linarith only [hh] - · rw [max_eq_right h,max_eq_left he]; rcases le_total 0 r with h'|h' - · rw [min_eq_left h'] - linarith only [h, min_le_left y r] - rw [min_eq_right h',min_eq_right (by linarith)] - linarith - · obtain rfl : x=y := by linarith - simp - rw [max_eq_left h,max_eq_left he] - rcases le_total x r with h'|h' - · rw [min_eq_left h']; linarith only [min_le_left y r] - rw [min_eq_right h',min_eq_right (by linarith)]; linarith - -theorem mcut_cost (r : ℝ) (u f g : Wgt A) (hu : ∀ i,0≤u i) : - lcost u (mcut r u f) (mcut r u g)≤ varOne f g := by - unfold lcost avg varOne; refine sum_le_sum fun i _ => ?_ - apply (mul_le_mul_of_nonneg_left (jelly r (density u f i) (density u g i)) (hu i)).trans - by_cases hx : u i=0 - · rw [hx,zero_mul]; exact abs_nonneg _ - unfold density; rw [←sub_div,abs_div,abs_of_nonneg (hu _)] - exact le_of_eq (by field_simp) - -set_option maxHeartbeats 500000 in -theorem roster_clip (r : ℝ) (u : Wgt A) (hu : IsLaw u) (hr : 0≤r) (Q : Wgt A→ Prop) - (k : ℕ) (ε : ℝ) (h : roster Q k ε) : - ∃ f : Fin (k+1)→Wgt A,(∀ i x,|f i x|≤r) ∧ - ∀ w,Q w→∃ i,lcost u (mcut r u w) (f i)≤ ε := by - classical - obtain ⟨t,ht,v,hv⟩:=h - let W:= fun i : Fin (k+1)=> if h:i.val 0) - refine ⟨W,fun i x=>?_,fun i hi=>?_⟩ - · unfold W; split - next h => - obtain ⟨he,hy⟩:=mcut_range r u (v (⟨i.val,h⟩)) hr x - rwa [abs_of_nonneg he] - simpa only [abs_zero] using hr - obtain ⟨j,hj⟩:=hv i hi - exact ⟨⟨j.val,Nat.lt_succ_of_lt (j.isLt.trans_le ht)⟩,by - unfold W; rw [dite_eq_left j.isLt]; exact (mcut_cost r u i _ hu.nz).trans hj⟩ -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ResidualRegularity + +namespace OAI + +/-! # Projection Error -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix LinearMap Module Filter Function +open scoped BigOperators +variable {A B I : Type} [Fintype A] [Fintype B] [Fintype I] + +def rebate (u f g : Wgt A) (p : A→B) := + dip u f g - dip u (banner u p f) (banner u p g) +omit [Fintype B] in +theorem rebate_sym (u f g : Wgt A) (p : A→B) : + rebate u f g p=rebate u g f p := by unfold rebate; rw [dip_sym u f,dip_sym u (banner u p f)] +theorem rebate_calc (u f g : Wgt A) (p : A→B) (hu : ∀ i,0≤u i) : + rebate u f g p=dip u (fun i=>f i-banner u p f i) g := by + unfold rebate + rw [dip_sub,dip_sym u (banner u p f) (banner u p g)] + exact congrArg (dip u f g - ·) ((show dip u (banner u p g) (banner u p f)=dip u g (banner u p f) from + cash_orth u hu p g (cashbook u p f)).trans (dip_sym ..)) +def lcost (u f g : Wgt A) := avg u (fun i=>|f i-g i|) + +theorem rebate_cost (u f g f' : Wgt A) (p : A→B) (hu : ∀ i,0≤u i) + (r : ℝ) (hr : 0 ≤ r) (h : ∀ i,|g i|≤r) : + |rebate u f g p-rebate u f' g p| ≤ lcost u f f' * (2*r) := by + rw [rebate_sym u f g,rebate_sym u f' g,rebate_calc u g f p hu,rebate_calc u g f' p hu] + unfold dip; rw [←avg_sub] + apply (abs_avg_le hu).trans + have hz i : |g i-banner u p g i|≤2*r := + ((abs_sub ..).trans (add_le_add (h i) (cashbook_bound u hu p g r hr h (p i)))).trans_eq + (two_mul _).symm + unfold lcost; rw [←avg_mul]; apply avg_mono hu + intro i + dsimp only + rw [←mul_sub,abs_mul,mul_comm] + exact mul_le_mul_of_nonneg_left (hz _) (abs_nonneg _) + +def syrup (r : ℝ) (x : ℝ) := min (max x 0) r +def mcut (r : ℝ) (u : Wgt A) (f : Wgt A) := syrup r ∘ density u f +theorem syrup_range (r x : ℝ) (h : 0≤r) : + 0≤ syrup r x∧ syrup r x ≤ r := ⟨le_min (le_max_right ..) h,min_le_right ..⟩ +omit [Fintype A] in +theorem mcut_range (r : ℝ) (u f : Wgt A) (h : 0≤r) (x) : + 0≤mcut r u f x∧mcut r u f x ≤ r := syrup_range _ _ h + +private theorem jelly (r x y : ℝ) : + |syrup r x-syrup r y| ≤ |x-y| := by + wlog hh : x≤y generalizing x y + · rw [abs_sub_comm,abs_sub_comm x y]; exact this y x (le_of_not_ge hh) + have hr : syrup r x ≤ syrup r y := min_le_min (max_le_max hh le_rfl) le_rfl + rw [abs_of_nonpos (sub_nonpos.mpr hh),abs_of_nonpos (sub_nonpos.mpr hr)] + unfold syrup + rcases le_total x 0 with h|h <;> rcases le_total y 0 with he|he + · rw [max_eq_right h,max_eq_right he]; linarith only [hh] + · rw [max_eq_right h,max_eq_left he]; rcases le_total 0 r with h'|h' + · rw [min_eq_left h'] + linarith only [h, min_le_left y r] + rw [min_eq_right h',min_eq_right (by linarith)] + linarith + · obtain rfl : x=y := by linarith + simp + rw [max_eq_left h,max_eq_left he] + rcases le_total x r with h'|h' + · rw [min_eq_left h']; linarith only [min_le_left y r] + rw [min_eq_right h',min_eq_right (by linarith)]; linarith + +theorem mcut_cost (r : ℝ) (u f g : Wgt A) (hu : ∀ i,0≤u i) : + lcost u (mcut r u f) (mcut r u g)≤ varOne f g := by + unfold lcost avg varOne; refine sum_le_sum fun i _ => ?_ + apply (mul_le_mul_of_nonneg_left (jelly r (density u f i) (density u g i)) (hu i)).trans + by_cases hx : u i=0 + · rw [hx,zero_mul]; exact abs_nonneg _ + unfold density; rw [←sub_div,abs_div,abs_of_nonneg (hu _)] + exact le_of_eq (by field_simp) + +set_option maxHeartbeats 500000 in +theorem roster_clip (r : ℝ) (u : Wgt A) (hu : IsLaw u) (hr : 0≤r) (Q : Wgt A→ Prop) + (k : ℕ) (ε : ℝ) (h : roster Q k ε) : + ∃ f : Fin (k+1)→Wgt A,(∀ i x,|f i x|≤r) ∧ + ∀ w,Q w→∃ i,lcost u (mcut r u w) (f i)≤ ε := by + classical + obtain ⟨t,ht,v,hv⟩:=h + let W:= fun i : Fin (k+1)=> if h:i.val 0) + refine ⟨W,fun i x=>?_,fun i hi=>?_⟩ + · unfold W; split + next h => + obtain ⟨he,hy⟩:=mcut_range r u (v (⟨i.val,h⟩)) hr x + rwa [abs_of_nonneg he] + simpa only [abs_zero] using hr + obtain ⟨j,hj⟩:=hv i hi + exact ⟨⟨j.val,Nat.lt_succ_of_lt (j.isLt.trans_le ht)⟩,by + unfold W; rw [dite_eq_left j.isLt]; exact (mcut_cost r u i _ hu.nz).trans hj⟩ +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectionNets.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectionNets.lean index 2384097be76efe2473934be908c1a54065cb7122..fe3cebc1e3d5b5eb978c9a623d1f35cae7ba9f12 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectionNets.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ProjectionNets.lean @@ -1,106 +1,106 @@ -import OAI.Combinatorics.HadwigerCounterexample.RoundedRefinements - -namespace OAI - -/-! # Projection Nets -/ - -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 stamina_equiv (p : Wgt A) (e : A≃C) (a : ℝ) - (h : stamina p a) : - stamina (mapW p e) a := by - intro i hi; rw [mapW_equiv_val] at * - exact h _ hi - -theorem tension_equiv (p q : Wgt A) (e : A≃C) : - tension (mapW p e) (mapW q e)=tension p q := by - unfold tension - rw [mapW_avg] - simp_rw [mapW_equiv_val,Equiv.symm_apply_apply] - -theorem budget_equiv (μ : Wgt A) (p : A → Wgt B) (f : B→C) (e : C≃D) : - budget μ p (e ∘ f)=budget μ p f := by - unfold budget - simp_rw [←map_nested f _,tension_equiv] - -def ample (μ : Wgt A) (p : A→Wgt B) (r : ℕ) (ε : ℝ) := - ∃ t : ℕ,t ≤ r ∧ ∃ f : B → Fin t,∀ w,catalog μ p w → - varOne w (bucket unif f w) ≤ ε - -set_option maxHeartbeats 800000 in -theorem ample_thresh (V ε : ℝ) (hε : 0<ε) : - ∃ (r : ℕ) (δ : ℝ),0<δ ∧ ∀ (A B : Type) [Fintype A] [Fintype B] [Nonempty B] - (μ : Wgt A) (p : A→ Wgt B), Ultra μ p → - tariffs μ p r δ V → ample μ p r ε := by - classical - let c := ε/8 - have hc : 0 ?_⟩ - let e : Wgt B := unif - have he : IsLaw e := unif_law - by_contra h - have hr2 : 2≤r := by - unfold r; rw [pow_succ] - have : 0<2^D := by positivity - omega - have ht := hh A B μ p hw (tariffs_monotone hV hr2 (min_le_left ..)) - have hstep (n : ℕ) (hn : n≤ D) : - ∃ f : B → Fin (2^n), stamina (mapW e f) (k^n) ∧ - ↑n*c^2 ≤ budget μ p f := by - induction n with - | zero => - let f := fun _ : B => (0 : Fin (2^0)) - refine ⟨f,?_,by simpa using budget_nonneg hw f⟩ - intro i hi - have hi : i = 0 := by - have hh := i.isLt; norm_num at hh - exact Fin.ext (by simp only [Fin.val_zero]; omega) - subst i; change 1 ≤ pr e (fun x => f x=0) - simp [f,he.total] - | succ i ih => - obtain ⟨f,hf,hB⟩ := ih (by omega) - let t := 2^i - have he' : ∃ w,catalog μ p w ∧ 8*c (min_le_right ..).trans (hf i hi) - have hz := hV _ (f:=f) (by simp; unfold r; rw [pow_succ]; omega) he' - exact (not_lt_of_ge (le_trans hf' hz)) hd -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RoundedRefinements + +namespace OAI + +/-! # Projection Nets -/ + +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 stamina_equiv (p : Wgt A) (e : A≃C) (a : ℝ) + (h : stamina p a) : + stamina (mapW p e) a := by + intro i hi; rw [mapW_equiv_val] at * + exact h _ hi + +theorem tension_equiv (p q : Wgt A) (e : A≃C) : + tension (mapW p e) (mapW q e)=tension p q := by + unfold tension + rw [mapW_avg] + simp_rw [mapW_equiv_val,Equiv.symm_apply_apply] + +theorem budget_equiv (μ : Wgt A) (p : A → Wgt B) (f : B→C) (e : C≃D) : + budget μ p (e ∘ f)=budget μ p f := by + unfold budget + simp_rw [←map_nested f _,tension_equiv] + +def ample (μ : Wgt A) (p : A→Wgt B) (r : ℕ) (ε : ℝ) := + ∃ t : ℕ,t ≤ r ∧ ∃ f : B → Fin t,∀ w,catalog μ p w → + varOne w (bucket unif f w) ≤ ε + +set_option maxHeartbeats 800000 in +theorem ample_thresh (V ε : ℝ) (hε : 0<ε) : + ∃ (r : ℕ) (δ : ℝ),0<δ ∧ ∀ (A B : Type) [Fintype A] [Fintype B] [Nonempty B] + (μ : Wgt A) (p : A→ Wgt B), Ultra μ p → + tariffs μ p r δ V → ample μ p r ε := by + classical + let c := ε/8 + have hc : 0 ?_⟩ + let e : Wgt B := unif + have he : IsLaw e := unif_law + by_contra h + have hr2 : 2≤r := by + unfold r; rw [pow_succ] + have : 0<2^D := by positivity + omega + have ht := hh A B μ p hw (tariffs_monotone hV hr2 (min_le_left ..)) + have hstep (n : ℕ) (hn : n≤ D) : + ∃ f : B → Fin (2^n), stamina (mapW e f) (k^n) ∧ + ↑n*c^2 ≤ budget μ p f := by + induction n with + | zero => + let f := fun _ : B => (0 : Fin (2^0)) + refine ⟨f,?_,by simpa using budget_nonneg hw f⟩ + intro i hi + have hi : i = 0 := by + have hh := i.isLt; norm_num at hh + exact Fin.ext (by simp only [Fin.val_zero]; omega) + subst i; change 1 ≤ pr e (fun x => f x=0) + simp [f,he.total] + | succ i ih => + obtain ⟨f,hf,hB⟩ := ih (by omega) + let t := 2^i + have he' : ∃ w,catalog μ p w ∧ 8*c (min_le_right ..).trans (hf i hi) + have hz := hV _ (f:=f) (by simp; unfold r; rw [pow_succ]; omega) he' + exact (not_lt_of_ge (le_trans hf' hz)) hd +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/QuadraticFourier.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/QuadraticFourier.lean index e65e615b7ebf5c3414ff10b7afca69f243dadf3c..2eb726d40c78bc0a4b60ec103a18568eae742214 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/QuadraticFourier.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/QuadraticFourier.lean @@ -1,83 +1,83 @@ -import OAI.Combinatorics.HadwigerCounterexample.FreeBlockFourier - -namespace OAI - -/-! # Quadratic Fourier -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Module LinearMap Submodule Function Finset -variable {I J : Type} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] - -theorem phase_trans (t : Vec I) (f : Wgt (Vec I)) : - avg unif (fun y => f (y+t))=avg unif f := by - let E : Vec I ≃ Vec I := ⟨(·+t),(·+t),add_polar t,add_polar t⟩ - exact avg_bij E unif f - -theorem half_power (x a : ℝ) (ha : x^2 ≤ bp a) : |x|≤ bp (a/2) := - le_of_pow_le_pow_left₀ (by decide : 2≠0) (bp_pos _).le (by - rw [sq_abs,pow_two (bp _),←bp_add,show a/2+a/2=a by ring]; exact ha) - -def polarize (f : Vec I→F) (M : Mat I I) := - ∀ x y,f (x+y)+f x=f y+f 0+dotProduct y (M *ᵥ x) - -set_option maxHeartbeats 600000 in -theorem flare_rank (f : Vec I→F) (M : Mat I I) (h : polarize f M) : - |avg unif (fun x => wsign (f x))| ≤ bp (-(M.rank:ℝ)/2) := by - classical - let g (x : Vec I) := wsign (f x) - have hh : - avg unif g ^ 2 = avg unif (fun x : Vec I => avg unif (fun y : Vec I => - g (x+y)*g y)) := by - have hi (i : Vec I) : avg unif (fun x => g (x+i)*g i)=avg unif g*g i := by - rw [avg_mul,phase_trans] - rw [avg_avg]; simp_rw [hi,avg_mul'] - ring - let L := Mᵀ - have hg x y : g (x+y)*g y= wsign (f x+f 0)*wsign (dotL (L *ᵥ x) y) := by - unfold g; rw [← wsign_add,← wsign_add,add_comm x y,h y x] - unfold L - congr 2 - change dotProduct x (M *ᵥ y)=dotProduct _ y - rw [dotProduct_comm _ y,dotProduct_transpose_mulVec] - have hi (x : Vec I) : - avg unif (fun y : Vec I => g (x+y)*g y) ≤ ind ((L *ᵥ x)=0) := by - simp_rw [hg x,avg_mul',wsign_lin] - have he : dotL (L *ᵥ x)=0 ↔ L *ᵥ x=0 := by - constructor - · exact fun h => dot_ext_zero fun y => by rw [dotProduct_comm]; exact LinearMap.congr_fun h y - intro h; rw [h]; exact LinearMap.ext (fun x => zero_dotProduct x) - rw [he] - exact (mul_le_mul_of_nonneg_right ((le_abs_self _).trans_eq (wsign_abs _)) - (ind_nonneg _)).trans_eq (one_mul _) - refine half_power _ _ (?_) - change avg unif g^2≤_ - rw [hh] - refine (avg_mono unif_law.nz hi).trans_eq ?_ - have he : pr unif (fun x => L.mulVecLin x=0) = _ := pr_unif_lin L.mulVecLin 0 - rw [ind_one (LinearMap.range L.mulVecLin).zero_mem,one_mul] at he - change pr unif _=_ - exact he.trans (by change bp (-(L.rank:ℝ))=_; rw [show L=Mᵀ from rfl,Matrix.rank_transpose]) - -omit [DecidableEq I] [DecidableEq J] in -theorem flare_affine (M : Mat J J) (P : Mat J I) (k : Vec J) (a : F) (i : Vec I) : - let Q := fun x => dotProduct i x + (a + evmat M (P *ᵥ x+k) (P *ᵥ x+k)) - polarize Q (pullM P P (M+Mᵀ)) := by - intro Q x y - have he : dotProduct y ((pullM P P (M+Mᵀ)) *ᵥ x)= - evmat M (P *ᵥ y) (P *ᵥ x) + evmat M (P *ᵥ x) (P *ᵥ y) := by - change evmat _ _ _=_ - rw [evmat_pull,evmat_addM, evmat_transpose] - rw [he] - unfold Q evmat - simp only [dotProduct_zero,Matrix.mulVec_zero,mulVec_add,dotProduct_add,add_dotProduct, - zero_add] - - ring_nf - simp only [mul_two,char_two,add_zero,zero_add] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FreeBlockFourier + +namespace OAI + +/-! # Quadratic Fourier -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Module LinearMap Submodule Function Finset +variable {I J : Type} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] + +theorem phase_trans (t : Vec I) (f : Wgt (Vec I)) : + avg unif (fun y => f (y+t))=avg unif f := by + let E : Vec I ≃ Vec I := ⟨(·+t),(·+t),add_polar t,add_polar t⟩ + exact avg_bij E unif f + +theorem half_power (x a : ℝ) (ha : x^2 ≤ bp a) : |x|≤ bp (a/2) := + le_of_pow_le_pow_left₀ (by decide : 2≠0) (bp_pos _).le (by + rw [sq_abs,pow_two (bp _),←bp_add,show a/2+a/2=a by ring]; exact ha) + +def polarize (f : Vec I→F) (M : Mat I I) := + ∀ x y,f (x+y)+f x=f y+f 0+dotProduct y (M *ᵥ x) + +set_option maxHeartbeats 600000 in +theorem flare_rank (f : Vec I→F) (M : Mat I I) (h : polarize f M) : + |avg unif (fun x => wsign (f x))| ≤ bp (-(M.rank:ℝ)/2) := by + classical + let g (x : Vec I) := wsign (f x) + have hh : + avg unif g ^ 2 = avg unif (fun x : Vec I => avg unif (fun y : Vec I => + g (x+y)*g y)) := by + have hi (i : Vec I) : avg unif (fun x => g (x+i)*g i)=avg unif g*g i := by + rw [avg_mul,phase_trans] + rw [avg_avg]; simp_rw [hi,avg_mul'] + ring + let L := Mᵀ + have hg x y : g (x+y)*g y= wsign (f x+f 0)*wsign (dotL (L *ᵥ x) y) := by + unfold g; rw [← wsign_add,← wsign_add,add_comm x y,h y x] + unfold L + congr 2 + change dotProduct x (M *ᵥ y)=dotProduct _ y + rw [dotProduct_comm _ y,dotProduct_transpose_mulVec] + have hi (x : Vec I) : + avg unif (fun y : Vec I => g (x+y)*g y) ≤ ind ((L *ᵥ x)=0) := by + simp_rw [hg x,avg_mul',wsign_lin] + have he : dotL (L *ᵥ x)=0 ↔ L *ᵥ x=0 := by + constructor + · exact fun h => dot_ext_zero fun y => by rw [dotProduct_comm]; exact LinearMap.congr_fun h y + intro h; rw [h]; exact LinearMap.ext (fun x => zero_dotProduct x) + rw [he] + exact (mul_le_mul_of_nonneg_right ((le_abs_self _).trans_eq (wsign_abs _)) + (ind_nonneg _)).trans_eq (one_mul _) + refine half_power _ _ (?_) + change avg unif g^2≤_ + rw [hh] + refine (avg_mono unif_law.nz hi).trans_eq ?_ + have he : pr unif (fun x => L.mulVecLin x=0) = _ := pr_unif_lin L.mulVecLin 0 + rw [ind_one (LinearMap.range L.mulVecLin).zero_mem,one_mul] at he + change pr unif _=_ + exact he.trans (by change bp (-(L.rank:ℝ))=_; rw [show L=Mᵀ from rfl,Matrix.rank_transpose]) + +omit [DecidableEq I] [DecidableEq J] in +theorem flare_affine (M : Mat J J) (P : Mat J I) (k : Vec J) (a : F) (i : Vec I) : + let Q := fun x => dotProduct i x + (a + evmat M (P *ᵥ x+k) (P *ᵥ x+k)) + polarize Q (pullM P P (M+Mᵀ)) := by + intro Q x y + have he : dotProduct y ((pullM P P (M+Mᵀ)) *ᵥ x)= + evmat M (P *ᵥ y) (P *ᵥ x) + evmat M (P *ᵥ x) (P *ᵥ y) := by + change evmat _ _ _=_ + rw [evmat_pull,evmat_addM, evmat_transpose] + rw [he] + unfold Q evmat + simp only [dotProduct_zero,Matrix.mulVec_zero,mulVec_add,dotProduct_add,add_dotProduct, + zero_add] + + ring_nf + simp only [mul_two,char_two,add_zero,zero_add] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/QuadraticTesters.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/QuadraticTesters.lean index 22bbf36fe8ae3343af3da946c30d1dca7fb48a40..483f17f267d8e2138ec2e6316cbcf19c63f94c2b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/QuadraticTesters.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/QuadraticTesters.lean @@ -1,163 +1,163 @@ -import OAI.Combinatorics.HadwigerCounterexample.MomentCoordinates - -namespace OAI - -/-! # Quadratic Testers -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix -open scoped BigOperators - -theorem pair_outers {I J : Type} [Fintype I] [Fintype J] (x x' : Vec I) (y y' : Vec J) : - mpair (vecMulVec x y) (vecMulVec x' y') = - dotProduct x x' * dotProduct y y' := by - simp only [mpair, dotProduct,vecMulVec_apply,LinearMap.coe_mk,AddHom.coe_mk, - Finset.sum_mul,Finset.mul_sum] - rw [Finset.sum_comm] - refine Finset.sum_congr rfl fun i _ => ?_ - refine Finset.sum_congr rfl fun j _ => ?_ - ring - -theorem mpair_sum {I J : Type} [Fintype I] [Fintype J] (m : Mat I J) - {α : Type*} (s : Finset α) (f : α → Mat I J) : - mpair (∑ i ∈ s, f i) m = ∑ i ∈ s, mpair (f i) m := by - rw [mpair_comm,map_sum] - exact Finset.sum_congr rfl fun i _ => mpair_comm _ _ - -theorem mpair_add {I J : Type} [Fintype I] [Fintype J] (A B M : Mat I J) : - mpair (A+B) M = mpair A M + mpair B M := by rw [mpair_comm,map_add,mpair_comm M,mpair_comm M] - -theorem mpair_smul {I J : Type} [Fintype I] [Fintype J] (b : F) (A M : Mat I J) : - mpair (b • A) M = b * mpair A M := by rw [mpair_comm,map_smul,mpair_comm M, smul_eq_mul] - -variable (p : Shape) - -def pick (n : ℕ) (u : SelIdx p.b p.j) (d : Block p.g) (i : ℕ) : Ray p n := - if h : i < n then Pi.single (u,some (d,⟨i,h⟩)) 1 else 0 - -def readBit {n g} (z : Base g n) (d : Block g) (i : ℕ) : F := - if h : i < n then z (d,⟨i,h⟩) else 0 - -def testM (n : ℕ) (d : Block p.g) : Moment p n := - ∑ i : Fin p.r, vecMulVec (pick p n emptySel d (2*i.val)) - (pick p n emptySel d (2*i.val+1)) - -def etab (n) (d : Block p.g) : Moment p n →ₗ[F] F := mpair (testM p n d) - -def test (n : ℕ) (d : Block p.g) (z z' : Base p.g n) : F := - ∑ i : Fin p.r, readBit z d (2*i.val) * readBit z' d (2*i.val+1) - -theorem pick_point {n} (s) (z : Base p.g n) (u : SelIdx p.b p.j) - (d : Block p.g) (i : ℕ) : - dotProduct (pick p n u d i) (point p s z) = selV _ s u * readBit z d i := by - by_cases hi : i < n - · rw [pick,dite_eq_left hi,single_one_dotProduct,readBit,dite_eq_left hi]; rfl - · rw [pick,dite_eq_right hi,zero_dotProduct, readBit,dite_eq_right hi,mul_zero] - -theorem etab_point {n} (d : Block p.g) (s s') (z z' : Base p.g n) : - etab p n d (vecMulVec (point p s z) (point p s' z')) = test p n d z z' := by - unfold etab testM test - simp only [mpair_sum,pair_outers,pick_point] - simp [selV,emptySel] - -theorem etab_disabled {n} {l d : Tag p.g} (h : ¬allowed d l) (t : Tag p.g) - {m : Moment p n} (hm : m ∈ Wtag p n l) : - etab p n (Block.O d t) m = 0 := by - unfold Wtag at hm - induction hm using Submodule.span_induction with - | mem m hm => - obtain ⟨s,z,hz,rfl⟩ := hm - rw [mom,etab_point] - have h' (i : ℕ) : readBit z (Block.O d t) i = 0 := by - simp [readBit,hz d t h] - simp only [test,h',mul_zero,Finset.sum_const_zero] - | zero => rw [map_zero] - | add _ _ _ _ h g => rw [map_add,h,g,add_zero] - | smul _ _ _ h => rw [map_smul,h,smul_zero] - -/-- all O testers. -/ -def etaO (n) : Moment p n →ₗ[F] F := - ∑ (d : Tag p.g), ∑ (t : Tag p.g), etab p n (Block.O d t) - -def eta (n) : Moment p n →ₗ[F] F := etaO p n + etab p n Block.S - -/-- a_t read on full ambient profile using allowed tags with partner d. -/ -def roleT (n : ℕ) (t : Tag p.g) : Profile p n →ₗ[F] F := - ∑ (l : Tag p.g), ∑ d ∈ Finset.univ.filter (fun d => allowed d l), - etab p n (Block.O d t) ∘ₗ getPair p n l d - -theorem roleT_cut {n} (t : Tag p.g) (w : Tag p.g → Moment p n) - (hw : ∀ i, w i ∈ Wtag p n i) : - roleT p n t (cut p n w) = - ∑ (l : Tag p.g), ∑ (d : Tag p.g), etab p n (Block.O d t) (w l) := by - simp only [roleT,LinearMap.sum_apply,LinearMap.comp_apply,getPair_cut,map_add] - refine Finset.sum_congr rfl fun l _ => ?_ - rw [Finset.sum_filter] - refine Finset.sum_congr rfl fun d _ => ?_ - by_cases h : allowed d l - · rw [ite_eq_left h,etab_disabled p (not_allowed d) t (hw d),add_zero] - · rw [ite_eq_right h,etab_disabled p h t (hw l)] - -def role (n : ℕ) := ∑ t : Tag p.g, roleT p n t - -theorem role_cut {n} (w : Tag p.g → Moment p n) (hw : ∀ i,w i ∈ Wtag p n i) : - role p n (cut p n w) = ∑ i, etaO p n (w i) := by - simp only [role,LinearMap.sum_apply,roleT_cut _ _ _ hw] - rw [Finset.sum_comm] - refine Finset.sum_congr rfl fun l _ => ?_ - rw [Finset.sum_comm] - simp only [etaO,LinearMap.sum_apply] - -/-- b_t read on the full ambient profile. -/ -def sharedT (n : ℕ) (t : Tag p.g) : Profile p n →ₗ[F] F := - ∑ (l : Tag p.g), etab p n Block.S ∘ₗ getPair p n l t - -theorem sharedT_cut {n} (hg : Odd p.g) (t : Tag p.g) (w : Tag p.g → Moment p n) : - sharedT p n t (cut p n w) = - (∑ i, etab p n Block.S (w i)) + etab p n Block.S (w t) := by - simp only [sharedT,LinearMap.sum_apply,LinearMap.comp_apply,getPair_cut,map_add, - Finset.sum_add_distrib,Finset.sum_const, Finset.card_univ] - simp [Tag,odd_smul_bit hg] - -def sharpPick (n : ℕ) (a : Fin p.b) (i : Fin n) : Ray p n := - if h : 1 ≤ p.j then pick p n ⟨{a},by simp [h]⟩ Block.sharp i.val else 0 - -def sharpM (n : ℕ) (Y : Fin p.b → Mat (Fin n) (Fin n)) : Moment p n := - ∑ a : Fin p.b, ∑ i : Fin n, ∑ j : Fin n, - Y a i j • (vecMulVec (sharpPick p n a i) (pick p n emptySel Block.sharp j.val) + - vecMulVec (pick p n emptySel Block.sharp i.val) (sharpPick p n a j)) - -theorem sharpM_point {n} (hj : 1 ≤ p.j) (Y) (s s') (z z' : Base p.g n) : - mpair (sharpM p n Y) (vecMulVec (point p s z) (point p s' z')) = - ∑ a : Fin p.b, (s a + s' a) * - evmat (Y a) (fun i => z (Block.sharp,i)) (fun i => z' (Block.sharp,i)) := by - simp only [sharpM,mpair_sum,mpair_smul,mpair_add,pair_outers, - sharpPick,dite_eq_left hj,pick_point,readBit,dite_eq_left (Fin.isLt _)] - simp [selV,emptySel,evmat,dotProduct,mulVec,Finset.mul_sum] - refine Finset.sum_congr rfl fun a _ => Finset.sum_congr rfl fun i _ => - Finset.sum_congr rfl fun j _ => ?_ - ring - -def selfM (n) (Y : Fin p.b → Mat (Fin n) (Fin n)) : Moment p n := - ((∑ d : Tag p.g, ∑ t : Tag p.g, testM p n (Block.O d t)) + - testM p n Block.S) + sharpM p n Y - -theorem selfM_pair {n} (hj : 1 ≤ p.j) (Y) {m : Moment p n} (hm : m ∈ Wspace p n) : - mpair (selfM p n Y) m = eta p n m := by - unfold Wspace at hm - induction hm using Submodule.span_induction with - | mem m h => - obtain ⟨s,z,rfl⟩ := h - simp only [selfM,mpair_sum,mpair_add,mom,sharpM_point p hj,char_two,zero_mul, - Finset.sum_const_zero, add_zero,eta,etaO,etab,LinearMap.add_apply, - LinearMap.sum_apply] - | zero => simp only [map_zero] - | add _ _ _ _ h g => rw [map_add,h,g,map_add] - | smul _ _ _ h => rw [map_smul,h,map_smul] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.MomentCoordinates + +namespace OAI + +/-! # Quadratic Testers -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix +open scoped BigOperators + +theorem pair_outers {I J : Type} [Fintype I] [Fintype J] (x x' : Vec I) (y y' : Vec J) : + mpair (vecMulVec x y) (vecMulVec x' y') = + dotProduct x x' * dotProduct y y' := by + simp only [mpair, dotProduct,vecMulVec_apply,LinearMap.coe_mk,AddHom.coe_mk, + Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun i _ => ?_ + refine Finset.sum_congr rfl fun j _ => ?_ + ring + +theorem mpair_sum {I J : Type} [Fintype I] [Fintype J] (m : Mat I J) + {α : Type*} (s : Finset α) (f : α → Mat I J) : + mpair (∑ i ∈ s, f i) m = ∑ i ∈ s, mpair (f i) m := by + rw [mpair_comm,map_sum] + exact Finset.sum_congr rfl fun i _ => mpair_comm _ _ + +theorem mpair_add {I J : Type} [Fintype I] [Fintype J] (A B M : Mat I J) : + mpair (A+B) M = mpair A M + mpair B M := by rw [mpair_comm,map_add,mpair_comm M,mpair_comm M] + +theorem mpair_smul {I J : Type} [Fintype I] [Fintype J] (b : F) (A M : Mat I J) : + mpair (b • A) M = b * mpair A M := by rw [mpair_comm,map_smul,mpair_comm M, smul_eq_mul] + +variable (p : Shape) + +def pick (n : ℕ) (u : SelIdx p.b p.j) (d : Block p.g) (i : ℕ) : Ray p n := + if h : i < n then Pi.single (u,some (d,⟨i,h⟩)) 1 else 0 + +def readBit {n g} (z : Base g n) (d : Block g) (i : ℕ) : F := + if h : i < n then z (d,⟨i,h⟩) else 0 + +def testM (n : ℕ) (d : Block p.g) : Moment p n := + ∑ i : Fin p.r, vecMulVec (pick p n emptySel d (2*i.val)) + (pick p n emptySel d (2*i.val+1)) + +def etab (n) (d : Block p.g) : Moment p n →ₗ[F] F := mpair (testM p n d) + +def test (n : ℕ) (d : Block p.g) (z z' : Base p.g n) : F := + ∑ i : Fin p.r, readBit z d (2*i.val) * readBit z' d (2*i.val+1) + +theorem pick_point {n} (s) (z : Base p.g n) (u : SelIdx p.b p.j) + (d : Block p.g) (i : ℕ) : + dotProduct (pick p n u d i) (point p s z) = selV _ s u * readBit z d i := by + by_cases hi : i < n + · rw [pick,dite_eq_left hi,single_one_dotProduct,readBit,dite_eq_left hi]; rfl + · rw [pick,dite_eq_right hi,zero_dotProduct, readBit,dite_eq_right hi,mul_zero] + +theorem etab_point {n} (d : Block p.g) (s s') (z z' : Base p.g n) : + etab p n d (vecMulVec (point p s z) (point p s' z')) = test p n d z z' := by + unfold etab testM test + simp only [mpair_sum,pair_outers,pick_point] + simp [selV,emptySel] + +theorem etab_disabled {n} {l d : Tag p.g} (h : ¬allowed d l) (t : Tag p.g) + {m : Moment p n} (hm : m ∈ Wtag p n l) : + etab p n (Block.O d t) m = 0 := by + unfold Wtag at hm + induction hm using Submodule.span_induction with + | mem m hm => + obtain ⟨s,z,hz,rfl⟩ := hm + rw [mom,etab_point] + have h' (i : ℕ) : readBit z (Block.O d t) i = 0 := by + simp [readBit,hz d t h] + simp only [test,h',mul_zero,Finset.sum_const_zero] + | zero => rw [map_zero] + | add _ _ _ _ h g => rw [map_add,h,g,add_zero] + | smul _ _ _ h => rw [map_smul,h,smul_zero] + +/-- all O testers. -/ +def etaO (n) : Moment p n →ₗ[F] F := + ∑ (d : Tag p.g), ∑ (t : Tag p.g), etab p n (Block.O d t) + +def eta (n) : Moment p n →ₗ[F] F := etaO p n + etab p n Block.S + +/-- a_t read on full ambient profile using allowed tags with partner d. -/ +def roleT (n : ℕ) (t : Tag p.g) : Profile p n →ₗ[F] F := + ∑ (l : Tag p.g), ∑ d ∈ Finset.univ.filter (fun d => allowed d l), + etab p n (Block.O d t) ∘ₗ getPair p n l d + +theorem roleT_cut {n} (t : Tag p.g) (w : Tag p.g → Moment p n) + (hw : ∀ i, w i ∈ Wtag p n i) : + roleT p n t (cut p n w) = + ∑ (l : Tag p.g), ∑ (d : Tag p.g), etab p n (Block.O d t) (w l) := by + simp only [roleT,LinearMap.sum_apply,LinearMap.comp_apply,getPair_cut,map_add] + refine Finset.sum_congr rfl fun l _ => ?_ + rw [Finset.sum_filter] + refine Finset.sum_congr rfl fun d _ => ?_ + by_cases h : allowed d l + · rw [ite_eq_left h,etab_disabled p (not_allowed d) t (hw d),add_zero] + · rw [ite_eq_right h,etab_disabled p h t (hw l)] + +def role (n : ℕ) := ∑ t : Tag p.g, roleT p n t + +theorem role_cut {n} (w : Tag p.g → Moment p n) (hw : ∀ i,w i ∈ Wtag p n i) : + role p n (cut p n w) = ∑ i, etaO p n (w i) := by + simp only [role,LinearMap.sum_apply,roleT_cut _ _ _ hw] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun l _ => ?_ + rw [Finset.sum_comm] + simp only [etaO,LinearMap.sum_apply] + +/-- b_t read on the full ambient profile. -/ +def sharedT (n : ℕ) (t : Tag p.g) : Profile p n →ₗ[F] F := + ∑ (l : Tag p.g), etab p n Block.S ∘ₗ getPair p n l t + +theorem sharedT_cut {n} (hg : Odd p.g) (t : Tag p.g) (w : Tag p.g → Moment p n) : + sharedT p n t (cut p n w) = + (∑ i, etab p n Block.S (w i)) + etab p n Block.S (w t) := by + simp only [sharedT,LinearMap.sum_apply,LinearMap.comp_apply,getPair_cut,map_add, + Finset.sum_add_distrib,Finset.sum_const, Finset.card_univ] + simp [Tag,odd_smul_bit hg] + +def sharpPick (n : ℕ) (a : Fin p.b) (i : Fin n) : Ray p n := + if h : 1 ≤ p.j then pick p n ⟨{a},by simp [h]⟩ Block.sharp i.val else 0 + +def sharpM (n : ℕ) (Y : Fin p.b → Mat (Fin n) (Fin n)) : Moment p n := + ∑ a : Fin p.b, ∑ i : Fin n, ∑ j : Fin n, + Y a i j • (vecMulVec (sharpPick p n a i) (pick p n emptySel Block.sharp j.val) + + vecMulVec (pick p n emptySel Block.sharp i.val) (sharpPick p n a j)) + +theorem sharpM_point {n} (hj : 1 ≤ p.j) (Y) (s s') (z z' : Base p.g n) : + mpair (sharpM p n Y) (vecMulVec (point p s z) (point p s' z')) = + ∑ a : Fin p.b, (s a + s' a) * + evmat (Y a) (fun i => z (Block.sharp,i)) (fun i => z' (Block.sharp,i)) := by + simp only [sharpM,mpair_sum,mpair_smul,mpair_add,pair_outers, + sharpPick,dite_eq_left hj,pick_point,readBit,dite_eq_left (Fin.isLt _)] + simp [selV,emptySel,evmat,dotProduct,mulVec,Finset.mul_sum] + refine Finset.sum_congr rfl fun a _ => Finset.sum_congr rfl fun i _ => + Finset.sum_congr rfl fun j _ => ?_ + ring + +def selfM (n) (Y : Fin p.b → Mat (Fin n) (Fin n)) : Moment p n := + ((∑ d : Tag p.g, ∑ t : Tag p.g, testM p n (Block.O d t)) + + testM p n Block.S) + sharpM p n Y + +theorem selfM_pair {n} (hj : 1 ≤ p.j) (Y) {m : Moment p n} (hm : m ∈ Wspace p n) : + mpair (selfM p n Y) m = eta p n m := by + unfold Wspace at hm + induction hm using Submodule.span_induction with + | mem m h => + obtain ⟨s,z,rfl⟩ := h + simp only [selfM,mpair_sum,mpair_add,mom,sharpM_point p hj,char_two,zero_mul, + Finset.sum_const_zero, add_zero,eta,etaO,etab,LinearMap.add_apply, + LinearMap.sum_apply] + | zero => simp only [map_zero] + | add _ _ _ _ h g => rw [map_add,h,g,map_add] + | smul _ _ _ h => rw [map_smul,h,map_smul] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/QueryConcentration.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/QueryConcentration.lean index 99f5818bf74eb84040da9032496eee9260acf1bf..165ce433a55f06a30609ebfd25eafeac1ad17737 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/QueryConcentration.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/QueryConcentration.lean @@ -1,172 +1,172 @@ -import OAI.Combinatorics.HadwigerCounterexample.GroupedQueryIndependence - -namespace OAI - -/-! # Query Concentration -/ - -noncomputable section -namespace HadwigerCounterexample -open Module Matrix Finset Function -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I G A K D : Type} [Fintype I] [Fintype G] [Fintype A] -variable [Fintype K] [Fintype D] [DecidableEq I] [DecidableEq G] [DecidableEq K] - -structure Program (p : Shape) (n : ℕ) {I G : Type} (g : Route I G) (A : Type) where - left : A→NomQuery p n g - right : A→NomQuery p n g - -variable {g : Route I G} - -namespace Program -variable (s : Program p n g A) - -def free (x : K→ A) := - (∀ i,Injective (pooled (s.left ∘ x) i).mulVec)∧ - (∀ i,Injective (pooled (s.right ∘ x) i).mulVec) - -def showKey (x : A) (o : Forum p n N G) := - peekR p g (s.left x) (s.right x) o - -def oexpect (w : Wgt A) (F : A → Rack I N → ℝ) (o : Forum p n N G) := - avg w (fun x => F x (s.showKey x o)) -end Program - -theorem forum_law (m : Mixer p n) {N : ℕ} (hN : 2*num (Full p n) unifOn_law (framesAt_exists (gramCond_exists m) - (by rw [←two_mul]; simpa only [num,Fintype.card_fin] using hN))) - -theorem avg_bound1 {w : Wgt A} (hw : IsLaw w) (f : Wgt A) (hf : ∀ x,|f x|≤1) : - |avg w f|≤1 := (abs_avg_le hw.nz).trans (hw.avg_le hf) -theorem avg_cross_sq (w : Wgt A) (f : Wgt A) : - avg w f ^ 2=avg (draws Bool w) (fun q => f (q true)* f (q false)) := by - let g (i : Bool) := f - have hh := prodW_avg (fun _ : Bool => w) g - have he : prodW g=(fun q => f (q true)* f (q false)) := by ext; unfold prodW; rw [Fintype.prod_bool] - rw [he,Fintype.prod_bool] at hh; rw [pow_two]; exact hh.symm - -theorem avg_var (w : Wgt A) (f : Wgt A) (hw : IsLaw w) : - avg w (fun x => (f x-avg w f)^2) = avg w (fun x => f x^2) - (avg w f)^2 := by - let g := avg w f - have hh (x) : (f x-g)^2=f x^2-2*g*f x+g^2 := by ring - change avg w (fun x => (f x-g)^2)=_ - simp_rw [hh,avg_add,avg_sub,avg_mul',hw.avg_const] - unfold g; ring - -namespace Program -variable {s : Program p n g A} - -set_option maxHeartbeats 800000 in -theorem oVar (m : Mixer p n) (hN : 2*num (Full p n) < N) - (T : A→Wgt (Rack I N)) - (w : Wgt A) (hw : IsLaw w) (hT : ∀ i x,|T i x|≤1) - (k : ℝ) (hk : ∀ i,num (Port (tied g Bool) i)≤k) - (hK : 2*k-N≤-1) - (r : ℝ) (hr : pr (draws Bool w) (fun x => ¬ s.free x) ≤ r) : - let v := forumLaw (G:=G) m N - let f := s.oexpect w T - avg v (fun o => (f o-avg v f)^2) ≤ - 2*r + 2*netFact (tied g Bool)*twinkle (tied g Bool) k N := by - classical - let v := forumLaw (G:=G) m N - let f := s.oexpect w T - let F (x : A) := fun o => T x (s.showKey x o) - let D := draws Bool w - let B := 2*netFact (tied g Bool)*twinkle (tied g Bool) k N - have hD : IsLaw D := draws_law hw - have hv : IsLaw v := forum_law _ hN - let V (x : Bool→A) := avg v (fun o => F (x true) o * F (x false) o) - let W (x : Bool→A) := avg v (F (x true))*avg v (F (x false)) - have hW : - (avg v f)^2 = avg D W := by - unfold f oexpect - rw [avg_avg,avg_cross_sq] - have hV : - avg v (fun x => f x^2) = avg D V := by - unfold f oexpect; simp_rw [avg_cross_sq]; rw [avg_avg] - have hi x : - V x-W x ≤ 2*ind (¬s.free x)+B := by - by_cases he : s.free x - · have hh := pooled_batch (s.left ∘ x) (s.right ∘ x) m hN k hk hK he.1 he.2 - (T ∘ x) (fun i y => hT _ _) - simp_rw [Fintype.prod_bool] at hh - rw [ind_zero (fun h => h he),mul_zero,zero_add] - exact (le_abs_self _).trans hh - have h1 (a b : ℝ) (h : |a|≤1) (g : |b|≤1) : |a*b|≤1 := by - rw [abs_mul] - exact (mul_le_mul h g (abs_nonneg _) zero_le_one).trans_eq (by ring) - have hh : |W x|≤1 := h1 _ _ (avg_bound1 hv _ (fun y => hT _ _)) (avg_bound1 hv _ - (fun y => hT _ _)) - have hg : |V x|≤1 := avg_bound1 hv _ (fun i => h1 _ _ (hT _ _) (hT _ _)) - have ht : 0 ≤ twinkle (tied g Bool) k N := add_nonneg (mul_nonneg (Nat.cast_nonneg _) - (mul_nonneg (by norm_num) (bp_pos _).le)) (bp_pos _).le - have h2 : 0 ≤ B := mul_nonneg (mul_nonneg (by norm_num) netFact_pos.le) ht - rw [ind_one he,mul_one] - exact sub_le_iff_le_add.mpr (by linarith [(abs_le.mp hh).1,(abs_le.mp hg).2]) - change avg v _ ≤ _ - rw [avg_var v f hv,hW,hV,← avg_sub] - apply (avg_mono hD.nz hi).trans - rw [avg_add,avg_mul',hD.avg_const] - exact add_le_add_left (mul_le_mul_of_nonneg_left hr (by norm_num)) _ - -def oFreq (w : Wgt A) (F : A → Rack I N→Prop) (o : Forum p n N G) - (s : Program p n g A) := - pr w (fun i => F i (s.showKey i o)) - -set_option maxHeartbeats 800000 in -theorem oTail (m : Mixer p n) (hN : 2*num (Full p n) < N) - (T : A→Rack I N →Prop) - (w : Wgt A) (hw : IsLaw w) - {k : ℝ} {l : ℕ} (hk : ∀ i,num (Port (tied g (Fin l)) i)≤k) - (hK : 2*k-N≤-1) - (r : ℝ) (hr : pr (draws (Fin l) w) (fun x => ¬ s.free x) ≤ r) - {ε : ℝ} (hε : 0 ≤ ε) : - let v := forumLaw (G:=G) m N - let f := (fun o => oFreq w T o s) - (ε^l - r)*pr v (fun x => ε ≤ f x) ≤ netFact (tied g (Fin l))* (avg v f)^l := by - classical - let v := forumLaw (G:=G) m N - let f := (fun o : Forum p n N G => oFreq w T o s) - have hv : IsLaw v := forum_law _ hN - let F := draws (Fin l) w - have hF : IsLaw F := draws_law hw - let P (x) (y : Fin l→A) := ∀ i,T (y i) (s.showKey (y i) x) - have hh (x) : pr F (fun y => P x y)= f x ^ l := by - unfold P F draws - rw [prodW_pr (fun (_ : Fin l) => w) (fun _ i => T i (s.showKey i x))] - simp only [Finset.prod_const, Finset.card_univ,Fintype.card_fin] - rfl - let Q (x : Fin l → A) := s.free x - let S (o) (x : Fin l→A) := P o x ∧ Q x - have hi (o) : - (ε^l-r)*ind (ε≤f o)≤ pr F (S o) := by - by_cases ht : ε≤f o - · rw [ind_one ht,mul_one] - refine (sub_le_sub (pow_le_pow_left₀ hε ht l) hr).trans ?_ - rw [←hh]; exact pr_shield hF.nz _ _ - rw [ind_zero ht,mul_zero]; exact pr_nonneg hF.nz - let W (x) := pr v (fun i => T x (s.showKey x i)) - let C := netFact (tied g (Fin l)) - have hq (x : Fin l → A) : - pr v (fun i => S i x) ≤ C*∏ i:Fin l,W (x i) := by - by_cases he : Q x - · have hg := pool_upper (s.left ∘ x) (s.right ∘ x) m hN he.1 he.2 - (fun i => by linarith only [hk i,hK]) (T ∘ x) - simp only [S,he,and_true] - exact hg - simp only [S,he,and_false,pr_false]; exact mul_nonneg netFact_pos.le - (Finset.prod_nonneg fun i _ => pr_nonneg hv.nz) - have hg : avg v f=avg w W := avg_avg _ _ _ - have he := avg_mono hv.nz hi - rw [avg_mul'] at he - change _ ≤ _ - apply le_trans he - calc avg v (fun x => pr F (S x)) = avg F (fun y => pr v (fun x => S x y)) := avg_avg _ _ _ - _ ≤ avg F (fun x => C*∏ i,W (x i)) := avg_mono hF.nz hq - _ = netFact _ * (avg v f)^l := by rw [avg_mul',hg, poweravg] -end Program -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.GroupedQueryIndependence + +namespace OAI + +/-! # Query Concentration -/ + +noncomputable section +namespace HadwigerCounterexample +open Module Matrix Finset Function +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I G A K D : Type} [Fintype I] [Fintype G] [Fintype A] +variable [Fintype K] [Fintype D] [DecidableEq I] [DecidableEq G] [DecidableEq K] + +structure Program (p : Shape) (n : ℕ) {I G : Type} (g : Route I G) (A : Type) where + left : A→NomQuery p n g + right : A→NomQuery p n g + +variable {g : Route I G} + +namespace Program +variable (s : Program p n g A) + +def free (x : K→ A) := + (∀ i,Injective (pooled (s.left ∘ x) i).mulVec)∧ + (∀ i,Injective (pooled (s.right ∘ x) i).mulVec) + +def showKey (x : A) (o : Forum p n N G) := + peekR p g (s.left x) (s.right x) o + +def oexpect (w : Wgt A) (F : A → Rack I N → ℝ) (o : Forum p n N G) := + avg w (fun x => F x (s.showKey x o)) +end Program + +theorem forum_law (m : Mixer p n) {N : ℕ} (hN : 2*num (Full p n) unifOn_law (framesAt_exists (gramCond_exists m) + (by rw [←two_mul]; simpa only [num,Fintype.card_fin] using hN))) + +theorem avg_bound1 {w : Wgt A} (hw : IsLaw w) (f : Wgt A) (hf : ∀ x,|f x|≤1) : + |avg w f|≤1 := (abs_avg_le hw.nz).trans (hw.avg_le hf) +theorem avg_cross_sq (w : Wgt A) (f : Wgt A) : + avg w f ^ 2=avg (draws Bool w) (fun q => f (q true)* f (q false)) := by + let g (i : Bool) := f + have hh := prodW_avg (fun _ : Bool => w) g + have he : prodW g=(fun q => f (q true)* f (q false)) := by ext; unfold prodW; rw [Fintype.prod_bool] + rw [he,Fintype.prod_bool] at hh; rw [pow_two]; exact hh.symm + +theorem avg_var (w : Wgt A) (f : Wgt A) (hw : IsLaw w) : + avg w (fun x => (f x-avg w f)^2) = avg w (fun x => f x^2) - (avg w f)^2 := by + let g := avg w f + have hh (x) : (f x-g)^2=f x^2-2*g*f x+g^2 := by ring + change avg w (fun x => (f x-g)^2)=_ + simp_rw [hh,avg_add,avg_sub,avg_mul',hw.avg_const] + unfold g; ring + +namespace Program +variable {s : Program p n g A} + +set_option maxHeartbeats 800000 in +theorem oVar (m : Mixer p n) (hN : 2*num (Full p n) < N) + (T : A→Wgt (Rack I N)) + (w : Wgt A) (hw : IsLaw w) (hT : ∀ i x,|T i x|≤1) + (k : ℝ) (hk : ∀ i,num (Port (tied g Bool) i)≤k) + (hK : 2*k-N≤-1) + (r : ℝ) (hr : pr (draws Bool w) (fun x => ¬ s.free x) ≤ r) : + let v := forumLaw (G:=G) m N + let f := s.oexpect w T + avg v (fun o => (f o-avg v f)^2) ≤ + 2*r + 2*netFact (tied g Bool)*twinkle (tied g Bool) k N := by + classical + let v := forumLaw (G:=G) m N + let f := s.oexpect w T + let F (x : A) := fun o => T x (s.showKey x o) + let D := draws Bool w + let B := 2*netFact (tied g Bool)*twinkle (tied g Bool) k N + have hD : IsLaw D := draws_law hw + have hv : IsLaw v := forum_law _ hN + let V (x : Bool→A) := avg v (fun o => F (x true) o * F (x false) o) + let W (x : Bool→A) := avg v (F (x true))*avg v (F (x false)) + have hW : + (avg v f)^2 = avg D W := by + unfold f oexpect + rw [avg_avg,avg_cross_sq] + have hV : + avg v (fun x => f x^2) = avg D V := by + unfold f oexpect; simp_rw [avg_cross_sq]; rw [avg_avg] + have hi x : + V x-W x ≤ 2*ind (¬s.free x)+B := by + by_cases he : s.free x + · have hh := pooled_batch (s.left ∘ x) (s.right ∘ x) m hN k hk hK he.1 he.2 + (T ∘ x) (fun i y => hT _ _) + simp_rw [Fintype.prod_bool] at hh + rw [ind_zero (fun h => h he),mul_zero,zero_add] + exact (le_abs_self _).trans hh + have h1 (a b : ℝ) (h : |a|≤1) (g : |b|≤1) : |a*b|≤1 := by + rw [abs_mul] + exact (mul_le_mul h g (abs_nonneg _) zero_le_one).trans_eq (by ring) + have hh : |W x|≤1 := h1 _ _ (avg_bound1 hv _ (fun y => hT _ _)) (avg_bound1 hv _ + (fun y => hT _ _)) + have hg : |V x|≤1 := avg_bound1 hv _ (fun i => h1 _ _ (hT _ _) (hT _ _)) + have ht : 0 ≤ twinkle (tied g Bool) k N := add_nonneg (mul_nonneg (Nat.cast_nonneg _) + (mul_nonneg (by norm_num) (bp_pos _).le)) (bp_pos _).le + have h2 : 0 ≤ B := mul_nonneg (mul_nonneg (by norm_num) netFact_pos.le) ht + rw [ind_one he,mul_one] + exact sub_le_iff_le_add.mpr (by linarith [(abs_le.mp hh).1,(abs_le.mp hg).2]) + change avg v _ ≤ _ + rw [avg_var v f hv,hW,hV,← avg_sub] + apply (avg_mono hD.nz hi).trans + rw [avg_add,avg_mul',hD.avg_const] + exact add_le_add_left (mul_le_mul_of_nonneg_left hr (by norm_num)) _ + +def oFreq (w : Wgt A) (F : A → Rack I N→Prop) (o : Forum p n N G) + (s : Program p n g A) := + pr w (fun i => F i (s.showKey i o)) + +set_option maxHeartbeats 800000 in +theorem oTail (m : Mixer p n) (hN : 2*num (Full p n) < N) + (T : A→Rack I N →Prop) + (w : Wgt A) (hw : IsLaw w) + {k : ℝ} {l : ℕ} (hk : ∀ i,num (Port (tied g (Fin l)) i)≤k) + (hK : 2*k-N≤-1) + (r : ℝ) (hr : pr (draws (Fin l) w) (fun x => ¬ s.free x) ≤ r) + {ε : ℝ} (hε : 0 ≤ ε) : + let v := forumLaw (G:=G) m N + let f := (fun o => oFreq w T o s) + (ε^l - r)*pr v (fun x => ε ≤ f x) ≤ netFact (tied g (Fin l))* (avg v f)^l := by + classical + let v := forumLaw (G:=G) m N + let f := (fun o : Forum p n N G => oFreq w T o s) + have hv : IsLaw v := forum_law _ hN + let F := draws (Fin l) w + have hF : IsLaw F := draws_law hw + let P (x) (y : Fin l→A) := ∀ i,T (y i) (s.showKey (y i) x) + have hh (x) : pr F (fun y => P x y)= f x ^ l := by + unfold P F draws + rw [prodW_pr (fun (_ : Fin l) => w) (fun _ i => T i (s.showKey i x))] + simp only [Finset.prod_const, Finset.card_univ,Fintype.card_fin] + rfl + let Q (x : Fin l → A) := s.free x + let S (o) (x : Fin l→A) := P o x ∧ Q x + have hi (o) : + (ε^l-r)*ind (ε≤f o)≤ pr F (S o) := by + by_cases ht : ε≤f o + · rw [ind_one ht,mul_one] + refine (sub_le_sub (pow_le_pow_left₀ hε ht l) hr).trans ?_ + rw [←hh]; exact pr_shield hF.nz _ _ + rw [ind_zero ht,mul_zero]; exact pr_nonneg hF.nz + let W (x) := pr v (fun i => T x (s.showKey x i)) + let C := netFact (tied g (Fin l)) + have hq (x : Fin l → A) : + pr v (fun i => S i x) ≤ C*∏ i:Fin l,W (x i) := by + by_cases he : Q x + · have hg := pool_upper (s.left ∘ x) (s.right ∘ x) m hN he.1 he.2 + (fun i => by linarith only [hk i,hK]) (T ∘ x) + simp only [S,he,and_true] + exact hg + simp only [S,he,and_false,pr_false]; exact mul_nonneg netFact_pos.le + (Finset.prod_nonneg fun i _ => pr_nonneg hv.nz) + have hg : avg v f=avg w W := avg_avg _ _ _ + have he := avg_mono hv.nz hi + rw [avg_mul'] at he + change _ ≤ _ + apply le_trans he + calc avg v (fun x => pr F (S x)) = avg F (fun y => pr v (fun x => S x y)) := avg_avg _ _ _ + _ ≤ avg F (fun x => C*∏ i,W (x i)) := avg_mono hF.nz hq + _ = netFact _ * (avg v f)^l := by rw [avg_mul',hg, poweravg] +end Program +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RandomBinaryMixing.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RandomBinaryMixing.lean index bed58e54e5f50997f7d311edfff6ffd03d22e83f..939935918d7747ee5df09c239071f64d3123b65d 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RandomBinaryMixing.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RandomBinaryMixing.lean @@ -1,120 +1,120 @@ -import OAI.Combinatorics.HadwigerCounterexample.BinaryEvaluationForms - -namespace OAI - -/-! # Random Binary Mixing -/ - -noncomputable section -namespace HadwigerCounterexample - -instance momFintype (p : Shape) (n : ℕ) : Fintype (Moment p n) := inferInstance -instance idxDec (p : Shape) : DecidableEq (MIdx p) := inferInstance -instance arrFintype (p : Shape) (n : ℕ) : Fintype (MArr p n) := inferInstance -instance drawFintype (p : Shape) (n : ℕ) : Fintype (Draw p n) := inferInstance - -open Filter Matrix Function -open scoped BigOperators Topology - -variable {p : Shape} {n : ℕ} - -theorem rank_fifth_bound (m n : ℕ) (hm : n/2≤m) (hn : 100 ≤ n) : - pr unif (fun M : Mat (Fin m) (Fin m) => 5*M.rank M.rank≤ n/5) (fun M h => by omega)) - refine (pr_matrix_rank _).trans ?_ - apply bp_le - simp only [num,Fintype.card_fin] - let r := n/5 - have h1 : 5*r≤n := by unfold r; omega - have h2 : n≤2*m+1 := by omega - have h3 : 45≤m := by omega - have hi : (m+m)*r+n≤m*m := by - nlinarith only [h1,h2,h3, - Nat.mul_le_mul_left m h1,Nat.mul_le_mul_left m h2,Nat.mul_le_mul_left m h3] - have hh : ((m:ℝ)+m)*r+n ≤ m*(m:ℝ) := by exact_mod_cast hi - unfold r at hh; linarith only [hh] - -theorem pr_surj_rank {m} (hn : 100≤n) (hm : n/2≤m) - (A : Draw p n →ₗ[F] Mat (Fin m) (Fin m)) - (h : Function.Surjective A) : - pr unif (fun x => 5*(A x).rank < n) ≤ bp (- (n:ℝ)) := by - classical - have he := mapW_pr unif A (fun x => 5*x.rank s ≠ t ∧ c≠0 ∧ - 5*blockRank Block.Z s t (indexedSum (drawn x) c+selfSum (drawn x) b) hx.2 - simp_rw [← and_assoc (a:=s≠t),h,false_and,pr_false] - exact (bp_pos _).le - -theorem stest_prob (p : Shape) (s t : Label p.b) (hj : 1≤p.j) - (b : Vec Bool) (hn : 100≤n) : - pr unif (fun x : Draw p n => s ≠ t ∧ b≠0 ∧ - 5*blockRank Block.sharp s t (selfSum (drawn x) b) ?_) ?_ - · exact Fin.ext (Nat.add_left_cancel (congrArg Fin.val h)) - intro i j h - have he : i.val = n/2+j.val := congrArg Fin.val h - have hg := i.isLt; omega - apply le_trans _ (pr_surj_rank hn (by omega) (obsHalf p s t b n l r) he) - refine pr_mono unif_law.nz fun x hx => lt_of_le_of_lt ?_ hx.2 - exact Nat.mul_le_mul_left _ ((selfPartial (p:=p) s t b x).rank_submatrix_le l r) - simp_rw [← and_assoc (a:=s≠t),h,false_and,pr_false] - exact (bp_pos _).le - -theorem binary_likely (p : Shape) (hj : 1≤p.j) : - ∀ᶠ n : ℕ in atTop, - pr unif (fun x : Draw p n => ¬binaryGood (drawn x)) < 1/4 := by - classical - let I := Label p.b × Label p.b × Vec (MBits p) × Vec Bool - let J := Label p.b × Label p.b × Vec Bool - let T := I⊕J - let m := num T - have h : Tendsto (fun n:ℕ=>m*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 m - filter_upwards [h.eventually (gt_mem_nhds (show (0:ℝ)<1/4 by norm_num)), - eventually_ge_atTop 100] with n hn hg - let bad (i : T) (x : Draw p n) := - match i with - | .inl (s,t,c,b) => s≠t ∧ c≠0 ∧ 5*blockRank Block.Z s t - (indexedSum (drawn x) c+selfSum (drawn x) b) s≠t ∧ b≠0 ∧ 5*blockRank Block.sharp s t (selfSum (drawn x) b) ∃ i, bad i x) ≤ m*bp (- (n:ℝ)) := - (pr_exists_le unif_law.nz bad).trans ((Finset.sum_le_sum (fun i _ => he i)).trans_eq (by - rw [Finset.sum_const, Finset.card_univ,nsmul_eq_mul])) - apply lt_of_le_of_lt (le_trans (pr_mono unif_law.nz ?_) hi) hn - intro x hx - by_contra! H - apply hx - intro s t hst - constructor - · intro c b hc - exact le_of_not_gt fun e => H (Sum.inl (s,t,c,b)) ⟨hst,hc,e⟩ - intro b hb - exact le_of_not_gt fun e => H (Sum.inr (s,t,b)) ⟨hst,hb,e⟩ -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BinaryEvaluationForms + +namespace OAI + +/-! # Random Binary Mixing -/ + +noncomputable section +namespace HadwigerCounterexample + +instance momFintype (p : Shape) (n : ℕ) : Fintype (Moment p n) := inferInstance +instance idxDec (p : Shape) : DecidableEq (MIdx p) := inferInstance +instance arrFintype (p : Shape) (n : ℕ) : Fintype (MArr p n) := inferInstance +instance drawFintype (p : Shape) (n : ℕ) : Fintype (Draw p n) := inferInstance + +open Filter Matrix Function +open scoped BigOperators Topology + +variable {p : Shape} {n : ℕ} + +theorem rank_fifth_bound (m n : ℕ) (hm : n/2≤m) (hn : 100 ≤ n) : + pr unif (fun M : Mat (Fin m) (Fin m) => 5*M.rank M.rank≤ n/5) (fun M h => by omega)) + refine (pr_matrix_rank _).trans ?_ + apply bp_le + simp only [num,Fintype.card_fin] + let r := n/5 + have h1 : 5*r≤n := by unfold r; omega + have h2 : n≤2*m+1 := by omega + have h3 : 45≤m := by omega + have hi : (m+m)*r+n≤m*m := by + nlinarith only [h1,h2,h3, + Nat.mul_le_mul_left m h1,Nat.mul_le_mul_left m h2,Nat.mul_le_mul_left m h3] + have hh : ((m:ℝ)+m)*r+n ≤ m*(m:ℝ) := by exact_mod_cast hi + unfold r at hh; linarith only [hh] + +theorem pr_surj_rank {m} (hn : 100≤n) (hm : n/2≤m) + (A : Draw p n →ₗ[F] Mat (Fin m) (Fin m)) + (h : Function.Surjective A) : + pr unif (fun x => 5*(A x).rank < n) ≤ bp (- (n:ℝ)) := by + classical + have he := mapW_pr unif A (fun x => 5*x.rank s ≠ t ∧ c≠0 ∧ + 5*blockRank Block.Z s t (indexedSum (drawn x) c+selfSum (drawn x) b) hx.2 + simp_rw [← and_assoc (a:=s≠t),h,false_and,pr_false] + exact (bp_pos _).le + +theorem stest_prob (p : Shape) (s t : Label p.b) (hj : 1≤p.j) + (b : Vec Bool) (hn : 100≤n) : + pr unif (fun x : Draw p n => s ≠ t ∧ b≠0 ∧ + 5*blockRank Block.sharp s t (selfSum (drawn x) b) ?_) ?_ + · exact Fin.ext (Nat.add_left_cancel (congrArg Fin.val h)) + intro i j h + have he : i.val = n/2+j.val := congrArg Fin.val h + have hg := i.isLt; omega + apply le_trans _ (pr_surj_rank hn (by omega) (obsHalf p s t b n l r) he) + refine pr_mono unif_law.nz fun x hx => lt_of_le_of_lt ?_ hx.2 + exact Nat.mul_le_mul_left _ ((selfPartial (p:=p) s t b x).rank_submatrix_le l r) + simp_rw [← and_assoc (a:=s≠t),h,false_and,pr_false] + exact (bp_pos _).le + +theorem binary_likely (p : Shape) (hj : 1≤p.j) : + ∀ᶠ n : ℕ in atTop, + pr unif (fun x : Draw p n => ¬binaryGood (drawn x)) < 1/4 := by + classical + let I := Label p.b × Label p.b × Vec (MBits p) × Vec Bool + let J := Label p.b × Label p.b × Vec Bool + let T := I⊕J + let m := num T + have h : Tendsto (fun n:ℕ=>m*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 m + filter_upwards [h.eventually (gt_mem_nhds (show (0:ℝ)<1/4 by norm_num)), + eventually_ge_atTop 100] with n hn hg + let bad (i : T) (x : Draw p n) := + match i with + | .inl (s,t,c,b) => s≠t ∧ c≠0 ∧ 5*blockRank Block.Z s t + (indexedSum (drawn x) c+selfSum (drawn x) b) s≠t ∧ b≠0 ∧ 5*blockRank Block.sharp s t (selfSum (drawn x) b) ∃ i, bad i x) ≤ m*bp (- (n:ℝ)) := + (pr_exists_le unif_law.nz bad).trans ((Finset.sum_le_sum (fun i _ => he i)).trans_eq (by + rw [Finset.sum_const, Finset.card_univ,nsmul_eq_mul])) + apply lt_of_le_of_lt (le_trans (pr_mono unif_law.nz ?_) hi) hn + intro x hx + by_contra! H + apply hx + intro s t hst + constructor + · intro c b hc + exact le_of_not_gt fun e => H (Sum.inl (s,t,c,b)) ⟨hst,hc,e⟩ + intro b hb + exact le_of_not_gt fun e => H (Sum.inr (s,t,b)) ⟨hst,hb,e⟩ +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RandomLinearTransforms.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RandomLinearTransforms.lean index e06d9411a503563dcc4246b2aa8bd6b054267027..dd1a5c27d62a5d95cb5df52ddd3888f33516b31e 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RandomLinearTransforms.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RandomLinearTransforms.lean @@ -1,141 +1,141 @@ -import OAI.Combinatorics.HadwigerCounterexample.FrameRotations - -namespace OAI - -/-! # Random Linear Transforms -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Submodule Finset Function -open scoped BigOperators -variable {I J K : Type} [Fintype I] [DecidableEq I] [Fintype J] [DecidableEq J] - [Fintype K] [DecidableEq K] - -namespace Move - -instance finiteMove (I : Type) [Fintype I] [DecidableEq I] : Fintype (Move I) := by - classical - let S := { z : Mat I I × Mat I I // z.1*z.2 = 1 ∧ z.2*z.1=1} - let e : S ≃ Move I := { - toFun z := ⟨z.val.1,z.val.2,z.property.1,z.property.2⟩ - invFun z := ⟨(z.L,z.R),z.LR,z.RL⟩ - left_inv _ := rfl - right_inv _ := rfl } - exact Fintype.ofEquiv S e - -instance identity_move (I : Type) [Fintype I] [DecidableEq I] : Nonempty (Move I) := - ⟨1,1, Matrix.one_mul _,Matrix.mul_one _⟩ -def combine (c d : Move I) : Move I := - ⟨c.L*d.L,d.R*c.R,by rw [Matrix.mul_assoc,←Matrix.mul_assoc d.L,d.LR,Matrix.one_mul,c.LR], - by rw [Matrix.mul_assoc,←Matrix.mul_assoc c.R,c.RL,Matrix.one_mul,d.RL]⟩ - -@[ext] theorem extn (p q : Move I) (h : p.L=q.L) (h' : p.R=q.R) : p=q := by - cases p; cases q; cases h; cases h'; rfl -def circShift (c : Move I) : Move I≃ Move I where - toFun := combine c - invFun := combine c.sym - left_inv d := extn _ _ (by simp only [combine,sym,←Matrix.mul_assoc,c.RL, Matrix.one_mul]) - (by simp only [combine,sym,Matrix.mul_assoc,c.RL, Matrix.mul_one]) - right_inv d := extn _ _ (by simp only [combine,sym,←Matrix.mul_assoc,c.LR, Matrix.one_mul]) - (by simp only [combine,sym,Matrix.mul_assoc,c.LR, Matrix.mul_one]) -def flipLines (I : Type) [Fintype I] [DecidableEq I] : Move I≃ Move I where - toFun := Move.dual - invFun := Move.dual - left_inv _ := rfl - right_inv _ := rfl - -theorem flit_obs (M : Mat I J) (h : Injective M.mulVec) : - mapW unif (fun c : Move I => c.L*M)=unifOn (fun A => Injective A.mulVec) := by - classical - rw [← unifOn_true] - refine uniform_orbit _ (by obtain ⟨i⟩ := identity_move I; exact ⟨i,trivial⟩) - (fun x _ => inj_comp_mat _ _ x.L_inj h) ?_ - intro x y hx hy - obtain ⟨c,hc⟩ := move_exists_one hx hy - refine ⟨circShift c,fun _ => Iff.rfl,fun w => ?_⟩ - change w.L*M=x ↔ c.L*w.L*M=y - rw [←hc,Matrix.mul_assoc]; exact (c.permMat J).injective.eq_iff.symm - -theorem flit_pmax (M Q : Mat I J) (h : Injective M.mulVec) - (ha : num J-num I≤ -1) : - pr unif (fun c : Move I => c.Rᵀ*M=Q) ≤ 2*bp (-num I*num J) := by - let P (M : Mat I J) := Injective M.mulVec - have ht : - pr unif (fun c : Move I=> c.Rᵀ*M=Q)=unifOn P Q := by - change pr unif (fun x : Move I => (flipLines I x).L*M=Q)=_ - rw [← mapW_pr unif (flipLines I) (fun c => c.L*M=Q),unif_equiv] - exact congr_fun (flit_obs M h) Q - have hh : 2⁻¹ ≤ pr unif P := by - have hv := @unif_fail J I _ _ _ _ - rw [pr_not,unif_law.total] at hv - have he := bp_le ha - rw [bp_neg,bp_one] at he; change 1-pr unif P ≤ _ at hv; linarith only [hv,he] - rw [ht,←on_unif] - have he : unif Q=bp (-num I*num J) := by rw [unif_apply,neg_mul,bp_neg,←cast_mat] - exact (on_mon unif_law.nz (show 0<(2:ℝ)⁻¹ from by norm_num) hh Q).trans_eq - (by rw [he,inv_inv]) - -variable {n : ℕ} -def plume {n : ℕ} (c : Flit n) (S : Space (Vec (Fin n))) := - colSp (c.Rᵀ*pack S) - -theorem plume_dim (c : Flit n) (S : Space (Vec (Fin n))) : dim (plume c S)=dim S := by - have hh := mrk_inj.mp (inj_comp_mat c.Rᵀ _ c.dual.L_inj (pack_inj S)) - rw [plume,colSp_dim,hh,Fintype.card_fin] - -omit [Fintype I] [DecidableEq I] [DecidableEq J] [DecidableEq K] in -private theorem smaller_cols (P : Mat I J) (Q : Mat I K) (h : colSp P ≤ colSp Q) : - ∃ M : Mat K J,Q*M=P := by - classical - choose f hf using fun i : J => - show ∃ z : Vec K,Q *ᵥ z=P.col i from h (colSp_mem i) - refine ⟨Matrix.of (fun i j => f j i),?_⟩ - ext i j; exact congr_fun (hf j) i - -set_option maxHeartbeats 800000 in -theorem plume_meets (n a : ℕ) (ha : a a≤dim (c.plume U ⊓ V : Space (Vec (Fin n))))≤ - bp (1+((dim U:ℝ)+dim V-n)*a) := by - classical - let P := Mat (Fin (dim U)) (Fin a); let Q := Mat (Fin (dim V)) (Fin a) - let S (z : P×Q) := pack U*z.1 - let q (p : P × Q) (c : Flit n) := - Injective (S p).mulVec∧c.Rᵀ*S p=pack V*p.2 - have hi (c : Flit n) (hc : a≤dim (c.plume U ⊓ V : Space (Vec (Fin n)))) : - ∃ i,q i c := by - let w := c.plume U⊓V - obtain ⟨M,hM,hg⟩ := bounded_pack w a - have he : Injective M.mulVec := mrk_inj.mpr (by - rw [← colSp_dim,hg,Fintype.card_fin,min_eq_right hc]) - have hU := le_trans hM (show w≤c.plume U from inf_le_left) - have hV : colSp M ≤ colSp (pack V) := by rw [colSp_pack]; exact le_trans hM inf_le_right - obtain ⟨P,hp⟩ := smaller_cols _ _ hU - obtain ⟨Q,hq⟩ := smaller_cols _ _ hV - rw [Matrix.mul_assoc] at hp - refine ⟨(P,Q),?_,hp.trans hq.symm⟩ - have hx (z : Vec (Fin a)) : - c.Rᵀ*ᵥ((pack U * P)*ᵥz)= M*ᵥz := by rw [mulVec_mulVec,hp] - intro i j hg; exact he ((hx i).symm.trans ((congrArg _ hg).trans (hx j))) - have ht (i : P × Q) : - pr unif (q i) ≤2*bp (-(n:ℝ)*a) := by - by_cases h : Injective (S i).mulVec - · unfold q; simp only [h,true_and] - have hx : num (Fin a)-num (Fin n) ≤ -1 := by - simp only [num,Fintype.card_fin] - have hi : (a:ℝ)+1≤n := by exact_mod_cast ha - linarith only [hi] - simpa only [num,Fintype.card_fin] using flit_pmax (S i) (pack V*i.2) h hx - simp only [q,h,false_and,pr_false] - exact mul_nonneg (by norm_num) (bp_pos _).le - refine (le_trans (pr_mono unif_law.nz hi) (pr_exists_le unif_law.nz q)).trans - ((sum_le_sum (fun i _ => ht i)).trans_eq ?_) - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,Fintype.card_prod,Nat.cast_mul] - change num P*num Q* _=_ - unfold P Q; rw [cast_mat,cast_mat,←bp_one,←bp_add,←bp_add,←bp_add] - congr 1; simp only [num,Fintype.card_fin]; ring -end Move -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FrameRotations + +namespace OAI + +/-! # Random Linear Transforms -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Submodule Finset Function +open scoped BigOperators +variable {I J K : Type} [Fintype I] [DecidableEq I] [Fintype J] [DecidableEq J] + [Fintype K] [DecidableEq K] + +namespace Move + +instance finiteMove (I : Type) [Fintype I] [DecidableEq I] : Fintype (Move I) := by + classical + let S := { z : Mat I I × Mat I I // z.1*z.2 = 1 ∧ z.2*z.1=1} + let e : S ≃ Move I := { + toFun z := ⟨z.val.1,z.val.2,z.property.1,z.property.2⟩ + invFun z := ⟨(z.L,z.R),z.LR,z.RL⟩ + left_inv _ := rfl + right_inv _ := rfl } + exact Fintype.ofEquiv S e + +instance identity_move (I : Type) [Fintype I] [DecidableEq I] : Nonempty (Move I) := + ⟨1,1, Matrix.one_mul _,Matrix.mul_one _⟩ +def combine (c d : Move I) : Move I := + ⟨c.L*d.L,d.R*c.R,by rw [Matrix.mul_assoc,←Matrix.mul_assoc d.L,d.LR,Matrix.one_mul,c.LR], + by rw [Matrix.mul_assoc,←Matrix.mul_assoc c.R,c.RL,Matrix.one_mul,d.RL]⟩ + +@[ext] theorem extn (p q : Move I) (h : p.L=q.L) (h' : p.R=q.R) : p=q := by + cases p; cases q; cases h; cases h'; rfl +def circShift (c : Move I) : Move I≃ Move I where + toFun := combine c + invFun := combine c.sym + left_inv d := extn _ _ (by simp only [combine,sym,←Matrix.mul_assoc,c.RL, Matrix.one_mul]) + (by simp only [combine,sym,Matrix.mul_assoc,c.RL, Matrix.mul_one]) + right_inv d := extn _ _ (by simp only [combine,sym,←Matrix.mul_assoc,c.LR, Matrix.one_mul]) + (by simp only [combine,sym,Matrix.mul_assoc,c.LR, Matrix.mul_one]) +def flipLines (I : Type) [Fintype I] [DecidableEq I] : Move I≃ Move I where + toFun := Move.dual + invFun := Move.dual + left_inv _ := rfl + right_inv _ := rfl + +theorem flit_obs (M : Mat I J) (h : Injective M.mulVec) : + mapW unif (fun c : Move I => c.L*M)=unifOn (fun A => Injective A.mulVec) := by + classical + rw [← unifOn_true] + refine uniform_orbit _ (by obtain ⟨i⟩ := identity_move I; exact ⟨i,trivial⟩) + (fun x _ => inj_comp_mat _ _ x.L_inj h) ?_ + intro x y hx hy + obtain ⟨c,hc⟩ := move_exists_one hx hy + refine ⟨circShift c,fun _ => Iff.rfl,fun w => ?_⟩ + change w.L*M=x ↔ c.L*w.L*M=y + rw [←hc,Matrix.mul_assoc]; exact (c.permMat J).injective.eq_iff.symm + +theorem flit_pmax (M Q : Mat I J) (h : Injective M.mulVec) + (ha : num J-num I≤ -1) : + pr unif (fun c : Move I => c.Rᵀ*M=Q) ≤ 2*bp (-num I*num J) := by + let P (M : Mat I J) := Injective M.mulVec + have ht : + pr unif (fun c : Move I=> c.Rᵀ*M=Q)=unifOn P Q := by + change pr unif (fun x : Move I => (flipLines I x).L*M=Q)=_ + rw [← mapW_pr unif (flipLines I) (fun c => c.L*M=Q),unif_equiv] + exact congr_fun (flit_obs M h) Q + have hh : 2⁻¹ ≤ pr unif P := by + have hv := @unif_fail J I _ _ _ _ + rw [pr_not,unif_law.total] at hv + have he := bp_le ha + rw [bp_neg,bp_one] at he; change 1-pr unif P ≤ _ at hv; linarith only [hv,he] + rw [ht,←on_unif] + have he : unif Q=bp (-num I*num J) := by rw [unif_apply,neg_mul,bp_neg,←cast_mat] + exact (on_mon unif_law.nz (show 0<(2:ℝ)⁻¹ from by norm_num) hh Q).trans_eq + (by rw [he,inv_inv]) + +variable {n : ℕ} +def plume {n : ℕ} (c : Flit n) (S : Space (Vec (Fin n))) := + colSp (c.Rᵀ*pack S) + +theorem plume_dim (c : Flit n) (S : Space (Vec (Fin n))) : dim (plume c S)=dim S := by + have hh := mrk_inj.mp (inj_comp_mat c.Rᵀ _ c.dual.L_inj (pack_inj S)) + rw [plume,colSp_dim,hh,Fintype.card_fin] + +omit [Fintype I] [DecidableEq I] [DecidableEq J] [DecidableEq K] in +private theorem smaller_cols (P : Mat I J) (Q : Mat I K) (h : colSp P ≤ colSp Q) : + ∃ M : Mat K J,Q*M=P := by + classical + choose f hf using fun i : J => + show ∃ z : Vec K,Q *ᵥ z=P.col i from h (colSp_mem i) + refine ⟨Matrix.of (fun i j => f j i),?_⟩ + ext i j; exact congr_fun (hf j) i + +set_option maxHeartbeats 800000 in +theorem plume_meets (n a : ℕ) (ha : a a≤dim (c.plume U ⊓ V : Space (Vec (Fin n))))≤ + bp (1+((dim U:ℝ)+dim V-n)*a) := by + classical + let P := Mat (Fin (dim U)) (Fin a); let Q := Mat (Fin (dim V)) (Fin a) + let S (z : P×Q) := pack U*z.1 + let q (p : P × Q) (c : Flit n) := + Injective (S p).mulVec∧c.Rᵀ*S p=pack V*p.2 + have hi (c : Flit n) (hc : a≤dim (c.plume U ⊓ V : Space (Vec (Fin n)))) : + ∃ i,q i c := by + let w := c.plume U⊓V + obtain ⟨M,hM,hg⟩ := bounded_pack w a + have he : Injective M.mulVec := mrk_inj.mpr (by + rw [← colSp_dim,hg,Fintype.card_fin,min_eq_right hc]) + have hU := le_trans hM (show w≤c.plume U from inf_le_left) + have hV : colSp M ≤ colSp (pack V) := by rw [colSp_pack]; exact le_trans hM inf_le_right + obtain ⟨P,hp⟩ := smaller_cols _ _ hU + obtain ⟨Q,hq⟩ := smaller_cols _ _ hV + rw [Matrix.mul_assoc] at hp + refine ⟨(P,Q),?_,hp.trans hq.symm⟩ + have hx (z : Vec (Fin a)) : + c.Rᵀ*ᵥ((pack U * P)*ᵥz)= M*ᵥz := by rw [mulVec_mulVec,hp] + intro i j hg; exact he ((hx i).symm.trans ((congrArg _ hg).trans (hx j))) + have ht (i : P × Q) : + pr unif (q i) ≤2*bp (-(n:ℝ)*a) := by + by_cases h : Injective (S i).mulVec + · unfold q; simp only [h,true_and] + have hx : num (Fin a)-num (Fin n) ≤ -1 := by + simp only [num,Fintype.card_fin] + have hi : (a:ℝ)+1≤n := by exact_mod_cast ha + linarith only [hi] + simpa only [num,Fintype.card_fin] using flit_pmax (S i) (pack V*i.2) h hx + simp only [q,h,false_and,pr_false] + exact mul_nonneg (by norm_num) (bp_pos _).le + refine (le_trans (pr_mono unif_law.nz hi) (pr_exists_le unif_law.nz q)).trans + ((sum_le_sum (fun i _ => ht i)).trans_eq ?_) + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,Fintype.card_prod,Nat.cast_mul] + change num P*num Q* _=_ + unfold P Q; rw [cast_mat,cast_mat,←bp_one,←bp_add,←bp_add,←bp_add] + congr 1; simp only [num,Fintype.card_fin]; ring +end Move +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RankEfficientDecomposition.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RankEfficientDecomposition.lean index 44d107e22342cd2947151f077406eb06c0048c05..f5621489075d1e20102ed9e6faf3b27a0e895328 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RankEfficientDecomposition.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RankEfficientDecomposition.lean @@ -1,130 +1,130 @@ -import OAI.Combinatorics.HadwigerCounterexample.DerivativeCompression - -namespace OAI - -/-! # Rank Efficient Decomposition -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Finset -open scoped BigOperators -variable {p : Shape} {n : ℕ} {I : Type} [Fintype I] - -/-- Evaluation of individual matrices on Xpair -/ -def obsI (p : Shape) {n} : Individual p n →ₗ[F] ReqF p n where - toFun A := combineF p (repF p A) - map_add' A B := by - rw [←map_add]; apply congrArg - funext i; refine LinearMap.ext fun x => ?_ - change repF p (A+B) i x= repF p A i x+ repF p B i x - rw [repF_rep, repF_rep,repF_rep] - simp only [Pi.add_apply,mpair_add,Finset.sum_add_distrib] - map_smul' a A := by - change combineF p (repF p (a•A))=a • _ - rw [←map_smul]; apply congrArg - funext i; refine LinearMap.ext fun x => ?_ - change repF p (a•A) i x= a • (repF p A i x) - rw [repF_rep,repF_rep] - simp only [Pi.smul_apply,mpair_smul,smul_eq_mul,Finset.mul_sum] - -theorem obsI_each (P : PureForms p n) : - obsI p (eachF p P)=obsPair p P := - (obsPair_each P).symm - -private theorem mrk_sub {I J : Type} [Fintype I] [Fintype J] (A B : Mat I J) : - (A-B).rank ≤ A.rank+B.rank := by rw [ZModModule.sub_eq_add]; exact mrk_add_le A B - -theorem primary_initial (M : Individual p n) (f : Plan p n) (H R : ℕ) - (hF : ∀ z i,dim (sPin f z i) ≤ H) (hR : ∀ i e, (M i e).rank≤R) : - ∃ P∈pureSpace p f, (∀ e,(P e).rank ≤ 2*R) ∧ - (∀ i e, ((M-eachF p P) i e).rank≤2*H) := by - classical - let S := sPin f - choose A hA using fun z i => proj_exists (S z i) ⊥ disjoint_bot_right - let B (z i) := 1-A z i - let T : Individual p n := fun i e => pullM (B (e,true) i) (B (e,false) i) (M i e) - refine ⟨sumF p T,?_,fun e => ?_, fun i e => ?_⟩ - · refine (pureSpace_mem _).mpr fun e => ?_ - apply Submodule.sum_mem - intro i _ - let P z := B (e,z) i * (IP p n i)ᵀ - have he (z : Bool) (x : Dir p n) (hx : x∈f (e,z)) : P z *ᵥ x=0 := by - unfold P B - let y := (IP p n i)ᵀ *ᵥ x - have hh : y∈ S (e,z) i := ⟨_,hx,rfl⟩ - rw [←Matrix.mulVec_mulVec,Matrix.sub_mulVec,Matrix.one_mulVec] - change y - A (e,z) i *ᵥ y=0 - rw [(hA _ _).fixes _ hh,sub_self] - have hh : liftM (IP p n i) (IP p n i) (T i e)=(P true)ᵀ * M i e * P false := by - simp only [liftM_def,T,pullM_def,P,Matrix.transpose_mul,Matrix.transpose_transpose, - Matrix.mul_assoc] - rw [hh,box_kill] - constructor - · intro x hx - simp only [transpose_mul,transpose_transpose,←mulVec_mulVec,he true x hx,mulVec_zero] - intro x hx - rw [← Matrix.mulVec_mulVec,he false x hx,mulVec_zero] - · refine (mrk_sum_le ..).trans ?_ - have ht i : (liftM (IP p n i) (IP p n i) (T i e)).rank≤R := (rank_lift_le ..).trans - ((rank_lift_le ..).trans (hR i e)) - exact (Fintype.sum_bool _).le.trans ((Nat.add_le_add (ht _) (ht _)).trans_eq (two_mul R).symm) - · rw [each_sumF] - let z : Place p := (e,true) - let z' : Place p := (e,false) - let C := M i e - change (C-(T i e)).rank≤2*H - have he : C-T i e=(A z i)ᵀ*C+(B z i)ᵀ*C*A z' i := by - unfold T; rw [pullM_def] - dsimp only [B] - simp only [transpose_sub,Matrix.transpose_one,Matrix.mul_sub,Matrix.sub_mul,Matrix.mul_one, - Matrix.one_mul,C,z,z'] - abel - have hh (z) : (A z i).rank ≤ H := (rank_maps (S z i) ((hA z i).onto)).trans (hF z i) - rw [he,two_mul] - refine (mrk_add_le ..).trans ?_ - exact Nat.add_le_add ((Matrix.rank_mul_le_left ..).trans (Matrix.rank_transpose (A z i) ▸ hh z)) - ((Matrix.rank_mul_le_right ..).trans (hh z')) - -set_option maxHeartbeats 800000 in -theorem split_linear {M : Individual p n} {f b : Plan p n} {j : Bool} - {C D : ChanOut p n} {P : PureForms p n} - (R T H : ℕ) (ht : ∀ z i,dim (sPin f z i)≤T) (hm : ∀ i e,(M i e).rank≤R) - (hc : outSmall H C) - (hd : D∈deltaSpace p f b j) (hp : P∈pureSpace p f) - (hh : obsPair p (chanInner p C C)+obsPair p (chanDeriv p C D)+obsPair p P=obsI p M) : - ∃ (B : ChanOut p n) (P' P0 : PureForms p n) (Mr : Individual p n), - B∈deltaSpace p f b j ∧ P'∈pureSpace p f ∧ P0∈pureSpace p f ∧ - outSmall (3*H) (C+B) ∧ (∀ e,(P0 e).rank≤2*R) ∧ - obsPair p (chanInner p (C+B) (C+B))+obsPair p (P'+P0)=obsI p M ∧ - obsPair p P'=obsI p Mr ∧ ∀ i e, (Mr i e).rank ≤2*T+3*H := by - classical - obtain ⟨B,hB,hK,hZ⟩ := deriv_compress hc hd - obtain ⟨P0,hQ,hA,hL⟩ := primary_initial M f T R ht hm - let P' := P-chanInner p B B-P0 - let CI := chanInner p (C+B) (C+B) - let E := eachF p CI - refine ⟨B,P',P0,M-eachF p P0-E,hB,(pureSpace p f).sub_mem - ((pureSpace p f).sub_mem hp (chanInner_pure hB hB)) hQ,hQ,?_⟩ - have hsmall : outSmall (3*H) (C+B) := by - intro z i - rw [Pi.add_apply,Matrix.add_mul] - apply le_trans (mrk_add_le ..) - exact (Nat.add_le_add (hc z i) ((Matrix.rank_mul_le_left ..).trans (hK z))).trans - (by omega) - have hg : obsPair p (chanInner p (C+B) (C+B)) + obsPair p (P'+P0)=obsI p M := by - rw [obsPair_chan_change,←hZ,show P'=P-chanInner p B B-P0 from rfl,sub_add_cancel,map_sub] - exact (show _=obsPair p (chanInner p C C)+obsPair p (chanDeriv p C D)+obsPair p P by - abel).trans hh - refine ⟨hsmall,hA,hg,?_,fun i e => ?_⟩ - · rw [map_sub (obsI p) (M-eachF p P0) E,map_sub (obsI p),← hg] - rw [obsI_each,show E= eachF p CI from rfl,obsI_each] - unfold CI - rw [map_add]; abel - rw [Pi.sub_apply,Pi.sub_apply] - exact (mrk_sub ..).trans (Nat.add_le_add (hL i e) (show (E i e).rank≤_ from by - unfold E CI; rw [each_chan_val]; exact (Matrix.rank_mul_le_right ..).trans (hsmall _ i))) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.DerivativeCompression + +namespace OAI + +/-! # Rank Efficient Decomposition -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Finset +open scoped BigOperators +variable {p : Shape} {n : ℕ} {I : Type} [Fintype I] + +/-- Evaluation of individual matrices on Xpair -/ +def obsI (p : Shape) {n} : Individual p n →ₗ[F] ReqF p n where + toFun A := combineF p (repF p A) + map_add' A B := by + rw [←map_add]; apply congrArg + funext i; refine LinearMap.ext fun x => ?_ + change repF p (A+B) i x= repF p A i x+ repF p B i x + rw [repF_rep, repF_rep,repF_rep] + simp only [Pi.add_apply,mpair_add,Finset.sum_add_distrib] + map_smul' a A := by + change combineF p (repF p (a•A))=a • _ + rw [←map_smul]; apply congrArg + funext i; refine LinearMap.ext fun x => ?_ + change repF p (a•A) i x= a • (repF p A i x) + rw [repF_rep,repF_rep] + simp only [Pi.smul_apply,mpair_smul,smul_eq_mul,Finset.mul_sum] + +theorem obsI_each (P : PureForms p n) : + obsI p (eachF p P)=obsPair p P := + (obsPair_each P).symm + +private theorem mrk_sub {I J : Type} [Fintype I] [Fintype J] (A B : Mat I J) : + (A-B).rank ≤ A.rank+B.rank := by rw [ZModModule.sub_eq_add]; exact mrk_add_le A B + +theorem primary_initial (M : Individual p n) (f : Plan p n) (H R : ℕ) + (hF : ∀ z i,dim (sPin f z i) ≤ H) (hR : ∀ i e, (M i e).rank≤R) : + ∃ P∈pureSpace p f, (∀ e,(P e).rank ≤ 2*R) ∧ + (∀ i e, ((M-eachF p P) i e).rank≤2*H) := by + classical + let S := sPin f + choose A hA using fun z i => proj_exists (S z i) ⊥ disjoint_bot_right + let B (z i) := 1-A z i + let T : Individual p n := fun i e => pullM (B (e,true) i) (B (e,false) i) (M i e) + refine ⟨sumF p T,?_,fun e => ?_, fun i e => ?_⟩ + · refine (pureSpace_mem _).mpr fun e => ?_ + apply Submodule.sum_mem + intro i _ + let P z := B (e,z) i * (IP p n i)ᵀ + have he (z : Bool) (x : Dir p n) (hx : x∈f (e,z)) : P z *ᵥ x=0 := by + unfold P B + let y := (IP p n i)ᵀ *ᵥ x + have hh : y∈ S (e,z) i := ⟨_,hx,rfl⟩ + rw [←Matrix.mulVec_mulVec,Matrix.sub_mulVec,Matrix.one_mulVec] + change y - A (e,z) i *ᵥ y=0 + rw [(hA _ _).fixes _ hh,sub_self] + have hh : liftM (IP p n i) (IP p n i) (T i e)=(P true)ᵀ * M i e * P false := by + simp only [liftM_def,T,pullM_def,P,Matrix.transpose_mul,Matrix.transpose_transpose, + Matrix.mul_assoc] + rw [hh,box_kill] + constructor + · intro x hx + simp only [transpose_mul,transpose_transpose,←mulVec_mulVec,he true x hx,mulVec_zero] + intro x hx + rw [← Matrix.mulVec_mulVec,he false x hx,mulVec_zero] + · refine (mrk_sum_le ..).trans ?_ + have ht i : (liftM (IP p n i) (IP p n i) (T i e)).rank≤R := (rank_lift_le ..).trans + ((rank_lift_le ..).trans (hR i e)) + exact (Fintype.sum_bool _).le.trans ((Nat.add_le_add (ht _) (ht _)).trans_eq (two_mul R).symm) + · rw [each_sumF] + let z : Place p := (e,true) + let z' : Place p := (e,false) + let C := M i e + change (C-(T i e)).rank≤2*H + have he : C-T i e=(A z i)ᵀ*C+(B z i)ᵀ*C*A z' i := by + unfold T; rw [pullM_def] + dsimp only [B] + simp only [transpose_sub,Matrix.transpose_one,Matrix.mul_sub,Matrix.sub_mul,Matrix.mul_one, + Matrix.one_mul,C,z,z'] + abel + have hh (z) : (A z i).rank ≤ H := (rank_maps (S z i) ((hA z i).onto)).trans (hF z i) + rw [he,two_mul] + refine (mrk_add_le ..).trans ?_ + exact Nat.add_le_add ((Matrix.rank_mul_le_left ..).trans (Matrix.rank_transpose (A z i) ▸ hh z)) + ((Matrix.rank_mul_le_right ..).trans (hh z')) + +set_option maxHeartbeats 800000 in +theorem split_linear {M : Individual p n} {f b : Plan p n} {j : Bool} + {C D : ChanOut p n} {P : PureForms p n} + (R T H : ℕ) (ht : ∀ z i,dim (sPin f z i)≤T) (hm : ∀ i e,(M i e).rank≤R) + (hc : outSmall H C) + (hd : D∈deltaSpace p f b j) (hp : P∈pureSpace p f) + (hh : obsPair p (chanInner p C C)+obsPair p (chanDeriv p C D)+obsPair p P=obsI p M) : + ∃ (B : ChanOut p n) (P' P0 : PureForms p n) (Mr : Individual p n), + B∈deltaSpace p f b j ∧ P'∈pureSpace p f ∧ P0∈pureSpace p f ∧ + outSmall (3*H) (C+B) ∧ (∀ e,(P0 e).rank≤2*R) ∧ + obsPair p (chanInner p (C+B) (C+B))+obsPair p (P'+P0)=obsI p M ∧ + obsPair p P'=obsI p Mr ∧ ∀ i e, (Mr i e).rank ≤2*T+3*H := by + classical + obtain ⟨B,hB,hK,hZ⟩ := deriv_compress hc hd + obtain ⟨P0,hQ,hA,hL⟩ := primary_initial M f T R ht hm + let P' := P-chanInner p B B-P0 + let CI := chanInner p (C+B) (C+B) + let E := eachF p CI + refine ⟨B,P',P0,M-eachF p P0-E,hB,(pureSpace p f).sub_mem + ((pureSpace p f).sub_mem hp (chanInner_pure hB hB)) hQ,hQ,?_⟩ + have hsmall : outSmall (3*H) (C+B) := by + intro z i + rw [Pi.add_apply,Matrix.add_mul] + apply le_trans (mrk_add_le ..) + exact (Nat.add_le_add (hc z i) ((Matrix.rank_mul_le_left ..).trans (hK z))).trans + (by omega) + have hg : obsPair p (chanInner p (C+B) (C+B)) + obsPair p (P'+P0)=obsI p M := by + rw [obsPair_chan_change,←hZ,show P'=P-chanInner p B B-P0 from rfl,sub_add_cancel,map_sub] + exact (show _=obsPair p (chanInner p C C)+obsPair p (chanDeriv p C D)+obsPair p P by + abel).trans hh + refine ⟨hsmall,hA,hg,?_,fun i e => ?_⟩ + · rw [map_sub (obsI p) (M-eachF p P0) E,map_sub (obsI p),← hg] + rw [obsI_each,show E= eachF p CI from rfl,obsI_each] + unfold CI + rw [map_add]; abel + rw [Pi.sub_apply,Pi.sub_apply] + exact (mrk_sub ..).trans (Nat.add_le_add (hL i e) (show (E i e).rank≤_ from by + unfold E CI; rw [each_chan_val]; exact (Matrix.rank_mul_le_right ..).trans (hsmall _ i))) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RankSubrectangles.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RankSubrectangles.lean index 1999e41ca4e62d283a47d8cbb993f1ad48d3bd58..3f8f772cc47aecee574498d1493715778a3d75b9 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RankSubrectangles.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RankSubrectangles.lean @@ -1,126 +1,126 @@ -import OAI.Combinatorics.HadwigerCounterexample.GramCharacterExpansion - -namespace OAI - -/-! # Rank Subrectangles -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Submodule Function Finset -open scoped BigOperators -variable {I J G : Type} [Fintype I] [Fintype J] [Fintype G] [DecidableEq I] [DecidableEq J] - -omit [DecidableEq I] in -theorem basis_subcolumns (A : Mat I J) : - ∃ f : Fin A.rank→J, Injective (A.submatrix _root_.id f).mulVec := by - classical - let M (S : Finset J) := Submodule.span F (A.col '' (S : Set J)) - have hg (S : Finset J) : ∃ T⊆S,M T=M S ∧ T.card=dim (M T) := by - induction S using Finset.induction with - | empty => - have he : M ∅ = ⊥ := by - unfold M - rw [show (A.col '' ((∅ : Finset J) : Set _))=∅ by ext; simp, Submodule.span_empty] - refine ⟨∅,by simp,rfl,?_⟩; rw [he]; exact (finrank_bot ..).symm - | insert x S hx ih => - obtain ⟨T,hT,hM,hD⟩ := ih - have he (S : Finset J) : - M (insert x S)=M S⊔Submodule.span F ({A.col x}:Set _) := by - unfold M - rw [← span_union] - congr 1 - ext; simp - rw [he,←hM] - by_cases h : A.col x∈M T - · exact ⟨T,hT.trans (Finset.subset_insert _ _), - (sup_eq_left.mpr (by rwa [Submodule.span_singleton_le_iff_mem])).symm,hD⟩ - refine ⟨insert x T,Finset.insert_subset_insert x hT,he T,?_⟩ - rw [Finset.card_insert_of_notMem (fun v => hx (hT v)), he,hD] - exact (Submodule.finrank_sup_span_singleton h).symm - obtain ⟨S,hS,hA,ht⟩ := hg Finset.univ - have hs : M S=colSp A := by - rw [hA,colSp, Matrix.range_mulVecLin]; unfold M - congr 1 - ext x; simp - have he : S.card=A.rank := by rw [ht,hs,colSp_dim] - let e := Fintype.equivFinOfCardEq (Fintype.card_coe S |>.trans he) - let f (x : Fin A.rank) := (e.symm x).val - have hB : colSp (A.submatrix _root_.id f)=M S := by - rw [colSp,Matrix.range_mulVecLin]; unfold M - congr 1 - ext x; constructor - · rintro ⟨k,rfl⟩; exact ⟨f k,(e.symm k).property,rfl⟩ - · rintro ⟨k,h,rfl⟩ - refine ⟨e ⟨k,h⟩,?_⟩ - have heq : f (e ⟨k,h⟩) = k := by unfold f; rw [Equiv.symm_apply_apply] - ext; simp [Matrix.col_apply,heq] - rw [hs] at hB - refine ⟨f,mrk_inj.mpr ?_⟩ - rw [← colSp_dim,hB,Fintype.card_fin,colSp_dim] - -theorem minor_arc (A : Mat I J) : - ∃ (f : Fin A.rank→ I) (g : Fin A.rank→ J), Injective (A.submatrix f g).mulVec := by - classical - let t := A.rank - obtain ⟨g,hg⟩ := basis_subcolumns A - let B := A.submatrix _root_.id g - have he : Bᵀ.rank=t := (Matrix.rank_transpose _).trans ((mrk_inj.mp hg).trans - (Fintype.card_fin _)) - obtain ⟨f,hf⟩ : ∃ f : Fin t→I,Injective ((Bᵀ.submatrix _root_.id f)).mulVec := by - have hi := basis_subcolumns Bᵀ - rwa [he] at hi - have hh := mrk_inj.mp hf - refine ⟨f,g,mrk_inj.mpr ?_⟩ - rw [← Matrix.rank_transpose] - exact hh - -private theorem lastCol {t : ℕ} {I J : Type} [Fintype I] [Fintype J] - [DecidableEq I] [DecidableEq J] (A : Mat I J) - (f : Fin t→I) (g : Fin t→J) (x : I) (y : J) - (h : (A.submatrix (Sum.elim f (fun _ : Unit => x)) - (Sum.elim g (fun _ : Unit => y))).rank ≤ t) - (hb : Injective (A.submatrix f g).mulVec) : - ∃ z : Vec (Fin t),(A.submatrix f g)*ᵥ z=(fun i => A (f i) y) ∧ - A x y=∑ i,A x (g i)*z i := by - classical - let C := A.submatrix (Sum.elim f (fun _ : Unit => x)) (Sum.elim g (fun _ : Unit => y)) - let M := C.submatrix _root_.id (.inl ·) - have hm : Injective M.mulVec := by - intro X Y h - apply hb - funext i - exact congr_fun h (.inl i) - have hM : colSp M≤colSp C := by - rw [colSp,colSp, Matrix.range_mulVecLin,Matrix.range_mulVecLin] - apply Submodule.span_mono - rintro s ⟨i,rfl⟩; exact ⟨.inl i,rfl⟩ - have he : colSp M=colSp C := Submodule.eq_of_le_of_finrank_le hM (by - have he : dim (colSp M)=t := (mrk_inj.mp hm).trans (Fintype.card_fin _) - change dim (colSp C) ≤ dim (colSp M) - rw [he]; exact h) - obtain ⟨v,hv⟩ := show C.col (.inr ()) ∈ colSp M from he.symm ▸ colSp_mem _ - exact ⟨v,funext (fun i => congr_fun hv (.inl i)),(congr_fun hv (.inr ())).symm⟩ - -theorem border_same {t : ℕ} (A B : Mat I J) (f : Fin t→I) (g : Fin t→J) - (x : I) (y : J) - (h : Injective (A.submatrix f g).mulVec) - (hx : ∀ i j,A (f i) j=B (f i) j) - (hy : ∀ i j,A i (g j)=B i (g j)) - (hA : (A.submatrix (Sum.elim f (fun _ : Unit => x)) - (Sum.elim g (fun _ : Unit => y))).rank ≤ t) - (hB : (B.submatrix (Sum.elim f (fun _ : Unit => x)) - (Sum.elim g (fun _ : Unit => y))).rank ≤ t) : - A x y=B x y := by - classical - have hh : A.submatrix f g=B.submatrix f g := Matrix.ext fun i j => hx i _ - obtain ⟨s,hs,hL⟩ := lastCol A f g x y hA h - obtain ⟨s',hs',hR⟩ := lastCol B f g x y hB (hh ▸ h) - obtain rfl : s=s' := h ((show A.submatrix f g *ᵥ s=(fun i => A (f i) y) from hs).trans - ((funext (fun i => hx i y)).trans (hh ▸ hs'.symm))) - rw [hL,hR]; simp_rw [hy] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.GramCharacterExpansion + +namespace OAI + +/-! # Rank Subrectangles -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Submodule Function Finset +open scoped BigOperators +variable {I J G : Type} [Fintype I] [Fintype J] [Fintype G] [DecidableEq I] [DecidableEq J] + +omit [DecidableEq I] in +theorem basis_subcolumns (A : Mat I J) : + ∃ f : Fin A.rank→J, Injective (A.submatrix _root_.id f).mulVec := by + classical + let M (S : Finset J) := Submodule.span F (A.col '' (S : Set J)) + have hg (S : Finset J) : ∃ T⊆S,M T=M S ∧ T.card=dim (M T) := by + induction S using Finset.induction with + | empty => + have he : M ∅ = ⊥ := by + unfold M + rw [show (A.col '' ((∅ : Finset J) : Set _))=∅ by ext; simp, Submodule.span_empty] + refine ⟨∅,by simp,rfl,?_⟩; rw [he]; exact (finrank_bot ..).symm + | insert x S hx ih => + obtain ⟨T,hT,hM,hD⟩ := ih + have he (S : Finset J) : + M (insert x S)=M S⊔Submodule.span F ({A.col x}:Set _) := by + unfold M + rw [← span_union] + congr 1 + ext; simp + rw [he,←hM] + by_cases h : A.col x∈M T + · exact ⟨T,hT.trans (Finset.subset_insert _ _), + (sup_eq_left.mpr (by rwa [Submodule.span_singleton_le_iff_mem])).symm,hD⟩ + refine ⟨insert x T,Finset.insert_subset_insert x hT,he T,?_⟩ + rw [Finset.card_insert_of_notMem (fun v => hx (hT v)), he,hD] + exact (Submodule.finrank_sup_span_singleton h).symm + obtain ⟨S,hS,hA,ht⟩ := hg Finset.univ + have hs : M S=colSp A := by + rw [hA,colSp, Matrix.range_mulVecLin]; unfold M + congr 1 + ext x; simp + have he : S.card=A.rank := by rw [ht,hs,colSp_dim] + let e := Fintype.equivFinOfCardEq (Fintype.card_coe S |>.trans he) + let f (x : Fin A.rank) := (e.symm x).val + have hB : colSp (A.submatrix _root_.id f)=M S := by + rw [colSp,Matrix.range_mulVecLin]; unfold M + congr 1 + ext x; constructor + · rintro ⟨k,rfl⟩; exact ⟨f k,(e.symm k).property,rfl⟩ + · rintro ⟨k,h,rfl⟩ + refine ⟨e ⟨k,h⟩,?_⟩ + have heq : f (e ⟨k,h⟩) = k := by unfold f; rw [Equiv.symm_apply_apply] + ext; simp [Matrix.col_apply,heq] + rw [hs] at hB + refine ⟨f,mrk_inj.mpr ?_⟩ + rw [← colSp_dim,hB,Fintype.card_fin,colSp_dim] + +theorem minor_arc (A : Mat I J) : + ∃ (f : Fin A.rank→ I) (g : Fin A.rank→ J), Injective (A.submatrix f g).mulVec := by + classical + let t := A.rank + obtain ⟨g,hg⟩ := basis_subcolumns A + let B := A.submatrix _root_.id g + have he : Bᵀ.rank=t := (Matrix.rank_transpose _).trans ((mrk_inj.mp hg).trans + (Fintype.card_fin _)) + obtain ⟨f,hf⟩ : ∃ f : Fin t→I,Injective ((Bᵀ.submatrix _root_.id f)).mulVec := by + have hi := basis_subcolumns Bᵀ + rwa [he] at hi + have hh := mrk_inj.mp hf + refine ⟨f,g,mrk_inj.mpr ?_⟩ + rw [← Matrix.rank_transpose] + exact hh + +private theorem lastCol {t : ℕ} {I J : Type} [Fintype I] [Fintype J] + [DecidableEq I] [DecidableEq J] (A : Mat I J) + (f : Fin t→I) (g : Fin t→J) (x : I) (y : J) + (h : (A.submatrix (Sum.elim f (fun _ : Unit => x)) + (Sum.elim g (fun _ : Unit => y))).rank ≤ t) + (hb : Injective (A.submatrix f g).mulVec) : + ∃ z : Vec (Fin t),(A.submatrix f g)*ᵥ z=(fun i => A (f i) y) ∧ + A x y=∑ i,A x (g i)*z i := by + classical + let C := A.submatrix (Sum.elim f (fun _ : Unit => x)) (Sum.elim g (fun _ : Unit => y)) + let M := C.submatrix _root_.id (.inl ·) + have hm : Injective M.mulVec := by + intro X Y h + apply hb + funext i + exact congr_fun h (.inl i) + have hM : colSp M≤colSp C := by + rw [colSp,colSp, Matrix.range_mulVecLin,Matrix.range_mulVecLin] + apply Submodule.span_mono + rintro s ⟨i,rfl⟩; exact ⟨.inl i,rfl⟩ + have he : colSp M=colSp C := Submodule.eq_of_le_of_finrank_le hM (by + have he : dim (colSp M)=t := (mrk_inj.mp hm).trans (Fintype.card_fin _) + change dim (colSp C) ≤ dim (colSp M) + rw [he]; exact h) + obtain ⟨v,hv⟩ := show C.col (.inr ()) ∈ colSp M from he.symm ▸ colSp_mem _ + exact ⟨v,funext (fun i => congr_fun hv (.inl i)),(congr_fun hv (.inr ())).symm⟩ + +theorem border_same {t : ℕ} (A B : Mat I J) (f : Fin t→I) (g : Fin t→J) + (x : I) (y : J) + (h : Injective (A.submatrix f g).mulVec) + (hx : ∀ i j,A (f i) j=B (f i) j) + (hy : ∀ i j,A i (g j)=B i (g j)) + (hA : (A.submatrix (Sum.elim f (fun _ : Unit => x)) + (Sum.elim g (fun _ : Unit => y))).rank ≤ t) + (hB : (B.submatrix (Sum.elim f (fun _ : Unit => x)) + (Sum.elim g (fun _ : Unit => y))).rank ≤ t) : + A x y=B x y := by + classical + have hh : A.submatrix f g=B.submatrix f g := Matrix.ext fun i j => hx i _ + obtain ⟨s,hs,hL⟩ := lastCol A f g x y hA h + obtain ⟨s',hs',hR⟩ := lastCol B f g x y hB (hh ▸ h) + obtain rfl : s=s' := h ((show A.submatrix f g *ᵥ s=(fun i => A (f i) y) from hs).trans + ((funext (fun i => hx i y)).trans (hh ▸ hs'.symm))) + rw [hL,hR]; simp_rw [hy] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RareLeafEvents.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RareLeafEvents.lean index 9708ba32c676303d695be38766cdf865bf328acc..47b37eb310d3398112d0ee9fc8def79e541a5a95 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RareLeafEvents.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RareLeafEvents.lean @@ -1,101 +1,101 @@ -import OAI.Combinatorics.HadwigerCounterexample.SuperlevelBounds - -namespace OAI - -/-! # Rare Leaf Events -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix Function -open scoped BigOperators Topology -open Template -variable {p:Shape} {M n N K s0:ℕ} -namespace StatusAnalysis -variable {q:Format} {d e:Rates} {b:Bool} - -namespace Quill -variable (w:Quill p q d b) (m:Mixer p n) (t : Tagging p (Messenger q)) - (z : Messenger q→F) -def qualified (s:Charts p n d) (K :ℕ) (μ:Wgt (UnitType p n N)) (P : UnitType p n N→Prop) (a:ℝ) := - 2*a ≤ pr μ P ∧ ∀ i,P i →μ i ≠0→ w.steady t z m K s i - -theorem qualify_hit (s : Charts p n d) (K:ℕ) (μ:Wgt (UnitType p n N)) - (P: UnitType p n N→Prop) (H:Keys (p:=p) t N→Prop) {a α:ℝ} (hα:0<α) - (h:w.qualified m t z s K μ P a) - (hw : IsLaw μ) (hg:∀ i,IsLaw (w.policies t z n i)) - (hp: pr μ (fun i=>¬w.sober t z K H m α i) ≤ a) : - a*α ≤ pr (w.sales t z μ P m s) H := by - classical - let Q:=w.sober t z K H m α - let V i:=w.prowl s t z m i (fun i=>ind (H i)) - have he:a ≤ pr μ (fun x=>P x∧ Q x) := - (le_trans (by linarith only [hp,h.1]) (pr_shield hw.nz _ _)) - unfold pr; rw [sales_mean] - refine (mul_le_mul_of_nonneg_right he hα.le).trans ?_ - unfold pr; rw [←avg_mul] - unfold avg - refine Finset.sum_le_sum fun i _=> ?_ - dsimp only - by_cases hi:μ i=0 - · simp only [hi,zero_mul]; rfl - refine mul_le_mul_of_nonneg_left ?_ (hw.nz i) - have hv : 0≤ V i := avg_nonneg (prodW_law hg).nz (fun j=> mul_nonneg (ind_nonneg _) (ind_nonneg _)) - by_cases hP:P i∧ Q i - · change ind (_∧_) *_ ≤ _*V i; rw [ind_one hP,ind_one hP.1,one_mul,one_mul] - exact hP.2 s (h.2 i hP.1 hi) - rw [ind_zero hP,zero_mul]; exact mul_nonneg (ind_nonneg _) hv -end Quill - -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)) - -def charter (a:ℝ) (i:w.T×w.T) := - x.permission ∧ - x.qA.qualified m x.t x.z (t.cAxes i.1 d) K (partW μ i.1.val) (t.frontPage x m i.1 i.2 k) a ∧ - x.qB.qualified m x.t x.z (t.cAxes i.2 e) K (partW μ i.2.val) (t.backPage x m i.1 i.2 k) a - -def berth (a:ℝ) := - pr (pairW (portionW μ w.T) (portionW μ w.T)) (charter t x m k μ a) - -theorem charterWeak {a b:ℝ} (hh:a≤b) (i:w.T×w.T) (hf:charter t x m k μ b i) : - charter t x m k μ a i := - ⟨hf.1,⟨(mul_le_mul_of_nonneg_left hh (by norm_num)).trans hf.2.1.1,hf.2.1.2⟩, - ⟨(mul_le_mul_of_nonneg_left hh (by norm_num)).trans hf.2.2.1,hf.2.2.2⟩⟩ -end Station - -variable {A I J : Type} [Fintype A] [Fintype I] [Fintype J] -set_option maxHeartbeats 800000 in -theorem vacantBound (w : Wgt I) (v : I→ Wgt A) (K : I→ J → A→Prop) (P : A→Prop) - (hw:IsLaw w) (hv:∀ i,IsLaw (v i)) - {b e ε:ℝ} (hb : 0 b< pr (v i) Q)≤ c/b := by - refine (le_div_iff₀ hb).mpr ?_ - rw [mul_comm] - unfold pr at h; rw [mixW_avg] at h - let f i:=pr (v i) Q - apply le_trans (b:=avg w f) ?_ h - exact le_trans (mul_le_mul_of_nonneg_left (pr_mono hw.nz - (q:=fun i=>b≤f i) (fun _ hh=>hh.le)) hb.le) (le_avg_markov hw.nz (fun i=> pr_nonneg (hv _).nz) b) - let Q i:= pr w (fun x=>∃ j,b hg _ _ (he i j))).trans_eq (by simp [num]) - let U (i:I×I):=∃ j,bhg _ _ hf - -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SuperlevelBounds + +namespace OAI + +/-! # Rare Leaf Events -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix Function +open scoped BigOperators Topology +open Template +variable {p:Shape} {M n N K s0:ℕ} +namespace StatusAnalysis +variable {q:Format} {d e:Rates} {b:Bool} + +namespace Quill +variable (w:Quill p q d b) (m:Mixer p n) (t : Tagging p (Messenger q)) + (z : Messenger q→F) +def qualified (s:Charts p n d) (K :ℕ) (μ:Wgt (UnitType p n N)) (P : UnitType p n N→Prop) (a:ℝ) := + 2*a ≤ pr μ P ∧ ∀ i,P i →μ i ≠0→ w.steady t z m K s i + +theorem qualify_hit (s : Charts p n d) (K:ℕ) (μ:Wgt (UnitType p n N)) + (P: UnitType p n N→Prop) (H:Keys (p:=p) t N→Prop) {a α:ℝ} (hα:0<α) + (h:w.qualified m t z s K μ P a) + (hw : IsLaw μ) (hg:∀ i,IsLaw (w.policies t z n i)) + (hp: pr μ (fun i=>¬w.sober t z K H m α i) ≤ a) : + a*α ≤ pr (w.sales t z μ P m s) H := by + classical + let Q:=w.sober t z K H m α + let V i:=w.prowl s t z m i (fun i=>ind (H i)) + have he:a ≤ pr μ (fun x=>P x∧ Q x) := + (le_trans (by linarith only [hp,h.1]) (pr_shield hw.nz _ _)) + unfold pr; rw [sales_mean] + refine (mul_le_mul_of_nonneg_right he hα.le).trans ?_ + unfold pr; rw [←avg_mul] + unfold avg + refine Finset.sum_le_sum fun i _=> ?_ + dsimp only + by_cases hi:μ i=0 + · simp only [hi,zero_mul]; rfl + refine mul_le_mul_of_nonneg_left ?_ (hw.nz i) + have hv : 0≤ V i := avg_nonneg (prodW_law hg).nz (fun j=> mul_nonneg (ind_nonneg _) (ind_nonneg _)) + by_cases hP:P i∧ Q i + · change ind (_∧_) *_ ≤ _*V i; rw [ind_one hP,ind_one hP.1,one_mul,one_mul] + exact hP.2 s (h.2 i hP.1 hi) + rw [ind_zero hP,zero_mul]; exact mul_nonneg (ind_nonneg _) hv +end Quill + +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)) + +def charter (a:ℝ) (i:w.T×w.T) := + x.permission ∧ + x.qA.qualified m x.t x.z (t.cAxes i.1 d) K (partW μ i.1.val) (t.frontPage x m i.1 i.2 k) a ∧ + x.qB.qualified m x.t x.z (t.cAxes i.2 e) K (partW μ i.2.val) (t.backPage x m i.1 i.2 k) a + +def berth (a:ℝ) := + pr (pairW (portionW μ w.T) (portionW μ w.T)) (charter t x m k μ a) + +theorem charterWeak {a b:ℝ} (hh:a≤b) (i:w.T×w.T) (hf:charter t x m k μ b i) : + charter t x m k μ a i := + ⟨hf.1,⟨(mul_le_mul_of_nonneg_left hh (by norm_num)).trans hf.2.1.1,hf.2.1.2⟩, + ⟨(mul_le_mul_of_nonneg_left hh (by norm_num)).trans hf.2.2.1,hf.2.2.2⟩⟩ +end Station + +variable {A I J : Type} [Fintype A] [Fintype I] [Fintype J] +set_option maxHeartbeats 800000 in +theorem vacantBound (w : Wgt I) (v : I→ Wgt A) (K : I→ J → A→Prop) (P : A→Prop) + (hw:IsLaw w) (hv:∀ i,IsLaw (v i)) + {b e ε:ℝ} (hb : 0 b< pr (v i) Q)≤ c/b := by + refine (le_div_iff₀ hb).mpr ?_ + rw [mul_comm] + unfold pr at h; rw [mixW_avg] at h + let f i:=pr (v i) Q + apply le_trans (b:=avg w f) ?_ h + exact le_trans (mul_le_mul_of_nonneg_left (pr_mono hw.nz + (q:=fun i=>b≤f i) (fun _ hh=>hh.le)) hb.le) (le_avg_markov hw.nz (fun i=> pr_nonneg (hv _).nz) b) + let Q i:= pr w (fun x=>∃ j,b hg _ _ (he i j))).trans_eq (by simp [num]) + let U (i:I×I):=∃ j,bhg _ _ hf + +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RareTestEvents.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RareTestEvents.lean index 1cd5edeb0df4efbdd3897e41200edd15e0d985a4..f957b5aa313533605cfe2822ec8a278c49330b0a 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RareTestEvents.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RareTestEvents.lean @@ -1,132 +1,132 @@ -import OAI.Combinatorics.HadwigerCounterexample.CompatibleOptionRealization - -namespace OAI - -/-! # Rare Test Events -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix LinearMap Module Function -open scoped BigOperators Topology -variable {p:Shape} {n N K M : ℕ} -namespace StatusAnalysis - -def singles : Format:=fun _=>1 -def volume1 : Volumes:=fun _=>1 -theorem singles_vol : singles=toFormat volume1 := rfl -theorem singles_card : Fintype.card (Messenger singles)=4 := by - decide -theorem singles_short : ∀ i,1≤singles i ∧ singles i≤7 :=by simp [singles] -theorem funds_one {b : Bool} {d : Rates} (f: Fabric p singles d b) (i:Grid) : - funds f.amp i=(f.amp ⟨i,(0:Fin 1)⟩).2 := by - unfold funds - let : Unique (Fin (singles i)) := (show Unique (Fin 1) from inferInstance) - exact Fintype.sum_unique _ - -theorem fourPens (s:Plan p n) (K:ℕ) (H : Stalls p) (h:booths p K s H) - (ht : 2*frameBills p.g K+4 ≤Fintype.card (Label p.b)) : - ∃ z:Messenger singles→Label p.b, Injective z ∧ ∀ i j, z i∉ H j := by - classical - let F:=H true ∪ H false; let T:=Fᶜ - have hp : F.card≤ 2* frameBills p.g K := - (Finset.card_union_le _ _).trans ((add_le_add (h.1 _) (h.1 _)).trans_eq (two_mul _).symm) - have he : Fintype.card (Messenger singles) ≤ Fintype.card (↑T:Type) := by - rw [Fintype.card_coe,singles_card]; unfold T; rw [Finset.card_compl]; omega - obtain ⟨i,hi⟩: ∃ i : Messenger singles → ↑T,Injective i := by - - obtain ⟨g⟩:=Function.Embedding.nonempty_of_card_le he - exact ⟨g,g.injective⟩ - refine ⟨fun x=>(i x).val,Subtype.val_injective.comp hi,fun x b=>?_⟩ - have hh:(i x).val∉F:=Finset.mem_compl.mp (i x).property - intro hx; cases b - · exact hh (Finset.mem_union_right _ hx) - exact hh (Finset.mem_union_left _ hx) - -variable {d:Rates} -def coordSpec (m:BMark p n N) (o:UnitType p n N) (s:Charts p n d) - (w:∀ i:Nodes,Cell (d i)) := ∀ i,s i (w i)= m o i - -def beacon (p:Shape) (s:Charts p n d) (w:∀ i:Nodes,Cell (d i)) (b:Bool) - (T: Cross p n) (z : Digest p.g) : Amounts p singles d b := - fun k => - let i:=parcel b k - let j:= parcel (!b) k - let x:=targetMark p s T i j - (z,(z.diagO,x), z.diagO+dotProduct x (w i)) - -set_option maxHeartbeats 800000 in -theorem stillBeacon (m:BMark p n N) (o:UnitType p n N) (s:Charts p n d) - (w:∀ i:Nodes,Cell (d i)) (b:Bool) (T:Cross p n) (z:Digest p.g) - (h:coordSpec m o s w) (hT:∀ i,cardTone m o T i= glint p (m o)) : - still b (beacon p s w b T z) s T := by - classical - let f:Amounts p singles d b:= beacon p s w b T z - have hf (i): funds f i=(f ⟨i,(0:Fin 1)⟩).2 := by - unfold funds; let : Unique (Fin (singles i)) := (show Unique (Fin 1) from inferInstance); exact Fintype.sum_unique _ - change (∀ i, _ ) ∧ _ - constructor - · intro i - change (funds f i).1.2=_ - rw [hf] - rfl - intro i - have hh t q : couple _ (funds f (transit b (t,q))) = - contract p T t q (m o t)+role p n (m o t) := by - rw [hf] - let k : Messenger singles:=⟨transit b (t,q),(0:Fin 1)⟩ - let a:= targetMark p s T (parcel b k) (parcel (!b) k) - change z.diagO+(z.diagO+dotProduct a (w _))=_ - rw [← add_assoc,char_two,zero_add]; unfold a targetMark - rw [← roll_project] - have he (i t): (contract p T i t+role p n) (s i (w i))=contract p T i t (m o i)+role p n (m o i) := - by rw [h]; rfl - rw [he]; cases b <;> rfl - change couple _ (funds f _) = couple _ (funds f _) - simp_rw [hh] - have ht:= hT i - unfold glint cardTone at ht; rw [Fintype.sum_bool,Fintype.sum_bool] at ht - apply sub_eq_zero.mp - rw [ZModModule.sub_eq_add] - rw [add_add_add_comm,ht,char_two] - -set_option maxHeartbeats 700000 in -theorem steadyBeacon {plan : Plan p n} (m:BMark p n N) (o:UnitType p n N) (s:Charts p n d) - (w:∀ i:Nodes,Cell (d i)) (b:Bool) (T:Cross p n) - (q:Quill p singles d b) (t:Tagging p (Messenger singles)) - (g: Mixer p n) (z:Digest p.g) (K:ℕ) - (hd:∀ i,d i≤K^2) - (ha:q.amp=beacon p s w b T z) - (hk:planRank plan≤K) - (hs:charted s plan) - (h:coordSpec m o s w) - (hF : PreparationParameters.frameSide p g o) - (hg : exactInk p g m o) : - q.steady t (fun _=>1) g K s o := by - classical - refine ⟨hF,fun i=> ⟨hd _,(hs _).2,fun y=>?_⟩,fun i=>by rw [ha];rfl, fun i v hv => ?_⟩ - · refine (effective_rank (i:=parcel b i) ?_).trans hk - rw [← (hs _).1]; exact mem_range_self _ _ - · let l:= q.allure t (fun _=>1) i; let j:=parcel b i - let V:= l.profile j o g (s j) v - have ht : V.1 = (q.amp i).1 ∧ V.2.1=(q.amp i).2.1 → V=q.amp i := by - rintro ⟨h1,h2⟩ - apply Prod.ext h1 (Prod.ext h2 _) - rw [ha] at h2 ⊢ - let a:= useAtom p l.l l.s l.f v - let k:=targetMark p s T j (parcel (!b) i) - have heq : V.2.2 = z.diagO + dotProduct k (w j) := by - have he := exactInner g m o hg j a - have hx : a∈Xspace p n:= mem_useAtom .. - have hg' : role p n a=z.diagO := congrArg Prod.fst h2 - have hk : roll (s j) (Tsym g a)=k := congrArg Prod.snd h2 - change innerP p o j a=_ - rw [he hx, grad_val,hg',T_swap, ←h,roll_project,hk] - exact heq - exact (hv ht).elim - -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CompatibleOptionRealization + +namespace OAI + +/-! # Rare Test Events -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix LinearMap Module Function +open scoped BigOperators Topology +variable {p:Shape} {n N K M : ℕ} +namespace StatusAnalysis + +def singles : Format:=fun _=>1 +def volume1 : Volumes:=fun _=>1 +theorem singles_vol : singles=toFormat volume1 := rfl +theorem singles_card : Fintype.card (Messenger singles)=4 := by + decide +theorem singles_short : ∀ i,1≤singles i ∧ singles i≤7 :=by simp [singles] +theorem funds_one {b : Bool} {d : Rates} (f: Fabric p singles d b) (i:Grid) : + funds f.amp i=(f.amp ⟨i,(0:Fin 1)⟩).2 := by + unfold funds + let : Unique (Fin (singles i)) := (show Unique (Fin 1) from inferInstance) + exact Fintype.sum_unique _ + +theorem fourPens (s:Plan p n) (K:ℕ) (H : Stalls p) (h:booths p K s H) + (ht : 2*frameBills p.g K+4 ≤Fintype.card (Label p.b)) : + ∃ z:Messenger singles→Label p.b, Injective z ∧ ∀ i j, z i∉ H j := by + classical + let F:=H true ∪ H false; let T:=Fᶜ + have hp : F.card≤ 2* frameBills p.g K := + (Finset.card_union_le _ _).trans ((add_le_add (h.1 _) (h.1 _)).trans_eq (two_mul _).symm) + have he : Fintype.card (Messenger singles) ≤ Fintype.card (↑T:Type) := by + rw [Fintype.card_coe,singles_card]; unfold T; rw [Finset.card_compl]; omega + obtain ⟨i,hi⟩: ∃ i : Messenger singles → ↑T,Injective i := by + + obtain ⟨g⟩:=Function.Embedding.nonempty_of_card_le he + exact ⟨g,g.injective⟩ + refine ⟨fun x=>(i x).val,Subtype.val_injective.comp hi,fun x b=>?_⟩ + have hh:(i x).val∉F:=Finset.mem_compl.mp (i x).property + intro hx; cases b + · exact hh (Finset.mem_union_right _ hx) + exact hh (Finset.mem_union_left _ hx) + +variable {d:Rates} +def coordSpec (m:BMark p n N) (o:UnitType p n N) (s:Charts p n d) + (w:∀ i:Nodes,Cell (d i)) := ∀ i,s i (w i)= m o i + +def beacon (p:Shape) (s:Charts p n d) (w:∀ i:Nodes,Cell (d i)) (b:Bool) + (T: Cross p n) (z : Digest p.g) : Amounts p singles d b := + fun k => + let i:=parcel b k + let j:= parcel (!b) k + let x:=targetMark p s T i j + (z,(z.diagO,x), z.diagO+dotProduct x (w i)) + +set_option maxHeartbeats 800000 in +theorem stillBeacon (m:BMark p n N) (o:UnitType p n N) (s:Charts p n d) + (w:∀ i:Nodes,Cell (d i)) (b:Bool) (T:Cross p n) (z:Digest p.g) + (h:coordSpec m o s w) (hT:∀ i,cardTone m o T i= glint p (m o)) : + still b (beacon p s w b T z) s T := by + classical + let f:Amounts p singles d b:= beacon p s w b T z + have hf (i): funds f i=(f ⟨i,(0:Fin 1)⟩).2 := by + unfold funds; let : Unique (Fin (singles i)) := (show Unique (Fin 1) from inferInstance); exact Fintype.sum_unique _ + change (∀ i, _ ) ∧ _ + constructor + · intro i + change (funds f i).1.2=_ + rw [hf] + rfl + intro i + have hh t q : couple _ (funds f (transit b (t,q))) = + contract p T t q (m o t)+role p n (m o t) := by + rw [hf] + let k : Messenger singles:=⟨transit b (t,q),(0:Fin 1)⟩ + let a:= targetMark p s T (parcel b k) (parcel (!b) k) + change z.diagO+(z.diagO+dotProduct a (w _))=_ + rw [← add_assoc,char_two,zero_add]; unfold a targetMark + rw [← roll_project] + have he (i t): (contract p T i t+role p n) (s i (w i))=contract p T i t (m o i)+role p n (m o i) := + by rw [h]; rfl + rw [he]; cases b <;> rfl + change couple _ (funds f _) = couple _ (funds f _) + simp_rw [hh] + have ht:= hT i + unfold glint cardTone at ht; rw [Fintype.sum_bool,Fintype.sum_bool] at ht + apply sub_eq_zero.mp + rw [ZModModule.sub_eq_add] + rw [add_add_add_comm,ht,char_two] + +set_option maxHeartbeats 700000 in +theorem steadyBeacon {plan : Plan p n} (m:BMark p n N) (o:UnitType p n N) (s:Charts p n d) + (w:∀ i:Nodes,Cell (d i)) (b:Bool) (T:Cross p n) + (q:Quill p singles d b) (t:Tagging p (Messenger singles)) + (g: Mixer p n) (z:Digest p.g) (K:ℕ) + (hd:∀ i,d i≤K^2) + (ha:q.amp=beacon p s w b T z) + (hk:planRank plan≤K) + (hs:charted s plan) + (h:coordSpec m o s w) + (hF : PreparationParameters.frameSide p g o) + (hg : exactInk p g m o) : + q.steady t (fun _=>1) g K s o := by + classical + refine ⟨hF,fun i=> ⟨hd _,(hs _).2,fun y=>?_⟩,fun i=>by rw [ha];rfl, fun i v hv => ?_⟩ + · refine (effective_rank (i:=parcel b i) ?_).trans hk + rw [← (hs _).1]; exact mem_range_self _ _ + · let l:= q.allure t (fun _=>1) i; let j:=parcel b i + let V:= l.profile j o g (s j) v + have ht : V.1 = (q.amp i).1 ∧ V.2.1=(q.amp i).2.1 → V=q.amp i := by + rintro ⟨h1,h2⟩ + apply Prod.ext h1 (Prod.ext h2 _) + rw [ha] at h2 ⊢ + let a:= useAtom p l.l l.s l.f v + let k:=targetMark p s T j (parcel (!b) i) + have heq : V.2.2 = z.diagO + dotProduct k (w j) := by + have he := exactInner g m o hg j a + have hx : a∈Xspace p n:= mem_useAtom .. + have hg' : role p n a=z.diagO := congrArg Prod.fst h2 + have hk : roll (s j) (Tsym g a)=k := congrArg Prod.snd h2 + change innerP p o j a=_ + rw [he hx, grad_val,hg',T_swap, ←h,roll_project,hk] + exact heq + exact (hv ht).elim + +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RawFrameLaws.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RawFrameLaws.lean index 8734d922bc13e826e55096c50dd13920dc49d663..f61bc835dab9d2dfdc4a67d9120809a65f72baf4 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RawFrameLaws.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RawFrameLaws.lean @@ -1,185 +1,185 @@ -import OAI.Combinatorics.HadwigerCounterexample.AffineFrames -import OAI.Combinatorics.HadwigerCounterexample.MixedImageBounds - -namespace OAI - -/-! # Raw Frame Laws -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix -open scoped BigOperators - -variable {p : Shape} {n N : ℕ} - -instance rowDecidableEq (p : Shape) (n : ℕ) : DecidableEq (Row p n) := inferInstance -instance fullDecidableEq (p : Shape) (n : ℕ) : DecidableEq (Full p n) := inferInstance -instance fullFintype (p : Shape) (n : ℕ) : Fintype (Full p n) := inferInstance -instance oframeFintype (p : Shape) (n N : ℕ) : Fintype (Oframe p n N) := inferInstance -instance orientFintype (p : Shape) (n N : ℕ) : Fintype (Orient p n N) := inferInstance - -def gramCond (m : Mixer p n) (G : Mat (Full p n) (Full p n)) : Prop := - G.toBlocks₁₁ = selfM p n m.mixM ∧ G.toBlocks₂₁ = 0 ∧ G.toBlocks₁₂ = 0 - -theorem gramCond_exists (m : Mixer p n) : ∃ G, gramCond m G := by - refine ⟨fromBlocks (selfM p n m.mixM) 0 0 0,?_,?_,?_⟩ <;> rfl - -theorem valid_iff (m : Mixer p n) (X : Oframe p n N) : - valid (selfM p n m.mixM) X ↔ FramesAt (gramCond m) X := by - have he : (X.1ᵀ*X.2).toBlocks₁₁ = (primary X.1)ᵀ * primary X.2 := by ext; rfl - have hf : (X.1ᵀ*X.2).toBlocks₂₁ = (channel X.1)ᵀ * primary X.2 := by ext; rfl - have hg : (X.1ᵀ*X.2).toBlocks₁₂ = (primary X.1)ᵀ * channel X.2 := by ext; rfl - unfold valid FramesAt gramCond - rw [he,hf,hg]; tauto - -def raw (m : Mixer p n) (N : ℕ) : Wgt (Orient p n N) := - prodW (fun (_ : Comp p.g) => unifOn (FramesAt (U := Fin N) (gramCond m))) - -theorem raw_law (m : Mixer p n) (hN : 2*num (Full p n) unifOn_law (framesAt_exists (gramCond_exists m) - (show num (Full p n) + num (Full p n) < num (Fin N) by - rw [← two_mul]; simpa [num] using hN))) - -theorem raw_nonneg (m : Mixer p n) (X : Orient p n N) : 0 ≤ raw m N X := - prodW_nonneg (fun _ _ => (unifOn_sub _).nz _) _ - -theorem raw_carried (m : Mixer p n) (N : ℕ) : carried (raw m N) (frameLaw m) := by - intro X h - unfold frameLaw at h - push Not at h - obtain ⟨e,he⟩ := h - unfold raw prodW - apply Finset.prod_eq_zero (Finset.mem_univ e) - exact unifOn_carried _ _ ((valid_iff _ _).not.mp he) - -abbrev UnitType (p : Shape) (n N : ℕ) := Orient p n N × Orient p n N -abbrev Place (p : Shape) := Comp p.g × Bool -abbrev JointIdx (p : Shape) (n : ℕ) := Full p n ⊕ Full p n - -def takeSign (w : Oframe p n N) (b : Bool) := if b then w.1 else w.2 - -def images (x : UnitType p n N) (z : Place p) : Mat (Fin N) (JointIdx p n) := - fromCols (takeSign (x.1 z.1) z.2) (takeSign (x.2 z.1) z.2) - -abbrev Dir (p : Shape) (n : ℕ) := Vec (JointIdx p n) -abbrev Plan (p : Shape) (n : ℕ) := Place p → Submodule F (Dir p n) -def planRank (s : Plan p n) := ∑ i, dim (s i) - -/-- Pin data: stored subspaces of directions with assigned images. We store a -full linear map for convenience; only its restriction to the pin directions -at each place is used. Counts charge only for the restrictions. -/ -structure Pin (p : Shape) (n N : ℕ) where - sp : Plan p n - target : Place p → Mat (Fin N) (JointIdx p n) - -def Pin.agree (a : Pin p n N) (x : UnitType p n N) := - ∀ i, ∀ v ∈ a.sp i, images x i *ᵥ v = a.target i *ᵥ v - -theorem Pin.agree_pack {a : Pin p n N} {x : UnitType p n N} : - a.agree x ↔ ∀ i : Place p, images x i * pack (a.sp i) = a.target i * pack (a.sp i) := by - have heq {I J L : Type} [Fintype I] [Fintype J] [Fintype L] (P Q : Mat I J) (M : Mat J L) : - (∀ v ∈ colSp M, P *ᵥ v = Q *ᵥ v) ↔ P*M=Q*M := by - constructor - · intro h - apply coe_mv_inj - exact LinearMap.ext fun v => by - change (P*M) *ᵥ v=(Q*M) *ᵥ v - rw [← mulVec_mulVec,← mulVec_mulVec] - exact h _ ⟨v,rfl⟩ - · rintro h x ⟨v,rfl⟩ - change P *ᵥ (M *ᵥ v) = Q *ᵥ (M *ᵥ v) - rw [mulVec_mulVec,mulVec_mulVec,h] - unfold Pin.agree - apply forall_congr'; intro i - have hh := heq (images x i) (a.target i) (pack (a.sp i)) - rw [colSp_pack] at hh - exact hh - -theorem bp_sum {A : Type*} (s : Finset A) (f : A → ℝ) : - bp (∑ i ∈ s, f i) = ∏ i ∈ s, bp (f i) := by - classical - induction s using Finset.induction with - | empty => simp - | insert a s ha hi => rw [Finset.sum_insert ha, Finset.prod_insert ha,bp_add,hi] - -/-- Image cap under two independent raw orientations. Uniform over all -simultaneous exact-image specifications. -/ -theorem reference_cap (m : Mixer p n) (a : Pin p n N) {δ : ℝ} (hd : 0 < δ) - (hu : 2*num (Full p n) - N ≤ -1) - (hδ : 2*num (Full p n) ≤ δ/2 * N) - (hA : 4*num (Comp p.g) ≤ δ/2 * N) : - pr (pairW (raw m N) (raw m N)) a.agree ≤ bp (-(1-δ)*(planRank a.sp)*N) := by - let s := a.sp - let μ := raw m N - have hn : 2*num (Full p n) ∀ e, f e (x.1 e,x.2 e)) := by - funext x; apply propext - rw [Pin.agree_pack] - constructor - · intro hi e - exact ⟨hi (e,true),hi (e,false)⟩ - · rintro h ⟨e,b⟩; cases b - · exact (h e).2 - · exact (h e).1 - rw [hfun] - exact prodW_pair_pr g g f - let y := fun e : Comp p.g => 4 - (1-δ/2) * (rankval (e,true)+rankval (e,false))*N - have hb (e) : pr (pairW (g e) (g e)) (f e) ≤ bp (y e) := by - have h1 := comp_image_cap (gramCond_exists m) - (show 2*num (Full p n)-num (Fin N) ≤ -1 by simpa [num] using hu) - _ _ (pack_inj (s (e,true))) (pack_inj (s (e,false))) (a.target (e,true)*D (e,true)) - (a.target (e,false)*D (e,false)) - have hnum (n : ℕ) : num (Fin n)=(n:ℝ) := by simp [num] - change pr _ _ ≤ _ - apply le_trans h1 - rw [show (16:ℝ)=bp 4 by - have hh := bp_nat 4; norm_num at hh ⊢; linarith,← bp_add,hnum,hnum,hnum] - apply bp_le - let rp := rankval (e,true) - let rm := rankval (e,false) - change 4+(-((N:ℝ))*rp-(_-2*num (Full p n))*rm) ≤ 4 - _ * (rp+rm)*_ - have hp := mul_nonneg (show 0 ≤ rp from Nat.cast_nonneg _) (mul_nonneg hd.le - (show (0:ℝ) ≤ N from Nat.cast_nonneg _)) - have hg := mul_le_mul_of_nonneg_right hδ (show 0 ≤ rm from Nat.cast_nonneg _) - linarith only [hp,hg] - have hg : pr (pairW μ μ) a.agree ≤ bp (∑ i, y i) := by - rw [hf,bp_sum] - apply Finset.prod_le_prod₀ _ fun i _ => hb i - exact fun i _ => pr_nonneg - (subLaw_pair (unifOn_sub _) (unifOn_sub _)).nz - apply hg.trans - apply bp_le - have ht : (planRank s : ℝ) = ∑ i : Comp p.g, (rankval (i,true) + rankval (i,false)) := by - rw [planRank,Fintype.sum_prod_type] - simp only [Fintype.sum_bool, Nat.cast_sum,Nat.cast_add,rankval] - have h1 : ∑ i, y i = 4*num (Comp p.g) - (1-δ/2)*(planRank s)*N := by - dsimp only [y] - rw [Finset.sum_sub_distrib,← Finset.sum_mul, ← Finset.mul_sum, ← ht] - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,num] - ring - have hk : 1 ≤ (planRank s : ℝ) := by - exact_mod_cast Nat.one_le_iff_ne_zero.mpr he - rw [h1] - change _ ≤ -(1-δ)*(planRank s)*N - have he := mul_le_mul_of_nonneg_right hk - (mul_nonneg hd.le (show (0:ℝ) ≤ N from Nat.cast_nonneg _)) - linarith only [hA,he] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.AffineFrames +import OAI.Combinatorics.HadwigerCounterexample.MixedImageBounds + +namespace OAI + +/-! # Raw Frame Laws -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix +open scoped BigOperators + +variable {p : Shape} {n N : ℕ} + +instance rowDecidableEq (p : Shape) (n : ℕ) : DecidableEq (Row p n) := inferInstance +instance fullDecidableEq (p : Shape) (n : ℕ) : DecidableEq (Full p n) := inferInstance +instance fullFintype (p : Shape) (n : ℕ) : Fintype (Full p n) := inferInstance +instance oframeFintype (p : Shape) (n N : ℕ) : Fintype (Oframe p n N) := inferInstance +instance orientFintype (p : Shape) (n N : ℕ) : Fintype (Orient p n N) := inferInstance + +def gramCond (m : Mixer p n) (G : Mat (Full p n) (Full p n)) : Prop := + G.toBlocks₁₁ = selfM p n m.mixM ∧ G.toBlocks₂₁ = 0 ∧ G.toBlocks₁₂ = 0 + +theorem gramCond_exists (m : Mixer p n) : ∃ G, gramCond m G := by + refine ⟨fromBlocks (selfM p n m.mixM) 0 0 0,?_,?_,?_⟩ <;> rfl + +theorem valid_iff (m : Mixer p n) (X : Oframe p n N) : + valid (selfM p n m.mixM) X ↔ FramesAt (gramCond m) X := by + have he : (X.1ᵀ*X.2).toBlocks₁₁ = (primary X.1)ᵀ * primary X.2 := by ext; rfl + have hf : (X.1ᵀ*X.2).toBlocks₂₁ = (channel X.1)ᵀ * primary X.2 := by ext; rfl + have hg : (X.1ᵀ*X.2).toBlocks₁₂ = (primary X.1)ᵀ * channel X.2 := by ext; rfl + unfold valid FramesAt gramCond + rw [he,hf,hg]; tauto + +def raw (m : Mixer p n) (N : ℕ) : Wgt (Orient p n N) := + prodW (fun (_ : Comp p.g) => unifOn (FramesAt (U := Fin N) (gramCond m))) + +theorem raw_law (m : Mixer p n) (hN : 2*num (Full p n) unifOn_law (framesAt_exists (gramCond_exists m) + (show num (Full p n) + num (Full p n) < num (Fin N) by + rw [← two_mul]; simpa [num] using hN))) + +theorem raw_nonneg (m : Mixer p n) (X : Orient p n N) : 0 ≤ raw m N X := + prodW_nonneg (fun _ _ => (unifOn_sub _).nz _) _ + +theorem raw_carried (m : Mixer p n) (N : ℕ) : carried (raw m N) (frameLaw m) := by + intro X h + unfold frameLaw at h + push Not at h + obtain ⟨e,he⟩ := h + unfold raw prodW + apply Finset.prod_eq_zero (Finset.mem_univ e) + exact unifOn_carried _ _ ((valid_iff _ _).not.mp he) + +abbrev UnitType (p : Shape) (n N : ℕ) := Orient p n N × Orient p n N +abbrev Place (p : Shape) := Comp p.g × Bool +abbrev JointIdx (p : Shape) (n : ℕ) := Full p n ⊕ Full p n + +def takeSign (w : Oframe p n N) (b : Bool) := if b then w.1 else w.2 + +def images (x : UnitType p n N) (z : Place p) : Mat (Fin N) (JointIdx p n) := + fromCols (takeSign (x.1 z.1) z.2) (takeSign (x.2 z.1) z.2) + +abbrev Dir (p : Shape) (n : ℕ) := Vec (JointIdx p n) +abbrev Plan (p : Shape) (n : ℕ) := Place p → Submodule F (Dir p n) +def planRank (s : Plan p n) := ∑ i, dim (s i) + +/-- Pin data: stored subspaces of directions with assigned images. We store a +full linear map for convenience; only its restriction to the pin directions +at each place is used. Counts charge only for the restrictions. -/ +structure Pin (p : Shape) (n N : ℕ) where + sp : Plan p n + target : Place p → Mat (Fin N) (JointIdx p n) + +def Pin.agree (a : Pin p n N) (x : UnitType p n N) := + ∀ i, ∀ v ∈ a.sp i, images x i *ᵥ v = a.target i *ᵥ v + +theorem Pin.agree_pack {a : Pin p n N} {x : UnitType p n N} : + a.agree x ↔ ∀ i : Place p, images x i * pack (a.sp i) = a.target i * pack (a.sp i) := by + have heq {I J L : Type} [Fintype I] [Fintype J] [Fintype L] (P Q : Mat I J) (M : Mat J L) : + (∀ v ∈ colSp M, P *ᵥ v = Q *ᵥ v) ↔ P*M=Q*M := by + constructor + · intro h + apply coe_mv_inj + exact LinearMap.ext fun v => by + change (P*M) *ᵥ v=(Q*M) *ᵥ v + rw [← mulVec_mulVec,← mulVec_mulVec] + exact h _ ⟨v,rfl⟩ + · rintro h x ⟨v,rfl⟩ + change P *ᵥ (M *ᵥ v) = Q *ᵥ (M *ᵥ v) + rw [mulVec_mulVec,mulVec_mulVec,h] + unfold Pin.agree + apply forall_congr'; intro i + have hh := heq (images x i) (a.target i) (pack (a.sp i)) + rw [colSp_pack] at hh + exact hh + +theorem bp_sum {A : Type*} (s : Finset A) (f : A → ℝ) : + bp (∑ i ∈ s, f i) = ∏ i ∈ s, bp (f i) := by + classical + induction s using Finset.induction with + | empty => simp + | insert a s ha hi => rw [Finset.sum_insert ha, Finset.prod_insert ha,bp_add,hi] + +/-- Image cap under two independent raw orientations. Uniform over all +simultaneous exact-image specifications. -/ +theorem reference_cap (m : Mixer p n) (a : Pin p n N) {δ : ℝ} (hd : 0 < δ) + (hu : 2*num (Full p n) - N ≤ -1) + (hδ : 2*num (Full p n) ≤ δ/2 * N) + (hA : 4*num (Comp p.g) ≤ δ/2 * N) : + pr (pairW (raw m N) (raw m N)) a.agree ≤ bp (-(1-δ)*(planRank a.sp)*N) := by + let s := a.sp + let μ := raw m N + have hn : 2*num (Full p n) ∀ e, f e (x.1 e,x.2 e)) := by + funext x; apply propext + rw [Pin.agree_pack] + constructor + · intro hi e + exact ⟨hi (e,true),hi (e,false)⟩ + · rintro h ⟨e,b⟩; cases b + · exact (h e).2 + · exact (h e).1 + rw [hfun] + exact prodW_pair_pr g g f + let y := fun e : Comp p.g => 4 - (1-δ/2) * (rankval (e,true)+rankval (e,false))*N + have hb (e) : pr (pairW (g e) (g e)) (f e) ≤ bp (y e) := by + have h1 := comp_image_cap (gramCond_exists m) + (show 2*num (Full p n)-num (Fin N) ≤ -1 by simpa [num] using hu) + _ _ (pack_inj (s (e,true))) (pack_inj (s (e,false))) (a.target (e,true)*D (e,true)) + (a.target (e,false)*D (e,false)) + have hnum (n : ℕ) : num (Fin n)=(n:ℝ) := by simp [num] + change pr _ _ ≤ _ + apply le_trans h1 + rw [show (16:ℝ)=bp 4 by + have hh := bp_nat 4; norm_num at hh ⊢; linarith,← bp_add,hnum,hnum,hnum] + apply bp_le + let rp := rankval (e,true) + let rm := rankval (e,false) + change 4+(-((N:ℝ))*rp-(_-2*num (Full p n))*rm) ≤ 4 - _ * (rp+rm)*_ + have hp := mul_nonneg (show 0 ≤ rp from Nat.cast_nonneg _) (mul_nonneg hd.le + (show (0:ℝ) ≤ N from Nat.cast_nonneg _)) + have hg := mul_le_mul_of_nonneg_right hδ (show 0 ≤ rm from Nat.cast_nonneg _) + linarith only [hp,hg] + have hg : pr (pairW μ μ) a.agree ≤ bp (∑ i, y i) := by + rw [hf,bp_sum] + apply Finset.prod_le_prod₀ _ fun i _ => hb i + exact fun i _ => pr_nonneg + (subLaw_pair (unifOn_sub _) (unifOn_sub _)).nz + apply hg.trans + apply bp_le + have ht : (planRank s : ℝ) = ∑ i : Comp p.g, (rankval (i,true) + rankval (i,false)) := by + rw [planRank,Fintype.sum_prod_type] + simp only [Fintype.sum_bool, Nat.cast_sum,Nat.cast_add,rankval] + have h1 : ∑ i, y i = 4*num (Comp p.g) - (1-δ/2)*(planRank s)*N := by + dsimp only [y] + rw [Finset.sum_sub_distrib,← Finset.sum_mul, ← Finset.mul_sum, ← ht] + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,num] + ring + have hk : 1 ≤ (planRank s : ℝ) := by + exact_mod_cast Nat.one_le_iff_ne_zero.mpr he + rw [h1] + change _ ≤ -(1-δ)*(planRank s)*N + have he := mul_le_mul_of_nonneg_right hk + (mul_nonneg hd.le (show (0:ℝ) ≤ N from Nat.cast_nonneg _)) + linarith only [hA,he] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RealizationConditions.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RealizationConditions.lean index c4d13cb10845b5500d508a229d275d1b3ed484f4..bbc464957840724fdbc486e1b70551822d201204 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RealizationConditions.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RealizationConditions.lean @@ -1,93 +1,93 @@ -import OAI.Combinatorics.HadwigerCounterexample.KeyDirections - -namespace OAI - -/-! # Realization Conditions -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] - -namespace Volley -variable (v w : Volley p n I) - -def legal (t : Tagging p I) := ∀ i : I, allows (t i) (v.par i) -def diagonalAt (i : I) := eta p n (mom p (v.sel i) (v.par i)) -def bounded (w' : I→Bool) := ∀ (i j : Bool), 1≤ (v.shoots w' i j).card ∧ - (v.shoots w' i j).card ≤7 - -/-- Conditions for one orientation of roles, §5 (scalar recipe). -/ -structure scalarRecipe (t : Tagging p I) (m : Mixer p n) (x : UnitType p n N) (S : Plan p n) - (M : Cross p n) : Prop where - summ (i j : Bool) : ∑ a ∈ v.shoots w.obj i j,v.diagonalAt a=1 - coupled (j : Bool) : ((innerP p x true)+role p n) (v.sumAt t w.obj true j) = - ((innerP p x false)+role p n) (v.sumAt t w.obj false j) - gradient (i j : Bool) (y : Profile p n) : y∈effective S i → - grad m (v.sumAt t w.obj i j) y= contract p M i j y - -def roleMatch (t : Tagging p I) := - ∀ i j, role p n (v.sumAt t w.obj i j)+ role p n (w.sumAt t v.obj j i)=1 - -def attackGrad (t : Tagging p I) (m : Mixer p n) (y : UnitType p n N) := - ∀ (a : I) (j : Bool), - grad m (v.sumAt t w.obj (v.obj a) j) (v.atomAt t a) = - if j=w.obj a then 0 else innerP p y (w.obj a) (w.atomAt t a) - -def realized (t : Tagging p I) (m : Mixer p n) (M : Cross p n) := - ∀ i j, ∀ y ∈ Xspace p n, grad m (v.sumAt t w.obj i j) y=contract p M i j y - -theorem shoots_swap (i j) : v.shoots w.obj i j=w.shoots v.obj j i := by - ext; simp [shoots,and_comm] - -theorem sum_share {t : Tagging p I} {x y : UnitType p n N} (h : v.keys t x=w.keys t y) - (i j : Bool) : Uembed (onSide x i) (v.sumAt t w.obj i j)= - Uembed (onSide y j) (w.sumAt t v.obj j i) := by - classical - unfold sumAt - rw [map_sum,map_sum,← shoots_swap v w] - refine Finset.sum_congr rfl fun k hk => ?_ - have hi := (Finset.mem_filter.mp hk).2 - rw [← hi.1, ← hi.2] - exact v.atom_share _ _ _ _ h k - -theorem sum_mem {t : Tagging p I} (h : v.legal t) (f : I → Bool) (i j : Bool) : - v.sumAt t f i j∈Xspace p n := - Submodule.sum_mem _ fun k _ => atom_mem _ (h k) - -theorem realized_conflicts {t : Tagging p I} (m : Mixer p n) - (x y : UnitType p n N) (hv : v.legal t) (hw : w.legal t) - (hL : ∀ i, frameLaw m (onSide x i)) (hR : ∀ i, frameLaw m (onSide y i)) - (h : v.keys t x=w.keys t y) (hm : v.roleMatch w t) - (hA : v.realized w t m (actual p x y)) (hB : w.realized v t m (actual p y x)) : - (rawHoles m).conflict x y := by - have hh i j : hole m (onSide x i) (onSide y j) := by - refine ⟨hL i,hR j,v.sumAt t w.obj i j,w.sumAt t v.obj j i, - v.sum_mem hv .., w.sum_mem hw .., v.sum_share _ h i j,fun q hq => ?_,fun q hq => ?_,hm i j⟩ - · rw [hA _ _ _ hq,contract_actual]; rfl - · rw [hB _ _ _ hq,contract_actual]; rfl - exact ⟨hh true true,hh true false,hh false true,hh false false⟩ - -end Volley - -def scalarBlocks (p : Shape) {n} (M : Cross p n) (e : Place p) (i j : Bool) := - channelOut p M j e * IP p n i - -theorem contract_val (p : Shape) {n} (M : Cross p n) (i j : Bool) (x : Profile p n) : - contract p M i j x = ∑ e,mpair - ((scalarBlocks p M (e,true) i j)ᵀ * scalarBlocks p M (e,false) i j) (x e) := by - change ∑ e : Comp p.g, _ = _ - refine Finset.sum_congr rfl fun e _ => ?_ - rw [mpair_liftM] - simp only [liftM_def,transpose_transpose,scalarBlocks,transpose_mul,Matrix.mul_assoc] - -theorem contract_scalars (A M : Cross p n) (h : scalarBlocks p A=scalarBlocks p M) (i j) : - contract p A i j=contract p M i j := by - refine LinearMap.ext fun v => ?_ - rw [contract_val,contract_val,h] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.KeyDirections + +namespace OAI + +/-! # Realization Conditions -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] + +namespace Volley +variable (v w : Volley p n I) + +def legal (t : Tagging p I) := ∀ i : I, allows (t i) (v.par i) +def diagonalAt (i : I) := eta p n (mom p (v.sel i) (v.par i)) +def bounded (w' : I→Bool) := ∀ (i j : Bool), 1≤ (v.shoots w' i j).card ∧ + (v.shoots w' i j).card ≤7 + +/-- Conditions for one orientation of roles, §5 (scalar recipe). -/ +structure scalarRecipe (t : Tagging p I) (m : Mixer p n) (x : UnitType p n N) (S : Plan p n) + (M : Cross p n) : Prop where + summ (i j : Bool) : ∑ a ∈ v.shoots w.obj i j,v.diagonalAt a=1 + coupled (j : Bool) : ((innerP p x true)+role p n) (v.sumAt t w.obj true j) = + ((innerP p x false)+role p n) (v.sumAt t w.obj false j) + gradient (i j : Bool) (y : Profile p n) : y∈effective S i → + grad m (v.sumAt t w.obj i j) y= contract p M i j y + +def roleMatch (t : Tagging p I) := + ∀ i j, role p n (v.sumAt t w.obj i j)+ role p n (w.sumAt t v.obj j i)=1 + +def attackGrad (t : Tagging p I) (m : Mixer p n) (y : UnitType p n N) := + ∀ (a : I) (j : Bool), + grad m (v.sumAt t w.obj (v.obj a) j) (v.atomAt t a) = + if j=w.obj a then 0 else innerP p y (w.obj a) (w.atomAt t a) + +def realized (t : Tagging p I) (m : Mixer p n) (M : Cross p n) := + ∀ i j, ∀ y ∈ Xspace p n, grad m (v.sumAt t w.obj i j) y=contract p M i j y + +theorem shoots_swap (i j) : v.shoots w.obj i j=w.shoots v.obj j i := by + ext; simp [shoots,and_comm] + +theorem sum_share {t : Tagging p I} {x y : UnitType p n N} (h : v.keys t x=w.keys t y) + (i j : Bool) : Uembed (onSide x i) (v.sumAt t w.obj i j)= + Uembed (onSide y j) (w.sumAt t v.obj j i) := by + classical + unfold sumAt + rw [map_sum,map_sum,← shoots_swap v w] + refine Finset.sum_congr rfl fun k hk => ?_ + have hi := (Finset.mem_filter.mp hk).2 + rw [← hi.1, ← hi.2] + exact v.atom_share _ _ _ _ h k + +theorem sum_mem {t : Tagging p I} (h : v.legal t) (f : I → Bool) (i j : Bool) : + v.sumAt t f i j∈Xspace p n := + Submodule.sum_mem _ fun k _ => atom_mem _ (h k) + +theorem realized_conflicts {t : Tagging p I} (m : Mixer p n) + (x y : UnitType p n N) (hv : v.legal t) (hw : w.legal t) + (hL : ∀ i, frameLaw m (onSide x i)) (hR : ∀ i, frameLaw m (onSide y i)) + (h : v.keys t x=w.keys t y) (hm : v.roleMatch w t) + (hA : v.realized w t m (actual p x y)) (hB : w.realized v t m (actual p y x)) : + (rawHoles m).conflict x y := by + have hh i j : hole m (onSide x i) (onSide y j) := by + refine ⟨hL i,hR j,v.sumAt t w.obj i j,w.sumAt t v.obj j i, + v.sum_mem hv .., w.sum_mem hw .., v.sum_share _ h i j,fun q hq => ?_,fun q hq => ?_,hm i j⟩ + · rw [hA _ _ _ hq,contract_actual]; rfl + · rw [hB _ _ _ hq,contract_actual]; rfl + exact ⟨hh true true,hh true false,hh false true,hh false false⟩ + +end Volley + +def scalarBlocks (p : Shape) {n} (M : Cross p n) (e : Place p) (i j : Bool) := + channelOut p M j e * IP p n i + +theorem contract_val (p : Shape) {n} (M : Cross p n) (i j : Bool) (x : Profile p n) : + contract p M i j x = ∑ e,mpair + ((scalarBlocks p M (e,true) i j)ᵀ * scalarBlocks p M (e,false) i j) (x e) := by + change ∑ e : Comp p.g, _ = _ + refine Finset.sum_congr rfl fun e _ => ?_ + rw [mpair_liftM] + simp only [liftM_def,transpose_transpose,scalarBlocks,transpose_mul,Matrix.mul_assoc] + +theorem contract_scalars (A M : Cross p n) (h : scalarBlocks p A=scalarBlocks p M) (i j) : + contract p A i j=contract p M i j := by + refine LinearMap.ext fun v => ?_ + rw [contract_val,contract_val,h] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RectangleComparisons.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RectangleComparisons.lean index 041a0e4624a53e44b879f99c5a796dedec47955f..81ae56cebfcd6928f9c276f686384b34f721e6e2 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RectangleComparisons.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RectangleComparisons.lean @@ -1,146 +1,146 @@ -import OAI.Combinatorics.HadwigerCounterexample.SurrogateProductBounds - -namespace OAI - -/-! # Rectangle Comparisons -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix Function -open scoped BigOperators Topology -variable {p:Shape} {n N r : ℕ} -open Template -namespace StatusAnalysis - -private theorem warm_bound {u v : ℝ} (h : |u|≤1) {r:ℝ} - (hv : |v|≤r) : |u*v|≤r := by - rw [abs_mul]; exact (mul_le_mul h hv (abs_nonneg _) zero_le_one).trans_eq (one_mul _) - -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) - -structure mirrorSpan (s:ℕ) (ε : ℝ) (Y:Silhouette p N r) (o:UnitType p n N) : Prop where - law : ∀ i,IsLaw (w.policies t z n i) - frame : ∀ i,frameLaw m (onSide o i) - close : ∀ i,(w.allure t z i).close Y (onSide o (parcel b i)) ε - ready : ∀ u:Messenger q → Wgt (Knobs p.g n),(∀ i x, |u i x|≤1) → - let v:=w.pen t; let x:=w.policies t z n - |avg (prodW x) (fun y=>ind (v.performs w.script m o y)*prodW u y)-v.kappa*∏ i:Messenger q, - avg (x i) (u i)|≤ ε - reference : ∀ f:∀ i:Messenger q,Wgt (AtomKey (p:=p) (t i) N),(∀ i x,|f i x|≤1) → - |avg (lawNu p N t z) (prodW f) - ∏ i:Messenger q,avg (lawOmega p N (t i) (z i)) (f i)| ≤ ε - -set_option maxHeartbeats 800000 in -theorem paint_agree (Y:Silhouette p N r) (o: UnitType p n N) (s : Charts p n d) - (f:Paint (w.pen t) N) (hF : pigments z Y f) - (hg : 2≤p.g) (hj : 1≤p.j) (hc : |f.coeff|≤1) {u ℓ} - (he : w.mirrorSpan t z m ℓ u Y o) : - |w.prowl s t z m o f.cost-w.sheen t z o m s Y f.cost|≤(2+num (Messenger q))*u := by - classical - let A:= w.suede t z o m s f; let x:= w.policies t z n - let V:= w.pen t - let B:= w.insidePaint t z o m s Y f - let Q:= avg (prodW x) (fun y=>ind (V.performs w.script m o y)*prodW A y) - let E:=avg (lawNu p N t z) (prodW B) - have hb i y := paintFloor w t z o m s Y f i y (he.law _) - have ha := suedeFloor w t z o m s f - let h := he.law - let P i := avg (x i) (A i); let R i:= avg (lawOmega p N (t i) (z i)) (B i) - have hm : |Q-V.kappa*(∏ i,P i)|≤u := he.ready A ha - have hf : |E-∏ i,R i|≤u := he.reference B hb - have hP i : |P i|≤1 := by - exact (abs_avg_le (h i).nz).trans ((avg_mono (h i).nz (ha i)).trans_eq ((h i).avg_const _)) - have hR i : |R i|≤1 := by - have hv : SubLaw (lawOmega p N (t i) (z i)) := unifOn_sub _ - exact (abs_avg_le hv.nz).trans (hv.avg_le zero_le_one (hb i)) - have hh : |(∏ i, P i)-(∏ i, R i)|≤num (Messenger q)*u := - cottonError _ _ _ _ hP hR (fun i =>(abs_sub_comm ..).trans_le - (surrogate_close w t z o m s Y f hF _ (h _) (he.close _))) - have hK : |V.kappa|≤1 := by rw [abs_of_pos V.kappa_pos]; exact w.kappaTop t - rw [score_prowl w t z o m s f he.frame hg hj,score_sheen w t z o m,←mul_sub] - apply warm_bound hc - have hh' : |V.kappa*(∏ i,P i)-V.kappa*E|≤num (Messenger q)*u+u := by - rw [←mul_sub]; exact warm_bound hK ((abs_sub_le (∏ i,P i) (∏ i,R i) E).trans (add_le_add hh - ((abs_sub_comm ..).trans_le hf))) - exact ((abs_sub_le Q _ (V.kappa*E)).trans (add_le_add hm hh')).trans_eq (by ring) - -set_option maxHeartbeats 800000 in -theorem paint_set (Y:Silhouette p N r) (o: UnitType p n N) (s : Charts p n d) - {r' : ℕ} - (f:Fin r' → Paint (w.pen t) N) (hF : ∀ i,pigments z Y (f i)) - (hg : 2≤p.g) (hj : 1≤p.j) (hc : ∀ i,|(f i).coeff|≤1) {u ℓ} - (he : w.mirrorSpan t z m ℓ u Y o) : - |w.prowl s t z m o (mural (w.pen t) f)-w.sheen t z o m s Y (mural (w.pen t) f)|≤ - r' * ((2+num (Messenger q))*u) := by - classical - let F i : Wgt (Keys (p:=p) t N) := (f i).cost - let R := show Wgt (Keys (p:=p) t N) from mural (w.pen t) f - have hf x : R x=∑ i:Fin r', F i x := rfl - change |w.prowl _ _ _ _ _ R-w.sheen _ _ _ _ _ _ R|≤_ - have hh : - w.prowl s t z m o R=∑ i:Fin r',w.prowl s t z m o (F i) := by - let key : Inputs p n (Messenger q) → Keys (p:=p) t N := (w.pen t).resultKey o - change avg ((w.pen t).state z n) (fun x => ind (w.deposit t z m o s x) * R (key x)) = - ∑ i : Fin r', avg ((w.pen t).state z n) - (fun x => ind (w.deposit t z m o s x) * F i (key x)) - simp_rw [hf, Finset.mul_sum,avg_sum] - have ht : - w.sheen t z o m s Y R=∑ i:Fin r',w.sheen t z o m s Y (F i) := by - unfold sheen; simp_rw [hf,Finset.mul_sum,avg_sum] - rw [hh,ht,←Finset.sum_sub_distrib] - apply (abs_sum_le_sum_abs ..).trans - exact (Finset.sum_le_sum fun i _=> paint_agree w t z m Y o s (f i) (hF i) hg hj (hc i) - he).trans_eq (by simp) - -structure witnessPaint (ε:ℝ) (W T : Wgt (Keys (p:=p) t N)) - (o : UnitType p n N) : Prop where - shadow : ∀ f : (w.pen t).Localist N,(∀ i j, |f i j|≤1) → - |avg (lawNu p N t z) (fun x=>(W x-T x)*prodW f x)|≤ε - tested : ¬ exceeds (w.pen t) z (W-T) w.script m (w.policies t z n) ε o - -set_option maxHeartbeats 800000 in -theorem bare_bridge (Y : Silhouette p N r) (o:UnitType p n N) (s:Charts p n d) - {r' : ℕ} - (f:Fin r' → Paint (w.pen t) N) (hF : ∀ i,pigments z Y (f i)) - (hg : 2≤p.g) (hj : 1≤p.j) (hc : ∀ i,|(f i).coeff|≤1) {u ℓ ε} - (he : w.mirrorSpan t z m ℓ u Y o) (W : Wgt (Keys (p:=p) t N)) - (hw : w.witnessPaint t z m ε W (mural (w.pen t) f) o) : - |w.prowl s t z m o W-w.sheen t z o m s Y W|≤ 2*ε +r'*((2+num (Messenger q))*u) := by - classical - let A:=w.pen t - let T:= show Wgt (Keys (p:=p) t N) from mural A f - let x:=w.prowl s t z m o; let y:= w.sheen t z o m s Y - have h1 : |x W-x T|≤ε := by - have hz : x W-x T=x (W-T) := by - let key : Inputs p n (Messenger q) → Keys (p:=p) t N := A.resultKey o - change avg (A.state z n) (fun x => ind (w.deposit t z m o s x) * W (key x)) - - avg (A.state z n) (fun x => ind (w.deposit t z m o s x) * T (key x)) = - avg (A.state z n) (fun x => ind (w.deposit t z m o s x) * (W-T) (key x)) - rw [←avg_sub] - simp only [Pi.sub_apply,mul_sub] - rw [hz] - change |w.prowl _ _ _ _ _ _|≤_ - rw [prowl_astonish] - exact le_of_not_gt (fun h=> hw.tested ⟨_, stencil_floor w t z o s m,h⟩) - have h2 : |y W-y T|≤ε := by - unfold y; rw [sheen_sun,sheen_sun,←mul_sub,←avg_sub] - let B:= w.seraph t z o m s Y - have hF (i j): |B i j|≤1 := by - have hh:= w.seraphFloor t z o m s Y i (he.law i) j; rw [abs_of_nonneg (show 0≤B i j - from hh.1)]; exact hh.2 - simp_rw [←sub_mul]; exact warm_bound (show |A.kappa|≤1 from (abs_of_pos A.kappa_pos).trans_le - (w.kappaTop t)) (hw.shadow B hF) - have h3 := paint_set w t z m Y o s f hF hg hj hc he - exact (abs_sub_le (x W) (x T) (y W)).trans ((add_le_add h1 - ((abs_sub_le (x T) (y T) (y W)).trans (add_le_add h3 ((abs_sub_comm ..).trans_le h2)))).trans_eq - (by ring)) - -end Quill -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SurrogateProductBounds + +namespace OAI + +/-! # Rectangle Comparisons -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix Function +open scoped BigOperators Topology +variable {p:Shape} {n N r : ℕ} +open Template +namespace StatusAnalysis + +private theorem warm_bound {u v : ℝ} (h : |u|≤1) {r:ℝ} + (hv : |v|≤r) : |u*v|≤r := by + rw [abs_mul]; exact (mul_le_mul h hv (abs_nonneg _) zero_le_one).trans_eq (one_mul _) + +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) + +structure mirrorSpan (s:ℕ) (ε : ℝ) (Y:Silhouette p N r) (o:UnitType p n N) : Prop where + law : ∀ i,IsLaw (w.policies t z n i) + frame : ∀ i,frameLaw m (onSide o i) + close : ∀ i,(w.allure t z i).close Y (onSide o (parcel b i)) ε + ready : ∀ u:Messenger q → Wgt (Knobs p.g n),(∀ i x, |u i x|≤1) → + let v:=w.pen t; let x:=w.policies t z n + |avg (prodW x) (fun y=>ind (v.performs w.script m o y)*prodW u y)-v.kappa*∏ i:Messenger q, + avg (x i) (u i)|≤ ε + reference : ∀ f:∀ i:Messenger q,Wgt (AtomKey (p:=p) (t i) N),(∀ i x,|f i x|≤1) → + |avg (lawNu p N t z) (prodW f) - ∏ i:Messenger q,avg (lawOmega p N (t i) (z i)) (f i)| ≤ ε + +set_option maxHeartbeats 800000 in +theorem paint_agree (Y:Silhouette p N r) (o: UnitType p n N) (s : Charts p n d) + (f:Paint (w.pen t) N) (hF : pigments z Y f) + (hg : 2≤p.g) (hj : 1≤p.j) (hc : |f.coeff|≤1) {u ℓ} + (he : w.mirrorSpan t z m ℓ u Y o) : + |w.prowl s t z m o f.cost-w.sheen t z o m s Y f.cost|≤(2+num (Messenger q))*u := by + classical + let A:= w.suede t z o m s f; let x:= w.policies t z n + let V:= w.pen t + let B:= w.insidePaint t z o m s Y f + let Q:= avg (prodW x) (fun y=>ind (V.performs w.script m o y)*prodW A y) + let E:=avg (lawNu p N t z) (prodW B) + have hb i y := paintFloor w t z o m s Y f i y (he.law _) + have ha := suedeFloor w t z o m s f + let h := he.law + let P i := avg (x i) (A i); let R i:= avg (lawOmega p N (t i) (z i)) (B i) + have hm : |Q-V.kappa*(∏ i,P i)|≤u := he.ready A ha + have hf : |E-∏ i,R i|≤u := he.reference B hb + have hP i : |P i|≤1 := by + exact (abs_avg_le (h i).nz).trans ((avg_mono (h i).nz (ha i)).trans_eq ((h i).avg_const _)) + have hR i : |R i|≤1 := by + have hv : SubLaw (lawOmega p N (t i) (z i)) := unifOn_sub _ + exact (abs_avg_le hv.nz).trans (hv.avg_le zero_le_one (hb i)) + have hh : |(∏ i, P i)-(∏ i, R i)|≤num (Messenger q)*u := + cottonError _ _ _ _ hP hR (fun i =>(abs_sub_comm ..).trans_le + (surrogate_close w t z o m s Y f hF _ (h _) (he.close _))) + have hK : |V.kappa|≤1 := by rw [abs_of_pos V.kappa_pos]; exact w.kappaTop t + rw [score_prowl w t z o m s f he.frame hg hj,score_sheen w t z o m,←mul_sub] + apply warm_bound hc + have hh' : |V.kappa*(∏ i,P i)-V.kappa*E|≤num (Messenger q)*u+u := by + rw [←mul_sub]; exact warm_bound hK ((abs_sub_le (∏ i,P i) (∏ i,R i) E).trans (add_le_add hh + ((abs_sub_comm ..).trans_le hf))) + exact ((abs_sub_le Q _ (V.kappa*E)).trans (add_le_add hm hh')).trans_eq (by ring) + +set_option maxHeartbeats 800000 in +theorem paint_set (Y:Silhouette p N r) (o: UnitType p n N) (s : Charts p n d) + {r' : ℕ} + (f:Fin r' → Paint (w.pen t) N) (hF : ∀ i,pigments z Y (f i)) + (hg : 2≤p.g) (hj : 1≤p.j) (hc : ∀ i,|(f i).coeff|≤1) {u ℓ} + (he : w.mirrorSpan t z m ℓ u Y o) : + |w.prowl s t z m o (mural (w.pen t) f)-w.sheen t z o m s Y (mural (w.pen t) f)|≤ + r' * ((2+num (Messenger q))*u) := by + classical + let F i : Wgt (Keys (p:=p) t N) := (f i).cost + let R := show Wgt (Keys (p:=p) t N) from mural (w.pen t) f + have hf x : R x=∑ i:Fin r', F i x := rfl + change |w.prowl _ _ _ _ _ R-w.sheen _ _ _ _ _ _ R|≤_ + have hh : + w.prowl s t z m o R=∑ i:Fin r',w.prowl s t z m o (F i) := by + let key : Inputs p n (Messenger q) → Keys (p:=p) t N := (w.pen t).resultKey o + change avg ((w.pen t).state z n) (fun x => ind (w.deposit t z m o s x) * R (key x)) = + ∑ i : Fin r', avg ((w.pen t).state z n) + (fun x => ind (w.deposit t z m o s x) * F i (key x)) + simp_rw [hf, Finset.mul_sum,avg_sum] + have ht : + w.sheen t z o m s Y R=∑ i:Fin r',w.sheen t z o m s Y (F i) := by + unfold sheen; simp_rw [hf,Finset.mul_sum,avg_sum] + rw [hh,ht,←Finset.sum_sub_distrib] + apply (abs_sum_le_sum_abs ..).trans + exact (Finset.sum_le_sum fun i _=> paint_agree w t z m Y o s (f i) (hF i) hg hj (hc i) + he).trans_eq (by simp) + +structure witnessPaint (ε:ℝ) (W T : Wgt (Keys (p:=p) t N)) + (o : UnitType p n N) : Prop where + shadow : ∀ f : (w.pen t).Localist N,(∀ i j, |f i j|≤1) → + |avg (lawNu p N t z) (fun x=>(W x-T x)*prodW f x)|≤ε + tested : ¬ exceeds (w.pen t) z (W-T) w.script m (w.policies t z n) ε o + +set_option maxHeartbeats 800000 in +theorem bare_bridge (Y : Silhouette p N r) (o:UnitType p n N) (s:Charts p n d) + {r' : ℕ} + (f:Fin r' → Paint (w.pen t) N) (hF : ∀ i,pigments z Y (f i)) + (hg : 2≤p.g) (hj : 1≤p.j) (hc : ∀ i,|(f i).coeff|≤1) {u ℓ ε} + (he : w.mirrorSpan t z m ℓ u Y o) (W : Wgt (Keys (p:=p) t N)) + (hw : w.witnessPaint t z m ε W (mural (w.pen t) f) o) : + |w.prowl s t z m o W-w.sheen t z o m s Y W|≤ 2*ε +r'*((2+num (Messenger q))*u) := by + classical + let A:=w.pen t + let T:= show Wgt (Keys (p:=p) t N) from mural A f + let x:=w.prowl s t z m o; let y:= w.sheen t z o m s Y + have h1 : |x W-x T|≤ε := by + have hz : x W-x T=x (W-T) := by + let key : Inputs p n (Messenger q) → Keys (p:=p) t N := A.resultKey o + change avg (A.state z n) (fun x => ind (w.deposit t z m o s x) * W (key x)) - + avg (A.state z n) (fun x => ind (w.deposit t z m o s x) * T (key x)) = + avg (A.state z n) (fun x => ind (w.deposit t z m o s x) * (W-T) (key x)) + rw [←avg_sub] + simp only [Pi.sub_apply,mul_sub] + rw [hz] + change |w.prowl _ _ _ _ _ _|≤_ + rw [prowl_astonish] + exact le_of_not_gt (fun h=> hw.tested ⟨_, stencil_floor w t z o s m,h⟩) + have h2 : |y W-y T|≤ε := by + unfold y; rw [sheen_sun,sheen_sun,←mul_sub,←avg_sub] + let B:= w.seraph t z o m s Y + have hF (i j): |B i j|≤1 := by + have hh:= w.seraphFloor t z o m s Y i (he.law i) j; rw [abs_of_nonneg (show 0≤B i j + from hh.1)]; exact hh.2 + simp_rw [←sub_mul]; exact warm_bound (show |A.kappa|≤1 from (abs_of_pos A.kappa_pos).trans_le + (w.kappaTop t)) (hw.shadow B hF) + have h3 := paint_set w t z m Y o s f hF hg hj hc he + exact (abs_sub_le (x W) (x T) (y W)).trans ((add_le_add h1 + ((abs_sub_le (x T) (y T) (y W)).trans (add_le_add h3 ((abs_sub_comm ..).trans_le h2)))).trans_eq + (by ring)) + +end Quill +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RectangleRegularity.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RectangleRegularity.lean index 84dbe1b903f405d7c1c4853130b893dca2847eda..5959604863a47b6506cada4c249b8404ff0912f4 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RectangleRegularity.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RectangleRegularity.lean @@ -1,115 +1,115 @@ -import OAI.Combinatorics.HadwigerCounterexample.ConditionalProjection - -namespace OAI - -/-! # Rectangle Regularity -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real Function -open scoped BigOperators -variable {A B C K : Type} [Fintype A] [Fintype B] [Fintype C] - -def thinCut (μ f : Wgt A) (x : A→B) (y : A→C) (ε : ℝ) := - ∀ u : Wgt B,(∀ i,|u i|≤1) → ∀ v : Wgt C,(∀ i,|v i|≤1) → - |avg μ (fun i=> f i*(u (x i)*v (y i)))|≤ ε -def doubleBook {L R : Type} (x : A→B) (y : A→C) (a : B→L) (b : C→R) := - fun i => (a (x i),b (y i)) -def swab (x : Bool) : ℝ := if x then 1 else -1 -theorem swab_abs (x) : |swab x|=1 := by cases x <;> simp [swab] - -private theorem sign_mass (w : Wgt A) (f : A→B) (u : Wgt B) (h : ∀ i,|u i|≤1) : - ∃ y : B→Bool,|avg w (u ∘ f)|≤|avg w (swab ∘ y ∘ f)| := by - classical - let p := mapW w f - let y (i) := decide (0≤p i) - have he i : - p i*swab (y i)=|p i| := by - by_cases hh : 0≤p i <;> simp [swab,y,hh,abs_of_nonneg,abs_of_neg,lt_of_not_ge] - have hu : - |avg p u| ≤ ∑ i,|p i| := by - unfold avg; refine (Finset.abs_sum_le_sum_abs ..).trans ?_ - refine Finset.sum_le_sum fun i _ => ?_ - rw [abs_mul] - exact (mul_le_mul_of_nonneg_left (h i) (abs_nonneg _)).trans_eq (mul_one _) - have hz : avg p (swab ∘ y) = ∑ i, |p i| := Finset.sum_congr rfl fun i _=> he i - refine ⟨y,?_⟩ - rw [show avg w (u∘f)=avg p u from (mapW_avg w f u).symm,show avg w (swab∘y∘f)= - avg p (swab∘y) from (mapW_avg w f (swab ∘ y)).symm] - exact hu.trans (hz.symm.le.trans (le_abs_self _)) - -theorem cut_witness (μ f : Wgt A) {x : A→B} {y : A→C} {ε : ℝ} (h : ¬ thinCut μ f x y ε) : - ∃ (i : B→Bool) (j : C→Bool), ε < |avg μ (fun z=>f z*(swab (i (x z))*swab (j (y z))))| := by - classical - unfold thinCut at h - push Not at h - obtain ⟨u,hu,v,hv,h⟩ := h - let Q (u : Wgt B) (v : Wgt C) := avg μ (fun z=>f z*(u (x z)*v (y z))) - let U z := μ z*f z*v (y z) - obtain ⟨i,hi⟩ := sign_mass U x u hu - have hx (u) : Q u v=avg U (u∘x) := Finset.sum_congr rfl (fun z _=>by unfold U Function.comp; ring) - let V z := μ z*f z*swab (i (x z)) - obtain ⟨j,hj⟩ := sign_mass V y v hv - have hy (v) : Q (swab ∘ i) v=avg V (v∘y) := Finset.sum_congr rfl (fun z _=>by - unfold V Function.comp; ring) - rw [←hx u,show avg U (swab ∘ i ∘ x)=Q (swab ∘ i) v from (hx (swab ∘ i)).symm] at hi - rw [←hy v,show avg V (swab ∘ j ∘ y)=Q (swab ∘ i) (swab∘j) from (hy (swab ∘ j)).symm] at hj - exact ⟨i,j, lt_of_lt_of_le h (hi.trans hj)⟩ - -def weakRank (μ f : Wgt A) (x : A→B) (y : A→C) (δ : ℝ) (R : ℕ) := - ∃ l : ℕ,l≤R ∧ ∃ (a:B→Fin l) (b:C→ Fin l), - thinCut μ (fun i=> f i-banner μ (doubleBook x y a b) f i) x y δ - -set_option maxHeartbeats 800000 in -theorem plenty_cuts (δ M : ℝ) (hδ : 0<δ) (hM : 0≤M) : - ∃ r:ℕ,∀ (A B C : Type) [Fintype A] [Fintype B] [Fintype C] - (μ f : Wgt A) (x : A→B) (y : A→C),SubLaw μ → (∀ i,|f i| ≤ M) → - weakRank μ f x y δ r := by - classical - obtain ⟨l,hl⟩ := exists_nat_gt (M^2 / δ^2) - refine ⟨2^l,fun A B C _ _ _ μ f x y hw hf => ?_⟩ - by_contra h - have hh (i : ℕ) (hi : i≤l) : - ∃ (a:B→Fin (2^i)) (b:C→Fin (2^i)), i*δ^2 ≤ ode μ (banner μ (doubleBook x y a b) f) := by - induction i with - | zero => exact ⟨fun _=>0,fun _=>0, by simpa using ode_nonneg hw.nz _⟩ - | succ i ih => - obtain ⟨a,b,he⟩ := ih (by omega) - let T := doubleBook x y a b - let d := fun z => f z-banner μ T f z - obtain ⟨u,v,e⟩ := cut_witness μ d (x:=x) (y:=y) (ε:=δ) (fun p => - h ⟨_,Nat.pow_le_pow_right (by decide) (by omega),a,b,p⟩) - let r := 2^i - let E : Fin r × Bool ≃ Fin (2^(i+1)) := Fintype.equivFinOfCardEq (by simp [r,pow_succ]) - let a' z := E (a z,u z); let b' z := E (b z,v z) - let S := doubleBook x y a' b' - let U (z j : Fin (2^(i+1))) := ((E.symm z).1,(E.symm j).1) - let V (z j : Fin (2^(i+1))) := swab (E.symm z).2*swab (E.symm j).2 - have hz : uncurry U ∘ S=T := by - funext i; simp only [doubleBook,a',b',Function.comp_apply,U,S,uncurry_apply_pair, - Equiv.symm_apply_apply]; rfl - have hH (i) : uncurry V (S i)=swab (u (x i))*swab (v (y i)) := by - simp only [S,doubleBook,a',b',V,uncurry_apply_pair,Equiv.symm_apply_apply] - have hh (i) : |uncurry V (S i)| ≤ 1 := by rw [hH,abs_mul,swab_abs,swab_abs,mul_one] - have hq := archive_gain hw f S (uncurry U) (uncurry V) hh - rw [hz] at hq - have ht : dip μ d (uncurry V ∘ S)= - avg μ (fun z => d z*(swab (u (x z))*swab (v (y z)))) := - avg_congr (fun i _=> congrArg _ (hH i)) - change (dip μ d _)^2≤_ at hq - rw [←ht] at e - refine ⟨a',b',?_⟩ - change ↑(i+1)*δ^2≤ode μ (banner μ S f) - change ↑i*δ^2≤ode μ (banner μ T f) at he - push_cast - nlinarith only [he,hq,e,sq_abs (dip μ d (uncurry V ∘ S)),hδ] - obtain ⟨a,b,he⟩ := hh l le_rfl - let F := doubleBook x y a b - have hb := cashbook_bound μ hw.nz F f M hM hf - have ht := he.trans (ode_upper hw _ M (fun i : A=> hb (F i))) - exact not_lt_of_ge ht ((div_lt_iff₀ (by positivity)).mp hl) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ConditionalProjection + +namespace OAI + +/-! # Rectangle Regularity -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real Function +open scoped BigOperators +variable {A B C K : Type} [Fintype A] [Fintype B] [Fintype C] + +def thinCut (μ f : Wgt A) (x : A→B) (y : A→C) (ε : ℝ) := + ∀ u : Wgt B,(∀ i,|u i|≤1) → ∀ v : Wgt C,(∀ i,|v i|≤1) → + |avg μ (fun i=> f i*(u (x i)*v (y i)))|≤ ε +def doubleBook {L R : Type} (x : A→B) (y : A→C) (a : B→L) (b : C→R) := + fun i => (a (x i),b (y i)) +def swab (x : Bool) : ℝ := if x then 1 else -1 +theorem swab_abs (x) : |swab x|=1 := by cases x <;> simp [swab] + +private theorem sign_mass (w : Wgt A) (f : A→B) (u : Wgt B) (h : ∀ i,|u i|≤1) : + ∃ y : B→Bool,|avg w (u ∘ f)|≤|avg w (swab ∘ y ∘ f)| := by + classical + let p := mapW w f + let y (i) := decide (0≤p i) + have he i : + p i*swab (y i)=|p i| := by + by_cases hh : 0≤p i <;> simp [swab,y,hh,abs_of_nonneg,abs_of_neg,lt_of_not_ge] + have hu : + |avg p u| ≤ ∑ i,|p i| := by + unfold avg; refine (Finset.abs_sum_le_sum_abs ..).trans ?_ + refine Finset.sum_le_sum fun i _ => ?_ + rw [abs_mul] + exact (mul_le_mul_of_nonneg_left (h i) (abs_nonneg _)).trans_eq (mul_one _) + have hz : avg p (swab ∘ y) = ∑ i, |p i| := Finset.sum_congr rfl fun i _=> he i + refine ⟨y,?_⟩ + rw [show avg w (u∘f)=avg p u from (mapW_avg w f u).symm,show avg w (swab∘y∘f)= + avg p (swab∘y) from (mapW_avg w f (swab ∘ y)).symm] + exact hu.trans (hz.symm.le.trans (le_abs_self _)) + +theorem cut_witness (μ f : Wgt A) {x : A→B} {y : A→C} {ε : ℝ} (h : ¬ thinCut μ f x y ε) : + ∃ (i : B→Bool) (j : C→Bool), ε < |avg μ (fun z=>f z*(swab (i (x z))*swab (j (y z))))| := by + classical + unfold thinCut at h + push Not at h + obtain ⟨u,hu,v,hv,h⟩ := h + let Q (u : Wgt B) (v : Wgt C) := avg μ (fun z=>f z*(u (x z)*v (y z))) + let U z := μ z*f z*v (y z) + obtain ⟨i,hi⟩ := sign_mass U x u hu + have hx (u) : Q u v=avg U (u∘x) := Finset.sum_congr rfl (fun z _=>by unfold U Function.comp; ring) + let V z := μ z*f z*swab (i (x z)) + obtain ⟨j,hj⟩ := sign_mass V y v hv + have hy (v) : Q (swab ∘ i) v=avg V (v∘y) := Finset.sum_congr rfl (fun z _=>by + unfold V Function.comp; ring) + rw [←hx u,show avg U (swab ∘ i ∘ x)=Q (swab ∘ i) v from (hx (swab ∘ i)).symm] at hi + rw [←hy v,show avg V (swab ∘ j ∘ y)=Q (swab ∘ i) (swab∘j) from (hy (swab ∘ j)).symm] at hj + exact ⟨i,j, lt_of_lt_of_le h (hi.trans hj)⟩ + +def weakRank (μ f : Wgt A) (x : A→B) (y : A→C) (δ : ℝ) (R : ℕ) := + ∃ l : ℕ,l≤R ∧ ∃ (a:B→Fin l) (b:C→ Fin l), + thinCut μ (fun i=> f i-banner μ (doubleBook x y a b) f i) x y δ + +set_option maxHeartbeats 800000 in +theorem plenty_cuts (δ M : ℝ) (hδ : 0<δ) (hM : 0≤M) : + ∃ r:ℕ,∀ (A B C : Type) [Fintype A] [Fintype B] [Fintype C] + (μ f : Wgt A) (x : A→B) (y : A→C),SubLaw μ → (∀ i,|f i| ≤ M) → + weakRank μ f x y δ r := by + classical + obtain ⟨l,hl⟩ := exists_nat_gt (M^2 / δ^2) + refine ⟨2^l,fun A B C _ _ _ μ f x y hw hf => ?_⟩ + by_contra h + have hh (i : ℕ) (hi : i≤l) : + ∃ (a:B→Fin (2^i)) (b:C→Fin (2^i)), i*δ^2 ≤ ode μ (banner μ (doubleBook x y a b) f) := by + induction i with + | zero => exact ⟨fun _=>0,fun _=>0, by simpa using ode_nonneg hw.nz _⟩ + | succ i ih => + obtain ⟨a,b,he⟩ := ih (by omega) + let T := doubleBook x y a b + let d := fun z => f z-banner μ T f z + obtain ⟨u,v,e⟩ := cut_witness μ d (x:=x) (y:=y) (ε:=δ) (fun p => + h ⟨_,Nat.pow_le_pow_right (by decide) (by omega),a,b,p⟩) + let r := 2^i + let E : Fin r × Bool ≃ Fin (2^(i+1)) := Fintype.equivFinOfCardEq (by simp [r,pow_succ]) + let a' z := E (a z,u z); let b' z := E (b z,v z) + let S := doubleBook x y a' b' + let U (z j : Fin (2^(i+1))) := ((E.symm z).1,(E.symm j).1) + let V (z j : Fin (2^(i+1))) := swab (E.symm z).2*swab (E.symm j).2 + have hz : uncurry U ∘ S=T := by + funext i; simp only [doubleBook,a',b',Function.comp_apply,U,S,uncurry_apply_pair, + Equiv.symm_apply_apply]; rfl + have hH (i) : uncurry V (S i)=swab (u (x i))*swab (v (y i)) := by + simp only [S,doubleBook,a',b',V,uncurry_apply_pair,Equiv.symm_apply_apply] + have hh (i) : |uncurry V (S i)| ≤ 1 := by rw [hH,abs_mul,swab_abs,swab_abs,mul_one] + have hq := archive_gain hw f S (uncurry U) (uncurry V) hh + rw [hz] at hq + have ht : dip μ d (uncurry V ∘ S)= + avg μ (fun z => d z*(swab (u (x z))*swab (v (y z)))) := + avg_congr (fun i _=> congrArg _ (hH i)) + change (dip μ d _)^2≤_ at hq + rw [←ht] at e + refine ⟨a',b',?_⟩ + change ↑(i+1)*δ^2≤ode μ (banner μ S f) + change ↑i*δ^2≤ode μ (banner μ T f) at he + push_cast + nlinarith only [he,hq,e,sq_abs (dip μ d (uncurry V ∘ S)),hδ] + obtain ⟨a,b,he⟩ := hh l le_rfl + let F := doubleBook x y a b + have hb := cashbook_bound μ hw.nz F f M hM hf + have ht := he.trans (ode_upper hw _ M (fun i : A=> hb (F i))) + exact not_lt_of_ge ht ((div_lt_iff₀ (by positivity)).mp hl) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RecursiveComparisonErrors.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RecursiveComparisonErrors.lean index 5c05901dc86a530d6a09fe271e1689bc761389c3..a8a0535316e1a12831032cdbb505dea39b57b978 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RecursiveComparisonErrors.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RecursiveComparisonErrors.lean @@ -1,93 +1,93 @@ -import OAI.Combinatorics.HadwigerCounterexample.HeadPartitionComparison - -namespace OAI - -/-! # Recursive Comparison Errors -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Function Filter Matrix -open scoped BigOperators -variable {p : Shape} {I : Type} [Fintype I] [DecidableEq I] {n N : ℕ} -namespace Template -variable (v : Template p I) - -theorem board_add (v : Template p I) (q : I→F) (U V : Wgt (Keys (p:=p) v.t N)) f : - board v q (U+V) f=board v q U f+board v q V f := by - unfold board curtain; simp only [Pi.add_apply,mul_add,add_mul,avg_add] - -theorem shadow_add (v : Template p I) (q : I→F) (U V : Wgt (Keys (p:=p) v.t N)) - (r s : ℝ) (h : shadowed v q U r) (h' : shadowed v q V s) : - shadowed v q (U+V) (r+s) := fun f hf => by - rw [board_add] - exact (abs_add_le _ _).trans (add_le_add (h f hf) (h' f hf)) - -theorem scene_join (v : Template p I) (q : I→ F) (U V : Wgt (Keys (p:=p) v.t N)) - (s : Script p I) (m : Mixer p n) (w : I→Wgt (Knobs p.g n)) - (x y : ℝ) (o : UnitType p n N) - (h : exceeds v q (U+V) s m w (x+y) o) : - exceeds v q U s m w x o ∨ exceeds v q V s m w y o := by - classical - obtain ⟨f,hf,h'⟩ := h - have he : - astonish v q (U+V) s m w f o=astonish v q U s m w f o+astonish v q V s m w f o := by - simp only [astonish_val,Pi.add_apply,mul_add,add_mul,avg_add] - change x+y < |astonish v q (U+V) s m w f o| at h' - rw [he] at h' - by_contra! hh - have ht : |astonish v q U s m w f o|≤x := le_of_not_gt (fun h=>hh.1 ⟨f,hf,h⟩) - have hv : |astonish v q V s m w f o|≤y := le_of_not_gt (fun h=>hh.2 ⟨f,hf,h⟩) - exact not_lt_of_ge ((abs_add_le _ _).trans (add_le_add ht hv)) h' - -def drained (m : Mixer p n) (C : ℝ) (w : Wgt (UnitType p n N)) := - let μ := raw m N; let H:=bp ((1/32:ℝ)*n) - IsLaw w ∧ (∀ x,mapW w Prod.fst x ≤ H*μ x) ∧ (∀ x,mapW w Prod.snd x≤H*μ x) ∧ - ∀ x,w x ≤ bp (C*N)*pairW μ μ x - -def engaged (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) - (n : ℕ) (C e ε : ℝ) := - ∀ (m : Mixer p n),2*num (Full p n)u i.val) ε - have he (o) (hf : exceeds v q g s m u ε o) : ∃ i,W i o := by - by_contra! hx - exact patched_exceed v j q a V ε u hu s m o hx hf - have hn := hw.1 - have hi : - pr w (fun x => ∃ i:Fin r,W i x) ≤ (r:ℝ)*y := by - refine (pr_exists_le hn.nz W).trans ((Finset.sum_le_sum - (g:=fun _=>y) (fun i _=>?_)).trans_eq (by simp)) - exact hh i m hN w hw (scriptTail s j) _ (fun i =>hu i.val) (fun i =>hz i.val) - apply (le_trans (pr_mono hn.nz (fun i => scene_join v q f g s m u _ _ i)) (pr_or_le hn.nz)).trans - exact add_le_add (h m hN w hw s u hu hz) ((pr_mono hn.nz he).trans hi) -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.HeadPartitionComparison + +namespace OAI + +/-! # Recursive Comparison Errors -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Function Filter Matrix +open scoped BigOperators +variable {p : Shape} {I : Type} [Fintype I] [DecidableEq I] {n N : ℕ} +namespace Template +variable (v : Template p I) + +theorem board_add (v : Template p I) (q : I→F) (U V : Wgt (Keys (p:=p) v.t N)) f : + board v q (U+V) f=board v q U f+board v q V f := by + unfold board curtain; simp only [Pi.add_apply,mul_add,add_mul,avg_add] + +theorem shadow_add (v : Template p I) (q : I→F) (U V : Wgt (Keys (p:=p) v.t N)) + (r s : ℝ) (h : shadowed v q U r) (h' : shadowed v q V s) : + shadowed v q (U+V) (r+s) := fun f hf => by + rw [board_add] + exact (abs_add_le _ _).trans (add_le_add (h f hf) (h' f hf)) + +theorem scene_join (v : Template p I) (q : I→ F) (U V : Wgt (Keys (p:=p) v.t N)) + (s : Script p I) (m : Mixer p n) (w : I→Wgt (Knobs p.g n)) + (x y : ℝ) (o : UnitType p n N) + (h : exceeds v q (U+V) s m w (x+y) o) : + exceeds v q U s m w x o ∨ exceeds v q V s m w y o := by + classical + obtain ⟨f,hf,h'⟩ := h + have he : + astonish v q (U+V) s m w f o=astonish v q U s m w f o+astonish v q V s m w f o := by + simp only [astonish_val,Pi.add_apply,mul_add,add_mul,avg_add] + change x+y < |astonish v q (U+V) s m w f o| at h' + rw [he] at h' + by_contra! hh + have ht : |astonish v q U s m w f o|≤x := le_of_not_gt (fun h=>hh.1 ⟨f,hf,h⟩) + have hv : |astonish v q V s m w f o|≤y := le_of_not_gt (fun h=>hh.2 ⟨f,hf,h⟩) + exact not_lt_of_ge ((abs_add_le _ _).trans (add_le_add ht hv)) h' + +def drained (m : Mixer p n) (C : ℝ) (w : Wgt (UnitType p n N)) := + let μ := raw m N; let H:=bp ((1/32:ℝ)*n) + IsLaw w ∧ (∀ x,mapW w Prod.fst x ≤ H*μ x) ∧ (∀ x,mapW w Prod.snd x≤H*μ x) ∧ + ∀ x,w x ≤ bp (C*N)*pairW μ μ x + +def engaged (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) + (n : ℕ) (C e ε : ℝ) := + ∀ (m : Mixer p n),2*num (Full p n)u i.val) ε + have he (o) (hf : exceeds v q g s m u ε o) : ∃ i,W i o := by + by_contra! hx + exact patched_exceed v j q a V ε u hu s m o hx hf + have hn := hw.1 + have hi : + pr w (fun x => ∃ i:Fin r,W i x) ≤ (r:ℝ)*y := by + refine (pr_exists_le hn.nz W).trans ((Finset.sum_le_sum + (g:=fun _=>y) (fun i _=>?_)).trans_eq (by simp)) + exact hh i m hN w hw (scriptTail s j) _ (fun i =>hu i.val) (fun i =>hz i.val) + apply (le_trans (pr_mono hn.nz (fun i => scene_join v q f g s m u _ _ i)) (pr_or_le hn.nz)).trans + exact add_le_add (h m hN w hw s u hu hz) ((pr_mono hn.nz he).trans hi) +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ReferenceProductTests.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ReferenceProductTests.lean index df9491fcc261232c1690b76ae6e45ba728db6ffa..ca112a334e7f763dcc48f99c94d9030e8cc91c09 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ReferenceProductTests.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ReferenceProductTests.lean @@ -1,85 +1,85 @@ -import OAI.Combinatorics.HadwigerCounterexample.KeyReferenceLaws -import OAI.Combinatorics.HadwigerCounterexample.EndpointTemplateConcentration - -namespace OAI - -/-! # Reference Product Tests -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Module Function Finset Filter -variable {p : Shape} {I : Type} [Fintype I] [DecidableEq I] {n N : ℕ} - -set_option maxHeartbeats 600000 in -theorem reference_product (t : Tagging p I) (q : I → F) - (f : ∀ i,Wgt (AtomKey (p:=p) (t i) N)) - (hf : ∀ i x,|f i x|≤1) (hN : 2*num (I×Toast p)-(N:ℝ)≤ -1) : - |avg (lawNu p N t q) (prodW f)- ∏ i,avg (lawOmega p N (t i) (q i)) (f i)|≤ - 2*netFact (trayPort p t)*bp (-(N:ℝ)/2) := by - classical - let F (i : I) := (f i)∘(mug p (t i) N).symm - let g := trayPort p t - let A := trayMap p t q - have hpL i := show 2*num (Port g i)-(N:ℝ)≤ -1 by linarith only [hN,port_limit g i] - have he : - avg (rackWave A N) (brightProd F) =avg (lawNu p N t q) (prodW f) := by - unfold A; rw [←lawtray,mapW_avg] - have hh x : brightProd F (tray p t N x)=prodW f x := by - simp_rw [brightProd,tray_sips,F,Function.comp_apply,Equiv.symm_apply_apply] - rfl - simp_rw [hh] - have hw i : avg (rackWave (laneM A i) N) (F i)=avg (lawOmega p N (t i) (q i)) (f i) := by - unfold A; rw [←lawmug,mapW_avg] - simp_rw [F,Function.comp_apply, Equiv.symm_apply_apply] - have h := compare_waves A F (fun i x => hf _ _) hpL - simp_rw [he,hw] at h; exact h - -theorem priceNu (t : Tagging p I) (q : I→F) (hN : 2*num (I×Toast p)-(N:ℝ) ≤ -1) : - (netFact (trayPort p t))⁻¹ ≤ pr unif (ownPart (p:=p) t q (N:=N)) := by - classical - let g := trayPort p t; let A := trayMap p t q - have hpL i := show 2*num (Port g i)-(N:ℝ)≤ -1 by linarith only [hN,port_limit g i] - have he : pr unif (gramPart A (N:=N))=pr unif (ownPart (p:=p) t q (N:=N)) := by - rw [← unif_equiv (tray p t N),mapW_pr] - unfold A - congr 1; ext i - exact (tray_wave ..).symm - rw [←he] - exact wave_norm A N hpL -theorem nuLaw (t : Tagging p I) (q : I → F) (hN : 2*num (I×Toast p)-(N:ℝ) ≤ -1) : - IsLaw (lawNu p N t q) := by - classical - rw [lawNu,←on_unif] - exact on_law unif_law.nz ((inv_pos_of_pos netFact_pos).trans_le (priceNu t q hN)) - -theorem priceOmega (t : Tagging p I) (q : I→F) (i : I) (hN : 2*num (I×Toast p)-(N:ℝ) ≤ -1) : - (netFact (street (trayPort p t) i))⁻¹ ≤ pr unif (ownOne p (t i) (q i) (N:=N)) := by - classical - let g := street (trayPort p t) i; let A := laneM (trayMap p t q) i - have hh j : num (Port g j)≤num (I×Toast p) := by - apply le_trans (port_limit g j) - exact_mod_cast Fintype.card_le_of_injective (fun j : Toast p => (i,j)) (fun i j h => - congrArg Prod.snd h) - have hpL j := show 2*num (Port g j)-(N:ℝ)≤ -1 by linarith only [hN,hh j] - have he : pr unif (gramPart A (N:=N))=pr unif (ownOne p (t i) (q i) (N:=N)) := by - rw [← unif_equiv (mug p (t i) N),mapW_pr] - unfold A - congr 1; ext x - exact (mug_wave ..).symm - rw [←he] - exact wave_norm A N hpL - -theorem omegaLaw (p : Shape) (l : Tag p.g) (q : F) (hN : 2*num (Toast p)-(N:ℝ)≤ -1) : - IsLaw (lawOmega p N l q) := by - classical - let t := fun (_ : Unit) => l - have hh : 2*num (Unit×Toast p)-(N:ℝ)≤ -1 := by simpa [num] using hN - rw [lawOmega,←on_unif] - exact on_law unif_law.nz ((inv_pos_of_pos netFact_pos).trans_le - (priceOmega t (fun _ : Unit => q) () hh)) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.KeyReferenceLaws +import OAI.Combinatorics.HadwigerCounterexample.EndpointTemplateConcentration + +namespace OAI + +/-! # Reference Product Tests -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Module Function Finset Filter +variable {p : Shape} {I : Type} [Fintype I] [DecidableEq I] {n N : ℕ} + +set_option maxHeartbeats 600000 in +theorem reference_product (t : Tagging p I) (q : I → F) + (f : ∀ i,Wgt (AtomKey (p:=p) (t i) N)) + (hf : ∀ i x,|f i x|≤1) (hN : 2*num (I×Toast p)-(N:ℝ)≤ -1) : + |avg (lawNu p N t q) (prodW f)- ∏ i,avg (lawOmega p N (t i) (q i)) (f i)|≤ + 2*netFact (trayPort p t)*bp (-(N:ℝ)/2) := by + classical + let F (i : I) := (f i)∘(mug p (t i) N).symm + let g := trayPort p t + let A := trayMap p t q + have hpL i := show 2*num (Port g i)-(N:ℝ)≤ -1 by linarith only [hN,port_limit g i] + have he : + avg (rackWave A N) (brightProd F) =avg (lawNu p N t q) (prodW f) := by + unfold A; rw [←lawtray,mapW_avg] + have hh x : brightProd F (tray p t N x)=prodW f x := by + simp_rw [brightProd,tray_sips,F,Function.comp_apply,Equiv.symm_apply_apply] + rfl + simp_rw [hh] + have hw i : avg (rackWave (laneM A i) N) (F i)=avg (lawOmega p N (t i) (q i)) (f i) := by + unfold A; rw [←lawmug,mapW_avg] + simp_rw [F,Function.comp_apply, Equiv.symm_apply_apply] + have h := compare_waves A F (fun i x => hf _ _) hpL + simp_rw [he,hw] at h; exact h + +theorem priceNu (t : Tagging p I) (q : I→F) (hN : 2*num (I×Toast p)-(N:ℝ) ≤ -1) : + (netFact (trayPort p t))⁻¹ ≤ pr unif (ownPart (p:=p) t q (N:=N)) := by + classical + let g := trayPort p t; let A := trayMap p t q + have hpL i := show 2*num (Port g i)-(N:ℝ)≤ -1 by linarith only [hN,port_limit g i] + have he : pr unif (gramPart A (N:=N))=pr unif (ownPart (p:=p) t q (N:=N)) := by + rw [← unif_equiv (tray p t N),mapW_pr] + unfold A + congr 1; ext i + exact (tray_wave ..).symm + rw [←he] + exact wave_norm A N hpL +theorem nuLaw (t : Tagging p I) (q : I → F) (hN : 2*num (I×Toast p)-(N:ℝ) ≤ -1) : + IsLaw (lawNu p N t q) := by + classical + rw [lawNu,←on_unif] + exact on_law unif_law.nz ((inv_pos_of_pos netFact_pos).trans_le (priceNu t q hN)) + +theorem priceOmega (t : Tagging p I) (q : I→F) (i : I) (hN : 2*num (I×Toast p)-(N:ℝ) ≤ -1) : + (netFact (street (trayPort p t) i))⁻¹ ≤ pr unif (ownOne p (t i) (q i) (N:=N)) := by + classical + let g := street (trayPort p t) i; let A := laneM (trayMap p t q) i + have hh j : num (Port g j)≤num (I×Toast p) := by + apply le_trans (port_limit g j) + exact_mod_cast Fintype.card_le_of_injective (fun j : Toast p => (i,j)) (fun i j h => + congrArg Prod.snd h) + have hpL j := show 2*num (Port g j)-(N:ℝ)≤ -1 by linarith only [hN,hh j] + have he : pr unif (gramPart A (N:=N))=pr unif (ownOne p (t i) (q i) (N:=N)) := by + rw [← unif_equiv (mug p (t i) N),mapW_pr] + unfold A + congr 1; ext x + exact (mug_wave ..).symm + rw [←he] + exact wave_norm A N hpL + +theorem omegaLaw (p : Shape) (l : Tag p.g) (q : F) (hN : 2*num (Toast p)-(N:ℝ)≤ -1) : + IsLaw (lawOmega p N l q) := by + classical + let t := fun (_ : Unit) => l + have hh : 2*num (Unit×Toast p)-(N:ℝ)≤ -1 := by simpa [num] using hN + rw [lawOmega,←on_unif] + exact on_law unif_law.nz ((inv_pos_of_pos netFact_pos).trans_le + (priceOmega t (fun _ : Unit => q) () hh)) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RefinedPinImages.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RefinedPinImages.lean index bf3723a793d38283f976ec3ccdc436a46b7cc55b..4d4fb356bfe60717e3ee850ee6b65b53f7ae9fcf 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RefinedPinImages.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RefinedPinImages.lean @@ -1,240 +1,240 @@ -import OAI.Combinatorics.HadwigerCounterexample.PartitionSelection -import OAI.Combinatorics.HadwigerCounterexample.FourPhaseBits - -namespace OAI - -/-! # Refined Pin Images -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Function Finset -open scoped BigOperators -variable {p : Shape} {n N : ℕ} - -def front (s : Plan p n) : Plan p n := prSmall s - -theorem front_rank (s : Plan p n) : planRank (front s) ≤2*planRank s := by - classical - unfold planRank - rw [Finset.mul_sum] - refine Finset.sum_le_sum fun i _ => ?_ - have hh (j) : - dim ((sPin s i j).map (IP p n j).mulVecLin)≤dim (s i) := - (Submodule.finrank_map_le ..).trans (sPin_dim ..) - exact ((Submodule.finrank_add_le_finrank_add_finrank ..).trans (add_le_add (hh _) (hh _))).trans_eq - (two_mul _).symm - -theorem combined_rank (s t : Plan p n) : planRank (s⊔t)≤planRank s+planRank t := by - unfold planRank; rw [←Finset.sum_add_distrib] - exact Finset.sum_le_sum fun i _ => finrank_add_le_finrank_add_finrank .. - -abbrev Signal (p : Shape) (N : ℕ) {n} (s : Plan p n) := DTuple (p:=p) (fun z => dim (s z)) N - -def readPin (x : UnitType p n N) (a : Plan p n) : Signal p N a := - fun z => images x z * pack (a z) - -abbrev EffSeq {p : Shape} {n} (s : Plan p n) := ∀ i : Bool,effective s i - -def entrySeq {p : Shape} {n} (s : Plan p n) (m : Bool → Profile p n) : EffSeq s := - open scoped Classical in - fun i => if h : m i ∈ effective s i then ⟨_,h⟩ else 0 - -abbrev Story {p : Shape} {n N} (T : Cov p N) (s : Plan p n) := - Daypair p T × Signal p N (front s) × EffSeq s - -instance fintypeStory {s : Plan p n} {T : Cov p N} : Fintype (Story T s) := by - classical - let A := (coverX p T) - letI : Finite (Module.Dual F A) := Finite.of_injective _ DFunLike.coe_injective - letI : Fintype (Module.Dual F A) := Fintype.ofFinite _ - letI : Fintype (Daypair p T) := inferInstanceAs (Fintype (Daypair p T)) - letI : ∀ i,Fintype (effective s i) := fun i => Fintype.ofFinite _ - letI : Fintype (EffSeq s) := inferInstanceAs (Fintype (EffSeq s)) - letI : Fintype (Signal p N (front s)) := inferInstanceAs (Fintype (Signal p N (front s))) - exact inferInstanceAs (Fintype (Story T s)) - -def story (T : Cov p N) (s : Plan p n) (m : BMark p n N) (x : UnitType p n N) : Story T s := - (daypair p T (delta m) (fun _ => 1) x,readPin x (front s),entrySeq s (m x)) - -def specialLeaf (T : Cov p N) (m : BMark p n N) (a : Pin p n N) - (G : CTile p n N) (b : Pin p n N) := - a.sp ≤ b.sp ∧ front a.sp ≤ b.sp ∧ - ∀ x∈G,∀ y∈G, m x=m y ∧ delta m x=delta m y ∧ - ∀ i,juris p T x (unary i) = juris p T y (unary i) - -private theorem storyOk (T : Cov p N) (m : BMark p n N) - (a : Pin p n N) (S : CTile p n N) (K : ℕ) (hk : planRank a.sp≤K) - (h : ∀ x∈S, a.agree x ∧ covered p T (delta m x) ∧ - ∀ i,m x i∈effective a.sp i) : - ∀ i : Story T a.sp,∃ b : Pin p n N, - (∀ x∈ S,story T a.sp m x=i → b.agree x) ∧ planRank b.sp ≤ 3*K ∧ - ∀ c (G : CTile p n N), G.Nonempty → - (∀ x∈G,x∈S ∧ story T a.sp m x=i) → b.sp ≤ c.sp → specialLeaf T m a G c := by - classical - intro i - let A := a.sp ⊔ front a.sp - have hK : planRank A≤3*K := by - apply (combined_rank ..).trans - have hh := front_rank a.sp - omega - have h1 : ∃ x : UnitType p n N, ∀ y∈ S,story T a.sp m y=i → (Pin.make A x).agree y := by - by_cases hg : ∃ x∈S,story T a.sp m x=i - · obtain ⟨x,hx,he⟩ := hg - refine ⟨x,fun y hy ht => ?_⟩ - let b := Pin.make (front a.sp) x - have hf : b.agree y := by - rw [Pin.agree_pack]; intro z - have hh : readPin y (front a.sp)=readPin x (front a.sp) := - congrArg (fun x : Story T a.sp => x.2.1) (ht.trans he.symm) - exact congr_fun hh z - exact (Pin.combine (b:=b) (h x hx).1 (show b.agree x from fun _ _ _ => rfl)).mpr - ⟨(h y hy).1,hf⟩ - exact ⟨0,fun x hx he => (hg ⟨x,hx,he⟩).elim⟩ - obtain ⟨x,hx⟩ := h1 - refine ⟨Pin.make A x,hx,hK,fun c G hm hC hA => ⟨le_trans le_sup_left hA, - le_trans le_sup_right hA, fun x hx y hy => ?_⟩⟩ - have he := (hC x hx).2.trans (hC y hy).2.symm - have hD := congrArg Prod.fst he - have hr z (hz : z∈G) : (story T a.sp m z).1.1.val=delta m z := by - unfold story daypair; change (cutDown p T (delta m) (fun _ => 1) z).val=_ - unfold cutDown; rw [dite_eq_left ⟨(by norm_num),(h z (hC z hz).1).2.1⟩] - have ht z (hz : z∈G) (i) : ((story T a.sp m z).2.2 i).val=m z i := by - unfold story entrySeq; dsimp only - rw [dite_eq_left ((h z (hC z hz).1).2.2 i)] - refine ⟨funext (fun i => ?_),?_,fun i => ?_⟩ - · rw [←ht x hx i,←ht y hy i,he] - · rw [←hr x hx, ←hr y hy,he] - exact congr_fun (congrArg Prod.snd hD) i - -theorem story_size (T : Cov p N) (s : Plan p n) (K d : ℕ) - (hK : planRank s≤K) (hd : cdim p T≤d) : - num (Story T s) ≤ bp ((3*d+2*K : ℝ)*N + 2*K^2) := by - classical - have h1 : dim (coverX p T)≤ N*d := (cover_dim p T).trans (Nat.mul_le_mul_left N hd) - have h2 : dim (Daypair p T) ≤ 3*d*N := by - unfold dim Daypair - rw [finrank_prod,finrank_pi_fintype, Fintype.sum_bool,Subspace.dual_finrank_eq] - change dim _+(dim _+dim _) ≤ _ - nlinarith - have h3 : dim (Signal p N (front s)) ≤ (2*K)*N := tuple_dim.trans_le (by - rw [mul_comm]; apply Nat.mul_le_mul_right - exact (front_rank s).trans (Nat.mul_le_mul_left _ hK)) - have h4 : dim (EffSeq s)≤ 2*K^2 := by - unfold EffSeq dim - rw [finrank_pi_fintype,Fintype.sum_bool,two_mul] - have hh i : dim (effective s i) ≤ K^2 := (effective_dim ..).trans (by gcongr) - exact add_le_add (hh _) (hh _) - unfold num - rw [card_space] - apply bp_le - have hh : dim (Story T s)≤ (3*d+2*K)*N+2*K^2 := by - unfold Story dim; rw [finrank_prod, finrank_prod (M:=Signal p N (front s))] - change dim (Daypair p T)+(dim (Signal p N (front s))+dim (EffSeq s)) ≤ _ - rw [Nat.add_mul,add_assoc] - exact add_le_add h2 (add_le_add h3 h4) - exact_mod_cast hh - -theorem plan_inc_eff (s t : Plan p n) (h : s ≤ t) (i : Bool) : - effective s i≤effective t i := by - intro x hx - obtain ⟨h1,h2⟩ := effective_mem.mp hx - have he z : sPin s z i ≤ sPin t z i := Submodule.map_mono (h z) - exact effective_mem.mpr ⟨h1,fun z => box_le (he _) (he _) (h2 _)⟩ - -/-- Old contractions on admissible tables evaluate correctly when -the enlarged leaf has pinned the entire front. -/ -theorem front_table (x y : UnitType p n N) - {a b : Pin p n N} (s : Plan p n) - (hf : front s≤a.sp) - {M : Cross p n} (hx : a.agree x) (hB : tableFlag b a (reciprocal p M) y) - (i j : Bool) (w : Profile p n) (h : w∈effective s i) : - contract p (actual p x y) i j w=contract p M i j w := by - have hz (z) (u : Dir p n) (hu : u∈a.sp z) : - channelOut p M j z *ᵥ u=channelOut p (actual p x y) j z *ᵥ u := by - refine channel_same j z u (fun v => ?_) - have h1 : IH p n j *ᵥ v∈tabSpace b.sp (flipZ p z) := - channel_le_table b.sp _ _ ⟨_,rfl⟩ - have h2 : u∈a.sp (flipZ p (flipZ p z)) := by rwa [flipZ_flip] - have he := hB (flipZ p z) _ h1 _ h2 - have hg := flag_actual (a:=b) y x hx (flipZ p z) _ h1 _ h2 - rw [← reciprocal_actual x y] at hg - simp only [reciprocal,flipZ_flip,evmat_transpose] at he hg - exact he.trans hg.symm - have he z : (sPin s z i).map (IP p n i).mulVecLin ≤ a.sp z := by - apply le_trans _ (hf z) - cases i; exact le_sup_right; exact le_sup_left - change ∑ e, _=_ - refine Finset.sum_congr rfl fun e _ => ?_ - refine (box_eval_iff (a.sp (e,true)) (a.sp (e,false)) _ _).mp ?_ _ - (box_le (he _) (he _) (lift_mem_box _ _ ((effective_mem.mp h).2 e))) - intro x hx y hy - rw [ev_duom,ev_duom,hz _ _ hx,hz _ _ hy] - -set_option maxHeartbeats 900000 in -theorem weave (P : UnitType p n N→Prop) - {w μ : Wgt (UnitType p n N)} - (m : BMark p n N) (T : Cov p N) - (hw : ∀ x,0≤w x) {D ζ u : ℝ} (hz : 0 < ζ) (hz' : ζ<1) {K K' d : ℕ} - (hn : 0 inTiles F x ∧ P x ∧ ¬inTiles V x) ≤ - allMass w F*(bp (-(N:ℝ))+bp (-ζ*N)) := by - classical - refine improve F w hw P - (fun i S => (∀ x∈ S,P x) ∧ ∃ b : Pin p n N,Ripe p w μ S b (D+u+K'+1) ζ (3*K+K') ∧ - specialLeaf T m (g i) S b) - hT (fun i hi => ?_) - let A := CTile p n N - let S := i.filter P - let Q := specialLeaf T m (g i) - have hs (x : UnitType p n N) : x∈S↔ x∈i∧ P x := Finset.mem_filter - have hq := h i hi - let w' := partW w i - have hw' : IsLaw w' := on_law hw hq.pos - have hg : ∀ x∈ S,(g i).agree x∧ covered p T (delta m x)∧∀ j,m x j∈effective (g i).sp j := - fun x h => ⟨hq.fixpin _ ((hs ..).mp h).1,hg i hi x ((hs ..).mp h).1 ((hs ..).mp h).2⟩ - obtain ⟨V,hV,hX,hZ⟩ := reparts w' μ hw' S D ζ u hn hz hz' hμ hq.density - (story T (g i).sp m) (3*K) K' Q - (storyOk T m (g i) S K hq.bound hg) hk - refine ⟨V,hV,fun x hx => ?_,?_⟩ - · obtain ⟨hS,b,hB,hL⟩ := hX x hx - have hx' : x⊆i := hS.trans (Finset.filter_subset ..) - obtain ⟨he,hLaw⟩ := issued_law w hw hq.pos hx' hB.pos - refine ⟨hx', (fun z hz => ((hs ..).mp (hS hz)).2),b,⟨he,hB.fixpin,hB.bound,?_,?_⟩,hL⟩ - · rw [hLaw]; exact hB.clear - rw [hLaw]; exact hB.density - simp_rw [hs,and_assoc] at hZ - refine hZ.trans (add_le_add_left ?_ _) - refine (mul_le_mul_of_nonneg_right (story_size T _ K d hq.bound hd) (bp_pos _).le).trans ?_ - rw [←bp_add]; apply bp_le - linarith only [hu] - -theorem phase_fixed (m : BMark p n N) (T : Cov p N) - (A A' B B' : Pin p n N) {S R : CTile p n N} - {x x' y y' : UnitType p n N} - (h : specialLeaf T m A S A') (hg : specialLeaf T m B R B') - (hx : x∈S) (hx' : x'∈S) (hy : y∈R) (hy' : y'∈R) - (hC : covered p T (delta m x)) (hC' : covered p T (delta m y)) : - quench p (delta m) (x,y)=quench p (delta m) (x',y') := by - obtain ⟨_,h1,h2⟩ := h.2.2 x hx x' hx' - obtain ⟨_,h3,h4⟩ := hg.2.2 y hy y' hy' - unfold quench; dsimp only - rw [← h1, ← h3] - exact Prod.ext - (funext fun i => LinearMap.congr_fun (h4 i) (⟨_,hC⟩ : coverX p T)) - (funext fun i => LinearMap.congr_fun (h2 i) (⟨_,hC'⟩ : coverX p T)) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PartitionSelection +import OAI.Combinatorics.HadwigerCounterexample.FourPhaseBits + +namespace OAI + +/-! # Refined Pin Images -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Function Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} + +def front (s : Plan p n) : Plan p n := prSmall s + +theorem front_rank (s : Plan p n) : planRank (front s) ≤2*planRank s := by + classical + unfold planRank + rw [Finset.mul_sum] + refine Finset.sum_le_sum fun i _ => ?_ + have hh (j) : + dim ((sPin s i j).map (IP p n j).mulVecLin)≤dim (s i) := + (Submodule.finrank_map_le ..).trans (sPin_dim ..) + exact ((Submodule.finrank_add_le_finrank_add_finrank ..).trans (add_le_add (hh _) (hh _))).trans_eq + (two_mul _).symm + +theorem combined_rank (s t : Plan p n) : planRank (s⊔t)≤planRank s+planRank t := by + unfold planRank; rw [←Finset.sum_add_distrib] + exact Finset.sum_le_sum fun i _ => finrank_add_le_finrank_add_finrank .. + +abbrev Signal (p : Shape) (N : ℕ) {n} (s : Plan p n) := DTuple (p:=p) (fun z => dim (s z)) N + +def readPin (x : UnitType p n N) (a : Plan p n) : Signal p N a := + fun z => images x z * pack (a z) + +abbrev EffSeq {p : Shape} {n} (s : Plan p n) := ∀ i : Bool,effective s i + +def entrySeq {p : Shape} {n} (s : Plan p n) (m : Bool → Profile p n) : EffSeq s := + open scoped Classical in + fun i => if h : m i ∈ effective s i then ⟨_,h⟩ else 0 + +abbrev Story {p : Shape} {n N} (T : Cov p N) (s : Plan p n) := + Daypair p T × Signal p N (front s) × EffSeq s + +instance fintypeStory {s : Plan p n} {T : Cov p N} : Fintype (Story T s) := by + classical + let A := (coverX p T) + letI : Finite (Module.Dual F A) := Finite.of_injective _ DFunLike.coe_injective + letI : Fintype (Module.Dual F A) := Fintype.ofFinite _ + letI : Fintype (Daypair p T) := inferInstanceAs (Fintype (Daypair p T)) + letI : ∀ i,Fintype (effective s i) := fun i => Fintype.ofFinite _ + letI : Fintype (EffSeq s) := inferInstanceAs (Fintype (EffSeq s)) + letI : Fintype (Signal p N (front s)) := inferInstanceAs (Fintype (Signal p N (front s))) + exact inferInstanceAs (Fintype (Story T s)) + +def story (T : Cov p N) (s : Plan p n) (m : BMark p n N) (x : UnitType p n N) : Story T s := + (daypair p T (delta m) (fun _ => 1) x,readPin x (front s),entrySeq s (m x)) + +def specialLeaf (T : Cov p N) (m : BMark p n N) (a : Pin p n N) + (G : CTile p n N) (b : Pin p n N) := + a.sp ≤ b.sp ∧ front a.sp ≤ b.sp ∧ + ∀ x∈G,∀ y∈G, m x=m y ∧ delta m x=delta m y ∧ + ∀ i,juris p T x (unary i) = juris p T y (unary i) + +private theorem storyOk (T : Cov p N) (m : BMark p n N) + (a : Pin p n N) (S : CTile p n N) (K : ℕ) (hk : planRank a.sp≤K) + (h : ∀ x∈S, a.agree x ∧ covered p T (delta m x) ∧ + ∀ i,m x i∈effective a.sp i) : + ∀ i : Story T a.sp,∃ b : Pin p n N, + (∀ x∈ S,story T a.sp m x=i → b.agree x) ∧ planRank b.sp ≤ 3*K ∧ + ∀ c (G : CTile p n N), G.Nonempty → + (∀ x∈G,x∈S ∧ story T a.sp m x=i) → b.sp ≤ c.sp → specialLeaf T m a G c := by + classical + intro i + let A := a.sp ⊔ front a.sp + have hK : planRank A≤3*K := by + apply (combined_rank ..).trans + have hh := front_rank a.sp + omega + have h1 : ∃ x : UnitType p n N, ∀ y∈ S,story T a.sp m y=i → (Pin.make A x).agree y := by + by_cases hg : ∃ x∈S,story T a.sp m x=i + · obtain ⟨x,hx,he⟩ := hg + refine ⟨x,fun y hy ht => ?_⟩ + let b := Pin.make (front a.sp) x + have hf : b.agree y := by + rw [Pin.agree_pack]; intro z + have hh : readPin y (front a.sp)=readPin x (front a.sp) := + congrArg (fun x : Story T a.sp => x.2.1) (ht.trans he.symm) + exact congr_fun hh z + exact (Pin.combine (b:=b) (h x hx).1 (show b.agree x from fun _ _ _ => rfl)).mpr + ⟨(h y hy).1,hf⟩ + exact ⟨0,fun x hx he => (hg ⟨x,hx,he⟩).elim⟩ + obtain ⟨x,hx⟩ := h1 + refine ⟨Pin.make A x,hx,hK,fun c G hm hC hA => ⟨le_trans le_sup_left hA, + le_trans le_sup_right hA, fun x hx y hy => ?_⟩⟩ + have he := (hC x hx).2.trans (hC y hy).2.symm + have hD := congrArg Prod.fst he + have hr z (hz : z∈G) : (story T a.sp m z).1.1.val=delta m z := by + unfold story daypair; change (cutDown p T (delta m) (fun _ => 1) z).val=_ + unfold cutDown; rw [dite_eq_left ⟨(by norm_num),(h z (hC z hz).1).2.1⟩] + have ht z (hz : z∈G) (i) : ((story T a.sp m z).2.2 i).val=m z i := by + unfold story entrySeq; dsimp only + rw [dite_eq_left ((h z (hC z hz).1).2.2 i)] + refine ⟨funext (fun i => ?_),?_,fun i => ?_⟩ + · rw [←ht x hx i,←ht y hy i,he] + · rw [←hr x hx, ←hr y hy,he] + exact congr_fun (congrArg Prod.snd hD) i + +theorem story_size (T : Cov p N) (s : Plan p n) (K d : ℕ) + (hK : planRank s≤K) (hd : cdim p T≤d) : + num (Story T s) ≤ bp ((3*d+2*K : ℝ)*N + 2*K^2) := by + classical + have h1 : dim (coverX p T)≤ N*d := (cover_dim p T).trans (Nat.mul_le_mul_left N hd) + have h2 : dim (Daypair p T) ≤ 3*d*N := by + unfold dim Daypair + rw [finrank_prod,finrank_pi_fintype, Fintype.sum_bool,Subspace.dual_finrank_eq] + change dim _+(dim _+dim _) ≤ _ + nlinarith + have h3 : dim (Signal p N (front s)) ≤ (2*K)*N := tuple_dim.trans_le (by + rw [mul_comm]; apply Nat.mul_le_mul_right + exact (front_rank s).trans (Nat.mul_le_mul_left _ hK)) + have h4 : dim (EffSeq s)≤ 2*K^2 := by + unfold EffSeq dim + rw [finrank_pi_fintype,Fintype.sum_bool,two_mul] + have hh i : dim (effective s i) ≤ K^2 := (effective_dim ..).trans (by gcongr) + exact add_le_add (hh _) (hh _) + unfold num + rw [card_space] + apply bp_le + have hh : dim (Story T s)≤ (3*d+2*K)*N+2*K^2 := by + unfold Story dim; rw [finrank_prod, finrank_prod (M:=Signal p N (front s))] + change dim (Daypair p T)+(dim (Signal p N (front s))+dim (EffSeq s)) ≤ _ + rw [Nat.add_mul,add_assoc] + exact add_le_add h2 (add_le_add h3 h4) + exact_mod_cast hh + +theorem plan_inc_eff (s t : Plan p n) (h : s ≤ t) (i : Bool) : + effective s i≤effective t i := by + intro x hx + obtain ⟨h1,h2⟩ := effective_mem.mp hx + have he z : sPin s z i ≤ sPin t z i := Submodule.map_mono (h z) + exact effective_mem.mpr ⟨h1,fun z => box_le (he _) (he _) (h2 _)⟩ + +/-- Old contractions on admissible tables evaluate correctly when +the enlarged leaf has pinned the entire front. -/ +theorem front_table (x y : UnitType p n N) + {a b : Pin p n N} (s : Plan p n) + (hf : front s≤a.sp) + {M : Cross p n} (hx : a.agree x) (hB : tableFlag b a (reciprocal p M) y) + (i j : Bool) (w : Profile p n) (h : w∈effective s i) : + contract p (actual p x y) i j w=contract p M i j w := by + have hz (z) (u : Dir p n) (hu : u∈a.sp z) : + channelOut p M j z *ᵥ u=channelOut p (actual p x y) j z *ᵥ u := by + refine channel_same j z u (fun v => ?_) + have h1 : IH p n j *ᵥ v∈tabSpace b.sp (flipZ p z) := + channel_le_table b.sp _ _ ⟨_,rfl⟩ + have h2 : u∈a.sp (flipZ p (flipZ p z)) := by rwa [flipZ_flip] + have he := hB (flipZ p z) _ h1 _ h2 + have hg := flag_actual (a:=b) y x hx (flipZ p z) _ h1 _ h2 + rw [← reciprocal_actual x y] at hg + simp only [reciprocal,flipZ_flip,evmat_transpose] at he hg + exact he.trans hg.symm + have he z : (sPin s z i).map (IP p n i).mulVecLin ≤ a.sp z := by + apply le_trans _ (hf z) + cases i; exact le_sup_right; exact le_sup_left + change ∑ e, _=_ + refine Finset.sum_congr rfl fun e _ => ?_ + refine (box_eval_iff (a.sp (e,true)) (a.sp (e,false)) _ _).mp ?_ _ + (box_le (he _) (he _) (lift_mem_box _ _ ((effective_mem.mp h).2 e))) + intro x hx y hy + rw [ev_duom,ev_duom,hz _ _ hx,hz _ _ hy] + +set_option maxHeartbeats 900000 in +theorem weave (P : UnitType p n N→Prop) + {w μ : Wgt (UnitType p n N)} + (m : BMark p n N) (T : Cov p N) + (hw : ∀ x,0≤w x) {D ζ u : ℝ} (hz : 0 < ζ) (hz' : ζ<1) {K K' d : ℕ} + (hn : 0 inTiles F x ∧ P x ∧ ¬inTiles V x) ≤ + allMass w F*(bp (-(N:ℝ))+bp (-ζ*N)) := by + classical + refine improve F w hw P + (fun i S => (∀ x∈ S,P x) ∧ ∃ b : Pin p n N,Ripe p w μ S b (D+u+K'+1) ζ (3*K+K') ∧ + specialLeaf T m (g i) S b) + hT (fun i hi => ?_) + let A := CTile p n N + let S := i.filter P + let Q := specialLeaf T m (g i) + have hs (x : UnitType p n N) : x∈S↔ x∈i∧ P x := Finset.mem_filter + have hq := h i hi + let w' := partW w i + have hw' : IsLaw w' := on_law hw hq.pos + have hg : ∀ x∈ S,(g i).agree x∧ covered p T (delta m x)∧∀ j,m x j∈effective (g i).sp j := + fun x h => ⟨hq.fixpin _ ((hs ..).mp h).1,hg i hi x ((hs ..).mp h).1 ((hs ..).mp h).2⟩ + obtain ⟨V,hV,hX,hZ⟩ := reparts w' μ hw' S D ζ u hn hz hz' hμ hq.density + (story T (g i).sp m) (3*K) K' Q + (storyOk T m (g i) S K hq.bound hg) hk + refine ⟨V,hV,fun x hx => ?_,?_⟩ + · obtain ⟨hS,b,hB,hL⟩ := hX x hx + have hx' : x⊆i := hS.trans (Finset.filter_subset ..) + obtain ⟨he,hLaw⟩ := issued_law w hw hq.pos hx' hB.pos + refine ⟨hx', (fun z hz => ((hs ..).mp (hS hz)).2),b,⟨he,hB.fixpin,hB.bound,?_,?_⟩,hL⟩ + · rw [hLaw]; exact hB.clear + rw [hLaw]; exact hB.density + simp_rw [hs,and_assoc] at hZ + refine hZ.trans (add_le_add_left ?_ _) + refine (mul_le_mul_of_nonneg_right (story_size T _ K d hq.bound hd) (bp_pos _).le).trans ?_ + rw [←bp_add]; apply bp_le + linarith only [hu] + +theorem phase_fixed (m : BMark p n N) (T : Cov p N) + (A A' B B' : Pin p n N) {S R : CTile p n N} + {x x' y y' : UnitType p n N} + (h : specialLeaf T m A S A') (hg : specialLeaf T m B R B') + (hx : x∈S) (hx' : x'∈S) (hy : y∈R) (hy' : y'∈R) + (hC : covered p T (delta m x)) (hC' : covered p T (delta m y)) : + quench p (delta m) (x,y)=quench p (delta m) (x',y') := by + obtain ⟨_,h1,h2⟩ := h.2.2 x hx x' hx' + obtain ⟨_,h3,h4⟩ := hg.2.2 y hy y' hy' + unfold quench; dsimp only + rw [← h1, ← h3] + exact Prod.ext + (funext fun i => LinearMap.congr_fun (h4 i) (⟨_,hC⟩ : coverX p T)) + (funext fun i => LinearMap.congr_fun (h2 i) (⟨_,hC'⟩ : coverX p T)) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RefinementEnergy.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RefinementEnergy.lean index 25645c02b8917ae20cf50eb1e03703fcc88d13b9..49bada4fa93262da93c5eaa12cd6da4f75c67677 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RefinementEnergy.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RefinementEnergy.lean @@ -1,105 +1,105 @@ -import OAI.Combinatorics.HadwigerCounterexample.InformationSmallSetBounds - -namespace OAI - -/-! # Refinement Energy -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Filter Real -open scoped BigOperators -variable {A B C D : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype D] - -theorem var_nonneg (p q : Wgt A) : 0≤ varOne p q := Finset.sum_nonneg fun _ _ => abs_nonneg _ -theorem var_tri (p q r : Wgt A) : - varOne p q≤varOne p r+varOne r q := by - unfold varOne; rw [← Finset.sum_add_distrib]; exact sum_le_sum fun i _ => abs_sub_le _ _ _ - -theorem var_pr (p q : Wgt A) (P : A→Prop) : - pr p P-pr q P ≤ varOne p q := by - unfold pr avg varOne - rw [← Finset.sum_sub_distrib] - refine sum_le_sum fun i _ => ?_ - by_cases h : P i - · simp only [ind_one h,mul_one]; exact le_abs_self _ - simp only [ind_zero h,mul_zero,sub_zero]; exact abs_nonneg _ - -theorem var_event (p q : Wgt A) (h : tot p=tot q) : - let P := fun i => q i

varOne (p i) (q i)) := by - unfold varOne mixW - rw [avg_sum] - simp_rw [←avg_sub]; exact sum_le_sum fun i _ => abs_avg_le hμ - -omit [Fintype D] in -theorem bucket_m (μ : Wgt A) (p : A → Wgt B) (f : B→C) (g : C→D) : - mapW (bucket unif (g∘f) (mixW μ p)) f = - mixW μ (fun x => bucket (mapW unif f) g (mapW (p x) f)) := by - rw [bucket_mix,map_mix] - simp only [bucket_nested] - -variable {μ : Wgt A} {p : A→Wgt B} - -theorem tariffs_monotone {r s : ℕ} {a b V : ℝ} (h : tariffs μ p r a V) - (hrs : s≤r) (hb : a ≤ b) : tariffs μ p s b V := - fun C _ hC f hf => h C (hC.trans hrs) f (fun _ hi => hb.trans (hf _ hi)) - -theorem budget_nonneg [Nonempty B] (h : Ultra μ p) (f : B→ C) : - 0≤budget μ p f := by - have h0 {p : Wgt B} : lsupp p unif := fun i _ => by rw [unif_apply]; positivity - have hv : IsLaw (mapW unif f) := mapW_law unif_law f - exact avg_nonneg h.law.nz (fun i => tension_nonneg (mapW_law (h.labs i) f) hv - (lsupp.map h0 unif_law.nz f)) - -set_option maxHeartbeats 800000 in -theorem budget_progress [Nonempty B] (h : Ultra μ p) (w : Wgt B) - (hw : catalog μ p w) (f : B→C) (g : C→D) : - varOne (mapW w f) (mapW (bucket unif (g∘f) w) f) ^ 2 ≤ - (budget μ p f-budget μ p (g∘f))*4 := by - classical - let q := mapW unif f - let Q (i : A) := mapW (p i) f - let R (i : A) := bucket q g (Q i) - have hu : IsLaw q := mapW_law unif_law f - have hQ (i) : IsLaw (Q i) := mapW_law (h.labs i) f - have he (i) : lsupp (Q i) q := lsupp.map - (p:=p i) (q:=unif) (fun i _ => by rw [unif_apply]; positivity) unif_law.nz f - have hp (i : A) : - varOne (Q i) (R i) ^ 2 ≤ tension (Q i) (R i) *4 := - var_tension _ _ (hQ i) (bucket_law (hQ i) g hu.nz (he i)) - (lsupp_bucket g (hQ i).nz hu.nz (he i)) - have hn : - budget μ p f=avg μ (fun i => tension (Q i) (R i))+budget μ p (g∘f) := by - unfold budget - have hi := fun i : A => tension_stage (Q i) q (hQ i).nz hu.nz (he i) g - unfold Q q at hi - simp_rw [map_nested] at hi - rw [← avg_add]; exact avg_congr fun i _ => hi i - let Z (i : A) := varOne (Q i) (R i) - have hs : avg μ Z ^ 2 ≤ avg μ (fun i => Z i ^ 2) := by - have hh := avg_CS h.law.nz Z (fun _ => 1) - simp only [mul_one,one_pow,h.law.avg_const] at hh; exact hh - obtain ⟨s,hs',ht,rfl⟩ := hw - rw [bucket_m,map_mix] - have h' := (var_mix Q R hs').trans (avg_mono_left (fun i => var_nonneg ..) ht) - refine (pow_le_pow_left₀ (var_nonneg ..) h' 2).trans (hs.trans ?_) - have hz := avg_mono h.law.nz hp; rw [avg_mul] at hz - rw [hn]; exact hz.trans_eq (by ring) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.InformationSmallSetBounds + +namespace OAI + +/-! # Refinement Energy -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Filter Real +open scoped BigOperators +variable {A B C D : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype D] + +theorem var_nonneg (p q : Wgt A) : 0≤ varOne p q := Finset.sum_nonneg fun _ _ => abs_nonneg _ +theorem var_tri (p q r : Wgt A) : + varOne p q≤varOne p r+varOne r q := by + unfold varOne; rw [← Finset.sum_add_distrib]; exact sum_le_sum fun i _ => abs_sub_le _ _ _ + +theorem var_pr (p q : Wgt A) (P : A→Prop) : + pr p P-pr q P ≤ varOne p q := by + unfold pr avg varOne + rw [← Finset.sum_sub_distrib] + refine sum_le_sum fun i _ => ?_ + by_cases h : P i + · simp only [ind_one h,mul_one]; exact le_abs_self _ + simp only [ind_zero h,mul_zero,sub_zero]; exact abs_nonneg _ + +theorem var_event (p q : Wgt A) (h : tot p=tot q) : + let P := fun i => q i

varOne (p i) (q i)) := by + unfold varOne mixW + rw [avg_sum] + simp_rw [←avg_sub]; exact sum_le_sum fun i _ => abs_avg_le hμ + +omit [Fintype D] in +theorem bucket_m (μ : Wgt A) (p : A → Wgt B) (f : B→C) (g : C→D) : + mapW (bucket unif (g∘f) (mixW μ p)) f = + mixW μ (fun x => bucket (mapW unif f) g (mapW (p x) f)) := by + rw [bucket_mix,map_mix] + simp only [bucket_nested] + +variable {μ : Wgt A} {p : A→Wgt B} + +theorem tariffs_monotone {r s : ℕ} {a b V : ℝ} (h : tariffs μ p r a V) + (hrs : s≤r) (hb : a ≤ b) : tariffs μ p s b V := + fun C _ hC f hf => h C (hC.trans hrs) f (fun _ hi => hb.trans (hf _ hi)) + +theorem budget_nonneg [Nonempty B] (h : Ultra μ p) (f : B→ C) : + 0≤budget μ p f := by + have h0 {p : Wgt B} : lsupp p unif := fun i _ => by rw [unif_apply]; positivity + have hv : IsLaw (mapW unif f) := mapW_law unif_law f + exact avg_nonneg h.law.nz (fun i => tension_nonneg (mapW_law (h.labs i) f) hv + (lsupp.map h0 unif_law.nz f)) + +set_option maxHeartbeats 800000 in +theorem budget_progress [Nonempty B] (h : Ultra μ p) (w : Wgt B) + (hw : catalog μ p w) (f : B→C) (g : C→D) : + varOne (mapW w f) (mapW (bucket unif (g∘f) w) f) ^ 2 ≤ + (budget μ p f-budget μ p (g∘f))*4 := by + classical + let q := mapW unif f + let Q (i : A) := mapW (p i) f + let R (i : A) := bucket q g (Q i) + have hu : IsLaw q := mapW_law unif_law f + have hQ (i) : IsLaw (Q i) := mapW_law (h.labs i) f + have he (i) : lsupp (Q i) q := lsupp.map + (p:=p i) (q:=unif) (fun i _ => by rw [unif_apply]; positivity) unif_law.nz f + have hp (i : A) : + varOne (Q i) (R i) ^ 2 ≤ tension (Q i) (R i) *4 := + var_tension _ _ (hQ i) (bucket_law (hQ i) g hu.nz (he i)) + (lsupp_bucket g (hQ i).nz hu.nz (he i)) + have hn : + budget μ p f=avg μ (fun i => tension (Q i) (R i))+budget μ p (g∘f) := by + unfold budget + have hi := fun i : A => tension_stage (Q i) q (hQ i).nz hu.nz (he i) g + unfold Q q at hi + simp_rw [map_nested] at hi + rw [← avg_add]; exact avg_congr fun i _ => hi i + let Z (i : A) := varOne (Q i) (R i) + have hs : avg μ Z ^ 2 ≤ avg μ (fun i => Z i ^ 2) := by + have hh := avg_CS h.law.nz Z (fun _ => 1) + simp only [mul_one,one_pow,h.law.avg_const] at hh; exact hh + obtain ⟨s,hs',ht,rfl⟩ := hw + rw [bucket_m,map_mix] + have h' := (var_mix Q R hs').trans (avg_mono_left (fun i => var_nonneg ..) ht) + refine (pow_le_pow_left₀ (var_nonneg ..) h' 2).trans (hs.trans ?_) + have hz := avg_mono h.law.nz hp; rw [avg_mul] at hz + rw [hn]; exact hz.trans_eq (by ring) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ReindexedFourierSupport.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ReindexedFourierSupport.lean index 2db0ef9d3961f2e37b12e593601ef8b3ede8cf8c..1dac1a887e92c271d5ee9e2abefb3097716e877b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ReindexedFourierSupport.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ReindexedFourierSupport.lean @@ -1,73 +1,73 @@ -import OAI.Combinatorics.HadwigerCounterexample.TesterFourierSupport - -namespace OAI - -/-! # Reindexed Fourier Support -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module LinearMap Submodule Function -open scoped BigOperators -variable {p : Shape} {n : ℕ} {I : Type} [Fintype I] - -namespace Move -variable (c : Flit n) {j k : Vec (Fin n)} -def jumpV : Vec (Fin n) ≃ Vec (Fin n) where - toFun := c.L.mulVec - invFun := c.R.mulVec - left_inv x := by change c.R*ᵥ(c.L *ᵥ x) = x; rw [mulVec_mulVec,c.RL,Matrix.one_mulVec] - right_inv x := by change c.L*ᵥ(c.R *ᵥ x) = x; rw [mulVec_mulVec,c.LR,Matrix.one_mulVec] -def zreroute (p : Shape) (c : Flit n) (f : Wgt (Knobs p.g n)) := - fun y => f ((vault p c).symm y) - -theorem zhat_jump (p : Shape) (c : Flit n) (f : Wgt (Knobs p.g n)) (y : Knobs p.g n) - (x : Vec (Fin n)) : - zhat p (zreroute p c f) y (c.dual.jumpV x)=zhat p f y x := by - classical - unfold zhat - rw [← avg_bij c.jumpV] - have he (z : Vec (Fin n)) : unif (c.jumpV z)=unif z := rfl - have hh (z) : - vectorPhase (c.dual.jumpV x) (c.jumpV z)= vectorPhase x z := by - unfold vectorPhase - change wsign (dotProduct (c.Rᵀ *ᵥ x) (c.L *ᵥ z))=_ - rw [dotProduct_comm, dotProduct_transpose_mulVec,mulVec_mulVec,c.RL, Matrix.one_mulVec] - have ht (z) : - zreroute p c f (update y Block.Z (c.jumpV z))=f (update y Block.Z z) := by - unfold zreroute vault; simp only [doZ,Equiv.coe_fn_symm_mk,update_self] - change f (update (update y Block.Z _) _ (c.jumpV.symm (c.jumpV z)))=_ - rw [Equiv.symm_apply_apply]; simp - simp_rw [he,hh,ht] - -theorem jump_in (c : Flit n) (S : Space (Vec (Fin n))) {z} (h : z ∈ S) : - c.dual.jumpV z∈c.plume S := by - rw [←colSp_pack S] at h - obtain ⟨u,h⟩ := h - refine ⟨u,?_⟩ - change (c.Rᵀ*pack S)*ᵥu=c.dual.jumpV z - rw [← mulVec_mulVec,show pack S *ᵥ u=z from h] - rfl -end Move - -namespace Template -variable (v : Solo p) - -def rotor (v : Solo p) (c : Flit n) (m : Mixer p n) (x : Profile p n) := - Move.zreroute p c (v.shanty m x) -theorem rotor_budget (v : Solo p) (c : Flit n) (m : Mixer p n) (x : Profile p n) - (K s : ℕ) (hg : Odd p.g) (hm : unaryGood m K s) (hK : totalRank x≤K) (hx : 0 - mul_eq_zero_of_left (shanty_outer v m x u hg i (fun he => h (Move.jump_in c _ he))) _⟩ -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.TesterFourierSupport + +namespace OAI + +/-! # Reindexed Fourier Support -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module LinearMap Submodule Function +open scoped BigOperators +variable {p : Shape} {n : ℕ} {I : Type} [Fintype I] + +namespace Move +variable (c : Flit n) {j k : Vec (Fin n)} +def jumpV : Vec (Fin n) ≃ Vec (Fin n) where + toFun := c.L.mulVec + invFun := c.R.mulVec + left_inv x := by change c.R*ᵥ(c.L *ᵥ x) = x; rw [mulVec_mulVec,c.RL,Matrix.one_mulVec] + right_inv x := by change c.L*ᵥ(c.R *ᵥ x) = x; rw [mulVec_mulVec,c.LR,Matrix.one_mulVec] +def zreroute (p : Shape) (c : Flit n) (f : Wgt (Knobs p.g n)) := + fun y => f ((vault p c).symm y) + +theorem zhat_jump (p : Shape) (c : Flit n) (f : Wgt (Knobs p.g n)) (y : Knobs p.g n) + (x : Vec (Fin n)) : + zhat p (zreroute p c f) y (c.dual.jumpV x)=zhat p f y x := by + classical + unfold zhat + rw [← avg_bij c.jumpV] + have he (z : Vec (Fin n)) : unif (c.jumpV z)=unif z := rfl + have hh (z) : + vectorPhase (c.dual.jumpV x) (c.jumpV z)= vectorPhase x z := by + unfold vectorPhase + change wsign (dotProduct (c.Rᵀ *ᵥ x) (c.L *ᵥ z))=_ + rw [dotProduct_comm, dotProduct_transpose_mulVec,mulVec_mulVec,c.RL, Matrix.one_mulVec] + have ht (z) : + zreroute p c f (update y Block.Z (c.jumpV z))=f (update y Block.Z z) := by + unfold zreroute vault; simp only [doZ,Equiv.coe_fn_symm_mk,update_self] + change f (update (update y Block.Z _) _ (c.jumpV.symm (c.jumpV z)))=_ + rw [Equiv.symm_apply_apply]; simp + simp_rw [he,hh,ht] + +theorem jump_in (c : Flit n) (S : Space (Vec (Fin n))) {z} (h : z ∈ S) : + c.dual.jumpV z∈c.plume S := by + rw [←colSp_pack S] at h + obtain ⟨u,h⟩ := h + refine ⟨u,?_⟩ + change (c.Rᵀ*pack S)*ᵥu=c.dual.jumpV z + rw [← mulVec_mulVec,show pack S *ᵥ u=z from h] + rfl +end Move + +namespace Template +variable (v : Solo p) + +def rotor (v : Solo p) (c : Flit n) (m : Mixer p n) (x : Profile p n) := + Move.zreroute p c (v.shanty m x) +theorem rotor_budget (v : Solo p) (c : Flit n) (m : Mixer p n) (x : Profile p n) + (K s : ℕ) (hg : Odd p.g) (hm : unaryGood m K s) (hK : totalRank x≤K) (hx : 0 + mul_eq_zero_of_left (shanty_outer v m x u hg i (fun he => h (Move.jump_in c _ he))) _⟩ +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RelationMismatchBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RelationMismatchBounds.lean index c774095785c5d8606e0af599d100629f7e8d72e4..76b4db305f3087dbc340e82b2dbbc5faaecb2a52 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RelationMismatchBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RelationMismatchBounds.lean @@ -1,129 +1,129 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteDualSystems - -namespace OAI - -/-! # Relation Mismatch Bounds -/ - -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} - {β η δ:ℝ} - -def seeking (p : Shape) (A : Stalls p) := - ∀ i, (A i).card+902 < Fintype.card (Label p.b) -theorem any_label (A : Finset (Label p.b)) (h : A.cardhh _) - rw [card_univ] at hf; exact h.not_ge hf - -theorem generic_apt (p:Shape) (hg:3≤p.g) (x:Appearance p) (hx:x.f=Flavor.full) : - x.apt := by obtain ⟨s,h1,h2,h3⟩:=generic_summary p hg x.l x.q 0; exact ⟨s,hx ▸ h1,h2⟩ - -set_option maxHeartbeats 900000 in -theorem plenitude (h:origami p r u δ) (hs:reports p r u s β δ) (ht:reports p r u t β δ) - (hg:3 ≤ p.g) (A B:Stalls p) (hk:seeking p A) (hl:seeking p B) - (hβ:0<β) (hz:0<η) (hη : playbook p K*η<1/2*β^2) - (hd:∀ i,d i≤K^2) (he:∀ i,e i≤K^2): - Guild.rich (stellar u s t η A B) := by - classical - intro i S hu y - have hh a (b:Finset (Label p.b)) (h : b.card+902hz (mem_union_left _ ht),fun ht=>hz (mem_union_right _ ht)⟩ - obtain ⟨v,h1,h2⟩:= hh true (A i.1) (hk _) - obtain ⟨w,h3,h4⟩:= hh false (B i.2) (hl _) - let x : Zodiac p:= ⟨⟨0,by omega⟩,y.1,fun i=>if i then v else w,fun _=>Flavor.full⟩ - have hh : x.common:= fun i=> generic_apt p hg _ rfl - obtain ⟨W,hA,hB,hC⟩:= sturdy_contact u s t h hs ht hβ x hh (fun _=>rfl) i y.2.1 y.2.2 hz - ((mul_le_mul_of_nonneg_right (booklet_cap p K _ _ (hd _) (he _)) hz.le).trans_lt hη) - refine ⟨(x,W),⟨⟨h1,h3,hA⟩,fun i=>?_⟩,?_⟩ - · cases i; exact h4; exact h2 - exact Prod.ext rfl (Prod.ext hB hC) - -structure RhymeSet (d : ℕ) where - bit : F - coal : Cell d - headBit : F - gamma : F - -def RhymeSet.read {k : ℕ} (s:RhymeSet k) (q:F) (x: Whole k) := - s.bit*x.2+ dotProduct s.coal x.1.2+ (s.bit+s.headBit)*x.1.1+s.gamma*q - -def RhymeSet.soot {k : ℕ} (s:RhymeSet k) {p:Shape} (x:Appearance p) (y:Magazine p k) := - s.read x.q y.2 - -def leftChime (q:DualCoefficients d e) (i:Grid) : RhymeSet (d i.1) := - ⟨q.left i.2,q.north i,q.hed i,0⟩ -def rightChime (q:DualCoefficients d e) (i:Grid) : RhymeSet (e i.2) := - ⟨q.right i.1,q.south i,q.hed i,q.gam i⟩ -set_option maxHeartbeats 900000 in -theorem dual_eq (q:DualCoefficients d e) (V : StatusSp d e) (hq:q.law V) - (i:Grid) (x:Suite d e i) (hx:x∈V i) : - (leftChime q i).read x.1 x.2.1=(rightChime q i).read x.1 x.2.2 := by - classical - specialize hq i x hx - rcases x with ⟨a,⟨⟨b,u⟩,s⟩,⟨c,v⟩,t⟩ - let f:= q.hed i; let W:= dotProduct (q.north i) u - let Z:= dotProduct (q.south i) v - let g:=q.left i.2; let h:=q.right i.1; let G:=q.gam i*a - change G+f*(b+c)+(W+Z)=g*(b+s)+h*(c+t) at hq - change g*s+W+(g+f)*b+0*_ = h*t+Z+(h+f)*c+G - apply sub_eq_zero.mp - rw [ZModModule.sub_eq_add] - calc _ - _=(G+f*(b+c)+(W+Z))+(g*(b+s)+h*(c+t)):=by ring - _=0:= by rw [hq,char_two] - -def charge (u:Terrain p r) (x: Zodiac p) (X:Gazette p r d) (Y:Gazette p r e) - (i:Grid) (a:RhymeSet (d i.1)) (b:RhymeSet (e i.2)) := - pr (circlet u X Y x i) (fun y=>a.soot (x.aspect true) y.1≠ b.soot (x.aspect false) y.2) - -def outstraps (a:Stalls p) (s:Straps (Label p.b)) (b:Bool):Stalls p:= - fun i=>a i∪s b - -set_option maxHeartbeats 900000 in -theorem charge_counter (h:origami p r u δ) (hs:reports p r u s β δ) (ht:reports p r u t β δ) - (A B:Stalls p) (S : Straps (Label p.b)) (q:DualCoefficients d e) - (he:q.law (chapter (stellar u s t η A B) S)) (hη:0≤η) - (x: Zodiac p) (i:Grid) (hx:x.common) (hk:x.s true∉outstraps A S true i.1) - (hl:x.s false∉outstraps B S false i.2) : - charge u x s t i (leftChime q i) (rightChime q i)≤ num (Touch p d e i)*η := by - classical - let W:=circlet u s t x i - obtain ⟨hm,hn⟩:=circlet_state u s t h hs ht x hx i - let P:=fun y : Touch p d e i=> (leftChime q i).soot (x.aspect true) y.1≠ - (rightChime q i).soot (x.aspect false) y.2 - have hh (y): W y*ind (P y)≤η := by - by_cases hp : P y - · rw [ind_one hp,mul_one] - by_contra! hy - let C:=stellar u s t η A B - let v : Scriptum p d e i := (x,y) - have heq : (x.aspect true).fitsink y.1∧ (x.aspect false).fitsink y.2 := not_not.mp - (fun h=> (hη.trans_lt hy).ne' (hn y h)) - have ht : (C i).zone S v := - ⟨⟨fun h=>hk (mem_union_left _ h),fun h=>hl (mem_union_left _ h),hx,heq.1,heq.2,hy.le⟩, - fun i=>by cases i; exact fun h=>hl (mem_union_right _ h); exact fun h=>hk (mem_union_right _ h)⟩ - exact hp (dual_eq q (chapter C S) he i ((C i).writes v) ((C i).band_write S ht)) - rw [ind_zero hp,mul_zero]; exact hη - change pr W P≤ _ - exact (Finset.sum_le_sum fun i _=> hh i).trans_eq (by simp [num]) - -end DualAnalysis -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteDualSystems + +namespace OAI + +/-! # Relation Mismatch Bounds -/ + +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} + {β η δ:ℝ} + +def seeking (p : Shape) (A : Stalls p) := + ∀ i, (A i).card+902 < Fintype.card (Label p.b) +theorem any_label (A : Finset (Label p.b)) (h : A.cardhh _) + rw [card_univ] at hf; exact h.not_ge hf + +theorem generic_apt (p:Shape) (hg:3≤p.g) (x:Appearance p) (hx:x.f=Flavor.full) : + x.apt := by obtain ⟨s,h1,h2,h3⟩:=generic_summary p hg x.l x.q 0; exact ⟨s,hx ▸ h1,h2⟩ + +set_option maxHeartbeats 900000 in +theorem plenitude (h:origami p r u δ) (hs:reports p r u s β δ) (ht:reports p r u t β δ) + (hg:3 ≤ p.g) (A B:Stalls p) (hk:seeking p A) (hl:seeking p B) + (hβ:0<β) (hz:0<η) (hη : playbook p K*η<1/2*β^2) + (hd:∀ i,d i≤K^2) (he:∀ i,e i≤K^2): + Guild.rich (stellar u s t η A B) := by + classical + intro i S hu y + have hh a (b:Finset (Label p.b)) (h : b.card+902hz (mem_union_left _ ht),fun ht=>hz (mem_union_right _ ht)⟩ + obtain ⟨v,h1,h2⟩:= hh true (A i.1) (hk _) + obtain ⟨w,h3,h4⟩:= hh false (B i.2) (hl _) + let x : Zodiac p:= ⟨⟨0,by omega⟩,y.1,fun i=>if i then v else w,fun _=>Flavor.full⟩ + have hh : x.common:= fun i=> generic_apt p hg _ rfl + obtain ⟨W,hA,hB,hC⟩:= sturdy_contact u s t h hs ht hβ x hh (fun _=>rfl) i y.2.1 y.2.2 hz + ((mul_le_mul_of_nonneg_right (booklet_cap p K _ _ (hd _) (he _)) hz.le).trans_lt hη) + refine ⟨(x,W),⟨⟨h1,h3,hA⟩,fun i=>?_⟩,?_⟩ + · cases i; exact h4; exact h2 + exact Prod.ext rfl (Prod.ext hB hC) + +structure RhymeSet (d : ℕ) where + bit : F + coal : Cell d + headBit : F + gamma : F + +def RhymeSet.read {k : ℕ} (s:RhymeSet k) (q:F) (x: Whole k) := + s.bit*x.2+ dotProduct s.coal x.1.2+ (s.bit+s.headBit)*x.1.1+s.gamma*q + +def RhymeSet.soot {k : ℕ} (s:RhymeSet k) {p:Shape} (x:Appearance p) (y:Magazine p k) := + s.read x.q y.2 + +def leftChime (q:DualCoefficients d e) (i:Grid) : RhymeSet (d i.1) := + ⟨q.left i.2,q.north i,q.hed i,0⟩ +def rightChime (q:DualCoefficients d e) (i:Grid) : RhymeSet (e i.2) := + ⟨q.right i.1,q.south i,q.hed i,q.gam i⟩ +set_option maxHeartbeats 900000 in +theorem dual_eq (q:DualCoefficients d e) (V : StatusSp d e) (hq:q.law V) + (i:Grid) (x:Suite d e i) (hx:x∈V i) : + (leftChime q i).read x.1 x.2.1=(rightChime q i).read x.1 x.2.2 := by + classical + specialize hq i x hx + rcases x with ⟨a,⟨⟨b,u⟩,s⟩,⟨c,v⟩,t⟩ + let f:= q.hed i; let W:= dotProduct (q.north i) u + let Z:= dotProduct (q.south i) v + let g:=q.left i.2; let h:=q.right i.1; let G:=q.gam i*a + change G+f*(b+c)+(W+Z)=g*(b+s)+h*(c+t) at hq + change g*s+W+(g+f)*b+0*_ = h*t+Z+(h+f)*c+G + apply sub_eq_zero.mp + rw [ZModModule.sub_eq_add] + calc _ + _=(G+f*(b+c)+(W+Z))+(g*(b+s)+h*(c+t)):=by ring + _=0:= by rw [hq,char_two] + +def charge (u:Terrain p r) (x: Zodiac p) (X:Gazette p r d) (Y:Gazette p r e) + (i:Grid) (a:RhymeSet (d i.1)) (b:RhymeSet (e i.2)) := + pr (circlet u X Y x i) (fun y=>a.soot (x.aspect true) y.1≠ b.soot (x.aspect false) y.2) + +def outstraps (a:Stalls p) (s:Straps (Label p.b)) (b:Bool):Stalls p:= + fun i=>a i∪s b + +set_option maxHeartbeats 900000 in +theorem charge_counter (h:origami p r u δ) (hs:reports p r u s β δ) (ht:reports p r u t β δ) + (A B:Stalls p) (S : Straps (Label p.b)) (q:DualCoefficients d e) + (he:q.law (chapter (stellar u s t η A B) S)) (hη:0≤η) + (x: Zodiac p) (i:Grid) (hx:x.common) (hk:x.s true∉outstraps A S true i.1) + (hl:x.s false∉outstraps B S false i.2) : + charge u x s t i (leftChime q i) (rightChime q i)≤ num (Touch p d e i)*η := by + classical + let W:=circlet u s t x i + obtain ⟨hm,hn⟩:=circlet_state u s t h hs ht x hx i + let P:=fun y : Touch p d e i=> (leftChime q i).soot (x.aspect true) y.1≠ + (rightChime q i).soot (x.aspect false) y.2 + have hh (y): W y*ind (P y)≤η := by + by_cases hp : P y + · rw [ind_one hp,mul_one] + by_contra! hy + let C:=stellar u s t η A B + let v : Scriptum p d e i := (x,y) + have heq : (x.aspect true).fitsink y.1∧ (x.aspect false).fitsink y.2 := not_not.mp + (fun h=> (hη.trans_lt hy).ne' (hn y h)) + have ht : (C i).zone S v := + ⟨⟨fun h=>hk (mem_union_left _ h),fun h=>hl (mem_union_left _ h),hx,heq.1,heq.2,hy.le⟩, + fun i=>by cases i; exact fun h=>hl (mem_union_right _ h); exact fun h=>hk (mem_union_right _ h)⟩ + exact hp (dual_eq q (chapter C S) he i ((C i).writes v) ((C i).band_write S ht)) + rw [ind_zero hp,mul_zero]; exact hη + change pr W P≤ _ + exact (Finset.sum_le_sum fun i _=> hh i).trans_eq (by simp [num]) + +end DualAnalysis +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RelativeEntropy.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RelativeEntropy.lean index 6088b5ec88a9be50ec8157e739e049f5cc210e25..22aa6fe1fb949739ea00e2185e46bcf56aa270cd 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RelativeEntropy.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RelativeEntropy.lean @@ -1,108 +1,108 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteEntropy -import OAI.Combinatorics.HadwigerCounterexample.WalshBounds - -namespace OAI - -/-! # Relative Entropy -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real -open scoped BigOperators -variable {A B C : Type} [Fintype A] [Fintype B] [Fintype C] - -def lsupp (p q : Wgt A) := ∀ x,p x ≠ 0 → q x≠0 - -def tension (p q : Wgt A) := avg p (fun x => log (p x)-log (q x)) -def varOne (p q : Wgt A) := ∑ x, |p x-q x| - -theorem tension_of_ratio {p q : Wgt A} (h : lsupp p q) : - tension p q=avg p (fun x => log (p x/q x)) := - avg_congr (fun i hi => (Real.log_div hi (h i hi)).symm) - -theorem tension_as_diff (p q : Wgt A) : - tension p q= negEnt p-avg p (fun x => log (q x)) := avg_sub p _ _ - -theorem tension_mix {μ : Wgt A} {f : A→Wgt B} (q : Wgt B) : - avg μ (fun x => tension (f x) q) = - avg μ (fun x => tension (f x) (mixW μ f))+tension (mixW μ f) q := by - let u := mixW μ f - have h (x : A) : tension (f x) q=tension (f x) u+ - avg (f x) (fun i => log (u i)-log (q i)) := by - simp only [tension_as_diff,avg_sub] - ring - simp_rw [h,avg_add,← mixW_avg]; rfl - -theorem tension_le_cap {p q : Wgt A} (hp : ∀ i,0 ≤ p i) (hq : ∀ i,0 ≤ q i) - (C : ℝ) (hc : 0 ?_ - rcases eq_or_lt_of_le (hp i) with h'|h' - · rw [←h']; simp - have hqi : q i ≠ 0 := - (pos_of_mul_pos_right (h'.trans_le (h i)) hc.le).ne' - have hg : 0 < q i := lt_of_le_of_ne (hq i) (Ne.symm hqi) - refine mul_le_mul_of_nonneg_left ?_ h'.le - change log (p i) - log (q i) ≤ log C - rw [← Real.log_div h'.ne' hg.ne'] - exact Real.log_le_log (by positivity) ((div_le_iff₀ hg).mpr (h i)) - -private theorem tension_cell (a b : ℝ) (ha : 0≤a) (hb : 0 ≤ b) (h : a≠0→b≠0) : - (√a-√b)^2 ≤ a*(log a - log b)+ b - a := by - rcases eq_or_lt_of_le ha with h'|h' - · rw [← h']; simp only [sqrt_zero,zero_sub,neg_sq,zero_mul,zero_add,sub_zero]; rw [sq_sqrt hb] - have hb' := lt_of_le_of_ne hb (Ne.symm (h h'.ne')) - have hc : 0<√a := by positivity - have ht := Real.log_le_sub_one_of_pos (x:=√b/√a) (by positivity) - rw [Real.log_div (by positivity) (by positivity), Real.log_sqrt hb,Real.log_sqrt ha] at ht - have hh := mul_le_mul_of_nonneg_right ht ha - have he : √b/√a*a = √b*√a := by - field_simp; rw [sq_sqrt ha] - rw [sub_mul,sub_mul,he] at hh - nlinarith only [hh,sq_sqrt ha,sq_sqrt hb] - -set_option maxHeartbeats 600000 in -theorem var_tension (p q : Wgt A) (hp : IsLaw p) (hq : IsLaw q) (h : lsupp p q) : - varOne p q ^ 2 ≤ tension p q * 4 := by - let a (i : A) := |√(p i)-√(q i)| - let b (i : A) := √(p i)+√(q i) - have ha : ∑ i, a i ^ 2 ≤ tension p q := by - have ht (x : A) : - a x ^2 ≤ p x * (log (p x)-log (q x))+q x-p x := by - unfold a; rw [sq_abs]; exact tension_cell _ _ (hp.nz _) (hq.nz _) (h _) - refine (sum_le_sum (fun i (_: i∈univ) => ht i)).trans_eq ?_ - simp only [Finset.sum_sub_distrib,Finset.sum_add_distrib] - change _ +tot q-tot p=tension p q - rw [hp.total,hq.total,add_sub_cancel_right] - rfl - have hb : ∑ i,b i^2 ≤ 4 := by - have ht (x : A) : - b x ^ 2 ≤ 2*p x+2*q x := by - unfold b; nlinarith only [sq_sqrt (hp.nz x),sq_sqrt (hq.nz x), - sq_nonneg (√(p x)-√(q x))] - refine (sum_le_sum (fun i (_: i∈univ) => ht i)).trans_eq ?_ - simp only [Finset.sum_add_distrib,← Finset.mul_sum] - change 2*tot p + 2*tot q = 4 - rw [hp.total,hq.total] - norm_num - have h0 : 0≤tension p q := le_trans (sum_nonneg (fun i _ => sq_nonneg _)) ha - have he : varOne p q = ∑ i, a i * b i := by - unfold varOne - refine sum_congr rfl (fun i _ => ?_) - have hy : - (√(p i)-√(q i))*b i=p i-q i := by - unfold b; nlinarith only [sq_sqrt (hp.nz i),sq_sqrt (hq.nz i)] - rw [← hy,abs_mul,abs_of_nonneg (show 0≤b i from by unfold b; positivity)] - rw [he] - exact (Finset.sum_mul_sq_le_sq_mul_sq ..).trans - (mul_le_mul ha hb (sum_nonneg (fun i _ => sq_nonneg _)) h0) - -theorem tension_nonneg {p q : Wgt A} (hp : IsLaw p) (hq : IsLaw q) (h : lsupp p q) : - 0 ≤ tension p q := by nlinarith only [var_tension p q hp hq h,sq_nonneg (varOne p q)] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteEntropy +import OAI.Combinatorics.HadwigerCounterexample.WalshBounds + +namespace OAI + +/-! # Relative Entropy -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real +open scoped BigOperators +variable {A B C : Type} [Fintype A] [Fintype B] [Fintype C] + +def lsupp (p q : Wgt A) := ∀ x,p x ≠ 0 → q x≠0 + +def tension (p q : Wgt A) := avg p (fun x => log (p x)-log (q x)) +def varOne (p q : Wgt A) := ∑ x, |p x-q x| + +theorem tension_of_ratio {p q : Wgt A} (h : lsupp p q) : + tension p q=avg p (fun x => log (p x/q x)) := + avg_congr (fun i hi => (Real.log_div hi (h i hi)).symm) + +theorem tension_as_diff (p q : Wgt A) : + tension p q= negEnt p-avg p (fun x => log (q x)) := avg_sub p _ _ + +theorem tension_mix {μ : Wgt A} {f : A→Wgt B} (q : Wgt B) : + avg μ (fun x => tension (f x) q) = + avg μ (fun x => tension (f x) (mixW μ f))+tension (mixW μ f) q := by + let u := mixW μ f + have h (x : A) : tension (f x) q=tension (f x) u+ + avg (f x) (fun i => log (u i)-log (q i)) := by + simp only [tension_as_diff,avg_sub] + ring + simp_rw [h,avg_add,← mixW_avg]; rfl + +theorem tension_le_cap {p q : Wgt A} (hp : ∀ i,0 ≤ p i) (hq : ∀ i,0 ≤ q i) + (C : ℝ) (hc : 0 ?_ + rcases eq_or_lt_of_le (hp i) with h'|h' + · rw [←h']; simp + have hqi : q i ≠ 0 := + (pos_of_mul_pos_right (h'.trans_le (h i)) hc.le).ne' + have hg : 0 < q i := lt_of_le_of_ne (hq i) (Ne.symm hqi) + refine mul_le_mul_of_nonneg_left ?_ h'.le + change log (p i) - log (q i) ≤ log C + rw [← Real.log_div h'.ne' hg.ne'] + exact Real.log_le_log (by positivity) ((div_le_iff₀ hg).mpr (h i)) + +private theorem tension_cell (a b : ℝ) (ha : 0≤a) (hb : 0 ≤ b) (h : a≠0→b≠0) : + (√a-√b)^2 ≤ a*(log a - log b)+ b - a := by + rcases eq_or_lt_of_le ha with h'|h' + · rw [← h']; simp only [sqrt_zero,zero_sub,neg_sq,zero_mul,zero_add,sub_zero]; rw [sq_sqrt hb] + have hb' := lt_of_le_of_ne hb (Ne.symm (h h'.ne')) + have hc : 0<√a := by positivity + have ht := Real.log_le_sub_one_of_pos (x:=√b/√a) (by positivity) + rw [Real.log_div (by positivity) (by positivity), Real.log_sqrt hb,Real.log_sqrt ha] at ht + have hh := mul_le_mul_of_nonneg_right ht ha + have he : √b/√a*a = √b*√a := by + field_simp; rw [sq_sqrt ha] + rw [sub_mul,sub_mul,he] at hh + nlinarith only [hh,sq_sqrt ha,sq_sqrt hb] + +set_option maxHeartbeats 600000 in +theorem var_tension (p q : Wgt A) (hp : IsLaw p) (hq : IsLaw q) (h : lsupp p q) : + varOne p q ^ 2 ≤ tension p q * 4 := by + let a (i : A) := |√(p i)-√(q i)| + let b (i : A) := √(p i)+√(q i) + have ha : ∑ i, a i ^ 2 ≤ tension p q := by + have ht (x : A) : + a x ^2 ≤ p x * (log (p x)-log (q x))+q x-p x := by + unfold a; rw [sq_abs]; exact tension_cell _ _ (hp.nz _) (hq.nz _) (h _) + refine (sum_le_sum (fun i (_: i∈univ) => ht i)).trans_eq ?_ + simp only [Finset.sum_sub_distrib,Finset.sum_add_distrib] + change _ +tot q-tot p=tension p q + rw [hp.total,hq.total,add_sub_cancel_right] + rfl + have hb : ∑ i,b i^2 ≤ 4 := by + have ht (x : A) : + b x ^ 2 ≤ 2*p x+2*q x := by + unfold b; nlinarith only [sq_sqrt (hp.nz x),sq_sqrt (hq.nz x), + sq_nonneg (√(p x)-√(q x))] + refine (sum_le_sum (fun i (_: i∈univ) => ht i)).trans_eq ?_ + simp only [Finset.sum_add_distrib,← Finset.mul_sum] + change 2*tot p + 2*tot q = 4 + rw [hp.total,hq.total] + norm_num + have h0 : 0≤tension p q := le_trans (sum_nonneg (fun i _ => sq_nonneg _)) ha + have he : varOne p q = ∑ i, a i * b i := by + unfold varOne + refine sum_congr rfl (fun i _ => ?_) + have hy : + (√(p i)-√(q i))*b i=p i-q i := by + unfold b; nlinarith only [sq_sqrt (hp.nz i),sq_sqrt (hq.nz i)] + rw [← hy,abs_mul,abs_of_nonneg (show 0≤b i from by unfold b; positivity)] + rw [he] + exact (Finset.sum_mul_sq_le_sq_mul_sq ..).trans + (mul_le_mul ha hb (sum_nonneg (fun i _ => sq_nonneg _)) h0) + +theorem tension_nonneg {p q : Wgt A} (hp : IsLaw p) (hq : IsLaw q) (h : lsupp p q) : + 0 ≤ tension p q := by nlinarith only [var_tension p q hp hq h,sq_nonneg (varOne p q)] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RelativeInjectionBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RelativeInjectionBounds.lean index a6a41fccbf63968175d1bc197a0a548c192cb939..9eb86d76acdb1b24008bd6ce19f37e297d32ef50 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RelativeInjectionBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RelativeInjectionBounds.lean @@ -1,110 +1,110 @@ -import OAI.Combinatorics.HadwigerCounterexample.TableInjectionTransfer - -namespace OAI - -/-! # Relative Injection Bounds -/ - -noncomputable section -namespace HadwigerCounterexample - -open Matrix LinearMap Module Submodule Function Finset Filter -open scoped BigOperators Topology -variable {p : Shape} {n N : ℕ} - -def fringe (N : ℕ) := bp (-0.01*N) -def shine (N : ℕ) := bp (0.01*N) -def edgeError (N : ℕ) := bp (-0.005*N) - -private theorem fire_budget (K : ℕ) (p : Shape) {l D : ℝ} - (hd : 0 ≤D) (hh : 2*K+l+200*(D+2 : ℝ) ≤ p.h) : - ∀ᶠ N : ℕ in atTop, - bp (D*N)*(fireBill p (N/100) K (shine N)/(pushCost (bp (-l)) K)^(N/100)) ≤ fringe N := by - have he := (tendsto_natCast_atTop_atTop (R:=ℝ)).eventually - (eventually_ge_atTop (1+p.h*(K:ℝ))) - filter_upwards [he,eventually_ge_atTop 100] with N hN hk - change (1+p.h*(K:ℝ))≤(N:ℝ) at hN - let k := N/100 - have ht : N ≤ 200*k := by - have h1 : 1 ≤ N/100 := (Nat.le_div_iff_mul_le (by omega)).mpr (by simpa using hk) - have h := Nat.div_add_mod' N 100 - unfold k; omega - have ht' : (N:ℝ)≤200*k := by exact_mod_cast ht - have h1 : (D+2)*N≤ (p.h-(2*K+(l:ℝ)))*k := by - have h := mul_le_mul_of_nonneg_left ht' (show 0≤D+2 by linarith) - have h' := mul_le_mul_of_nonneg_right hh (Nat.cast_nonneg k : 0≤(k:ℝ)) - linarith only [h,h'] - change bp _*(fireBill p k K (shine N)/_ ^ k)≤_ - unfold fireBill pushCost shine fringe - rw [←bp_sub, ← bp_mul_nat, ← bp_one,←bp_add,←bp_add,←bp_sub,←bp_add] - apply bp_le - linarith only [h1,hN,(Nat.cast_nonneg N : 0≤(N:ℝ))] - -set_option maxHeartbeats 1000000 in -theorem guard_grid (g K : ℕ) (D ε : ℝ) (hd : 0≤D) (he : 0<ε) : - ∀ᶠ h : ℕ in atTop,∀ p : Shape,p.g=g → p.h=h → - ∀ᶠ M : ℕ in atTop,∀ᶠ n : ℕ in atTop,let N:=M*n; - ∀ (P : UnitType p n N×UnitType p n N→Prop), - named P (bp (D*N)) → named (P ∘ Prod.swap) (bp (D*N)) → - ∀ w (b : Fpins p n N) (m : Mixer p n), (∀ x,planRank (b x)≤ K) → - IsLaw w → bySide p w m (shine N) → (∀ x,w x≠0 → ∀ i,frameLaw m (onSide x i)) → - pr (pairW w w) (fun x => P x ∧ ¬ secureAt p b x) ≤ - ε*pr (pairW w w) P+edgeError N := by - let W := 8*num (Comp g×Bool) - obtain ⟨k,hk⟩ : ∃ k : ℕ,W*(3*bp (-(k:ℝ)))≤ ε := by - have hh : Tendsto (fun n : ℕ => W*(3*bp (-(n:ℝ)))) atTop (𝓝 0) := by - have hi := ((bp_nat_vanish (by norm_num : 0<(1:ℝ))).const_mul 3).const_mul W - simpa using hi - obtain ⟨n,hn⟩ := (hh.eventually (gt_mem_nhds he)).exists - exact ⟨n,hn.le⟩ - let l := bp (-(k:ℝ)) - filter_upwards [tendsto_natCast_atTop_atTop.eventually - (eventually_ge_atTop (2*K+(k:ℝ)+200*(D+2)))] with h hH p hg hp - - have heq : (8*num (Place p):ℝ)*(3*l) ≤ ε := by - change (8*num (Comp p.g×Bool):ℝ)*(3*l) ≤ _ - rwa [hg] - have hFire : ∀ᶠ N : ℕ in atTop, - bp (D*N)*(fireBill p (N/100) K (shine N)/(pushCost l K)^(N/100)) ≤ fringe N := - fire_budget K p hd (hp.symm ▸ hH) - have hsmall : ∀ᶠ N : ℕ in atTop, - 8*num (Place p)*(fringe N +fringe N)≤edgeError N := by - filter_upwards [bp_poly_dom_nat (by norm_num : 0<(0.005:ℝ)) (8*num (Place p)*2) 0] with N hN - unfold fringe edgeError - rw [←two_mul,←mul_assoc] - refine (mul_le_mul_of_nonneg_right (show _≤bp (0.005*N) from by simpa using hN.le) - (bp_pos _).le).trans_eq ?_ - rw [←bp_add]; congr 1; ring - filter_upwards [eventually_grid hFire,eventually_grid hsmall, - columns_budget p (δ:=1) zero_lt_one 2 1 (by norm_num) zero_le_one, - eventually_grid (tendsto_natCast_atTop_atTop.eventually - (eventually_ge_atTop (10*((k:ℝ)+1))))] with M hM hT hS hY - filter_upwards [hM,hT,eventually_ge_atTop 1,hY] with n hM hT hn hY - dsimp only - intro P hP hQ w b m hb hw hW hx - let N := M*n - have hN : 2*num (Full p n)+1≤N := (hS n hn).trans_eq (one_mul _) - have hρ : rhUp (shine N) (2*fringe N)*2 * bp (num (Row p n)+(N/100:ℕ)-N)≤l := by - change 10*((k:ℝ)+1) ≤ N at hY - have hh : 100*((N/100:ℕ):ℝ)≤N := by exact_mod_cast (show 100*(N/100) ≤ N from Nat.mul_div_le _ _) - unfold rhUp shine fringe - rw [show 2*bp (-0.01*N)/2=bp (-0.01*N) from (by ring), ← bp_neg, ←bp_one, - ←bp_add,←bp_add,←bp_add] - apply bp_le - linarith only [hY,hN,hh,row_le p n] - have hl : 0 P x ∧ ¬ secureAt p b x) ≤ + ε*pr (pairW w w) P+edgeError N := by + let W := 8*num (Comp g×Bool) + obtain ⟨k,hk⟩ : ∃ k : ℕ,W*(3*bp (-(k:ℝ)))≤ ε := by + have hh : Tendsto (fun n : ℕ => W*(3*bp (-(n:ℝ)))) atTop (𝓝 0) := by + have hi := ((bp_nat_vanish (by norm_num : 0<(1:ℝ))).const_mul 3).const_mul W + simpa using hi + obtain ⟨n,hn⟩ := (hh.eventually (gt_mem_nhds he)).exists + exact ⟨n,hn.le⟩ + let l := bp (-(k:ℝ)) + filter_upwards [tendsto_natCast_atTop_atTop.eventually + (eventually_ge_atTop (2*K+(k:ℝ)+200*(D+2)))] with h hH p hg hp + + have heq : (8*num (Place p):ℝ)*(3*l) ≤ ε := by + change (8*num (Comp p.g×Bool):ℝ)*(3*l) ≤ _ + rwa [hg] + have hFire : ∀ᶠ N : ℕ in atTop, + bp (D*N)*(fireBill p (N/100) K (shine N)/(pushCost l K)^(N/100)) ≤ fringe N := + fire_budget K p hd (hp.symm ▸ hH) + have hsmall : ∀ᶠ N : ℕ in atTop, + 8*num (Place p)*(fringe N +fringe N)≤edgeError N := by + filter_upwards [bp_poly_dom_nat (by norm_num : 0<(0.005:ℝ)) (8*num (Place p)*2) 0] with N hN + unfold fringe edgeError + rw [←two_mul,←mul_assoc] + refine (mul_le_mul_of_nonneg_right (show _≤bp (0.005*N) from by simpa using hN.le) + (bp_pos _).le).trans_eq ?_ + rw [←bp_add]; congr 1; ring + filter_upwards [eventually_grid hFire,eventually_grid hsmall, + columns_budget p (δ:=1) zero_lt_one 2 1 (by norm_num) zero_le_one, + eventually_grid (tendsto_natCast_atTop_atTop.eventually + (eventually_ge_atTop (10*((k:ℝ)+1))))] with M hM hT hS hY + filter_upwards [hM,hT,eventually_ge_atTop 1,hY] with n hM hT hn hY + dsimp only + intro P hP hQ w b m hb hw hW hx + let N := M*n + have hN : 2*num (Full p n)+1≤N := (hS n hn).trans_eq (one_mul _) + have hρ : rhUp (shine N) (2*fringe N)*2 * bp (num (Row p n)+(N/100:ℕ)-N)≤l := by + change 10*((k:ℝ)+1) ≤ N at hY + have hh : 100*((N/100:ℕ):ℝ)≤N := by exact_mod_cast (show 100*(N/100) ≤ N from Nat.mul_div_le _ _) + unfold rhUp shine fringe + rw [show 2*bp (-0.01*N)/2=bp (-0.01*N) from (by ring), ← bp_neg, ←bp_one, + ←bp_add,←bp_add,←bp_add] + apply bp_le + linarith only [hY,hN,hh,row_le p n] + have hl : 0 Matrix.of (fun i j => A j.val.1 g i (⟨j.val.2,j.property⟩)) - -omit [Fintype I] [Fintype J] [Fintype G] [DecidableEq I] [DecidableEq J] [DecidableEq G] in -theorem peek_pooled (A B : J→NomQuery p n f) (x : Forum p n N G) (i : J) : - led i (peekR p (tied f J) (pooled A) (pooled B) x)=peekR p f (A i) (B i) x := by - apply Prod.ext <;> ext <;> rfl - -omit [Fintype I] [Fintype J] [Fintype G] [DecidableEq I] [DecidableEq J] [DecidableEq G] in -theorem lane_pooled (A B : J→NomQuery p n f) (m : Mixer p n) (i : J) : - laneM (database m (pooled A) (pooled B)) i=database m (A i) (B i) := by - funext z; ext x y; rfl - -omit [Fintype G] in -theorem pool_injective {A : J → NomQuery p n f} (h : ∀ i, Injective (pooled A i).mulVec) : - ∀ z i,Injective (A z i).mulVec := by - classical - intro z i - let e := condLane (tied f J) z i - have he : Injective e := by - intro a b h; exact Subtype.ext (congrArg (fun x : Port (tied f J) i => x.val.2) h) - have ho : A z i=pooled A i*embedMat e := by rw [mul_embedMat]; rfl - rw [ho]; exact inj_comp_mat _ _ (h i) (embedMat_inj he) - -theorem poUse (A B : J→NomQuery p n f) (m : Mixer p n) - (hN : 2*num (Full p n) F (peekR p (tied f J) (pooled A) (pooled B) x))= - avg (rackStation (database m (pooled A) (pooled B)) N) F := by - rw [← mapW_avg,law_peekR m hN ha hb] - -set_option maxHeartbeats 800000 in -theorem pooled_batch (A B : J → NomQuery p n f) (m : Mixer p n) - (hN : 2*num (Full p n) ∏ i, F i (peekR p f (A i) (B i) x)) - - ∏ i, avg w (fun x => F i (peekR p f (A i) (B i) x))|≤ - 2*netFact (tied f J)*twinkle (tied f J) k N := by - classical - let w := forumLaw m N (G:=G) - let Z := database m (pooled A) (pooled B) - have he i : - avg w (fun x => F i (peekR p f (A i) (B i) x))= - avg (rackStation (database m (A i) (B i)) N) (F i) := by - unfold w; rw [←mapW_avg,law_peekR m hN (pool_injective ha i) (pool_injective hb i)] - have hx : - avg w (fun x => ∏ i, F i (peekR p f (A i) (B i) x)) = - avg (rackStation Z N) (brightProd F) := by - rw [show avg (rackStation Z N) _ =_ from (poUse A B m hN ha hb (brightProd F)).symm] - refine avg_congr fun x _ => ?_ - simp_rw [brightProd, peek_pooled] - dsimp only - change |avg w _ - ∏ i, avg w _| ≤ _ - simp_rw [he]; rw [hx] - have hi := compare_lanes Z F hf k hk (fun i => by linarith only [hk i,hL]) - simp_rw [Z,lane_pooled] at * - exact hi - -set_option maxHeartbeats 600000 in -theorem pool_upper (A B : J → NomQuery p n f) (m : Mixer p n) - (hN : 2*num (Full p n) ∀ i,P i (peekR p f (A i) (B i) x))≤ - netFact (tied f J)* ∏ i, pr w (fun x => P i (peekR p f (A i) (B i) x)) := by - classical - let w := forumLaw (G:=G) m N - let S := database m (pooled A) (pooled B) - let q (x : Rack (J×I) N) := ∀ i,P i (led i x) - have h1 i : - pr w (fun x => P i (peekR p f (A i) (B i) x)) = - pr (rackStation (database m (A i) (B i)) N) (P i) := by - unfold w; rw [←mapW_pr,law_peekR m hN (pool_injective ha i) (pool_injective hb i)] - have ht : - pr w (fun x => ∀ i,P i (peekR p f (A i) (B i) x)) = - pr (rackStation S N) q := by - rw [show pr (rackStation S N) q= _ from - (poUse A B m hN ha hb (fun x => ind (q x))).symm] - refine avg_congr fun x _ => ?_ - simp_rw [q,peek_pooled] - let M := netFact (tied f J) - let g (i : J) := bothPart (laneM S i) (N:=N) - have hg x (hh : bothPart S x ∧ q x) : - ∀ i,g i (led i x)∧ P i (led i x) := fun i => ⟨laneGram S _ hh.1 _,hh.2 i⟩ - change pr w _ ≤ _ - rw [ht, rackStation,← on_unif,pr_on] - have hx : pr unif (fun x : Rack (J×I) N => ∀ i,g i (led i x)∧ P i (led i x)) = - ∏ i,pr unif (fun x => g i x∧P i x) := by - change avg unif _=_ - simp_rw [ind_all] - exact led_piece Finset.univ (fun i x => g i x∧P i x) - have hh0 := net_norm S N hL - refine (div_le_div₀ (pr_nonneg unif_law.nz) - (pr_mono unif_law.nz hg) (inv_pos_of_pos netFact_pos) hh0.1).trans ?_ - rw [hx,div_eq_mul_inv,inv_inv,mul_comm] - apply mul_le_mul_of_nonneg_left _ netFact_pos.le - refine Finset.prod_le_prod₀ (fun i _ => pr_nonneg unif_law.nz) (fun i _ => ?_) - rw [pr_of_on unif_law.nz (g _),on_unif,h1] - have h0 (i) : pr unif (g i)≤1 := (pr_le_tot unif_law.nz).trans unif_law.total.le - apply le_trans (mul_le_mul_of_nonneg_right (h0 _) (pr_nonneg (unifOn_sub _).nz)) - unfold g S; rw [lane_pooled,one_mul]; exact le_rfl - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ConditionedBatchLaws + +namespace OAI + +/-! # Repeated Batch Laws -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Submodule Finset Function +open scoped BigOperators +variable {I J G : Type} [Fintype I] [Fintype J] [Fintype G] [DecidableEq I] +variable [DecidableEq J] [DecidableEq G] {p : Shape} {n N : ℕ} + +def tied (f : Route I G) (J : Type) : Route (J×I) G := f ∘ Prod.snd +variable {f : Route I G} + +def pooled (A : J → NomQuery p n f) : NomQuery p n (tied f J) := + fun g => Matrix.of (fun i j => A j.val.1 g i (⟨j.val.2,j.property⟩)) + +omit [Fintype I] [Fintype J] [Fintype G] [DecidableEq I] [DecidableEq J] [DecidableEq G] in +theorem peek_pooled (A B : J→NomQuery p n f) (x : Forum p n N G) (i : J) : + led i (peekR p (tied f J) (pooled A) (pooled B) x)=peekR p f (A i) (B i) x := by + apply Prod.ext <;> ext <;> rfl + +omit [Fintype I] [Fintype J] [Fintype G] [DecidableEq I] [DecidableEq J] [DecidableEq G] in +theorem lane_pooled (A B : J→NomQuery p n f) (m : Mixer p n) (i : J) : + laneM (database m (pooled A) (pooled B)) i=database m (A i) (B i) := by + funext z; ext x y; rfl + +omit [Fintype G] in +theorem pool_injective {A : J → NomQuery p n f} (h : ∀ i, Injective (pooled A i).mulVec) : + ∀ z i,Injective (A z i).mulVec := by + classical + intro z i + let e := condLane (tied f J) z i + have he : Injective e := by + intro a b h; exact Subtype.ext (congrArg (fun x : Port (tied f J) i => x.val.2) h) + have ho : A z i=pooled A i*embedMat e := by rw [mul_embedMat]; rfl + rw [ho]; exact inj_comp_mat _ _ (h i) (embedMat_inj he) + +theorem poUse (A B : J→NomQuery p n f) (m : Mixer p n) + (hN : 2*num (Full p n) F (peekR p (tied f J) (pooled A) (pooled B) x))= + avg (rackStation (database m (pooled A) (pooled B)) N) F := by + rw [← mapW_avg,law_peekR m hN ha hb] + +set_option maxHeartbeats 800000 in +theorem pooled_batch (A B : J → NomQuery p n f) (m : Mixer p n) + (hN : 2*num (Full p n) ∏ i, F i (peekR p f (A i) (B i) x)) - + ∏ i, avg w (fun x => F i (peekR p f (A i) (B i) x))|≤ + 2*netFact (tied f J)*twinkle (tied f J) k N := by + classical + let w := forumLaw m N (G:=G) + let Z := database m (pooled A) (pooled B) + have he i : + avg w (fun x => F i (peekR p f (A i) (B i) x))= + avg (rackStation (database m (A i) (B i)) N) (F i) := by + unfold w; rw [←mapW_avg,law_peekR m hN (pool_injective ha i) (pool_injective hb i)] + have hx : + avg w (fun x => ∏ i, F i (peekR p f (A i) (B i) x)) = + avg (rackStation Z N) (brightProd F) := by + rw [show avg (rackStation Z N) _ =_ from (poUse A B m hN ha hb (brightProd F)).symm] + refine avg_congr fun x _ => ?_ + simp_rw [brightProd, peek_pooled] + dsimp only + change |avg w _ - ∏ i, avg w _| ≤ _ + simp_rw [he]; rw [hx] + have hi := compare_lanes Z F hf k hk (fun i => by linarith only [hk i,hL]) + simp_rw [Z,lane_pooled] at * + exact hi + +set_option maxHeartbeats 600000 in +theorem pool_upper (A B : J → NomQuery p n f) (m : Mixer p n) + (hN : 2*num (Full p n) ∀ i,P i (peekR p f (A i) (B i) x))≤ + netFact (tied f J)* ∏ i, pr w (fun x => P i (peekR p f (A i) (B i) x)) := by + classical + let w := forumLaw (G:=G) m N + let S := database m (pooled A) (pooled B) + let q (x : Rack (J×I) N) := ∀ i,P i (led i x) + have h1 i : + pr w (fun x => P i (peekR p f (A i) (B i) x)) = + pr (rackStation (database m (A i) (B i)) N) (P i) := by + unfold w; rw [←mapW_pr,law_peekR m hN (pool_injective ha i) (pool_injective hb i)] + have ht : + pr w (fun x => ∀ i,P i (peekR p f (A i) (B i) x)) = + pr (rackStation S N) q := by + rw [show pr (rackStation S N) q= _ from + (poUse A B m hN ha hb (fun x => ind (q x))).symm] + refine avg_congr fun x _ => ?_ + simp_rw [q,peek_pooled] + let M := netFact (tied f J) + let g (i : J) := bothPart (laneM S i) (N:=N) + have hg x (hh : bothPart S x ∧ q x) : + ∀ i,g i (led i x)∧ P i (led i x) := fun i => ⟨laneGram S _ hh.1 _,hh.2 i⟩ + change pr w _ ≤ _ + rw [ht, rackStation,← on_unif,pr_on] + have hx : pr unif (fun x : Rack (J×I) N => ∀ i,g i (led i x)∧ P i (led i x)) = + ∏ i,pr unif (fun x => g i x∧P i x) := by + change avg unif _=_ + simp_rw [ind_all] + exact led_piece Finset.univ (fun i x => g i x∧P i x) + have hh0 := net_norm S N hL + refine (div_le_div₀ (pr_nonneg unif_law.nz) + (pr_mono unif_law.nz hg) (inv_pos_of_pos netFact_pos) hh0.1).trans ?_ + rw [hx,div_eq_mul_inv,inv_inv,mul_comm] + apply mul_le_mul_of_nonneg_left _ netFact_pos.le + refine Finset.prod_le_prod₀ (fun i _ => pr_nonneg unif_law.nz) (fun i _ => ?_) + rw [pr_of_on unif_law.nz (g _),on_unif,h1] + have h0 (i) : pr unif (g i)≤1 := (pr_le_tot unif_law.nz).trans unif_law.total.le + apply le_trans (mul_le_mul_of_nonneg_right (h0 _) (pr_nonneg (unifOn_sub _).nz)) + unfold g S; rw [lane_pooled,one_mul]; exact le_rfl + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RepeatedQueryBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RepeatedQueryBounds.lean index 43a1c0389dbc77dc91f61b129af892848352ce1f..074d6fc176e92b375d615168f022e1f783e98191 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RepeatedQueryBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RepeatedQueryBounds.lean @@ -1,161 +1,161 @@ -import OAI.Combinatorics.HadwigerCounterexample.BatchCharacters - -namespace OAI - -/-! # Repeated Query Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Submodule Function Finset -open scoped BigOperators -variable {I J G : Type} [Fintype I] [Fintype J] [Fintype G] -variable [DecidableEq I] [DecidableEq J] [DecidableEq G] -variable {N : ℕ} - -private theorem num_cross_peak (E : Rail (I×J)) - (he : ∀ i∈E,i.1.1≠i.2.1) (t : ℕ) : - nbr (fun v : Vec E=> peak (ledgerM E v)=t) ≤ bp (peakExpense I J t) := by - classical - let Γ := fun M : Avenue I J => interDraw M ∧ peak M=t - have hh (v) : interDraw (ledgerM E v) := fun i j k => within_recorded E v _ _ - (fun h => he _ h rfl) - rw [nbr_eq_card] - apply le_trans _ (price_peak (I:=I) (J:=J) t) - rw [nbr_eq_card] - let f (v : {v : Vec E//peak (ledgerM E v)=t}) : { M//Γ M} := - ⟨ledgerM E v.val, hh _,v.property⟩ - have h : Injective f := by - intro v w he - apply Subtype.ext - have h : ledgerM E v.val=ledgerM E w.val := congrArg Subtype.val he - rw [←inLedger E v.val,h,inLedger] - exact_mod_cast Fintype.card_le_of_injective f h - -private theorem peak_sum (E : Rail (I×J)) - (he : ∀ i∈E,i.1.1≠ i.2.1) (u : ℝ) - (h : peakExpense I J 1+u≤0) : - ∑ v : Vec E,bp (u*peak (ledgerM E v))≤num (I×J)+1 := by - classical - let T := Fintype.card (I×J) - let f (v : Vec E) : Fin (T+1) := - ⟨peak (ledgerM E v), Nat.lt_succ_of_le (peak_le _)⟩ - have hg : ∑ v : Vec E,bp (u*peak (ledgerM E v))= - ∑ i : Fin (T+1),bp (u*i.val) * nbr (fun v : Vec E => peak (ledgerM E v)=i.val) := by - unfold nbr tot; simp only [Finset.mul_sum]; rw [Finset.sum_comm] - refine Finset.sum_congr rfl fun v _ => ?_ - rw [Finset.sum_eq_single (f v)] - · simp only [f,ind_true,mul_one] - · intro i _ hi; rw [ind_zero (show peak _≠i.val from - fun h => hi (Fin.ext h.symm)),mul_zero] - simp - have hi (i : Fin (T+1)) : - bp (u*i.val)*nbr (fun v : Vec E=>peak (ledgerM E v)=i.val) ≤ 1 := by - refine (mul_le_mul_of_nonneg_left (num_cross_peak E he i.val) (bp_pos _).le).trans ?_ - rw [←bp_add,←bp_zero] - apply bp_le - unfold peakExpense at * - have h1 := mul_nonpos_of_nonpos_of_nonneg h (Nat.cast_nonneg i.val : 0≤(i.val:ℝ)) - norm_num at h1 - linarith only [h1] - rw [hg] - exact (Finset.sum_le_sum fun i _ => hi i).trans_eq (by simp [num,T]) - -set_option maxHeartbeats 800000 in -theorem cross_flood (E : Rail (I×J)) (Z : Vec E) - (he : ∀ i∈E,i.1.1≠ i.2.1) (u : ℝ) (hu : 0≤u) - (P : I → Rack J N → Prop) (hp : ∀ i,bp (-u)≤pr unif (P i)) - (hδ : peakExpense I J 1+(-(N:ℝ)/2+2*u) ≤0) : - pr unif (fun x => traced x E Z ∧ ∀ i,P i (led i x))≤ - bp (-(E.card:ℝ)) * (num (I×J)+1) *∏ i,pr unif (P i) := by - classical - let H := ∏ i,pr unif (P i) - have hg : 0≤H := Finset.prod_nonneg fun _ _ => pr_nonneg unif_law.nz - let C : ℝ := -(N:ℝ)/2+2*u - let F (v : Vec E) := - vectorPhase v Z*avg unif (fun x => phasedBy (ledgerM E v) x*phot P x) - have hh v : F v ≤ bp (C*peak (ledgerM E v))*H := by - refine (le_abs_self _).trans ?_ - unfold F; rw [abs_mul,vectorPhase,wsign_abs,one_mul] - exact light_bound _ P u hu hp - have heq : pr unif (fun x => traced x E Z ∧ ∀ i,P i (led i x))= - avg unif F := by - unfold pr F - simp_rw [ind_and,ind_all,rail_expand,← avg_mul,← avg_mul'] - rw [avg_avg] - refine avg_congr fun v _ => avg_congr fun x _ => ?_ - unfold phot; ring - rw [heq] - refine (avg_mono unif_law.nz hh).trans ?_ - let lamh := bp (-(E.card:ℝ)) - have he' (x : Vec E) : - unif x=lamh := by rw [unif_apply,card_space,dim_vec,Fintype.card_coe, ← bp_neg] - simp only [avg,he',← Finset.mul_sum] - rw [← Finset.sum_mul,mul_assoc] - exact mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_right (peak_sum E he _ hδ) hg) - (bp_pos _).le - -def cInside (g : Route (I×J) G) := - (crowded g).filter (fun i => i.1.1=i.2.1) - -omit [Fintype G] in -theorem inside_count (g : Route (I×J) G) : - (cInside g).card≤ Fintype.card I*Fintype.card J*Fintype.card J := by - classical - let f : I×J×J → (I×J)×(I×J) := fun x => ((x.1,x.2.1),(x.1,x.2.2)) - have h : cInside g ⊆ Finset.univ.image f := by - rintro ⟨⟨x,i⟩,y,j⟩ hv - obtain rfl : x=y := (mem_filter.mp hv).2 - exact mem_image.mpr ⟨(x,i,j),mem_univ _,rfl⟩ - exact (card_le_card h).trans (card_image_le.trans_eq (by simp [mul_assoc])) - -set_option maxHeartbeats 800000 in -theorem many_frames (g : Route (I×J) G) (Z : GeoM g) (hN : ∀ i,2*num (Port g i)-N≤ -1) - (u : ℝ) (hu : 0≤u) (P : I→Rack J N→Prop) (hp : ∀ i,bp (-u) ≤ pr unif (P i)) - (hd : peakExpense I J 1+ (-(N:ℝ)/2+2*u) ≤0) : - pr (rackStation Z N) (fun x => ∀ i,P i (led i x))≤ - (4:ℝ)^Fintype.card G * bp (num I * num J * num J) * (num (I×J)+1) * - ∏ i:I,pr unif (P i) := by - classical - let E := crowded g - let Y := cInside g - let R := E\Y - have hn := (net_norm Z N hN).1 - let Z' := directions g Z - let w (x : R) := Z' ⟨x.val,sdiff_subset x.property⟩ - have hl (x : Rack (I×J) N) (h : gramPart Z x) : - traced x R w := by - have he := (match_crowd x g Z).mpr h - funext i - exact congr_fun he (⟨i.val,sdiff_subset i.property⟩ : ↑E) - have he i (h : i∈R) : i.1.1≠ i.2.1 := by - intro hx - obtain ⟨h1,h2⟩ := Finset.mem_sdiff.mp h - exact h2 (Finset.mem_filter.mpr ⟨h1,hx⟩) - let Q := fun x => ∀ i, P i (led i x) - let H := ∏ i,pr unif (P i) - have h0 := netFact_pos (f:=g) - unfold rackStation - rw [← on_unif, pr_on] - have hh : pr unif (fun x => bothPart (N:=N) Z x ∧ Q x) ≤ - pr unif (fun x => traced x R w ∧ Q x) := - pr_mono unif_law.nz (fun x h => ⟨hl x ((both_test ..).mp h.1).1,h.2⟩) - have hf := cross_flood R w he u hu P hp hd - refine le_trans (div_le_div₀ ((pr_nonneg unif_law.nz).trans hf) - (hh.trans hf) (inv_pos_of_pos h0) hn) ?_ - let K : ℝ := num (I×J)+1 - have hk : 0 ≤ K := by unfold K num; positivity - change bp (- (R.card:ℝ)) * K * H / (netFact g)⁻¹ ≤ (4:ℝ)^_ * _ * K * H - have hY : Y ⊆ E := Finset.filter_subset .. - have hy : (R.card:ℝ)+(Y.card:ℝ) = netSize g := by - rw [← rail_count]; exact_mod_cast Finset.card_sdiff_add_card_eq_card hY - have hY' : (Y.card:ℝ) ≤ num I * num J * num J := by exact_mod_cast inside_count g - unfold netFact - have hg : 0 ≤ H := Finset.prod_nonneg fun i _ => pr_nonneg unif_law.nz - calc _ = (4:ℝ)^Fintype.card G * bp (netSize g- (R.card:ℝ))*K*H := by - rw [div_eq_mul_inv,inv_inv,bp_sub,bp_neg]; ring - _ ≤ _ := by gcongr; linarith -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BatchCharacters + +namespace OAI + +/-! # Repeated Query Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Submodule Function Finset +open scoped BigOperators +variable {I J G : Type} [Fintype I] [Fintype J] [Fintype G] +variable [DecidableEq I] [DecidableEq J] [DecidableEq G] +variable {N : ℕ} + +private theorem num_cross_peak (E : Rail (I×J)) + (he : ∀ i∈E,i.1.1≠i.2.1) (t : ℕ) : + nbr (fun v : Vec E=> peak (ledgerM E v)=t) ≤ bp (peakExpense I J t) := by + classical + let Γ := fun M : Avenue I J => interDraw M ∧ peak M=t + have hh (v) : interDraw (ledgerM E v) := fun i j k => within_recorded E v _ _ + (fun h => he _ h rfl) + rw [nbr_eq_card] + apply le_trans _ (price_peak (I:=I) (J:=J) t) + rw [nbr_eq_card] + let f (v : {v : Vec E//peak (ledgerM E v)=t}) : { M//Γ M} := + ⟨ledgerM E v.val, hh _,v.property⟩ + have h : Injective f := by + intro v w he + apply Subtype.ext + have h : ledgerM E v.val=ledgerM E w.val := congrArg Subtype.val he + rw [←inLedger E v.val,h,inLedger] + exact_mod_cast Fintype.card_le_of_injective f h + +private theorem peak_sum (E : Rail (I×J)) + (he : ∀ i∈E,i.1.1≠ i.2.1) (u : ℝ) + (h : peakExpense I J 1+u≤0) : + ∑ v : Vec E,bp (u*peak (ledgerM E v))≤num (I×J)+1 := by + classical + let T := Fintype.card (I×J) + let f (v : Vec E) : Fin (T+1) := + ⟨peak (ledgerM E v), Nat.lt_succ_of_le (peak_le _)⟩ + have hg : ∑ v : Vec E,bp (u*peak (ledgerM E v))= + ∑ i : Fin (T+1),bp (u*i.val) * nbr (fun v : Vec E => peak (ledgerM E v)=i.val) := by + unfold nbr tot; simp only [Finset.mul_sum]; rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun v _ => ?_ + rw [Finset.sum_eq_single (f v)] + · simp only [f,ind_true,mul_one] + · intro i _ hi; rw [ind_zero (show peak _≠i.val from + fun h => hi (Fin.ext h.symm)),mul_zero] + simp + have hi (i : Fin (T+1)) : + bp (u*i.val)*nbr (fun v : Vec E=>peak (ledgerM E v)=i.val) ≤ 1 := by + refine (mul_le_mul_of_nonneg_left (num_cross_peak E he i.val) (bp_pos _).le).trans ?_ + rw [←bp_add,←bp_zero] + apply bp_le + unfold peakExpense at * + have h1 := mul_nonpos_of_nonpos_of_nonneg h (Nat.cast_nonneg i.val : 0≤(i.val:ℝ)) + norm_num at h1 + linarith only [h1] + rw [hg] + exact (Finset.sum_le_sum fun i _ => hi i).trans_eq (by simp [num,T]) + +set_option maxHeartbeats 800000 in +theorem cross_flood (E : Rail (I×J)) (Z : Vec E) + (he : ∀ i∈E,i.1.1≠ i.2.1) (u : ℝ) (hu : 0≤u) + (P : I → Rack J N → Prop) (hp : ∀ i,bp (-u)≤pr unif (P i)) + (hδ : peakExpense I J 1+(-(N:ℝ)/2+2*u) ≤0) : + pr unif (fun x => traced x E Z ∧ ∀ i,P i (led i x))≤ + bp (-(E.card:ℝ)) * (num (I×J)+1) *∏ i,pr unif (P i) := by + classical + let H := ∏ i,pr unif (P i) + have hg : 0≤H := Finset.prod_nonneg fun _ _ => pr_nonneg unif_law.nz + let C : ℝ := -(N:ℝ)/2+2*u + let F (v : Vec E) := + vectorPhase v Z*avg unif (fun x => phasedBy (ledgerM E v) x*phot P x) + have hh v : F v ≤ bp (C*peak (ledgerM E v))*H := by + refine (le_abs_self _).trans ?_ + unfold F; rw [abs_mul,vectorPhase,wsign_abs,one_mul] + exact light_bound _ P u hu hp + have heq : pr unif (fun x => traced x E Z ∧ ∀ i,P i (led i x))= + avg unif F := by + unfold pr F + simp_rw [ind_and,ind_all,rail_expand,← avg_mul,← avg_mul'] + rw [avg_avg] + refine avg_congr fun v _ => avg_congr fun x _ => ?_ + unfold phot; ring + rw [heq] + refine (avg_mono unif_law.nz hh).trans ?_ + let lamh := bp (-(E.card:ℝ)) + have he' (x : Vec E) : + unif x=lamh := by rw [unif_apply,card_space,dim_vec,Fintype.card_coe, ← bp_neg] + simp only [avg,he',← Finset.mul_sum] + rw [← Finset.sum_mul,mul_assoc] + exact mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_right (peak_sum E he _ hδ) hg) + (bp_pos _).le + +def cInside (g : Route (I×J) G) := + (crowded g).filter (fun i => i.1.1=i.2.1) + +omit [Fintype G] in +theorem inside_count (g : Route (I×J) G) : + (cInside g).card≤ Fintype.card I*Fintype.card J*Fintype.card J := by + classical + let f : I×J×J → (I×J)×(I×J) := fun x => ((x.1,x.2.1),(x.1,x.2.2)) + have h : cInside g ⊆ Finset.univ.image f := by + rintro ⟨⟨x,i⟩,y,j⟩ hv + obtain rfl : x=y := (mem_filter.mp hv).2 + exact mem_image.mpr ⟨(x,i,j),mem_univ _,rfl⟩ + exact (card_le_card h).trans (card_image_le.trans_eq (by simp [mul_assoc])) + +set_option maxHeartbeats 800000 in +theorem many_frames (g : Route (I×J) G) (Z : GeoM g) (hN : ∀ i,2*num (Port g i)-N≤ -1) + (u : ℝ) (hu : 0≤u) (P : I→Rack J N→Prop) (hp : ∀ i,bp (-u) ≤ pr unif (P i)) + (hd : peakExpense I J 1+ (-(N:ℝ)/2+2*u) ≤0) : + pr (rackStation Z N) (fun x => ∀ i,P i (led i x))≤ + (4:ℝ)^Fintype.card G * bp (num I * num J * num J) * (num (I×J)+1) * + ∏ i:I,pr unif (P i) := by + classical + let E := crowded g + let Y := cInside g + let R := E\Y + have hn := (net_norm Z N hN).1 + let Z' := directions g Z + let w (x : R) := Z' ⟨x.val,sdiff_subset x.property⟩ + have hl (x : Rack (I×J) N) (h : gramPart Z x) : + traced x R w := by + have he := (match_crowd x g Z).mpr h + funext i + exact congr_fun he (⟨i.val,sdiff_subset i.property⟩ : ↑E) + have he i (h : i∈R) : i.1.1≠ i.2.1 := by + intro hx + obtain ⟨h1,h2⟩ := Finset.mem_sdiff.mp h + exact h2 (Finset.mem_filter.mpr ⟨h1,hx⟩) + let Q := fun x => ∀ i, P i (led i x) + let H := ∏ i,pr unif (P i) + have h0 := netFact_pos (f:=g) + unfold rackStation + rw [← on_unif, pr_on] + have hh : pr unif (fun x => bothPart (N:=N) Z x ∧ Q x) ≤ + pr unif (fun x => traced x R w ∧ Q x) := + pr_mono unif_law.nz (fun x h => ⟨hl x ((both_test ..).mp h.1).1,h.2⟩) + have hf := cross_flood R w he u hu P hp hd + refine le_trans (div_le_div₀ ((pr_nonneg unif_law.nz).trans hf) + (hh.trans hf) (inv_pos_of_pos h0) hn) ?_ + let K : ℝ := num (I×J)+1 + have hk : 0 ≤ K := by unfold K num; positivity + change bp (- (R.card:ℝ)) * K * H / (netFact g)⁻¹ ≤ (4:ℝ)^_ * _ * K * H + have hY : Y ⊆ E := Finset.filter_subset .. + have hy : (R.card:ℝ)+(Y.card:ℝ) = netSize g := by + rw [← rail_count]; exact_mod_cast Finset.card_sdiff_add_card_eq_card hY + have hY' : (Y.card:ℝ) ≤ num I * num J * num J := by exact_mod_cast inside_count g + unfold netFact + have hg : 0 ≤ H := Finset.prod_nonneg fun i _ => pr_nonneg unif_law.nz + calc _ = (4:ℝ)^Fintype.card G * bp (netSize g- (R.card:ℝ))*K*H := by + rw [div_eq_mul_inv,inv_inv,bp_sub,bp_neg]; ring + _ ≤ _ := by gcongr; linarith +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RepeatedQueryEnergy.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RepeatedQueryEnergy.lean index 1122fd963f4f6b33d421d50185722cbbd8966637..7aaab39ba97dd18aafd181ea32e32bd9b81fe00a 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RepeatedQueryEnergy.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RepeatedQueryEnergy.lean @@ -1,117 +1,117 @@ -import OAI.Combinatorics.HadwigerCounterexample.EmpiricalInformation - -namespace OAI - -/-! # Repeated Query Energy -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real -open scoped BigOperators -variable {A B C X J : Type} [Fintype A] [Fintype B] [Fintype X] [Fintype J] -variable [DecidableEq J] - -omit [Fintype B] in -theorem path_repeat {μ : Wgt A} {w : Wgt X} (f : A→ X→B) : - mixW μ (fun i => draws J (mapW w (f i))) = - mixW (draws J w) (fun x => mapW μ (fun i => f i ∘ x)) := by - classical - funext i - have h (j : A) : - draws J (mapW w (f j)) i=pr (draws J w) (fun x => f j ∘ x=i) := by - simp_rw [funext_iff] - exact Eq.symm (prodW_pr _ (fun l y => f j y=i l)) - simp_rw [mixW,h] - exact avg_avg .. - -theorem path_sub (w : Wgt X) (p : X→Prop) (f : X → Wgt A) - (hw : SubLaw w) (hf : ∀ i,IsLaw (f i)) : - SubLaw (mixW (subW w p) f) ∧ tot (mixW (subW w p) f)=pr w p := by - have hh : tot (mixW (subW w p) f)=pr w p := by - rw [mixW_tot]; simp_rw [(hf _).total,avg_const,mul_one,subW_tot] - exact ⟨⟨fun i => avg_nonneg (subLaw_sub hw p).nz (fun j => (hf j).nz i), - hh ▸ (pr_le_tot hw.nz).trans hw.total⟩,hh⟩ - -omit [Fintype A] in -theorem path_patch (w : Wgt X) (p : X→Prop) (f : X → Wgt A) : - ∀ i,mixW w f i=mixW (subW w p) f i+mixW (subW w (fun x=>¬ p x)) f i := by - intro i - unfold mixW subW avg - rw [←Finset.sum_add_distrib]; simp_rw [ind_not] - exact sum_congr rfl fun j _ => by ring - -set_option maxHeartbeats 1000000 in -theorem path_energy (μ : Wgt A) (w : Wgt X) (q : Wgt B) - (f : A → X→B) (hμ : IsLaw μ) (hw : IsLaw w) (hq : IsLaw q) - (h : ∀ i j,q (f i j)≠0) - (u : ℝ) (hu : 0≤u) (hp : ∀ i,q i ≠0 → bp (-u)≤q i) - (l : ℕ) (P : (Fin l→X)→ Prop) (r : ℝ) - (hr : pr (draws (Fin l) w) (fun x => ¬ P x)≤r) - (C : ℝ) (hc : 0≤C) - (hP : ∀ x,P x→ ∀ y,mapW μ (fun i => f i ∘ x) y ≤ bp C * draws (Fin l) q y) : - (l:ℝ)* avg μ (fun i => tension (mapW w (f i)) q) ≤ - num B*log (↑l+1)+(C+r*u*l+1)*log 2 := by - classical - let F (i : A) := mapW w (f i) - let W := draws (Fin l) w - let Q := draws (Fin l) q - let k (x : Fin l → X) := mapW μ (fun i => f i ∘ x) - let g := mixW (subW W P) k - let b := mixW (subW W (fun x => ¬ P x)) k - let V := mixW μ (fun i => draws (Fin l) (F i)) - have h0 : ∀ i, lsupp (F i) q := by - intro i j hj; obtain ⟨t,ht,rfl⟩ := lsupp_witness hj - exact h _ _ - have hF : ∀ i,IsLaw (F i) := fun i => mapW_law hw (f i) - have hV : IsLaw V := mixW_law hμ (fun i => draws_law (hF i)) - have hQ : IsLaw Q := draws_law hq - have hW : IsLaw W := draws_law hw - have hk : ∀ i,IsLaw (k i) := fun i => mapW_law hμ _ - have h1 := traj_charge (l:=l) μ F q hμ hF h0 - have h2 : ∀ i,V i=g i+b i := by unfold V F; rw [path_repeat]; exact path_patch W P k - have hg := path_sub W P k hW.sub hk - have hb := path_sub W (fun x => ¬ P x) k hW.sub hk - have h2L : 0 ≤ log (2:ℝ) := (Real.log_pos (by norm_num)).le - have h3 : tension g Q ≤ C*log 2 := by - have hz i : g i ≤ bp C*Q i := by - let c := bp C*Q i - have hc : 0≤c := mul_nonneg (bp_pos _).le (hQ.nz _) - have he (j) : ind (P j)*k j i ≤ c := by - by_cases h : P j - · rw [ind_one h,one_mul]; exact hP j h i - rw [ind_zero h,zero_mul]; exact hc - refine le_trans ?_ (hW.avg_le he) - simp only [g,mixW,subW,avg,mul_assoc]; rfl - refine (tension_le_cap hg.1.nz hQ.nz _ (bp_pos _) hz).trans ?_ - rw [log_bp] - exact (mul_le_mul_of_nonneg_right hg.1.total - (mul_nonneg hc h2L)).trans_eq (one_mul _) - have h4 : tension b Q ≤ r*(u*l*log 2) := by - have hz (i : Fin l → B) : b i ≤ bp (u*l)*Q i := by - by_cases he : Q i=0 - · have ht (j) : k j i=0 := by - by_contra h - obtain ⟨z,hz,rfl⟩ := lsupp_witness h - have ht : Q (f z ∘ j) ≠ 0 := by - change ∏ i:Fin l,q (f z (j i)) ≠0 - rw [Finset.prod_ne_zero_iff]; exact fun i _ => ‹∀ i j,q (f i j)≠0› _ _ - exact ht he - unfold b mixW; simp_rw [ht]; rw [he,avg_zero,mul_zero] - have hq := traj_cap q hq u hp i he - refine (hb.1.weight_le_one i).trans ?_ - exact (le_of_eq (by rw [←bp_add,show u*l+ -u*l = 0 by ring,bp_zero])).trans - (mul_le_mul_of_nonneg_left hq (bp_pos _).le) - refine (tension_le_cap hb.1.nz hQ.nz _ (bp_pos _) hz).trans ?_ - rw [log_bp] - exact mul_le_mul_of_nonneg_right (hb.2.le.trans hr) - (by apply mul_nonneg (by positivity) h2L) - apply h1.trans - refine add_le_add_right ?_ _ - have h5 := tension_add_le V g b Q h2 hg.1.nz hb.1.nz - rw [hV.total] at h5 - linarith only [h5,h4,h3] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.EmpiricalInformation + +namespace OAI + +/-! # Repeated Query Energy -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real +open scoped BigOperators +variable {A B C X J : Type} [Fintype A] [Fintype B] [Fintype X] [Fintype J] +variable [DecidableEq J] + +omit [Fintype B] in +theorem path_repeat {μ : Wgt A} {w : Wgt X} (f : A→ X→B) : + mixW μ (fun i => draws J (mapW w (f i))) = + mixW (draws J w) (fun x => mapW μ (fun i => f i ∘ x)) := by + classical + funext i + have h (j : A) : + draws J (mapW w (f j)) i=pr (draws J w) (fun x => f j ∘ x=i) := by + simp_rw [funext_iff] + exact Eq.symm (prodW_pr _ (fun l y => f j y=i l)) + simp_rw [mixW,h] + exact avg_avg .. + +theorem path_sub (w : Wgt X) (p : X→Prop) (f : X → Wgt A) + (hw : SubLaw w) (hf : ∀ i,IsLaw (f i)) : + SubLaw (mixW (subW w p) f) ∧ tot (mixW (subW w p) f)=pr w p := by + have hh : tot (mixW (subW w p) f)=pr w p := by + rw [mixW_tot]; simp_rw [(hf _).total,avg_const,mul_one,subW_tot] + exact ⟨⟨fun i => avg_nonneg (subLaw_sub hw p).nz (fun j => (hf j).nz i), + hh ▸ (pr_le_tot hw.nz).trans hw.total⟩,hh⟩ + +omit [Fintype A] in +theorem path_patch (w : Wgt X) (p : X→Prop) (f : X → Wgt A) : + ∀ i,mixW w f i=mixW (subW w p) f i+mixW (subW w (fun x=>¬ p x)) f i := by + intro i + unfold mixW subW avg + rw [←Finset.sum_add_distrib]; simp_rw [ind_not] + exact sum_congr rfl fun j _ => by ring + +set_option maxHeartbeats 1000000 in +theorem path_energy (μ : Wgt A) (w : Wgt X) (q : Wgt B) + (f : A → X→B) (hμ : IsLaw μ) (hw : IsLaw w) (hq : IsLaw q) + (h : ∀ i j,q (f i j)≠0) + (u : ℝ) (hu : 0≤u) (hp : ∀ i,q i ≠0 → bp (-u)≤q i) + (l : ℕ) (P : (Fin l→X)→ Prop) (r : ℝ) + (hr : pr (draws (Fin l) w) (fun x => ¬ P x)≤r) + (C : ℝ) (hc : 0≤C) + (hP : ∀ x,P x→ ∀ y,mapW μ (fun i => f i ∘ x) y ≤ bp C * draws (Fin l) q y) : + (l:ℝ)* avg μ (fun i => tension (mapW w (f i)) q) ≤ + num B*log (↑l+1)+(C+r*u*l+1)*log 2 := by + classical + let F (i : A) := mapW w (f i) + let W := draws (Fin l) w + let Q := draws (Fin l) q + let k (x : Fin l → X) := mapW μ (fun i => f i ∘ x) + let g := mixW (subW W P) k + let b := mixW (subW W (fun x => ¬ P x)) k + let V := mixW μ (fun i => draws (Fin l) (F i)) + have h0 : ∀ i, lsupp (F i) q := by + intro i j hj; obtain ⟨t,ht,rfl⟩ := lsupp_witness hj + exact h _ _ + have hF : ∀ i,IsLaw (F i) := fun i => mapW_law hw (f i) + have hV : IsLaw V := mixW_law hμ (fun i => draws_law (hF i)) + have hQ : IsLaw Q := draws_law hq + have hW : IsLaw W := draws_law hw + have hk : ∀ i,IsLaw (k i) := fun i => mapW_law hμ _ + have h1 := traj_charge (l:=l) μ F q hμ hF h0 + have h2 : ∀ i,V i=g i+b i := by unfold V F; rw [path_repeat]; exact path_patch W P k + have hg := path_sub W P k hW.sub hk + have hb := path_sub W (fun x => ¬ P x) k hW.sub hk + have h2L : 0 ≤ log (2:ℝ) := (Real.log_pos (by norm_num)).le + have h3 : tension g Q ≤ C*log 2 := by + have hz i : g i ≤ bp C*Q i := by + let c := bp C*Q i + have hc : 0≤c := mul_nonneg (bp_pos _).le (hQ.nz _) + have he (j) : ind (P j)*k j i ≤ c := by + by_cases h : P j + · rw [ind_one h,one_mul]; exact hP j h i + rw [ind_zero h,zero_mul]; exact hc + refine le_trans ?_ (hW.avg_le he) + simp only [g,mixW,subW,avg,mul_assoc]; rfl + refine (tension_le_cap hg.1.nz hQ.nz _ (bp_pos _) hz).trans ?_ + rw [log_bp] + exact (mul_le_mul_of_nonneg_right hg.1.total + (mul_nonneg hc h2L)).trans_eq (one_mul _) + have h4 : tension b Q ≤ r*(u*l*log 2) := by + have hz (i : Fin l → B) : b i ≤ bp (u*l)*Q i := by + by_cases he : Q i=0 + · have ht (j) : k j i=0 := by + by_contra h + obtain ⟨z,hz,rfl⟩ := lsupp_witness h + have ht : Q (f z ∘ j) ≠ 0 := by + change ∏ i:Fin l,q (f z (j i)) ≠0 + rw [Finset.prod_ne_zero_iff]; exact fun i _ => ‹∀ i j,q (f i j)≠0› _ _ + exact ht he + unfold b mixW; simp_rw [ht]; rw [he,avg_zero,mul_zero] + have hq := traj_cap q hq u hp i he + refine (hb.1.weight_le_one i).trans ?_ + exact (le_of_eq (by rw [←bp_add,show u*l+ -u*l = 0 by ring,bp_zero])).trans + (mul_le_mul_of_nonneg_left hq (bp_pos _).le) + refine (tension_le_cap hb.1.nz hQ.nz _ (bp_pos _) hz).trans ?_ + rw [log_bp] + exact mul_le_mul_of_nonneg_right (hb.2.le.trans hr) + (by apply mul_nonneg (by positivity) h2L) + apply h1.trans + refine add_le_add_right ?_ _ + have h5 := tension_add_le V g b Q h2 hg.1.nz hb.1.nz + rw [hV.total] at h5 + linarith only [h5,h4,h3] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ReservedLabels.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ReservedLabels.lean index 0b7bebcd183193ef90190f969a47f0a748b671c3..8cce2e8fe236705582e1cb09ef4f33f0b1355e04 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ReservedLabels.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ReservedLabels.lean @@ -1,122 +1,122 @@ -import OAI.Combinatorics.HadwigerCounterexample.FreshGeneratorCorrection - -namespace OAI - -/-! # Reserved Labels -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Submodule Function Finset -open scoped BigOperators -namespace StatusAnalysis -variable {I L : Type} [DecidableEq L] [DecidableEq I] {d e : ℕ} -open Club -set_option maxHeartbeats 600000 in -theorem fresh_single (C : Club I (Signal d e) L) {s : Straps L} {V} - (h : C.travels s 4 (view d e) V) (x : Signal d e) (hx : x∈V) : - ∃ p:Finset I,C.bundle p s∧ C.contents p=x∧1≤p.card∧p.card≤7 := by - classical - obtain ⟨hh,hC⟩:= C.travel_now h - let Q:= view d e - obtain ⟨i,hi,hI,_⟩:= C.yield_after s Q hC ∅ (by simp) (Q x) - let p : Finset I:= {i} - have hp := C.bundle_one s hi - have hr : C.travels (s⊔ C.addrs p) 3 Q V := C.travel_more h (C.addrs p) - (fun i=>card_image_le.trans (by unfold p; simp : p.card≤1)) (by norm_num) - obtain ⟨q,hq,hQ,hT⟩ := jump_two C hr (ker_two _) (x-C.writes i) (by - constructor - · exact Submodule.sub_mem _ hx (hh ▸ C.band_write s hi) - change Q (x-C.writes i)=0 - rw [map_sub,hI,sub_self]) - obtain ⟨ha,hb⟩:= C.bundle_combine hp hq - refine ⟨p∪q,ha,?_,?_,(card_union_le ..).trans ?_⟩ - · change ∑ j∈p∪q,_=_ - rw [sum_union hb, ←show C.contents q=(∑ j∈q,_) from rfl, hT] - simp only [sum_singleton,add_sub_cancel] - · exact card_pos.mpr ⟨i, mem_union_left _ (by simp [p])⟩ - simp only [p,card_singleton] - omega - -variable {I : Grid → Type} [∀ i,DecidableEq (I i)] {A B : Rates} -abbrev Congress (I : Grid→Type) (A B : Rates) (L : Type) := ∀ i,Club (I i) (Suite A B i) L -namespace Guild -variable (C : Congress I A B L) -def chapter (s : Straps L) : StatusSp A B := fun i=> (C i).band s -def excess (s : Straps L) := ∑ i:Grid,overage (chapter C s i) - -omit [DecidableEq L] [∀ i,DecidableEq (I i)] in -theorem excess_bound (s : Straps L) : excess C s ≤8 := by - unfold excess - exact (Finset.sum_le_sum (g:=fun _=>2) (fun i _=>overage_two - (chapter C s i))).trans_eq (by norm_num [Grid,Nodes]) - -omit [DecidableEq L] [∀ i,DecidableEq (I i)] in -theorem chapter_mono {s t : Straps L} (h : s≤t) (i) : - chapter C t i ≤ chapter C s i := span_mono (fun _ ⟨a,ht,hx⟩=> - ⟨a,(C i).zone_smaller h a ht,hx⟩) - -def rich (C : Congress I A B L) := - ∀ i:Grid,∀ s:Straps L,sizeB s 902 → ∀ y:View (A i.1) (B i.2),∃ j, - (C i).zone s j ∧ view _ _ ((C i).writes j)=y - -omit [DecidableEq L] [∀ i,DecidableEq (I i)] in -theorem rich_covers (h : rich C) (s : Straps L) (hs : sizeB s 902) (i) : - coverBase (chapter C s i) := by - intro y - obtain ⟨j,hj,hy⟩:=h i s hs y - exact ⟨⟨_, (C i).band_write s hj⟩,hy⟩ - -set_option maxHeartbeats 800000 in -omit [∀ i,DecidableEq (I i)] in -theorem stable (h : rich C) : - ∃ s:Straps L,sizeB s 800 ∧ - ∀ i:Grid,(C i).travels s 100 (view _ _) (chapter C s i) := by - classical - have hh (k : ℕ) (hk : k≤ 8) (t : Straps L) - (ht : sizeB t ((8-k)*100)) (hb : excess C t≤ k) : - ∃ s:Straps L,sizeB s 800 ∧ - ∀ i:Grid,(C i).travels s 100 (view _ _) (chapter C s i) := by - induction k generalizing t with - | zero => - refine ⟨t,ht,fun i u hu=>?_⟩ - let v:=t⊔u - have he : sizeB v 900:= fun i=> (card_union_le ..).trans (Nat.add_le_add (ht i) (hu i)) - constructor - · change chapter C v i=chapter C t i - have hm (i:Grid) : overage (chapter C t i)=0 := by - have hy : overage (chapter C t i) ≤ 0 := le_trans (Finset.single_le_sum (s:=Finset.univ) - (fun i _=>Nat.zero_le (overage (chapter C t i))) (Finset.mem_univ i)) hb - exact Nat.eq_zero_of_le_zero hy - exact eq_of_le_of_not_lt (chapter_mono C le_sup_left i) (fun hx=> Nat.not_lt_zero _ - ((overage_lt hx (rich_covers C h v (fun i=> (he i).trans (by decide)) i)).trans_eq (hm i))) - intro w hw y - exact h i (v⊔w) (fun i=> (card_union_le ..).trans (Nat.add_le_add (he i) (hw i))) y - | succ k ih => - have hT : sizeB t 800 := fun i=> (ht i).trans (by omega) - by_cases hE : ∃ (s:Straps L), sizeB s 100∧∃ i:Grid, chapter C (t⊔s) i < chapter C t i - · obtain ⟨u,hu,i,hU⟩:=hE - let s:=t⊔u - have he : sizeB s ((8-k)*100):= fun i=> (card_union_le ..).trans - ((Nat.add_le_add (ht i) (hu i)).trans (by omega)) - refine ih (by omega) s he ?_ - have hS : excess C s < excess C t := by - unfold excess - have h1 := overage_lt hU (rich_covers C h s (fun i=> (he i).trans (by omega)) i) - exact Finset.sum_lt_sum (fun i _=> overage_mono (chapter_mono C le_sup_left i)) - ⟨i,mem_univ _,h1⟩ - omega - refine ⟨t,hT,fun i u hu=>?_⟩ - constructor - · exact eq_of_le_of_not_lt (chapter_mono C (s:=t) (t:=t⊔u) le_sup_left i) (fun hx => - hE ⟨u,hu,i,hx⟩) - intro w hw y - have he : sizeB (t⊔u) 900:= fun i=> (card_union_le ..).trans (Nat.add_le_add (hT i) (hu i)) - exact h i ((t⊔u)⊔w) (fun i=> (card_union_le ..).trans (Nat.add_le_add (he i) (hw i))) y - exact hh 8 (Nat.le_refl _) ⊥ (by intro i; change (∅:Finset L).card ≤_; simp) (excess_bound C _) -end Guild -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FreshGeneratorCorrection + +namespace OAI + +/-! # Reserved Labels -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Submodule Function Finset +open scoped BigOperators +namespace StatusAnalysis +variable {I L : Type} [DecidableEq L] [DecidableEq I] {d e : ℕ} +open Club +set_option maxHeartbeats 600000 in +theorem fresh_single (C : Club I (Signal d e) L) {s : Straps L} {V} + (h : C.travels s 4 (view d e) V) (x : Signal d e) (hx : x∈V) : + ∃ p:Finset I,C.bundle p s∧ C.contents p=x∧1≤p.card∧p.card≤7 := by + classical + obtain ⟨hh,hC⟩:= C.travel_now h + let Q:= view d e + obtain ⟨i,hi,hI,_⟩:= C.yield_after s Q hC ∅ (by simp) (Q x) + let p : Finset I:= {i} + have hp := C.bundle_one s hi + have hr : C.travels (s⊔ C.addrs p) 3 Q V := C.travel_more h (C.addrs p) + (fun i=>card_image_le.trans (by unfold p; simp : p.card≤1)) (by norm_num) + obtain ⟨q,hq,hQ,hT⟩ := jump_two C hr (ker_two _) (x-C.writes i) (by + constructor + · exact Submodule.sub_mem _ hx (hh ▸ C.band_write s hi) + change Q (x-C.writes i)=0 + rw [map_sub,hI,sub_self]) + obtain ⟨ha,hb⟩:= C.bundle_combine hp hq + refine ⟨p∪q,ha,?_,?_,(card_union_le ..).trans ?_⟩ + · change ∑ j∈p∪q,_=_ + rw [sum_union hb, ←show C.contents q=(∑ j∈q,_) from rfl, hT] + simp only [sum_singleton,add_sub_cancel] + · exact card_pos.mpr ⟨i, mem_union_left _ (by simp [p])⟩ + simp only [p,card_singleton] + omega + +variable {I : Grid → Type} [∀ i,DecidableEq (I i)] {A B : Rates} +abbrev Congress (I : Grid→Type) (A B : Rates) (L : Type) := ∀ i,Club (I i) (Suite A B i) L +namespace Guild +variable (C : Congress I A B L) +def chapter (s : Straps L) : StatusSp A B := fun i=> (C i).band s +def excess (s : Straps L) := ∑ i:Grid,overage (chapter C s i) + +omit [DecidableEq L] [∀ i,DecidableEq (I i)] in +theorem excess_bound (s : Straps L) : excess C s ≤8 := by + unfold excess + exact (Finset.sum_le_sum (g:=fun _=>2) (fun i _=>overage_two + (chapter C s i))).trans_eq (by norm_num [Grid,Nodes]) + +omit [DecidableEq L] [∀ i,DecidableEq (I i)] in +theorem chapter_mono {s t : Straps L} (h : s≤t) (i) : + chapter C t i ≤ chapter C s i := span_mono (fun _ ⟨a,ht,hx⟩=> + ⟨a,(C i).zone_smaller h a ht,hx⟩) + +def rich (C : Congress I A B L) := + ∀ i:Grid,∀ s:Straps L,sizeB s 902 → ∀ y:View (A i.1) (B i.2),∃ j, + (C i).zone s j ∧ view _ _ ((C i).writes j)=y + +omit [DecidableEq L] [∀ i,DecidableEq (I i)] in +theorem rich_covers (h : rich C) (s : Straps L) (hs : sizeB s 902) (i) : + coverBase (chapter C s i) := by + intro y + obtain ⟨j,hj,hy⟩:=h i s hs y + exact ⟨⟨_, (C i).band_write s hj⟩,hy⟩ + +set_option maxHeartbeats 800000 in +omit [∀ i,DecidableEq (I i)] in +theorem stable (h : rich C) : + ∃ s:Straps L,sizeB s 800 ∧ + ∀ i:Grid,(C i).travels s 100 (view _ _) (chapter C s i) := by + classical + have hh (k : ℕ) (hk : k≤ 8) (t : Straps L) + (ht : sizeB t ((8-k)*100)) (hb : excess C t≤ k) : + ∃ s:Straps L,sizeB s 800 ∧ + ∀ i:Grid,(C i).travels s 100 (view _ _) (chapter C s i) := by + induction k generalizing t with + | zero => + refine ⟨t,ht,fun i u hu=>?_⟩ + let v:=t⊔u + have he : sizeB v 900:= fun i=> (card_union_le ..).trans (Nat.add_le_add (ht i) (hu i)) + constructor + · change chapter C v i=chapter C t i + have hm (i:Grid) : overage (chapter C t i)=0 := by + have hy : overage (chapter C t i) ≤ 0 := le_trans (Finset.single_le_sum (s:=Finset.univ) + (fun i _=>Nat.zero_le (overage (chapter C t i))) (Finset.mem_univ i)) hb + exact Nat.eq_zero_of_le_zero hy + exact eq_of_le_of_not_lt (chapter_mono C le_sup_left i) (fun hx=> Nat.not_lt_zero _ + ((overage_lt hx (rich_covers C h v (fun i=> (he i).trans (by decide)) i)).trans_eq (hm i))) + intro w hw y + exact h i (v⊔w) (fun i=> (card_union_le ..).trans (Nat.add_le_add (he i) (hw i))) y + | succ k ih => + have hT : sizeB t 800 := fun i=> (ht i).trans (by omega) + by_cases hE : ∃ (s:Straps L), sizeB s 100∧∃ i:Grid, chapter C (t⊔s) i < chapter C t i + · obtain ⟨u,hu,i,hU⟩:=hE + let s:=t⊔u + have he : sizeB s ((8-k)*100):= fun i=> (card_union_le ..).trans + ((Nat.add_le_add (ht i) (hu i)).trans (by omega)) + refine ih (by omega) s he ?_ + have hS : excess C s < excess C t := by + unfold excess + have h1 := overage_lt hU (rich_covers C h s (fun i=> (he i).trans (by omega)) i) + exact Finset.sum_lt_sum (fun i _=> overage_mono (chapter_mono C le_sup_left i)) + ⟨i,mem_univ _,h1⟩ + omega + refine ⟨t,hT,fun i u hu=>?_⟩ + constructor + · exact eq_of_le_of_not_lt (chapter_mono C (s:=t) (t:=t⊔u) le_sup_left i) (fun hx => + hE ⟨u,hu,i,hx⟩) + intro w hw y + have he : sizeB (t⊔u) 900:= fun i=> (card_union_le ..).trans (Nat.add_le_add (hT i) (hu i)) + exact h i ((t⊔u)⊔w) (fun i=> (card_union_le ..).trans (Nat.add_le_add (he i) (hw i))) y + exact hh 8 (Nat.le_refl _) ⊥ (by intro i; change (∅:Finset L).card ≤_; simp) (excess_bound C _) +end Guild +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ResidualCutPairs.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ResidualCutPairs.lean index 159fa8cca92f57f933a7b0ff0bec23079ba726b5..4645773e0d1e7b500b21a8ef5184a8aa295bd63b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ResidualCutPairs.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ResidualCutPairs.lean @@ -1,202 +1,202 @@ -import OAI.Combinatorics.HadwigerCounterexample.AttackCutDecomposition - -namespace OAI - -/-! # Residual Cut Pairs -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix LinearMap Submodule Module Finset -variable {p : Shape} {n : ℕ} {I : Type} [Fintype I] -namespace Volley - -def CleanRay (v : Volley p n I) (i : Bool) (R : ℕ) (x : Ray p n) := - ∃ (L : Finset (Label p.b)) (u : LabVals p n), x=labcomb p n L u ∧ L.card≤R ∧ - Disjoint L (v.marked i) - -variable {v : Volley p n I} -private theorem clean_apply {i : Bool} {R : ℕ} {M : Moment p n} (h : v.clean i R M) (x : Ray p n) : - v.CleanRay i R (M *ᵥ x) := by - classical - obtain ⟨L,Z,rfl,hL,ht⟩ := h - refine ⟨L,(fun s => Z s *ᵥ ((labMat p n s)ᵀ *ᵥ x)),?_,hL,ht⟩ - rw [labcomb_eval,labelSum,Matrix.sum_mulVec] - refine Finset.sum_congr rfl fun i _ => ?_ - simp only [mput,liftM_def,←Matrix.mulVec_mulVec] - rw [labMat_act] - -private theorem clean_zero (v : Volley p n I) (i : Bool) (R : ℕ) : - v.CleanRay i R 0 := - ⟨∅,0,(map_zero _).symm,by simp,by simp⟩ - -/-- Key coefficients cannot contribute to a short nonattack primal -combination even if only the primal projection is specified. -/ -private theorem clean_proj {w : I → Bool} {a : Plan p n} (t : Tagging p I) {R q : ℕ} - (hb : v.bounded w) (hv : v.avoids a q) (hr : R+14 ≤ q) - (x : Ray p n) (z : Place p) (i : Bool) (hx : v.CleanRay i R x) - (b : Vec (visits p t z.1)) (he : x-(IP p n i)ᵀ *ᵥ (v.keyM t z.1 *ᵥ b) ∈ sPin a z i) : - ∀ j∈v.visitH t i z.1,b j = 0 := by - classical - let K := v.visitH t i z.1 - obtain ⟨B,hB,hE,hG,hsel⟩ := hv i - obtain ⟨L,u,hx,hL,hdis⟩ := hx - let s (j : visits p t z.1) := v.sel j.val - let T := K.image s - have hk (i' : visits p t z.1) (h : i'∈K) : i'.val∈v.here i := - (v.visitH_here ..).mp h - have hs : Set.InjOn s (K : Set _) := by - intro x hx y hy h - exact Subtype.ext (hsel (hk _ hx) (hk _ hy) h) - obtain ⟨y,hy,hZ⟩ := point_comb K s (v.par ∘ Subtype.val) b hs - rw [key_proj] at he - let r : LabVals p n := withinL p L u - withinL p T y - have h : labcomb p n (L∪T) r∈sPin a z i := by - rw [show r =_ - _ from rfl,map_sub,← within_eq subset_union_left u, - ← within_eq subset_union_right y,← hx, show labcomb p n T y =_ from hZ.symm] - exact he - have hh : (L∪T).card≤q := - (Finset.card_union_le ..).trans ((Nat.add_le_add hL (Finset.card_image_le.trans - (v.visitH_card hb t i z.1))).trans hr) - intro j hj - have hj' : s j ∈ T := mem_image_of_mem s hj - have hj'' : s j ∉ L := fun hh => Finset.disjoint_left.mp hdis hh - (mem_image_of_mem _ (hk j hj)) - have hy' := hB z (L∪T) r h hh _ (mem_union_right _ hj') (hE _ (hk _ hj)) - unfold r withinL at hy' - simp only [Pi.sub_apply,ite_eq_right hj'',ite_eq_left hj',hy j hj,zero_sub,neg_eq_zero] at hy' - simpa only [Function.comp_apply,Pi.zero_apply,Pi.smul_apply,smul_eq_mul,baseV, - Option.elim',mul_one] using congr_fun hy' none - -private theorem clean_sPin {w : I → Bool} {a : Plan p n} (t : Tagging p I) {R q : ℕ} - (hb : v.bounded w) (hv : v.avoids a q) (hr : R+14 ≤ q) - (x : Ray p n) (z : Place p) (i : Bool) (hx : v.CleanRay i R x) - (hg : x∈sPin (v.frozen a t) z i) : - x∈sPin a z i := by - classical - rw [sPin_frozen,Submodule.mem_sup] at hg - obtain ⟨y,hy,q',⟨q',⟨b,rfl⟩,rfl⟩,hX⟩ := hg - have he : x - ((IP p n i)ᵀ *ᵥ (v.keyM t z.1 *ᵥ b))=y := by - rw [← hX]; exact add_sub_cancel_right _ _ - have h := clean_proj t hb hv hr x z i hx b (he ▸ hy) - rw [key_proj,Finset.sum_eq_zero (fun j hj => by rw [h j hj,zero_smul]),sub_zero] at he - rwa [he] - -private theorem clean_Pin {w : I→Bool} {a : Plan p n} (t : Tagging p I) - {R q : ℕ} (hb : v.bounded w) (hv : v.avoids a q) (hr : R+14 ≤ q) - (x : Ray p n) (z : Place p) (i : Bool) (hx : v.CleanRay i R x) - (hg : IP p n i *ᵥ x ∈ v.frozen a t z) : - IP p n i *ᵥ x∈a z := by - classical - obtain ⟨d,hd,q',⟨b,rfl⟩,hX⟩ := Submodule.mem_sup.mp - (show IP p n i *ᵥ x∈a z ⊔ v.keyPlan t z from hg) - let f (k : Bool) := (IP p n k)ᵀ - have hzero : b=0 := by - funext j - let k := v.obj j.val - let x' := f k *ᵥ (IP p n i *ᵥ x) - have h : x' - ((IP p n k)ᵀ *ᵥ (v.keyM t z.1 *ᵥ b))∈sPin a z k := by - unfold x' - rw [← hX,Matrix.mulVec_add] - change f k *ᵥ d + _ - f k *ᵥ (_ *ᵥ _) ∈ _ - rw [mulVecLin_apply,add_sub_cancel_right] - exact ⟨d,hd,rfl⟩ - have h' : v.CleanRay k R x' := by - unfold x' f; rw [Matrix.mulVec_mulVec] - by_cases h : k=i - · rw [h,IP_self,Matrix.one_mulVec] - exact hx - rw [IP_cross h,Matrix.zero_mulVec]; exact clean_zero v k R - exact clean_proj t hb hv hr x' z k h' b h j (mem_filter.mpr ⟨mem_univ _,rfl⟩) - rw [hzero,map_zero,add_zero] at hX - rwa [← hX] - -end Volley - -theorem orth_delta_probe {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) - (hφ : φ∈annih (sPin f (flipZ p z) i)) : - C z *ᵥ (IP p n i *ᵥ ((x i).val z.1 *ᵥ φ)) ∈ hPin b z j := by - classical - rw [← annih_annih (hPin b z j), annih_mem] - intro y hy - rw [← pure_ip] - let Q := IP p n i *ᵥ φ - have hQ := (ip_annih ..).mpr hφ - let D : ChanOut p n := Pi.single (flipZ p z) (vecMulVec y Q) - have hD : D∈deltaSpace p f b j := by - refine (deltaSpace_mem _).mpr (fun z' => ?_) - by_cases hz : z'=flipZ p z - · subst z' - unfold D; rw [Pi.single_eq_same,flipZ_flip] - exact outer_in_box y Q hy hQ - simp [D,hz] - have hg := h D hD 0 (Submodule.zero_mem _) - change ∑ i, mpair ((chanDeriv p C D+0) i) (purePair p n x i) = _ at hg - rw [add_zero,Finset.sum_eq_single z.1] at hg - · let T := (C z)ᵀ * vecMulVec y Q - let X := purePair p n x z.1 - have hh : mpair T X = dotProduct (C z *ᵥ (X *ᵥ Q)) y := by - unfold T; rw [mul_vecMulVec,mpair_comm,mpair_outer,evmat] - rw [dotProduct_comm, dotProduct_transpose_mulVec,dotProduct_comm] - change dotProduct (C z *ᵥ (X *ᵥ Q)) y = _ - rw [← hh] - have hZ : z≠flipZ p z := by cases z with | mk e c => cases c <;> simp [flipZ] - have h1 : D z=0 := Pi.single_eq_of_ne hZ _ - have h2 : D (flipZ p z)=vecMulVec y Q := Pi.single_eq_same _ _ - rcases z with ⟨e,c|c⟩ - · change mpair ((C (e,true))ᵀ * D (e,false)+(D (e,true))ᵀ * C (e,false)) X=0 at hg - change D (e,true)=_ at h2 - rw [h1,h2,Matrix.mul_zero,zero_add,transpose_vecMulVec,vecMulVec_mul] at hg - unfold T; rw [mul_vecMulVec, Matrix.mulVec_transpose,mpair_comm,mpair_outer, - ←evmat_transpose, show Xᵀ=X from purePair_sym x e] - rw [mpair_comm,mpair_outer] at hg - exact hg - change mpair ((C (e,true))ᵀ * D (e,false)+(D (e,true))ᵀ * C (e,false)) X=0 at hg - change D (e,false)=_ at h2 - rw [h1,Matrix.transpose_zero,Matrix.zero_mul,add_zero,h2] at hg - exact hg - · intro k _ hk - have h1 (i : Bool) : D (k,i)=0 := Pi.single_eq_of_ne (show (_,_)≠flipZ p z from - fun hh => hk (congrArg Prod.fst hh)) _ - simp only [chanDeriv,chanInner,Pi.add_apply,h1,Matrix.transpose_zero,Matrix.mul_zero, - Matrix.zero_mul,zero_add] - rw [mpair_comm,map_zero] - simp - -namespace Volley -variable {v : Volley p n I} -theorem clean_effective {w : I→Bool} {a b : Plan p n} (t : Tagging p I) - {q R : ℕ} (hb : v.bounded w) (hv : v.avoids a q) (hr : R+14≤q) - {j : Bool} (M : Cross p n) (x : Xpair p n) - (hh : orth p (channelOut p M j) (v.frozen a t) b j x) - (hg : tableInj a b M) (i : Bool) (hx : ∀ e,v.clean i R ((x i).val e)) : - (x i).val∈effective a i := by - classical - refine effective_mem.mpr ⟨(x i).property,fun e => ?_⟩ - let A := (x i).val e - let S (z) := sPin (v.frozen a t) (e,z) i - have hd (c : Bool) (φ : Ray p n) (hφ : φ∈annih (S (!c))) : A *ᵥ φ=0 := by - have hray := clean_apply (hx e) φ - have hm := orth_ip_frozen hh i (e,c) φ hφ - exact hg (e,c) i j (A *ᵥ φ) (clean_Pin t hb hv hr _ _ i hray hm) - (orth_delta_probe hh i (e,c) φ hφ) - have hsym : Aᵀ=A := orth_pair_sym x e i - have h (c : Bool) : colSp A ≤ sPin a (e,c) i := by - have hh' : colSp A ≤ S c := by - have hf : colSp A ≤ annih (annih (S c)) := (colSp_kill ..).mpr (fun φ hφ => by - rw [hsym] - exact hd (!c) φ (by simpa using hφ)) - rwa [annih_annih] at hf - rintro x' ⟨y,rfl⟩ - exact clean_sPin t hb hv hr _ _ i (clean_apply (hx e) y) (hh' ⟨y,rfl⟩) - change A∈box _ _ - rw [box_mem,hsym] - exact ⟨h _,h _⟩ - -end Volley -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.AttackCutDecomposition + +namespace OAI + +/-! # Residual Cut Pairs -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix LinearMap Submodule Module Finset +variable {p : Shape} {n : ℕ} {I : Type} [Fintype I] +namespace Volley + +def CleanRay (v : Volley p n I) (i : Bool) (R : ℕ) (x : Ray p n) := + ∃ (L : Finset (Label p.b)) (u : LabVals p n), x=labcomb p n L u ∧ L.card≤R ∧ + Disjoint L (v.marked i) + +variable {v : Volley p n I} +private theorem clean_apply {i : Bool} {R : ℕ} {M : Moment p n} (h : v.clean i R M) (x : Ray p n) : + v.CleanRay i R (M *ᵥ x) := by + classical + obtain ⟨L,Z,rfl,hL,ht⟩ := h + refine ⟨L,(fun s => Z s *ᵥ ((labMat p n s)ᵀ *ᵥ x)),?_,hL,ht⟩ + rw [labcomb_eval,labelSum,Matrix.sum_mulVec] + refine Finset.sum_congr rfl fun i _ => ?_ + simp only [mput,liftM_def,←Matrix.mulVec_mulVec] + rw [labMat_act] + +private theorem clean_zero (v : Volley p n I) (i : Bool) (R : ℕ) : + v.CleanRay i R 0 := + ⟨∅,0,(map_zero _).symm,by simp,by simp⟩ + +/-- Key coefficients cannot contribute to a short nonattack primal +combination even if only the primal projection is specified. -/ +private theorem clean_proj {w : I → Bool} {a : Plan p n} (t : Tagging p I) {R q : ℕ} + (hb : v.bounded w) (hv : v.avoids a q) (hr : R+14 ≤ q) + (x : Ray p n) (z : Place p) (i : Bool) (hx : v.CleanRay i R x) + (b : Vec (visits p t z.1)) (he : x-(IP p n i)ᵀ *ᵥ (v.keyM t z.1 *ᵥ b) ∈ sPin a z i) : + ∀ j∈v.visitH t i z.1,b j = 0 := by + classical + let K := v.visitH t i z.1 + obtain ⟨B,hB,hE,hG,hsel⟩ := hv i + obtain ⟨L,u,hx,hL,hdis⟩ := hx + let s (j : visits p t z.1) := v.sel j.val + let T := K.image s + have hk (i' : visits p t z.1) (h : i'∈K) : i'.val∈v.here i := + (v.visitH_here ..).mp h + have hs : Set.InjOn s (K : Set _) := by + intro x hx y hy h + exact Subtype.ext (hsel (hk _ hx) (hk _ hy) h) + obtain ⟨y,hy,hZ⟩ := point_comb K s (v.par ∘ Subtype.val) b hs + rw [key_proj] at he + let r : LabVals p n := withinL p L u - withinL p T y + have h : labcomb p n (L∪T) r∈sPin a z i := by + rw [show r =_ - _ from rfl,map_sub,← within_eq subset_union_left u, + ← within_eq subset_union_right y,← hx, show labcomb p n T y =_ from hZ.symm] + exact he + have hh : (L∪T).card≤q := + (Finset.card_union_le ..).trans ((Nat.add_le_add hL (Finset.card_image_le.trans + (v.visitH_card hb t i z.1))).trans hr) + intro j hj + have hj' : s j ∈ T := mem_image_of_mem s hj + have hj'' : s j ∉ L := fun hh => Finset.disjoint_left.mp hdis hh + (mem_image_of_mem _ (hk j hj)) + have hy' := hB z (L∪T) r h hh _ (mem_union_right _ hj') (hE _ (hk _ hj)) + unfold r withinL at hy' + simp only [Pi.sub_apply,ite_eq_right hj'',ite_eq_left hj',hy j hj,zero_sub,neg_eq_zero] at hy' + simpa only [Function.comp_apply,Pi.zero_apply,Pi.smul_apply,smul_eq_mul,baseV, + Option.elim',mul_one] using congr_fun hy' none + +private theorem clean_sPin {w : I → Bool} {a : Plan p n} (t : Tagging p I) {R q : ℕ} + (hb : v.bounded w) (hv : v.avoids a q) (hr : R+14 ≤ q) + (x : Ray p n) (z : Place p) (i : Bool) (hx : v.CleanRay i R x) + (hg : x∈sPin (v.frozen a t) z i) : + x∈sPin a z i := by + classical + rw [sPin_frozen,Submodule.mem_sup] at hg + obtain ⟨y,hy,q',⟨q',⟨b,rfl⟩,rfl⟩,hX⟩ := hg + have he : x - ((IP p n i)ᵀ *ᵥ (v.keyM t z.1 *ᵥ b))=y := by + rw [← hX]; exact add_sub_cancel_right _ _ + have h := clean_proj t hb hv hr x z i hx b (he ▸ hy) + rw [key_proj,Finset.sum_eq_zero (fun j hj => by rw [h j hj,zero_smul]),sub_zero] at he + rwa [he] + +private theorem clean_Pin {w : I→Bool} {a : Plan p n} (t : Tagging p I) + {R q : ℕ} (hb : v.bounded w) (hv : v.avoids a q) (hr : R+14 ≤ q) + (x : Ray p n) (z : Place p) (i : Bool) (hx : v.CleanRay i R x) + (hg : IP p n i *ᵥ x ∈ v.frozen a t z) : + IP p n i *ᵥ x∈a z := by + classical + obtain ⟨d,hd,q',⟨b,rfl⟩,hX⟩ := Submodule.mem_sup.mp + (show IP p n i *ᵥ x∈a z ⊔ v.keyPlan t z from hg) + let f (k : Bool) := (IP p n k)ᵀ + have hzero : b=0 := by + funext j + let k := v.obj j.val + let x' := f k *ᵥ (IP p n i *ᵥ x) + have h : x' - ((IP p n k)ᵀ *ᵥ (v.keyM t z.1 *ᵥ b))∈sPin a z k := by + unfold x' + rw [← hX,Matrix.mulVec_add] + change f k *ᵥ d + _ - f k *ᵥ (_ *ᵥ _) ∈ _ + rw [mulVecLin_apply,add_sub_cancel_right] + exact ⟨d,hd,rfl⟩ + have h' : v.CleanRay k R x' := by + unfold x' f; rw [Matrix.mulVec_mulVec] + by_cases h : k=i + · rw [h,IP_self,Matrix.one_mulVec] + exact hx + rw [IP_cross h,Matrix.zero_mulVec]; exact clean_zero v k R + exact clean_proj t hb hv hr x' z k h' b h j (mem_filter.mpr ⟨mem_univ _,rfl⟩) + rw [hzero,map_zero,add_zero] at hX + rwa [← hX] + +end Volley + +theorem orth_delta_probe {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) + (hφ : φ∈annih (sPin f (flipZ p z) i)) : + C z *ᵥ (IP p n i *ᵥ ((x i).val z.1 *ᵥ φ)) ∈ hPin b z j := by + classical + rw [← annih_annih (hPin b z j), annih_mem] + intro y hy + rw [← pure_ip] + let Q := IP p n i *ᵥ φ + have hQ := (ip_annih ..).mpr hφ + let D : ChanOut p n := Pi.single (flipZ p z) (vecMulVec y Q) + have hD : D∈deltaSpace p f b j := by + refine (deltaSpace_mem _).mpr (fun z' => ?_) + by_cases hz : z'=flipZ p z + · subst z' + unfold D; rw [Pi.single_eq_same,flipZ_flip] + exact outer_in_box y Q hy hQ + simp [D,hz] + have hg := h D hD 0 (Submodule.zero_mem _) + change ∑ i, mpair ((chanDeriv p C D+0) i) (purePair p n x i) = _ at hg + rw [add_zero,Finset.sum_eq_single z.1] at hg + · let T := (C z)ᵀ * vecMulVec y Q + let X := purePair p n x z.1 + have hh : mpair T X = dotProduct (C z *ᵥ (X *ᵥ Q)) y := by + unfold T; rw [mul_vecMulVec,mpair_comm,mpair_outer,evmat] + rw [dotProduct_comm, dotProduct_transpose_mulVec,dotProduct_comm] + change dotProduct (C z *ᵥ (X *ᵥ Q)) y = _ + rw [← hh] + have hZ : z≠flipZ p z := by cases z with | mk e c => cases c <;> simp [flipZ] + have h1 : D z=0 := Pi.single_eq_of_ne hZ _ + have h2 : D (flipZ p z)=vecMulVec y Q := Pi.single_eq_same _ _ + rcases z with ⟨e,c|c⟩ + · change mpair ((C (e,true))ᵀ * D (e,false)+(D (e,true))ᵀ * C (e,false)) X=0 at hg + change D (e,true)=_ at h2 + rw [h1,h2,Matrix.mul_zero,zero_add,transpose_vecMulVec,vecMulVec_mul] at hg + unfold T; rw [mul_vecMulVec, Matrix.mulVec_transpose,mpair_comm,mpair_outer, + ←evmat_transpose, show Xᵀ=X from purePair_sym x e] + rw [mpair_comm,mpair_outer] at hg + exact hg + change mpair ((C (e,true))ᵀ * D (e,false)+(D (e,true))ᵀ * C (e,false)) X=0 at hg + change D (e,false)=_ at h2 + rw [h1,Matrix.transpose_zero,Matrix.zero_mul,add_zero,h2] at hg + exact hg + · intro k _ hk + have h1 (i : Bool) : D (k,i)=0 := Pi.single_eq_of_ne (show (_,_)≠flipZ p z from + fun hh => hk (congrArg Prod.fst hh)) _ + simp only [chanDeriv,chanInner,Pi.add_apply,h1,Matrix.transpose_zero,Matrix.mul_zero, + Matrix.zero_mul,zero_add] + rw [mpair_comm,map_zero] + simp + +namespace Volley +variable {v : Volley p n I} +theorem clean_effective {w : I→Bool} {a b : Plan p n} (t : Tagging p I) + {q R : ℕ} (hb : v.bounded w) (hv : v.avoids a q) (hr : R+14≤q) + {j : Bool} (M : Cross p n) (x : Xpair p n) + (hh : orth p (channelOut p M j) (v.frozen a t) b j x) + (hg : tableInj a b M) (i : Bool) (hx : ∀ e,v.clean i R ((x i).val e)) : + (x i).val∈effective a i := by + classical + refine effective_mem.mpr ⟨(x i).property,fun e => ?_⟩ + let A := (x i).val e + let S (z) := sPin (v.frozen a t) (e,z) i + have hd (c : Bool) (φ : Ray p n) (hφ : φ∈annih (S (!c))) : A *ᵥ φ=0 := by + have hray := clean_apply (hx e) φ + have hm := orth_ip_frozen hh i (e,c) φ hφ + exact hg (e,c) i j (A *ᵥ φ) (clean_Pin t hb hv hr _ _ i hray hm) + (orth_delta_probe hh i (e,c) φ hφ) + have hsym : Aᵀ=A := orth_pair_sym x e i + have h (c : Bool) : colSp A ≤ sPin a (e,c) i := by + have hh' : colSp A ≤ S c := by + have hf : colSp A ≤ annih (annih (S c)) := (colSp_kill ..).mpr (fun φ hφ => by + rw [hsym] + exact hd (!c) φ (by simpa using hφ)) + rwa [annih_annih] at hf + rintro x' ⟨y,rfl⟩ + exact clean_sPin t hb hv hr _ _ i (clean_apply (hx e) y) (hh' ⟨y,rfl⟩) + change A∈box _ _ + rw [box_mem,hsym] + exact ⟨h _,h _⟩ + +end Volley +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ResidualRegularity.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ResidualRegularity.lean index 1ea3173ddf357f55b4f859fe56a4d0f4d31ee5e8..8e5baac0275331bfb24d3021298fb131007455bb 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ResidualRegularity.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ResidualRegularity.lean @@ -1,107 +1,107 @@ -import OAI.Combinatorics.HadwigerCounterexample.RectangleRegularity - -namespace OAI - -/-! # Residual Regularity -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix LinearMap Function Filter Real -open scoped BigOperators -variable {A B I : Type} [Fintype A] [Fintype B] [Fintype I] - -def wanes (u : Wgt I) (w : Wgt A) (f : I→Wgt A) (p : A→B) (ε : ℝ) := - ∀ h : Wgt A,(∀ x,|h x| ≤ 1) → - avg u (fun i => |dip w (fun x=> f i x - banner w p (f i) x) h|) ≤ ε -def hits (u : Wgt I) (w : Wgt A) (f : I→ Wgt A) (p : A→ B) := - avg u (fun i => ode w (banner w p (f i))) - -private def twistSign (b : ℝ) := decide (0≤ b) -private theorem twistabs (b : ℝ) : b*swab (twistSign b)=|b| := by - classical by_cases h : 0≤b <;> simp [swab,twistSign,h,abs_of_nonneg,abs_of_neg,lt_of_not_ge] - -set_option maxHeartbeats 600000 in -theorem tilt_test (w : Wgt A) (u : Wgt I) (hu : ∀ i,0 ≤ u i) (f : I → Wgt A) (h : Wgt A) - (hh : ∀ x,|h x|≤1) : - ∃ p : A→Bool, avg u (fun i=>|dip w (f i) h|) ≤ avg u (fun i => |dip w (f i) (swab∘ p)|) := by - classical - let q (i:I) := swab (twistSign (dip w (f i) h)) - let V (x) := avg u (fun i=> f i x * q i) - have hx (h : Wgt A) : - avg u (fun i=> dip w (f i) h * q i)=dip w V h := by - unfold V dip; simp_rw [← avg_mul] - rw [avg_avg] - refine avg_congr fun i _=> avg_congr fun j _=>by ring - let p (x:A) := twistSign (w x*V x) - refine ⟨p,?_⟩ - have hV : dip w V h ≤ dip w V (swab ∘ p) := by - unfold dip avg; refine Finset.sum_le_sum fun i _=> ?_ - dsimp only [Function.comp_apply,p] - set t := w i*V i with ht - rw [←mul_assoc,←mul_assoc,←ht,twistabs] - refine (le_abs_self _).trans ?_ - rw [abs_mul] - exact (mul_le_mul_of_nonneg_left (hh _) (abs_nonneg _)).trans_eq (mul_one _) - have h0 i : - |dip w (f i) h|=dip w (f i) h*q i := (twistabs ..).symm - simp_rw [h0,hx]; rw [←hx (swab ∘ p)] at hV - apply le_trans hV - apply avg_mono hu - intro i - rw [← show |dip w (f i) (swab∘p)* q i|=|dip w (f i) (swab∘p)| by rw [abs_mul,swab_abs,mul_one]] - exact le_abs_self _ - -theorem mean_sq (u : Wgt I) (hu : IsLaw u) (f : Wgt I) : - avg u f ^ 2 ≤ avg u (fun i=> f i^2) := by - simpa only [mul_one,one_pow, hu.avg_const] using avg_CS hu.nz f (fun _=>1) - -set_option maxHeartbeats 800000 in -theorem erosive (M ε : ℝ) (hM : 0≤M) (hε : 0<ε) : - ∃ k:ℕ,∀ (A I : Type) [Fintype A] [Fintype I] - (u : Wgt I) (w : Wgt A) (f : I→Wgt A), - IsLaw u → IsLaw w → (∀ i j,|f i j|≤ M) → - ∃ l:ℕ,l≤ k∧∃ p:A→Fin l,wanes u w f p ε := by - classical - obtain ⟨n,hn⟩:=exists_nat_gt (M^2/ε^2) - rw [div_lt_iff₀ (by positivity)] at hn - refine ⟨2^n,fun A I _ _ u w f hu hw hf =>?_⟩ - by_contra! h - have hh (i:ℕ) (hi : i≤ n) : - ∃ p : A→ Fin (2^i),i*ε^2 ≤ hits u w f p := by - induction i with - | zero => exact ⟨fun _=>0,(by simp only [Nat.cast_zero,zero_mul,hits]; exact avg_nonneg hu.nz (fun i=>ode_nonneg hw.nz _))⟩ - | succ i ih => - obtain ⟨p,hp⟩:=ih (by omega) - obtain h := h (2^i) (Nat.pow_le_pow_right (by decide) (by omega)) p - let T (i:I) (x:A) := f i x-banner w p (f i) x - unfold wanes at h; push Not at h; obtain ⟨a,ha,h⟩:=h - obtain ⟨s,hs⟩:=tilt_test w u hu.nz T a ha - let q:= swab∘s - let e : (Fin (2^i) × Bool)≃ Fin (2^(i+1)) := Fintype.equivFinOfCardEq (by simp [pow_succ]) - let b x := e (p x,s x) - let P := Prod.fst ∘ e.symm; let Q:= swab ∘ Prod.snd ∘ e.symm - have hP : P∘b=p := by funext i; simp [P,b] - have hQ : Q∘b=q := by funext i; simp [q,Q,b] - have he x : ode w (banner w p (f x)) + dip w (T x) q ^2 ≤ ode w (banner w b (f x)) := by - have he := archive_gain hw.sub (f x) b P Q (fun i=>by unfold Q; simp [swab_abs]) - rw [hP,hQ] at he - change ode _ _+dip w (fun i=> f x i-banner w p (f x) i) q ^2≤_ - linarith only [he] - let V i:= |dip w (T i) q| - have hz : ε ≤ avg u V := h.le.trans hs - have hb := (pow_le_pow_left₀ hε.le hz 2).trans (mean_sq u hu V) - have hh := avg_mono hu.nz he - rw [avg_add] at hh - change hits u w f p + _ ≤ hits u w f b at hh - unfold V at hb; simp_rw [sq_abs] at hb - refine ⟨b,?_⟩ - push_cast; linarith only [hp,hb,hh] - obtain ⟨p,hp⟩ := hh n le_rfl - have h (i:I) : ∀ x:A,|banner w p (f i) x|≤ M := - fun i'=> cashbook_bound w hw.nz p _ _ hM (hf i) (p i') - exact not_lt_of_ge (hp.trans (hu.avg_le (fun i=> ode_upper hw.sub _ M (h i)))) hn -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RectangleRegularity + +namespace OAI + +/-! # Residual Regularity -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix LinearMap Function Filter Real +open scoped BigOperators +variable {A B I : Type} [Fintype A] [Fintype B] [Fintype I] + +def wanes (u : Wgt I) (w : Wgt A) (f : I→Wgt A) (p : A→B) (ε : ℝ) := + ∀ h : Wgt A,(∀ x,|h x| ≤ 1) → + avg u (fun i => |dip w (fun x=> f i x - banner w p (f i) x) h|) ≤ ε +def hits (u : Wgt I) (w : Wgt A) (f : I→ Wgt A) (p : A→ B) := + avg u (fun i => ode w (banner w p (f i))) + +private def twistSign (b : ℝ) := decide (0≤ b) +private theorem twistabs (b : ℝ) : b*swab (twistSign b)=|b| := by + classical by_cases h : 0≤b <;> simp [swab,twistSign,h,abs_of_nonneg,abs_of_neg,lt_of_not_ge] + +set_option maxHeartbeats 600000 in +theorem tilt_test (w : Wgt A) (u : Wgt I) (hu : ∀ i,0 ≤ u i) (f : I → Wgt A) (h : Wgt A) + (hh : ∀ x,|h x|≤1) : + ∃ p : A→Bool, avg u (fun i=>|dip w (f i) h|) ≤ avg u (fun i => |dip w (f i) (swab∘ p)|) := by + classical + let q (i:I) := swab (twistSign (dip w (f i) h)) + let V (x) := avg u (fun i=> f i x * q i) + have hx (h : Wgt A) : + avg u (fun i=> dip w (f i) h * q i)=dip w V h := by + unfold V dip; simp_rw [← avg_mul] + rw [avg_avg] + refine avg_congr fun i _=> avg_congr fun j _=>by ring + let p (x:A) := twistSign (w x*V x) + refine ⟨p,?_⟩ + have hV : dip w V h ≤ dip w V (swab ∘ p) := by + unfold dip avg; refine Finset.sum_le_sum fun i _=> ?_ + dsimp only [Function.comp_apply,p] + set t := w i*V i with ht + rw [←mul_assoc,←mul_assoc,←ht,twistabs] + refine (le_abs_self _).trans ?_ + rw [abs_mul] + exact (mul_le_mul_of_nonneg_left (hh _) (abs_nonneg _)).trans_eq (mul_one _) + have h0 i : + |dip w (f i) h|=dip w (f i) h*q i := (twistabs ..).symm + simp_rw [h0,hx]; rw [←hx (swab ∘ p)] at hV + apply le_trans hV + apply avg_mono hu + intro i + rw [← show |dip w (f i) (swab∘p)* q i|=|dip w (f i) (swab∘p)| by rw [abs_mul,swab_abs,mul_one]] + exact le_abs_self _ + +theorem mean_sq (u : Wgt I) (hu : IsLaw u) (f : Wgt I) : + avg u f ^ 2 ≤ avg u (fun i=> f i^2) := by + simpa only [mul_one,one_pow, hu.avg_const] using avg_CS hu.nz f (fun _=>1) + +set_option maxHeartbeats 800000 in +theorem erosive (M ε : ℝ) (hM : 0≤M) (hε : 0<ε) : + ∃ k:ℕ,∀ (A I : Type) [Fintype A] [Fintype I] + (u : Wgt I) (w : Wgt A) (f : I→Wgt A), + IsLaw u → IsLaw w → (∀ i j,|f i j|≤ M) → + ∃ l:ℕ,l≤ k∧∃ p:A→Fin l,wanes u w f p ε := by + classical + obtain ⟨n,hn⟩:=exists_nat_gt (M^2/ε^2) + rw [div_lt_iff₀ (by positivity)] at hn + refine ⟨2^n,fun A I _ _ u w f hu hw hf =>?_⟩ + by_contra! h + have hh (i:ℕ) (hi : i≤ n) : + ∃ p : A→ Fin (2^i),i*ε^2 ≤ hits u w f p := by + induction i with + | zero => exact ⟨fun _=>0,(by simp only [Nat.cast_zero,zero_mul,hits]; exact avg_nonneg hu.nz (fun i=>ode_nonneg hw.nz _))⟩ + | succ i ih => + obtain ⟨p,hp⟩:=ih (by omega) + obtain h := h (2^i) (Nat.pow_le_pow_right (by decide) (by omega)) p + let T (i:I) (x:A) := f i x-banner w p (f i) x + unfold wanes at h; push Not at h; obtain ⟨a,ha,h⟩:=h + obtain ⟨s,hs⟩:=tilt_test w u hu.nz T a ha + let q:= swab∘s + let e : (Fin (2^i) × Bool)≃ Fin (2^(i+1)) := Fintype.equivFinOfCardEq (by simp [pow_succ]) + let b x := e (p x,s x) + let P := Prod.fst ∘ e.symm; let Q:= swab ∘ Prod.snd ∘ e.symm + have hP : P∘b=p := by funext i; simp [P,b] + have hQ : Q∘b=q := by funext i; simp [q,Q,b] + have he x : ode w (banner w p (f x)) + dip w (T x) q ^2 ≤ ode w (banner w b (f x)) := by + have he := archive_gain hw.sub (f x) b P Q (fun i=>by unfold Q; simp [swab_abs]) + rw [hP,hQ] at he + change ode _ _+dip w (fun i=> f x i-banner w p (f x) i) q ^2≤_ + linarith only [he] + let V i:= |dip w (T i) q| + have hz : ε ≤ avg u V := h.le.trans hs + have hb := (pow_le_pow_left₀ hε.le hz 2).trans (mean_sq u hu V) + have hh := avg_mono hu.nz he + rw [avg_add] at hh + change hits u w f p + _ ≤ hits u w f b at hh + unfold V at hb; simp_rw [sq_abs] at hb + refine ⟨b,?_⟩ + push_cast; linarith only [hp,hb,hh] + obtain ⟨p,hp⟩ := hh n le_rfl + have h (i:I) : ∀ x:A,|banner w p (f i) x|≤ M := + fun i'=> cashbook_bound w hw.nz p _ _ hM (hf i) (p i') + exact not_lt_of_ge (hp.trans (hu.avg_le (fun i=> ode_upper hw.sub _ M (h i)))) hn +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ResponseAnnihilators.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ResponseAnnihilators.lean index 746c42017592395c2a65ef1f98f3804c70a8be3b..8d4cc8c2341dd0b9c2506eaf41833339a7c732ea 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ResponseAnnihilators.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ResponseAnnihilators.lean @@ -1,206 +1,206 @@ -import OAI.Combinatorics.HadwigerCounterexample.FrozenProjections - -namespace OAI - -/-! # Response Annihilators -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Finset LinearMap Submodule Module -open scoped BigOperators -variable {p : Shape} {n : ℕ} -variable {I : Type} [Fintype I] - -def dotL (x : Vec I) : Vec I →ₗ[F] F where - toFun y := dotProduct x y - map_add' u v := dotProduct_add x _ _ - map_smul' b u := by - simp only [dotProduct,Pi.smul_apply,RingHom.id_apply,smul_eq_mul,mul_sum,mul_left_comm] - -theorem dotL_surj (x : Vec I →ₗ[F] F) : ∃ y : Vec I,x=dotL y := by - classical - let y (i:I) := x (Pi.single i 1) - refine ⟨y,LinearMap.ext fun v => ?_⟩ - have he : x v=x (∑ i, Pi.single i (v i)) := by rw [Finset.univ_sum_single] - rw [he,map_sum] - change (∑ i,x (Pi.single i (v i)))=∑ i,y i*v i - refine Finset.sum_congr rfl fun i _ => ?_ - rw [show Pi.single i (v i)=v i • (Pi.single i 1 : Vec I) from (by - funext j - by_cases h : j = i - · simp [h] - simp [Pi.single_eq_of_ne h]), - map_smul] - exact mul_comm _ _ - -private theorem protection_test {S : Space (Ray p n)} {q} {E L : Finset (Label p.b)} - (h : protectedBy p S q E) {s} (hs : s∈L) (he : s∉E) (hl : L.card≤q) - (ψ : Vec (AIdx p.g n)) : - ∃ x ∈ annih S,∀ j∈L,(labMat p n j)ᵀ *ᵥ x= if j=s then ψ else 0 := by - classical - let P := S.subtype.coprod (labcomb p n L) - let Q := dotL ψ ∘ₗ LinearMap.proj s ∘ₗ (LinearMap.snd F S (LabVals p n)) - obtain ⟨f,hf⟩ : ∃ f,f ∘ₗ P=Q := by - refine HadwigerCounterexample.mem_range_comp (show LinearMap.ker P≤LinearMap.ker Q from ?_) - rintro ⟨w,z⟩ hw - change w.val + labcomb p n L z=0 at hw - have hb : labcomb p n L z ∈ S := by - rw [show labcomb p n L z=w.val from add_left_cancel (hw.trans (char_two w.val).symm)] - exact w.property - change dotProduct ψ (z s)=0 - rw [h L z hb hl s hs he,dotProduct_zero] - obtain ⟨x,rfl⟩ := dotL_surj f - refine ⟨x,?_,fun j hj => ?_⟩ - · rw [annih_mem]; intro y hy - have hh := LinearMap.congr_fun hf (⟨y,hy⟩,0) - change dotProduct x (y+labcomb p n L 0)=dotProduct ψ 0 at hh - rw [map_zero,add_zero,dotProduct_zero] at hh - exact hh - have h1 (z : Vec (AIdx p.g n)) : dotProduct z ((labMat p n j)ᵀ *ᵥ x)= - if j=s then dotProduct ψ z else 0 := by - let y : LabVals p n := Pi.single j z - have hh := LinearMap.congr_fun hf (0,y) - change dotProduct x (0+labcomb p n L y)=dotProduct ψ (y s) at hh - have hh' : labcomb p n L y = putLab p n j z := by - rw [labcomb_eval,Finset.sum_eq_single j] - · simp [y] - · intro k _ hk; simp [y,Pi.single_eq_of_ne hk] - simp [hj] - rw [dotProduct_transpose_mulVec,labMat_act] - rw [zero_add,hh'] at hh - rw [hh] - by_cases h : j = s - · simp [y,h] - simp [y,h] - funext i - have h2 := h1 (Pi.single i 1) - by_cases hh : j = s - · simpa only [hh,ite_true,dotProduct_single,single_dotProduct,mul_one,one_mul] using h2 - simpa only [ite_eq_right hh,Pi.zero_apply,single_dotProduct,one_mul] using h2 - -namespace Volley -variable {v : Volley p n I} - -private theorem mark_test {w : I → Bool} (hb : v.bounded w) - (t : Tagging p I) {a : Plan p n} {q} (hv : v.avoids a q) - (j : I) (z : Place p) (L : Finset (Label p.b)) (hl : L.card+14 ≤ q) - (ψ : Vec (AIdx p.g n)) - (hh : inc z.1 (t j) → dotProduct ψ (baseV (v.par j)) = 0) : - ∃ x ∈ annih (sPin (v.frozen a t) z (v.obj j)),∀ k∈L,(labMat p n k)ᵀ *ᵥ x= - if k=v.sel j then ψ else 0 := by - classical - let i := v.obj j - obtain ⟨B,hB,hj,hc,hsel⟩ := hv i - let T := L∪v.marked i - have hT : T.card ≤ q := - (Finset.card_union_le _ _).trans ((Nat.add_le_add_left (v.marked_card hb i) L.card).trans hl) - have hjj : j ∈ v.here i := by simp [here,i] - obtain ⟨x,hx,hX⟩ := protection_test (L:=T) (hB z) - (mem_union_right L (v.marked_mem j)) (hj _ hjj) hT ψ - refine ⟨x, ?_, fun k hk => hX k (mem_union_left _ hk)⟩ - have he : sPin (v.frozen a t) z i ≤ LinearMap.ker (dotL x) := by - rw [v.sPin_frozen] - refine sup_le (fun y hy => (annih_mem ..).mp hx y hy) ?_ - rintro y ⟨y,⟨u,rfl⟩,rfl⟩ - rw [LinearMap.mem_ker] - rw [mulVecLin_apply,mulVecLin_apply,v.key_proj,map_sum] - refine Finset.sum_eq_zero fun k hk => ?_ - rw [map_smul] - suffices h : dotL x (v.rayAt k.val)=0 by rw [h,smul_zero] - change dotProduct x (point p (v.sel k.val) (v.par k.val))= _ - have hh' : k.val ∈ v.here i := (v.visitH_here ..).mp hk - have hx' : v.sel k.val ∈ T := mem_union_right _ (Finset.mem_image_of_mem _ hh') - rw [point,←labMat_act, ←dotProduct_transpose_mulVec,hX _ hx'] - by_cases h : v.sel k.val=v.sel j - · have he' : k.val=j := hsel hh' hjj h - rw [ite_eq_left h,dotProduct_comm,he'] - exact hh (he' ▸ k.property) - rw [ite_eq_right h,dotProduct_zero] - rw [annih_mem] - exact fun y hy => he hy - -private theorem ev_mput (s : Label p.b) (M : BaseMat p n) (x y : Ray p n) : - evmat (mput p s M) x y = evmat M ((labMat p n s)ᵀ *ᵥ x) ((labMat p n s)ᵀ *ᵥ y) := by - rw [← evmat_pull] - unfold mput pullM - rw [transpose_transpose] - -/-- Diagnostic for the two quotients by one affine ray. -/ -private theorem mark_diag {J : Type} [Fintype J] (Z : Mat (Option J) (Option J)) - (hZ : Zᵀ = Z) (hd : ∀ i,Z i i=Z none i) (v : Vec (Option J)) - (hv : v none=1) (he : ∀ φ, dotProduct φ v = 0 → ∀ ψ, dotProduct ψ v = 0 → - evmat Z φ ψ=0) : - Z = (Z none none) • vecMulVec v v := by - classical - let θ (i : Option J) := Pi.single i 1 + (Pi.single none (v i) : Vec (Option J)) - have hθ (i) : dotProduct (θ i) v=0 := by - rw [show θ i=_+_ from rfl,add_dotProduct,single_dotProduct,single_dotProduct, - hv,one_mul,mul_one,char_two] - have hg (i j : Option J) : - Z i j + Z i none * v j + (v i*(Z none j)+v i * (Z none none * v j)) = 0 := by - - have hh := he _ (hθ i) _ (hθ j) - simp only [θ,evmat,Matrix.mulVec_add,add_dotProduct,dotProduct_add, single_dotProduct,Matrix.mulVec_single,op_smul_eq_smul, one_mul,one_smul,Pi.smul_apply,smul_eq_mul,col_apply] at hh - simpa only [mul_comm,mul_left_comm,mul_assoc,add_comm,add_left_comm,add_assoc] using hh - have hf i : Z i none=Z none i := congr_fun (congr_fun hZ none) i - have h0 (i : Option J) : Z none i=Z none none * v i := by - have h := hg i i - rw [hd i,hf,mul_comm (Z none i),show v i*(Z none none*v i)=Z none none*v i from - (by rw [mul_left_comm,bit_sq])] at h - have h' : Z none i+Z none none*v i=0 := calc - _ = Z none i + ((v i * Z none i+v i * Z none i)+Z none none*v i) := by rw [char_two,zero_add] - _ = 0 := (by simpa only [add_assoc] using h) - exact add_right_cancel (h'.trans (char_two _).symm) - ext i j - change Z i j=Z none none*(v i*v j) - have h := hg i j - rw [h0 j,char_two,add_zero,hf,h0, mul_assoc] at h - exact add_right_cancel (h.trans (char_two _).symm) - -set_option maxHeartbeats 600000 in -theorem mark_atom {w : I → Bool} (hb : v.bounded w) - (t : Tagging p I) {a : Plan p n} {q} (hv : v.avoids a q) - (j : I) (e : Comp p.g) - (L : Finset (Label p.b)) (hl : L.card+14≤q) - (Z : Label p.b → BaseMat p n) - (ht : ∀ s,s∉L → Z s=0) (hh : ∀ s∈L,(Z s)ᵀ=Z s ∧ ∀ i,Z s i i=Z s none i) - (hg : vanish (sPin (v.frozen a t) (e,true) (v.obj j)) - (sPin (v.frozen a t) (e,false) (v.obj j)) (labelSum p L Z)) : - Z (v.sel j) = if inc e (t j) then - Z (v.sel j) none none • vecMulVec (baseV (v.par j)) (baseV (v.par j)) else 0 := by - classical - let s := v.sel j - change Z s = if inc e (t j) then _ else _ - by_cases hs : s∈L - · let y := baseV (v.par j) - have he (φ ψ : Vec (AIdx p.g n)) (hφ : inc e (t j) → dotProduct φ y=0) - (hψ : inc e (t j) → dotProduct ψ y=0) : - evmat (Z s) φ ψ=0 := by - obtain ⟨x,hx,hX⟩ := mark_test hb t hv j (e,true) L hl φ hφ - obtain ⟨y,hy,hY⟩ := mark_test hb t hv j (e,false) L hl ψ hψ - have h := hg x hx y hy - unfold labelSum at h - rw [←mpair_outer,mpair_sum,Finset.sum_eq_single s] at h - · rwa [mpair_outer,ev_mput,hX _ hs,hY _ hs,ite_eq_left rfl,ite_eq_left rfl] at h - · intro i hi he; rw [mpair_outer,ev_mput,hX _ hi,hY _ hi,ite_eq_right he,ite_eq_right he] - simp [evmat] - simp [hs] - by_cases h : inc e (t j) - · rw [ite_eq_left h] - exact mark_diag _ (hh s hs).1 (hh s hs).2 y rfl (fun φ hφ ψ hψ => he φ ψ (fun _ => hφ) - (fun _ => hψ)) - rw [ite_eq_right h] - apply evmat_ext - intro φ ψ - rw [he φ ψ (fun e => (h e).elim) (fun e => (h e).elim)] - simp [evmat] - change Z s = if inc e (t j) then Z s none none • _ else _ - rw [ht s hs] - simp - -end Volley -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FrozenProjections + +namespace OAI + +/-! # Response Annihilators -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Finset LinearMap Submodule Module +open scoped BigOperators +variable {p : Shape} {n : ℕ} +variable {I : Type} [Fintype I] + +def dotL (x : Vec I) : Vec I →ₗ[F] F where + toFun y := dotProduct x y + map_add' u v := dotProduct_add x _ _ + map_smul' b u := by + simp only [dotProduct,Pi.smul_apply,RingHom.id_apply,smul_eq_mul,mul_sum,mul_left_comm] + +theorem dotL_surj (x : Vec I →ₗ[F] F) : ∃ y : Vec I,x=dotL y := by + classical + let y (i:I) := x (Pi.single i 1) + refine ⟨y,LinearMap.ext fun v => ?_⟩ + have he : x v=x (∑ i, Pi.single i (v i)) := by rw [Finset.univ_sum_single] + rw [he,map_sum] + change (∑ i,x (Pi.single i (v i)))=∑ i,y i*v i + refine Finset.sum_congr rfl fun i _ => ?_ + rw [show Pi.single i (v i)=v i • (Pi.single i 1 : Vec I) from (by + funext j + by_cases h : j = i + · simp [h] + simp [Pi.single_eq_of_ne h]), + map_smul] + exact mul_comm _ _ + +private theorem protection_test {S : Space (Ray p n)} {q} {E L : Finset (Label p.b)} + (h : protectedBy p S q E) {s} (hs : s∈L) (he : s∉E) (hl : L.card≤q) + (ψ : Vec (AIdx p.g n)) : + ∃ x ∈ annih S,∀ j∈L,(labMat p n j)ᵀ *ᵥ x= if j=s then ψ else 0 := by + classical + let P := S.subtype.coprod (labcomb p n L) + let Q := dotL ψ ∘ₗ LinearMap.proj s ∘ₗ (LinearMap.snd F S (LabVals p n)) + obtain ⟨f,hf⟩ : ∃ f,f ∘ₗ P=Q := by + refine HadwigerCounterexample.mem_range_comp (show LinearMap.ker P≤LinearMap.ker Q from ?_) + rintro ⟨w,z⟩ hw + change w.val + labcomb p n L z=0 at hw + have hb : labcomb p n L z ∈ S := by + rw [show labcomb p n L z=w.val from add_left_cancel (hw.trans (char_two w.val).symm)] + exact w.property + change dotProduct ψ (z s)=0 + rw [h L z hb hl s hs he,dotProduct_zero] + obtain ⟨x,rfl⟩ := dotL_surj f + refine ⟨x,?_,fun j hj => ?_⟩ + · rw [annih_mem]; intro y hy + have hh := LinearMap.congr_fun hf (⟨y,hy⟩,0) + change dotProduct x (y+labcomb p n L 0)=dotProduct ψ 0 at hh + rw [map_zero,add_zero,dotProduct_zero] at hh + exact hh + have h1 (z : Vec (AIdx p.g n)) : dotProduct z ((labMat p n j)ᵀ *ᵥ x)= + if j=s then dotProduct ψ z else 0 := by + let y : LabVals p n := Pi.single j z + have hh := LinearMap.congr_fun hf (0,y) + change dotProduct x (0+labcomb p n L y)=dotProduct ψ (y s) at hh + have hh' : labcomb p n L y = putLab p n j z := by + rw [labcomb_eval,Finset.sum_eq_single j] + · simp [y] + · intro k _ hk; simp [y,Pi.single_eq_of_ne hk] + simp [hj] + rw [dotProduct_transpose_mulVec,labMat_act] + rw [zero_add,hh'] at hh + rw [hh] + by_cases h : j = s + · simp [y,h] + simp [y,h] + funext i + have h2 := h1 (Pi.single i 1) + by_cases hh : j = s + · simpa only [hh,ite_true,dotProduct_single,single_dotProduct,mul_one,one_mul] using h2 + simpa only [ite_eq_right hh,Pi.zero_apply,single_dotProduct,one_mul] using h2 + +namespace Volley +variable {v : Volley p n I} + +private theorem mark_test {w : I → Bool} (hb : v.bounded w) + (t : Tagging p I) {a : Plan p n} {q} (hv : v.avoids a q) + (j : I) (z : Place p) (L : Finset (Label p.b)) (hl : L.card+14 ≤ q) + (ψ : Vec (AIdx p.g n)) + (hh : inc z.1 (t j) → dotProduct ψ (baseV (v.par j)) = 0) : + ∃ x ∈ annih (sPin (v.frozen a t) z (v.obj j)),∀ k∈L,(labMat p n k)ᵀ *ᵥ x= + if k=v.sel j then ψ else 0 := by + classical + let i := v.obj j + obtain ⟨B,hB,hj,hc,hsel⟩ := hv i + let T := L∪v.marked i + have hT : T.card ≤ q := + (Finset.card_union_le _ _).trans ((Nat.add_le_add_left (v.marked_card hb i) L.card).trans hl) + have hjj : j ∈ v.here i := by simp [here,i] + obtain ⟨x,hx,hX⟩ := protection_test (L:=T) (hB z) + (mem_union_right L (v.marked_mem j)) (hj _ hjj) hT ψ + refine ⟨x, ?_, fun k hk => hX k (mem_union_left _ hk)⟩ + have he : sPin (v.frozen a t) z i ≤ LinearMap.ker (dotL x) := by + rw [v.sPin_frozen] + refine sup_le (fun y hy => (annih_mem ..).mp hx y hy) ?_ + rintro y ⟨y,⟨u,rfl⟩,rfl⟩ + rw [LinearMap.mem_ker] + rw [mulVecLin_apply,mulVecLin_apply,v.key_proj,map_sum] + refine Finset.sum_eq_zero fun k hk => ?_ + rw [map_smul] + suffices h : dotL x (v.rayAt k.val)=0 by rw [h,smul_zero] + change dotProduct x (point p (v.sel k.val) (v.par k.val))= _ + have hh' : k.val ∈ v.here i := (v.visitH_here ..).mp hk + have hx' : v.sel k.val ∈ T := mem_union_right _ (Finset.mem_image_of_mem _ hh') + rw [point,←labMat_act, ←dotProduct_transpose_mulVec,hX _ hx'] + by_cases h : v.sel k.val=v.sel j + · have he' : k.val=j := hsel hh' hjj h + rw [ite_eq_left h,dotProduct_comm,he'] + exact hh (he' ▸ k.property) + rw [ite_eq_right h,dotProduct_zero] + rw [annih_mem] + exact fun y hy => he hy + +private theorem ev_mput (s : Label p.b) (M : BaseMat p n) (x y : Ray p n) : + evmat (mput p s M) x y = evmat M ((labMat p n s)ᵀ *ᵥ x) ((labMat p n s)ᵀ *ᵥ y) := by + rw [← evmat_pull] + unfold mput pullM + rw [transpose_transpose] + +/-- Diagnostic for the two quotients by one affine ray. -/ +private theorem mark_diag {J : Type} [Fintype J] (Z : Mat (Option J) (Option J)) + (hZ : Zᵀ = Z) (hd : ∀ i,Z i i=Z none i) (v : Vec (Option J)) + (hv : v none=1) (he : ∀ φ, dotProduct φ v = 0 → ∀ ψ, dotProduct ψ v = 0 → + evmat Z φ ψ=0) : + Z = (Z none none) • vecMulVec v v := by + classical + let θ (i : Option J) := Pi.single i 1 + (Pi.single none (v i) : Vec (Option J)) + have hθ (i) : dotProduct (θ i) v=0 := by + rw [show θ i=_+_ from rfl,add_dotProduct,single_dotProduct,single_dotProduct, + hv,one_mul,mul_one,char_two] + have hg (i j : Option J) : + Z i j + Z i none * v j + (v i*(Z none j)+v i * (Z none none * v j)) = 0 := by + + have hh := he _ (hθ i) _ (hθ j) + simp only [θ,evmat,Matrix.mulVec_add,add_dotProduct,dotProduct_add, single_dotProduct,Matrix.mulVec_single,op_smul_eq_smul, one_mul,one_smul,Pi.smul_apply,smul_eq_mul,col_apply] at hh + simpa only [mul_comm,mul_left_comm,mul_assoc,add_comm,add_left_comm,add_assoc] using hh + have hf i : Z i none=Z none i := congr_fun (congr_fun hZ none) i + have h0 (i : Option J) : Z none i=Z none none * v i := by + have h := hg i i + rw [hd i,hf,mul_comm (Z none i),show v i*(Z none none*v i)=Z none none*v i from + (by rw [mul_left_comm,bit_sq])] at h + have h' : Z none i+Z none none*v i=0 := calc + _ = Z none i + ((v i * Z none i+v i * Z none i)+Z none none*v i) := by rw [char_two,zero_add] + _ = 0 := (by simpa only [add_assoc] using h) + exact add_right_cancel (h'.trans (char_two _).symm) + ext i j + change Z i j=Z none none*(v i*v j) + have h := hg i j + rw [h0 j,char_two,add_zero,hf,h0, mul_assoc] at h + exact add_right_cancel (h.trans (char_two _).symm) + +set_option maxHeartbeats 600000 in +theorem mark_atom {w : I → Bool} (hb : v.bounded w) + (t : Tagging p I) {a : Plan p n} {q} (hv : v.avoids a q) + (j : I) (e : Comp p.g) + (L : Finset (Label p.b)) (hl : L.card+14≤q) + (Z : Label p.b → BaseMat p n) + (ht : ∀ s,s∉L → Z s=0) (hh : ∀ s∈L,(Z s)ᵀ=Z s ∧ ∀ i,Z s i i=Z s none i) + (hg : vanish (sPin (v.frozen a t) (e,true) (v.obj j)) + (sPin (v.frozen a t) (e,false) (v.obj j)) (labelSum p L Z)) : + Z (v.sel j) = if inc e (t j) then + Z (v.sel j) none none • vecMulVec (baseV (v.par j)) (baseV (v.par j)) else 0 := by + classical + let s := v.sel j + change Z s = if inc e (t j) then _ else _ + by_cases hs : s∈L + · let y := baseV (v.par j) + have he (φ ψ : Vec (AIdx p.g n)) (hφ : inc e (t j) → dotProduct φ y=0) + (hψ : inc e (t j) → dotProduct ψ y=0) : + evmat (Z s) φ ψ=0 := by + obtain ⟨x,hx,hX⟩ := mark_test hb t hv j (e,true) L hl φ hφ + obtain ⟨y,hy,hY⟩ := mark_test hb t hv j (e,false) L hl ψ hψ + have h := hg x hx y hy + unfold labelSum at h + rw [←mpair_outer,mpair_sum,Finset.sum_eq_single s] at h + · rwa [mpair_outer,ev_mput,hX _ hs,hY _ hs,ite_eq_left rfl,ite_eq_left rfl] at h + · intro i hi he; rw [mpair_outer,ev_mput,hX _ hi,hY _ hi,ite_eq_right he,ite_eq_right he] + simp [evmat] + simp [hs] + by_cases h : inc e (t j) + · rw [ite_eq_left h] + exact mark_diag _ (hh s hs).1 (hh s hs).2 y rfl (fun φ hφ ψ hψ => he φ ψ (fun _ => hφ) + (fun _ => hψ)) + rw [ite_eq_right h] + apply evmat_ext + intro φ ψ + rw [he φ ψ (fun e => (h e).elim) (fun e => (h e).elim)] + simp [evmat] + change Z s = if inc e (t j) then Z s none none • _ else _ + rw [ht s hs] + simp + +end Volley +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ResponseSolvability.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ResponseSolvability.lean index b31b3d2b9e98f4f642cfc25bc9cceabfdd523905..ee529194db4af5c3bb8c281b369d39a9ec349463 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ResponseSolvability.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ResponseSolvability.lean @@ -1,188 +1,188 @@ -import OAI.Combinatorics.HadwigerCounterexample.ResidualCutPairs - -namespace OAI - -/-! # Response Solvability -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Finset Submodule -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] - -abbrev Individual (p : Shape) (n : ℕ) := Bool → Profile p n -abbrev OnForms (p : Shape) (n : ℕ) := Bool → (Profile p n →ₗ[F] F) -abbrev ReqF (p : Shape) (n : ℕ) := Module.Dual F (Xpair p n) - -def combineF (p : Shape) {n} : OnForms p n →ₗ[F] ReqF p n where - toFun f := ∑ i : Bool, f i ∘ₗ (Xspace p n).subtype ∘ₗ LinearMap.proj i - map_add' f g := LinearMap.ext fun x => by - simp only [LinearMap.sum_apply,LinearMap.comp_apply,Pi.add_apply,LinearMap.add_apply, - Finset.sum_add_distrib] - map_smul' a f := LinearMap.ext fun x => by - simp only [LinearMap.sum_apply,LinearMap.comp_apply,Pi.smul_apply,LinearMap.smul_apply, - RingHom.id_apply,smul_eq_mul,mul_sum] - -theorem combineF_val (f : OnForms p n) (x : Xpair p n) : - combineF p f x= ∑ i, f i (x i).val := by - simp only [combineF,LinearMap.coe_mk,AddHom.coe_mk,LinearMap.sum_apply]; rfl - -theorem combineF_single (f : OnForms p n) (i : Bool) (x : Xspace p n) : - combineF p f (Pi.single i x)=f i x.val := by - rw [combineF_val,Finset.sum_eq_single i] - · rw [Pi.single_eq_same] - · intro j _ hj; simp [hj] - simp - -theorem combineF_same (f g : OnForms p n) : combineF p f=combineF p g ↔ - ∀ i,∀ x ∈ Xspace p n,f i x=g i x := by - constructor - · intro h i x hx - exact (combineF_single f i ⟨x,hx⟩).symm.trans (h ▸ combineF_single g i ⟨x,hx⟩) - intro h - apply LinearMap.ext; intro x - rw [combineF_val,combineF_val] - exact Finset.sum_congr rfl fun i _ => h i _ (x i).property - -def obsPair (p : Shape) {n} : PureForms p n →ₗ[F] ReqF p n := - react p 0 ∘ₗ LinearMap.inr F (ChanOut p n) (PureForms p n) - -theorem obsPair_val (A : PureForms p n) (x : Xpair p n) : - obsPair p A x=∑ i,mpair (A i) (purePair p n x i) := by - change ∑ i : Comp p.g, _ = _ - refine Finset.sum_congr rfl fun i _ => ?_ - change mpair ((chanDeriv p (n:=n) 0 0+A) _) _=_ - simp only [chanDeriv,chanInner,Pi.add_apply,Pi.zero_apply,Matrix.transpose_zero,Matrix.zero_mul, - zero_add] - -/-- Restrict pure form to individual diagonal blocks. -/ -def eachF (p : Shape) {n} : - PureForms p n →ₗ[F] Individual p n where - toFun P i e := pullM (IP p n i) (IP p n i) (P e) - map_add' P Q := by ext; simp only [Pi.add_apply,map_add] - map_smul' a P := by ext; simp only [Pi.smul_apply,map_smul,RingHom.id_apply] - -/-- Extend the individual forms by zero outside respective blocks, then add. -/ -def sumF (p : Shape) {n} : Individual p n → PureForms p n := - fun A e => ∑ i,liftM (IP p n i) (IP p n i) (A i e) -theorem each_sumF (A : Individual p n) : eachF p (sumF p A)=A := by - classical - funext i e - change pullM _ _ (∑ j,_) = _ - rw [map_sum,Finset.sum_eq_single i] - · unfold pullM; rw [liftM_comp,IP_self] - simp [liftM_def] - · intro j _ hj - unfold pullM - rw [liftM_comp,IP_cross (Ne.symm hj)] - simp [liftM_def] - simp - -def repF (p : Shape) {n} (A : Individual p n) : OnForms p n := - fun i => ∑ e : Comp p.g, mpair (A i e) ∘ₗ LinearMap.proj e - -theorem repF_rep (A : Individual p n) (i) : - Represents (repF p A i) (A i) := by - intro x - simp only [repF,LinearMap.sum_apply]; rfl - -theorem obsPair_each (P : PureForms p n) : - obsPair p P=combineF p (repF p (eachF p P)) := by - apply LinearMap.ext - intro x - rw [obsPair_val,combineF_val] - simp_rw [purePair,Finset.sum_apply,map_sum] - rw [Finset.sum_comm] - refine Finset.sum_congr rfl fun i _ => ?_ - rw [repF_rep] - refine Finset.sum_congr rfl fun e _ => ?_ - rw [mpair_liftM]; rfl - -theorem obsPair_chan (B : Cross p n) (j : Bool) : - obsPair p (chanInner p (channelOut p B j) (channelOut p B j))= - combineF p (fun i => contract p B i j) := by - apply LinearMap.ext; intro x - rw [obsPair_val,combineF_val] - simp_rw [purePair,Finset.sum_apply,map_sum] - rw [Finset.sum_comm]; rfl - -theorem each_chan_val (B C : ChanOut p n) (i) (e : Comp p.g) : - eachF p (chanInner p B C) i e=(B (e,true) * IP p n i)ᵀ * (C (e,false)*IP p n i) := by - change pullM _ _ _=_ - simp only [pullM_def,chanInner,transpose_mul,Matrix.mul_assoc] - -theorem obsPair_chan_change (B C : ChanOut p n) : - obsPair p (chanInner p (B+C) (B+C))= - obsPair p (chanInner p B B)+ obsPair p (chanDeriv p B C) + obsPair p (chanInner p C C) := by - rw [←map_add,←map_add] - congr 1 - unfold chanInner chanDeriv - funext i - simp only [chanInner,Pi.add_apply,Matrix.transpose_add,Matrix.add_mul,Matrix.mul_add,add_assoc] - ac_rfl - -theorem react_obsPair (B C : ChanOut p n) (D : PureForms p n) : - react p B (C,D)=obsPair p (chanDeriv p B C) + obsPair p D := by - rw [←map_add] - exact LinearMap.ext (fun x => (obsPair_val _ x).symm) - -namespace Volley -variable (v w : Volley p n I) - -def demand (t : Tagging p I) (m : Mixer p n) (j : Bool) : OnForms p n := - fun i => grad m (v.sumAt t w.obj i j) - -theorem realize_linear {t : Tagging p I} (m : Mixer p n) - (x y : UnitType p n N) (a b : Plan p n) (t' B : Cross p n) - (hb : v.bounded w.obj) (ht : v.legal t) - (q R : ℕ) (hv : v.avoids a q) (hj : 6*R+4≤p.j) - (hr : 2*planRank a+28≤R) (hq : R+14≤q) - (hB : fitsTable a b B t') (hT : tableInj a b t') - (hf : rowAgree (v.frozen a t) B (actual p x y)) - (hR : v.scalarRecipe w t m x a t') (hk : v.keys t x=w.keys t y) - (hL : ∀ i, frameLaw m (onSide y i)) - (hS : v.attackGrad w t m y) (j : Bool) : - ∃ C∈deltaSpace p (v.frozen a t) b j, - ∃ P∈pureSpace p (v.frozen a t), - obsPair p (chanInner p (channelOut p B j) (channelOut p B j))+ - obsPair p (chanDeriv p (channelOut p B j) C) + obsPair p P= - combineF p (v.demand w t m j) := by - classical - let G := v.demand w t m j - let K : OnForms p n := fun i => contract p B i j - let CC := channelOut p B j - have h1 (i : I) : G (v.obj i) (v.atomAt t i) = K (v.obj i) (v.atomAt t i) := by - change grad m (v.sumAt t w.obj (v.obj i) j) _ = contract p B _ _ _ - rw [frozen_contract_key v t hf,contract_actual,LinearMap.comp_apply,hS i j, - v.atom_share w t x y hk] - by_cases h : j=w.obj i - · rw [ite_eq_left h,h,ufun_self (hL _)] - have hh : (! (w.obj i))=j := by cases j <;> cases e : w.obj i <;> simp_all - rw [ite_eq_right h, innerP, hh]; rfl - have hg (z : Xpair p n) (h : orth p CC (v.frozen a t) b j z) : - combineF p (G-K) z=0 := by - obtain ⟨c,z,rfl,ho,hy⟩ := split_orth hb ht h hv hj hr hq - have he (i : Bool) := clean_effective t hb hv hq B z ho (fits_inj hB hT) i (hy i) - rw [map_add,map_sum] - have h2 : combineF p (G-K) z = 0 := by - rw [combineF_val] - refine Finset.sum_eq_zero fun i _ => ?_ - rw [Pi.sub_apply,LinearMap.sub_apply] - exact sub_eq_zero.mpr ((hR.gradient i j _ (he i)).trans (fits_contract hB i j _ (he i)).symm) - rw [h2,zero_add] - refine Finset.sum_eq_zero fun i _ => ?_ - rw [map_smul,strike,combineF_single,Pi.sub_apply,LinearMap.sub_apply, - h1 i,sub_self,smul_zero] - - obtain ⟨C,hC,P,hP,h⟩ := solve_by_dual _ hg - rw [react_obsPair,map_sub] at h - rw [obsPair_chan] - refine ⟨C,hC,P,hP,?_⟩ - rw [add_assoc,h,add_sub_cancel] -end Volley - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ResidualCutPairs + +namespace OAI + +/-! # Response Solvability -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Finset Submodule +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] + +abbrev Individual (p : Shape) (n : ℕ) := Bool → Profile p n +abbrev OnForms (p : Shape) (n : ℕ) := Bool → (Profile p n →ₗ[F] F) +abbrev ReqF (p : Shape) (n : ℕ) := Module.Dual F (Xpair p n) + +def combineF (p : Shape) {n} : OnForms p n →ₗ[F] ReqF p n where + toFun f := ∑ i : Bool, f i ∘ₗ (Xspace p n).subtype ∘ₗ LinearMap.proj i + map_add' f g := LinearMap.ext fun x => by + simp only [LinearMap.sum_apply,LinearMap.comp_apply,Pi.add_apply,LinearMap.add_apply, + Finset.sum_add_distrib] + map_smul' a f := LinearMap.ext fun x => by + simp only [LinearMap.sum_apply,LinearMap.comp_apply,Pi.smul_apply,LinearMap.smul_apply, + RingHom.id_apply,smul_eq_mul,mul_sum] + +theorem combineF_val (f : OnForms p n) (x : Xpair p n) : + combineF p f x= ∑ i, f i (x i).val := by + simp only [combineF,LinearMap.coe_mk,AddHom.coe_mk,LinearMap.sum_apply]; rfl + +theorem combineF_single (f : OnForms p n) (i : Bool) (x : Xspace p n) : + combineF p f (Pi.single i x)=f i x.val := by + rw [combineF_val,Finset.sum_eq_single i] + · rw [Pi.single_eq_same] + · intro j _ hj; simp [hj] + simp + +theorem combineF_same (f g : OnForms p n) : combineF p f=combineF p g ↔ + ∀ i,∀ x ∈ Xspace p n,f i x=g i x := by + constructor + · intro h i x hx + exact (combineF_single f i ⟨x,hx⟩).symm.trans (h ▸ combineF_single g i ⟨x,hx⟩) + intro h + apply LinearMap.ext; intro x + rw [combineF_val,combineF_val] + exact Finset.sum_congr rfl fun i _ => h i _ (x i).property + +def obsPair (p : Shape) {n} : PureForms p n →ₗ[F] ReqF p n := + react p 0 ∘ₗ LinearMap.inr F (ChanOut p n) (PureForms p n) + +theorem obsPair_val (A : PureForms p n) (x : Xpair p n) : + obsPair p A x=∑ i,mpair (A i) (purePair p n x i) := by + change ∑ i : Comp p.g, _ = _ + refine Finset.sum_congr rfl fun i _ => ?_ + change mpair ((chanDeriv p (n:=n) 0 0+A) _) _=_ + simp only [chanDeriv,chanInner,Pi.add_apply,Pi.zero_apply,Matrix.transpose_zero,Matrix.zero_mul, + zero_add] + +/-- Restrict pure form to individual diagonal blocks. -/ +def eachF (p : Shape) {n} : + PureForms p n →ₗ[F] Individual p n where + toFun P i e := pullM (IP p n i) (IP p n i) (P e) + map_add' P Q := by ext; simp only [Pi.add_apply,map_add] + map_smul' a P := by ext; simp only [Pi.smul_apply,map_smul,RingHom.id_apply] + +/-- Extend the individual forms by zero outside respective blocks, then add. -/ +def sumF (p : Shape) {n} : Individual p n → PureForms p n := + fun A e => ∑ i,liftM (IP p n i) (IP p n i) (A i e) +theorem each_sumF (A : Individual p n) : eachF p (sumF p A)=A := by + classical + funext i e + change pullM _ _ (∑ j,_) = _ + rw [map_sum,Finset.sum_eq_single i] + · unfold pullM; rw [liftM_comp,IP_self] + simp [liftM_def] + · intro j _ hj + unfold pullM + rw [liftM_comp,IP_cross (Ne.symm hj)] + simp [liftM_def] + simp + +def repF (p : Shape) {n} (A : Individual p n) : OnForms p n := + fun i => ∑ e : Comp p.g, mpair (A i e) ∘ₗ LinearMap.proj e + +theorem repF_rep (A : Individual p n) (i) : + Represents (repF p A i) (A i) := by + intro x + simp only [repF,LinearMap.sum_apply]; rfl + +theorem obsPair_each (P : PureForms p n) : + obsPair p P=combineF p (repF p (eachF p P)) := by + apply LinearMap.ext + intro x + rw [obsPair_val,combineF_val] + simp_rw [purePair,Finset.sum_apply,map_sum] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [repF_rep] + refine Finset.sum_congr rfl fun e _ => ?_ + rw [mpair_liftM]; rfl + +theorem obsPair_chan (B : Cross p n) (j : Bool) : + obsPair p (chanInner p (channelOut p B j) (channelOut p B j))= + combineF p (fun i => contract p B i j) := by + apply LinearMap.ext; intro x + rw [obsPair_val,combineF_val] + simp_rw [purePair,Finset.sum_apply,map_sum] + rw [Finset.sum_comm]; rfl + +theorem each_chan_val (B C : ChanOut p n) (i) (e : Comp p.g) : + eachF p (chanInner p B C) i e=(B (e,true) * IP p n i)ᵀ * (C (e,false)*IP p n i) := by + change pullM _ _ _=_ + simp only [pullM_def,chanInner,transpose_mul,Matrix.mul_assoc] + +theorem obsPair_chan_change (B C : ChanOut p n) : + obsPair p (chanInner p (B+C) (B+C))= + obsPair p (chanInner p B B)+ obsPair p (chanDeriv p B C) + obsPair p (chanInner p C C) := by + rw [←map_add,←map_add] + congr 1 + unfold chanInner chanDeriv + funext i + simp only [chanInner,Pi.add_apply,Matrix.transpose_add,Matrix.add_mul,Matrix.mul_add,add_assoc] + ac_rfl + +theorem react_obsPair (B C : ChanOut p n) (D : PureForms p n) : + react p B (C,D)=obsPair p (chanDeriv p B C) + obsPair p D := by + rw [←map_add] + exact LinearMap.ext (fun x => (obsPair_val _ x).symm) + +namespace Volley +variable (v w : Volley p n I) + +def demand (t : Tagging p I) (m : Mixer p n) (j : Bool) : OnForms p n := + fun i => grad m (v.sumAt t w.obj i j) + +theorem realize_linear {t : Tagging p I} (m : Mixer p n) + (x y : UnitType p n N) (a b : Plan p n) (t' B : Cross p n) + (hb : v.bounded w.obj) (ht : v.legal t) + (q R : ℕ) (hv : v.avoids a q) (hj : 6*R+4≤p.j) + (hr : 2*planRank a+28≤R) (hq : R+14≤q) + (hB : fitsTable a b B t') (hT : tableInj a b t') + (hf : rowAgree (v.frozen a t) B (actual p x y)) + (hR : v.scalarRecipe w t m x a t') (hk : v.keys t x=w.keys t y) + (hL : ∀ i, frameLaw m (onSide y i)) + (hS : v.attackGrad w t m y) (j : Bool) : + ∃ C∈deltaSpace p (v.frozen a t) b j, + ∃ P∈pureSpace p (v.frozen a t), + obsPair p (chanInner p (channelOut p B j) (channelOut p B j))+ + obsPair p (chanDeriv p (channelOut p B j) C) + obsPair p P= + combineF p (v.demand w t m j) := by + classical + let G := v.demand w t m j + let K : OnForms p n := fun i => contract p B i j + let CC := channelOut p B j + have h1 (i : I) : G (v.obj i) (v.atomAt t i) = K (v.obj i) (v.atomAt t i) := by + change grad m (v.sumAt t w.obj (v.obj i) j) _ = contract p B _ _ _ + rw [frozen_contract_key v t hf,contract_actual,LinearMap.comp_apply,hS i j, + v.atom_share w t x y hk] + by_cases h : j=w.obj i + · rw [ite_eq_left h,h,ufun_self (hL _)] + have hh : (! (w.obj i))=j := by cases j <;> cases e : w.obj i <;> simp_all + rw [ite_eq_right h, innerP, hh]; rfl + have hg (z : Xpair p n) (h : orth p CC (v.frozen a t) b j z) : + combineF p (G-K) z=0 := by + obtain ⟨c,z,rfl,ho,hy⟩ := split_orth hb ht h hv hj hr hq + have he (i : Bool) := clean_effective t hb hv hq B z ho (fits_inj hB hT) i (hy i) + rw [map_add,map_sum] + have h2 : combineF p (G-K) z = 0 := by + rw [combineF_val] + refine Finset.sum_eq_zero fun i _ => ?_ + rw [Pi.sub_apply,LinearMap.sub_apply] + exact sub_eq_zero.mpr ((hR.gradient i j _ (he i)).trans (fits_contract hB i j _ (he i)).symm) + rw [h2,zero_add] + refine Finset.sum_eq_zero fun i _ => ?_ + rw [map_smul,strike,combineF_single,Pi.sub_apply,LinearMap.sub_apply, + h1 i,sub_self,smul_zero] + + obtain ⟨C,hC,P,hP,h⟩ := solve_by_dual _ hg + rw [react_obsPair,map_sub] at h + rw [obsPair_chan] + refine ⟨C,hC,P,hP,?_⟩ + rw [add_assoc,h,add_sub_cancel] +end Volley + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RestrictedComparisonLaws.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RestrictedComparisonLaws.lean index 8a944452aa207f9afa645f0657d650926685c60d..696e2613b4c47c17cd8b3e305dab1ff68f97cb08 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RestrictedComparisonLaws.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RestrictedComparisonLaws.lean @@ -1,101 +1,101 @@ -import OAI.Combinatorics.HadwigerCounterexample.ConditionalFlags - -namespace OAI - -/-! # Restricted Comparison Laws -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real -open scoped BigOperators -variable {A B C : Type} [Fintype A] [Fintype B] [Fintype C] - -def hung (Q : Wgt B→Prop) (P : B→Prop) (w : Wgt B) := - ∃ v : Wgt B, Q v ∧ w=subW v P -def smallSet (Q : Wgt B→Prop) (q : Wgt B) (δ η : ℝ) := - ∀ p,Q p → ∀ P : B→ Prop, pr q P ≤ δ → pr p P ≤ η -def rosterTail (Q : Wgt B→Prop) (q : Wgt B) (R η : ℝ) := - ∀ p,Q p → pr p (fun x => R≤density q p x)≤η - -theorem hung_roster (Q : Wgt B → Prop) (P : B→Prop) (r : ℕ) (ε : ℝ) : - roster Q r ε → roster (hung Q P) r ε := by - classical - rintro ⟨t,ht,w,hw⟩ - refine ⟨t,ht,fun i => subW (w i) P,?_⟩ - rintro p ⟨v,h,rfl⟩ - obtain ⟨i,hi⟩ := hw v h - refine ⟨i,le_trans ?_ hi⟩ - unfold varOne subW - refine sum_le_sum fun x _ => ?_ - by_cases h : P x <;> simp [ind,h] - -variable [Nonempty B] - -theorem hung_small (Q : Wgt B→Prop) (P : B→Prop) (δ η : ℝ) - (hq : smallSet Q unif δ η) : smallSet (hung Q P) (unifOn P) δ η := by - classical - rintro p ⟨v,hv,rfl⟩ S hs - rw [pr_sub] - refine hq v hv (fun x => P x∧ S x) ?_ - rw [pr_of_on unif_law.nz,on_unif] - refine le_trans ?_ hs - have ht := (pr_le_tot (α:=B) (p:=P) unif_law.nz).trans unif_law.total.le - exact (mul_le_mul_of_nonneg_right ht (pr_nonneg (unifOn_sub _).nz)).trans_eq (one_mul _) - -omit [Nonempty B] in -theorem density_hung (P : B→Prop) (w : Wgt B) (hw : carried w P) : - ∀ i, unifOn P i * density (unifOn P) w i=w i := by - classical - intro i - by_cases h : w i =0 - · simp only [density,h,zero_div,mul_zero] - have ht : P i := not_not.mp fun hi => h (hw i hi) - have hn := unifOn_law (p:=P) ⟨i,ht⟩ - have he : unifOn P i≠0 := by - rw [unifOn_val,ind_one ht] - have hh : nbr P ≠0 := by - have he := weight_le_tot (fun j => ind_nonneg (P j)) i - rw [ind_one ht] at he - exact (lt_of_lt_of_le zero_lt_one he).ne' - exact div_ne_zero one_ne_zero hh - unfold density; field_simp - -theorem hung_tail (Q : Wgt B→Prop) (P : B→ Prop) - (h : ∀ p,Q p → SubLaw p) (δ η : ℝ) - (hδ : 0<δ) (hh : smallSet Q unif δ η) : - rosterTail (hung Q P) (unifOn P) δ⁻¹ η := by - intro p hp - apply hung_small Q P δ η hh p hp - obtain ⟨w,hw,rfl⟩ := hp - let q := unifOn P - let v := subW w P - let f := density q v - have hq := unifOn_sub P - have hv := subLaw_sub (h w hw) P - have hh : - avg q f = tot v := Finset.sum_congr rfl fun i _ => density_hung P v - (subW_carried w P) i - have hz := le_avg_markov hq.nz (fun i => div_nonneg (hv.nz i) (hq.nz i)) δ⁻¹ - change δ⁻¹*pr q _≤avg q f at hz - apply le_of_mul_le_mul_left _ (inv_pos_of_pos hδ) - rw [inv_mul_cancel₀ hδ.ne'] - exact (hz.trans_eq hh).trans hv.total - -omit [Nonempty B] in -theorem hung_var (P : B→Prop) (p q : Wgt B) (hp : carried p P) (hq : carried q P) : - avg (unifOn P) (fun i => |density (unifOn P) p i-density (unifOn P) q i|)=varOne p q := by - classical - unfold avg varOne - refine sum_congr rfl fun i _ => ?_ - rw [←abs_of_nonneg ((unifOn_sub P).nz i)] - have he := density_hung P p hp i - - simp_rw [abs_of_nonneg ((unifOn_sub P).nz i)] - calc _ = |unifOn P i * (density (unifOn P) p i - density (unifOn P) q i)| := - by rw [abs_mul,abs_of_nonneg ((unifOn_sub P).nz i)] - _ = _ := by rw [mul_sub,he,density_hung P q hq i] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ConditionalFlags + +namespace OAI + +/-! # Restricted Comparison Laws -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real +open scoped BigOperators +variable {A B C : Type} [Fintype A] [Fintype B] [Fintype C] + +def hung (Q : Wgt B→Prop) (P : B→Prop) (w : Wgt B) := + ∃ v : Wgt B, Q v ∧ w=subW v P +def smallSet (Q : Wgt B→Prop) (q : Wgt B) (δ η : ℝ) := + ∀ p,Q p → ∀ P : B→ Prop, pr q P ≤ δ → pr p P ≤ η +def rosterTail (Q : Wgt B→Prop) (q : Wgt B) (R η : ℝ) := + ∀ p,Q p → pr p (fun x => R≤density q p x)≤η + +theorem hung_roster (Q : Wgt B → Prop) (P : B→Prop) (r : ℕ) (ε : ℝ) : + roster Q r ε → roster (hung Q P) r ε := by + classical + rintro ⟨t,ht,w,hw⟩ + refine ⟨t,ht,fun i => subW (w i) P,?_⟩ + rintro p ⟨v,h,rfl⟩ + obtain ⟨i,hi⟩ := hw v h + refine ⟨i,le_trans ?_ hi⟩ + unfold varOne subW + refine sum_le_sum fun x _ => ?_ + by_cases h : P x <;> simp [ind,h] + +variable [Nonempty B] + +theorem hung_small (Q : Wgt B→Prop) (P : B→Prop) (δ η : ℝ) + (hq : smallSet Q unif δ η) : smallSet (hung Q P) (unifOn P) δ η := by + classical + rintro p ⟨v,hv,rfl⟩ S hs + rw [pr_sub] + refine hq v hv (fun x => P x∧ S x) ?_ + rw [pr_of_on unif_law.nz,on_unif] + refine le_trans ?_ hs + have ht := (pr_le_tot (α:=B) (p:=P) unif_law.nz).trans unif_law.total.le + exact (mul_le_mul_of_nonneg_right ht (pr_nonneg (unifOn_sub _).nz)).trans_eq (one_mul _) + +omit [Nonempty B] in +theorem density_hung (P : B→Prop) (w : Wgt B) (hw : carried w P) : + ∀ i, unifOn P i * density (unifOn P) w i=w i := by + classical + intro i + by_cases h : w i =0 + · simp only [density,h,zero_div,mul_zero] + have ht : P i := not_not.mp fun hi => h (hw i hi) + have hn := unifOn_law (p:=P) ⟨i,ht⟩ + have he : unifOn P i≠0 := by + rw [unifOn_val,ind_one ht] + have hh : nbr P ≠0 := by + have he := weight_le_tot (fun j => ind_nonneg (P j)) i + rw [ind_one ht] at he + exact (lt_of_lt_of_le zero_lt_one he).ne' + exact div_ne_zero one_ne_zero hh + unfold density; field_simp + +theorem hung_tail (Q : Wgt B→Prop) (P : B→ Prop) + (h : ∀ p,Q p → SubLaw p) (δ η : ℝ) + (hδ : 0<δ) (hh : smallSet Q unif δ η) : + rosterTail (hung Q P) (unifOn P) δ⁻¹ η := by + intro p hp + apply hung_small Q P δ η hh p hp + obtain ⟨w,hw,rfl⟩ := hp + let q := unifOn P + let v := subW w P + let f := density q v + have hq := unifOn_sub P + have hv := subLaw_sub (h w hw) P + have hh : + avg q f = tot v := Finset.sum_congr rfl fun i _ => density_hung P v + (subW_carried w P) i + have hz := le_avg_markov hq.nz (fun i => div_nonneg (hv.nz i) (hq.nz i)) δ⁻¹ + change δ⁻¹*pr q _≤avg q f at hz + apply le_of_mul_le_mul_left _ (inv_pos_of_pos hδ) + rw [inv_mul_cancel₀ hδ.ne'] + exact (hz.trans_eq hh).trans hv.total + +omit [Nonempty B] in +theorem hung_var (P : B→Prop) (p q : Wgt B) (hp : carried p P) (hq : carried q P) : + avg (unifOn P) (fun i => |density (unifOn P) p i-density (unifOn P) q i|)=varOne p q := by + classical + unfold avg varOne + refine sum_congr rfl fun i _ => ?_ + rw [←abs_of_nonneg ((unifOn_sub P).nz i)] + have he := density_hung P p hp i + + simp_rw [abs_of_nonneg ((unifOn_sub P).nz i)] + calc _ = |unifOn P i * (density (unifOn P) p i - density (unifOn P) q i)| := + by rw [abs_mul,abs_of_nonneg ((unifOn_sub P).nz i)] + _ = _ := by rw [mul_sub,he,density_hung P q hq i] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/RoundedRefinements.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/RoundedRefinements.lean index 13066cf286dd6a6febeed97fe0f1befeaab2d569..59908cfe42c3a0534507609b7291f14acfc95420 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/RoundedRefinements.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/RoundedRefinements.lean @@ -1,156 +1,156 @@ -import OAI.Combinatorics.HadwigerCounterexample.RefinementEnergy - -namespace OAI - -/-! # Rounded Refinements -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Filter Matrix Real -open scoped BigOperators -variable {A B C D : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype D] - -set_option maxHeartbeats 900000 in -theorem divide_fit (q : Wgt B) (hq : IsLaw q) (f : B→C) (P : B→Prop) - (δ γ : ℝ) (hγ : 0<γ) (hz : 2*γ ≤ δ) (h : stamina (mapW q f) δ) : - ∃ F : B→C×Bool, f=Prod.fst∘F ∧ stamina (mapW q F) γ ∧ - pr q (fun i => ¬(P i ↔ (F i).2))≤num (C×Bool)*γ := by - classical - let g (i : B) : C × Bool := (f i,decide (P i)) - let Q := mapW q g - have hQ := mapW_law hq g - have hf : f=Prod.fst∘g := rfl - have hi (i) : mapW q f i=Q (i,true)+Q (i,false) := by - have hs : mapW q f=mapW Q Prod.fst := hf ▸ Eq.symm (map_nested g Prod.fst) - rw [hs] - simp only [mapW,pr,avg,Fintype.sum_prod_type,Fintype.sum_bool]; simp [ind,Finset.sum_add_distrib] - let s (j:C×Bool) : Bool := if Q (j.1,true) < γ then false else - if Q (j.1,false) < γ then true else j.2 - let F (j : C × Bool) : C × Bool := (j.1,s j) - refine ⟨F ∘ g,rfl,?_,?_⟩ - · rintro ⟨i,b⟩ h' - have hb : - mapW Q F (i,b)=Q (i,true)*ind (s (i,true)=b)+ - Q (i,false)*ind (s (i,false)=b) := by - unfold mapW pr avg - rw [Fintype.sum_prod_type, sum_eq_single i] - · rw [Fintype.sum_bool]; simp [ind,F] - · intro j _ hj; rw [Fintype.sum_bool]; simp [ind,F,hj] - simp - rw [←map_nested,hb] at h' ⊢ - by_cases hx : Q (i,true)<γ - · cases b - · simp only [s,hx,ite_true,ind_true,mul_one] at * - rw [←hi] at * - exact le_trans (by linarith only [hz,hγ]) (h i h') - simp [s,hx,ind] at h' - by_cases hy : Q (i,false)<γ - · cases b - · simp [s,hx,hy,ind] at h' - simp only [s,hx,hy,ite_true,ite_false,ind_true,mul_one] at * - rw [←hi] at * - exact le_trans (by linarith only [hz,hγ]) (h i h') - cases b - · simpa [s,hx,hy,ind] using (le_of_not_gt hy) - simpa [s,hx,hy,ind] using (le_of_not_gt hx) - let R (i : C×Bool) := i.2≠s i - have he j : (¬ (P j ↔ (F (g j)).2)) ↔ R (g j) := by - change (¬ (P j ↔ s (g j)=true)) ↔ decide (P j)≠s (g j) - cases s (g j) <;> simp - have h1 (j : C×Bool) : R j→ Q j≤γ := by - intro hj - rcases j with ⟨i,b⟩ - by_cases hx : Q (i,true)<γ - · cases b - · simp [R,s,hx] at hj - exact hx.le - by_cases hy : Q (i,false)<γ - · cases b - · exact hy.le - simp [R,s,hx,hy] at hj - simp [R,s,hx,hy] at hj - have hg (j) : Q j * ind (R j) ≤ γ := by - by_cases hh : R j - · simpa only [ind_one hh,mul_one] using h1 j hh - rw [ind_zero hh,mul_zero]; exact hγ.le - simp_rw [Function.comp_apply,he] - rw [← mapW_pr] - exact (Finset.sum_le_sum fun i _ => hg i).trans_eq (by simp only [Finset.sum_const, - Finset.card_univ,nsmul_eq_mul,num]) - -theorem bucket_upper (w : Wgt B) (hw : SubLaw w) (q : Wgt B) (hq : IsLaw q) - (f : B→ C) (δ : ℝ) (h0 : 0<δ) (hz : stamina (mapW q f) δ) : - ∀ i,bucket q f w i ≤ δ⁻¹*q i := by - intro i - have he : mapW w f (f i) ≤1 := by - exact (pr_le_tot hw.nz).trans hw.total - unfold bucket pour - by_cases hi : mapW q f (f i)=0 - · rw [hi,div_zero,mul_zero]; exact mul_nonneg (inv_pos_of_pos h0).le (hq.nz _) - rw [mul_comm δ⁻¹] - exact mul_le_mul_of_nonneg_left ((div_le_div₀ zero_le_one he h0 (hz _ hi)).trans_eq - (one_div _)) (hq.nz _) - -theorem pr_ref_delta (w : Wgt A) (hw : ∀ i,0 ≤ w i) (P Q : A→ Prop) : - pr w P ≤ pr w Q + pr w (fun i => ¬(P i↔Q i)) := - (pr_mono hw (q:=fun i => Q i ∨ ¬(P i↔Q i)) fun i _ => by tauto).trans (pr_or_le hw) - -variable {μ : Wgt A} {p : A →Wgt B} - -set_option maxHeartbeats 1000000 in -theorem divide_progress [Nonempty B] (h : Ultra μ p) - (ε δ α k : ℝ) (hε : 0<ε) (hk : 0 by unfold q; rw [unif_apply]; positivity - exact var_event w v (by rw [←map_mass w f,←map_mass v f,bucket_scale q w hq.nz hx]) - obtain ⟨F,hF,hφ,hL⟩ := divide_fit q hq f P δ (k*δ) (by positivity) - ((le_of_eq (by rw [← mul_assoc])).trans ((mul_le_mul_of_nonneg_right hk' hδ.le).trans_eq - (one_mul _))) hz - refine ⟨F,hφ,?_⟩ - let Q := fun i : B => ((F i).2=true) - let S := fun i => ¬(P i ↔ Q i) - have h1 : pr w S ≤ ε := by - obtain ⟨hu,he⟩ := h.cat_dom w hw - have hs : pr q S ≤α := by - have hμ := (le_min_iff.mp hC).1 - have : 0≤num (C×Bool) := Nat.cast_nonneg _ - exact hL.trans (by nlinarith only [this,hk,hα,hμ, - mul_le_mul_of_nonneg_left hα (mul_nonneg this hk.le)]) - exact (pr_mono_left he S).trans (hB S hs) - have h2 : pr v S ≤ ε := by - have hh := (pr_cap (bucket_upper w ht q hq f δ hδ hz) S).trans - (mul_le_mul_of_nonneg_left hL (inv_pos_of_pos hδ).le) - exact hh.trans ((le_of_eq (by field_simp)).trans (le_min_iff.mp hC).2) - have h3 : 2*ε < pr w Q-pr v Q := by - have he := pr_ref_delta w ht.nz P Q - have hr' := pr_ref_delta v hv Q P - have heq : (fun i=>¬(Q i↔P i))=S := funext fun i => propext (by unfold S; tauto) - rw [heq] at hr' - change 8*ε < varOne w v at hr - rw [hh] at hr; change pr w P≤pr w Q+pr w S at he - linarith only [hr,h1,h2,he,hr'] - have h4 := var_pr (mapW w F) (mapW v F) (fun i:C×Bool => i.2=true) - rw [mapW_pr,mapW_pr] at h4 - have he := budget_progress h w hw F Prod.fst - change varOne _ (mapW (bucket q (Prod.fst ∘ F) w) F) ^ 2 ≤ _ at he - rw [← hF] at he - nlinarith only [he,hε,(le_trans h3.le h4)] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RefinementEnergy + +namespace OAI + +/-! # Rounded Refinements -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Filter Matrix Real +open scoped BigOperators +variable {A B C D : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype D] + +set_option maxHeartbeats 900000 in +theorem divide_fit (q : Wgt B) (hq : IsLaw q) (f : B→C) (P : B→Prop) + (δ γ : ℝ) (hγ : 0<γ) (hz : 2*γ ≤ δ) (h : stamina (mapW q f) δ) : + ∃ F : B→C×Bool, f=Prod.fst∘F ∧ stamina (mapW q F) γ ∧ + pr q (fun i => ¬(P i ↔ (F i).2))≤num (C×Bool)*γ := by + classical + let g (i : B) : C × Bool := (f i,decide (P i)) + let Q := mapW q g + have hQ := mapW_law hq g + have hf : f=Prod.fst∘g := rfl + have hi (i) : mapW q f i=Q (i,true)+Q (i,false) := by + have hs : mapW q f=mapW Q Prod.fst := hf ▸ Eq.symm (map_nested g Prod.fst) + rw [hs] + simp only [mapW,pr,avg,Fintype.sum_prod_type,Fintype.sum_bool]; simp [ind,Finset.sum_add_distrib] + let s (j:C×Bool) : Bool := if Q (j.1,true) < γ then false else + if Q (j.1,false) < γ then true else j.2 + let F (j : C × Bool) : C × Bool := (j.1,s j) + refine ⟨F ∘ g,rfl,?_,?_⟩ + · rintro ⟨i,b⟩ h' + have hb : + mapW Q F (i,b)=Q (i,true)*ind (s (i,true)=b)+ + Q (i,false)*ind (s (i,false)=b) := by + unfold mapW pr avg + rw [Fintype.sum_prod_type, sum_eq_single i] + · rw [Fintype.sum_bool]; simp [ind,F] + · intro j _ hj; rw [Fintype.sum_bool]; simp [ind,F,hj] + simp + rw [←map_nested,hb] at h' ⊢ + by_cases hx : Q (i,true)<γ + · cases b + · simp only [s,hx,ite_true,ind_true,mul_one] at * + rw [←hi] at * + exact le_trans (by linarith only [hz,hγ]) (h i h') + simp [s,hx,ind] at h' + by_cases hy : Q (i,false)<γ + · cases b + · simp [s,hx,hy,ind] at h' + simp only [s,hx,hy,ite_true,ite_false,ind_true,mul_one] at * + rw [←hi] at * + exact le_trans (by linarith only [hz,hγ]) (h i h') + cases b + · simpa [s,hx,hy,ind] using (le_of_not_gt hy) + simpa [s,hx,hy,ind] using (le_of_not_gt hx) + let R (i : C×Bool) := i.2≠s i + have he j : (¬ (P j ↔ (F (g j)).2)) ↔ R (g j) := by + change (¬ (P j ↔ s (g j)=true)) ↔ decide (P j)≠s (g j) + cases s (g j) <;> simp + have h1 (j : C×Bool) : R j→ Q j≤γ := by + intro hj + rcases j with ⟨i,b⟩ + by_cases hx : Q (i,true)<γ + · cases b + · simp [R,s,hx] at hj + exact hx.le + by_cases hy : Q (i,false)<γ + · cases b + · exact hy.le + simp [R,s,hx,hy] at hj + simp [R,s,hx,hy] at hj + have hg (j) : Q j * ind (R j) ≤ γ := by + by_cases hh : R j + · simpa only [ind_one hh,mul_one] using h1 j hh + rw [ind_zero hh,mul_zero]; exact hγ.le + simp_rw [Function.comp_apply,he] + rw [← mapW_pr] + exact (Finset.sum_le_sum fun i _ => hg i).trans_eq (by simp only [Finset.sum_const, + Finset.card_univ,nsmul_eq_mul,num]) + +theorem bucket_upper (w : Wgt B) (hw : SubLaw w) (q : Wgt B) (hq : IsLaw q) + (f : B→ C) (δ : ℝ) (h0 : 0<δ) (hz : stamina (mapW q f) δ) : + ∀ i,bucket q f w i ≤ δ⁻¹*q i := by + intro i + have he : mapW w f (f i) ≤1 := by + exact (pr_le_tot hw.nz).trans hw.total + unfold bucket pour + by_cases hi : mapW q f (f i)=0 + · rw [hi,div_zero,mul_zero]; exact mul_nonneg (inv_pos_of_pos h0).le (hq.nz _) + rw [mul_comm δ⁻¹] + exact mul_le_mul_of_nonneg_left ((div_le_div₀ zero_le_one he h0 (hz _ hi)).trans_eq + (one_div _)) (hq.nz _) + +theorem pr_ref_delta (w : Wgt A) (hw : ∀ i,0 ≤ w i) (P Q : A→ Prop) : + pr w P ≤ pr w Q + pr w (fun i => ¬(P i↔Q i)) := + (pr_mono hw (q:=fun i => Q i ∨ ¬(P i↔Q i)) fun i _ => by tauto).trans (pr_or_le hw) + +variable {μ : Wgt A} {p : A →Wgt B} + +set_option maxHeartbeats 1000000 in +theorem divide_progress [Nonempty B] (h : Ultra μ p) + (ε δ α k : ℝ) (hε : 0<ε) (hk : 0 by unfold q; rw [unif_apply]; positivity + exact var_event w v (by rw [←map_mass w f,←map_mass v f,bucket_scale q w hq.nz hx]) + obtain ⟨F,hF,hφ,hL⟩ := divide_fit q hq f P δ (k*δ) (by positivity) + ((le_of_eq (by rw [← mul_assoc])).trans ((mul_le_mul_of_nonneg_right hk' hδ.le).trans_eq + (one_mul _))) hz + refine ⟨F,hφ,?_⟩ + let Q := fun i : B => ((F i).2=true) + let S := fun i => ¬(P i ↔ Q i) + have h1 : pr w S ≤ ε := by + obtain ⟨hu,he⟩ := h.cat_dom w hw + have hs : pr q S ≤α := by + have hμ := (le_min_iff.mp hC).1 + have : 0≤num (C×Bool) := Nat.cast_nonneg _ + exact hL.trans (by nlinarith only [this,hk,hα,hμ, + mul_le_mul_of_nonneg_left hα (mul_nonneg this hk.le)]) + exact (pr_mono_left he S).trans (hB S hs) + have h2 : pr v S ≤ ε := by + have hh := (pr_cap (bucket_upper w ht q hq f δ hδ hz) S).trans + (mul_le_mul_of_nonneg_left hL (inv_pos_of_pos hδ).le) + exact hh.trans ((le_of_eq (by field_simp)).trans (le_min_iff.mp hC).2) + have h3 : 2*ε < pr w Q-pr v Q := by + have he := pr_ref_delta w ht.nz P Q + have hr' := pr_ref_delta v hv Q P + have heq : (fun i=>¬(Q i↔P i))=S := funext fun i => propext (by unfold S; tauto) + rw [heq] at hr' + change 8*ε < varOne w v at hr + rw [hh] at hr; change pr w P≤pr w Q+pr w S at he + linarith only [hr,h1,h2,he,hr'] + have h4 := var_pr (mapW w F) (mapW v F) (fun i:C×Bool => i.2=true) + rw [mapW_pr,mapW_pr] at h4 + have he := budget_progress h w hw F Prod.fst + change varOne _ (mapW (bucket q (Prod.fst ∘ F) w) F) ^ 2 ≤ _ at he + rw [← hF] at he + nlinarith only [he,hε,(le_trans h3.le h4)] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SampledGraphs.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SampledGraphs.lean index e7d8951aa74dc63ef985e92e3e3b24bde39e62e3..9b9db3278633df25dc61a9d5be1b5e6edc5a6ace 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SampledGraphs.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SampledGraphs.lean @@ -1,102 +1,102 @@ -import OAI.Combinatorics.HadwigerMatching.BasicMatching -import Mathlib.Data.Fintype.EquivFin -import Mathlib.Combinatorics.SimpleGraph.Clique -import Lean.Elab.Tactic.Omega - -namespace OAI - -/-! # Sampled Graphs -/ - -noncomputable section -namespace HadwigerCounterexample -open HadwigerMatching Finset -variable {A V : Type*} - -structure Holes (A : Type*) where - rel : A → A → Prop - sym {x y : A} : rel x y → rel y x - irr (x : A) : ¬ rel x x - ntri {x y z : A} : rel x y → rel y z → ¬ rel x z - -namespace Holes - -variable (H : Holes A) -def unit (p : A × A) := ¬H.rel p.1 p.2 -def conflict (p q : A × A) := H.rel p.1 q.1 ∧ H.rel p.1 q.2 ∧ H.rel p.2 q.1 ∧ H.rel p.2 q.2 - -theorem no_self_conflict (p : A × A) : ¬ H.conflict p p := fun h => H.irr p.1 h.1 - -def graph (x : V → A) : SimpleGraph V where - Adj i j := i ≠ j ∧ ¬H.rel (x i) (x j) - symm := ⟨fun _ _ ⟨hne,h⟩ => ⟨hne.symm,fun h' => h (H.sym h')⟩⟩ - loopless := ⟨fun _ h => h.1 rfl⟩ - -theorem indepNum_graph_le [Fintype V] (x : V → A) : (graph H x).indepNum ≤ 2 := by - classical - obtain ⟨S, hS, he⟩ := (graph H x).exists_isNIndepSet_indepNum - rw [← he] - by_contra h - have hr : Fintype.card (Fin 3) ≤ Fintype.card S := by simp; omega - obtain ⟨e⟩ := Function.Embedding.nonempty_of_card_le hr - let f : Fin 3 → V := fun i => e i - have hf {i j} (h : i ≠ j) : H.rel (x (f i)) (x (f j)) := by - by_contra hp - apply hS (show f i ∈ (S : Set V) from (e i).property) - (show f j ∈ (S : Set V) from (e j).property) - (show f i ≠ f j from fun g => h (e.injective (Subtype.ext g))) - exact ⟨fun g => h (e.injective (Subtype.ext g)), hp⟩ - exact H.ntri (hf (i:=0) (j:=1) (by decide)) (hf (j:=2) (by decide)) - (hf (by decide)) - -/-- Enumerate endpoints of an actual maximum connected matching on positions to -obtain pairwise disjoint ordered pairs; their raw unit types do not conflict. -/ -theorem matching_pairs [Fintype V] (x : V → A) : - let t := connectedMatchingNumber (graph H x) - ∃ e : (Fin t ⊕ Fin t) → V, Function.Injective e ∧ - let f : Fin t → A × A := fun i => (x (e (.inl i)), x (e (.inr i))) - (∀ i, H.unit (f i)) ∧ (∀ i j, ¬H.conflict (f i) (f j)) := by - classical - let G := graph H x - let t := connectedMatchingNumber G - obtain ⟨M,hM,hc⟩ := exists_matching_card_eq_number G - have ht : Fintype.card M = t := by rw [Fintype.card_coe,hc] - let m := (Fintype.equivFinOfCardEq ht).symm - let m' (i : Fin t) : Finset V := (m i).val - have hm i : m' i ∈ M := (m i).property - have hex (i : Fin t) : ∃ v w : V, v ≠ w ∧ m' i = {v,w} := - card_eq_two.mp (hM.1 _ (hm i)).1 - choose v w hv he using hex - let e := Sum.elim v w - have hmem (i : Fin t ⊕ Fin t) : e i ∈ m' (Sum.elim id id i) := by - cases i <;> simp [e,he] - have hminj : Function.Injective m' := fun i j g => m.injective (Subtype.ext g) - have hei : Function.Injective e := by - intro i j h - have hi : Sum.elim id id i = Sum.elim id id j := by - by_contra hn - have hh := hM.2.1 _ (hm _) _ (hm _) (hminj.ne hn) - exact Finset.disjoint_left.mp hh (hmem i) (by rw [h]; exact hmem j) - cases i <;> cases j <;> simp_all [e] - exact hv _ h.symm - refine ⟨e, hei, fun i => ?_, fun i j => ?_⟩ - · have h1 : v i ∈ m' i := by simp [he] - have h2 : w i ∈ m' i := by simp [he] - exact ((hM.1 _ (hm i)).2 h1 h2 (hv i)).2 - · by_cases h : i = j - · subst j; exact no_self_conflict _ _ - · obtain ⟨a,ha,b,hb,hadj⟩ := hM.2.2 _ (hm i) _ (hm j) (hminj.ne h) - have ha' : a = v i ∨ a = w i := by simpa [he] using ha - have hb' : b = v j ∨ b = w j := by simpa [he] using hb - intro hz - apply hadj.2 - rcases ha' with h1|h1 <;> rcases hb' with h2|h2 <;> rw [h1,h2] - · exact hz.1 - · exact hz.2.1 - · exact hz.2.2.1 - · exact hz.2.2.2 -end Holes -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerMatching.BasicMatching +import Mathlib.Data.Fintype.EquivFin +import Mathlib.Combinatorics.SimpleGraph.Clique +import Lean.Elab.Tactic.Omega + +namespace OAI + +/-! # Sampled Graphs -/ + +noncomputable section +namespace HadwigerCounterexample +open HadwigerMatching Finset +variable {A V : Type*} + +structure Holes (A : Type*) where + rel : A → A → Prop + sym {x y : A} : rel x y → rel y x + irr (x : A) : ¬ rel x x + ntri {x y z : A} : rel x y → rel y z → ¬ rel x z + +namespace Holes + +variable (H : Holes A) +def unit (p : A × A) := ¬H.rel p.1 p.2 +def conflict (p q : A × A) := H.rel p.1 q.1 ∧ H.rel p.1 q.2 ∧ H.rel p.2 q.1 ∧ H.rel p.2 q.2 + +theorem no_self_conflict (p : A × A) : ¬ H.conflict p p := fun h => H.irr p.1 h.1 + +def graph (x : V → A) : SimpleGraph V where + Adj i j := i ≠ j ∧ ¬H.rel (x i) (x j) + symm := ⟨fun _ _ ⟨hne,h⟩ => ⟨hne.symm,fun h' => h (H.sym h')⟩⟩ + loopless := ⟨fun _ h => h.1 rfl⟩ + +theorem indepNum_graph_le [Fintype V] (x : V → A) : (graph H x).indepNum ≤ 2 := by + classical + obtain ⟨S, hS, he⟩ := (graph H x).exists_isNIndepSet_indepNum + rw [← he] + by_contra h + have hr : Fintype.card (Fin 3) ≤ Fintype.card S := by simp; omega + obtain ⟨e⟩ := Function.Embedding.nonempty_of_card_le hr + let f : Fin 3 → V := fun i => e i + have hf {i j} (h : i ≠ j) : H.rel (x (f i)) (x (f j)) := by + by_contra hp + apply hS (show f i ∈ (S : Set V) from (e i).property) + (show f j ∈ (S : Set V) from (e j).property) + (show f i ≠ f j from fun g => h (e.injective (Subtype.ext g))) + exact ⟨fun g => h (e.injective (Subtype.ext g)), hp⟩ + exact H.ntri (hf (i:=0) (j:=1) (by decide)) (hf (j:=2) (by decide)) + (hf (by decide)) + +/-- Enumerate endpoints of an actual maximum connected matching on positions to +obtain pairwise disjoint ordered pairs; their raw unit types do not conflict. -/ +theorem matching_pairs [Fintype V] (x : V → A) : + let t := connectedMatchingNumber (graph H x) + ∃ e : (Fin t ⊕ Fin t) → V, Function.Injective e ∧ + let f : Fin t → A × A := fun i => (x (e (.inl i)), x (e (.inr i))) + (∀ i, H.unit (f i)) ∧ (∀ i j, ¬H.conflict (f i) (f j)) := by + classical + let G := graph H x + let t := connectedMatchingNumber G + obtain ⟨M,hM,hc⟩ := exists_matching_card_eq_number G + have ht : Fintype.card M = t := by rw [Fintype.card_coe,hc] + let m := (Fintype.equivFinOfCardEq ht).symm + let m' (i : Fin t) : Finset V := (m i).val + have hm i : m' i ∈ M := (m i).property + have hex (i : Fin t) : ∃ v w : V, v ≠ w ∧ m' i = {v,w} := + card_eq_two.mp (hM.1 _ (hm i)).1 + choose v w hv he using hex + let e := Sum.elim v w + have hmem (i : Fin t ⊕ Fin t) : e i ∈ m' (Sum.elim id id i) := by + cases i <;> simp [e,he] + have hminj : Function.Injective m' := fun i j g => m.injective (Subtype.ext g) + have hei : Function.Injective e := by + intro i j h + have hi : Sum.elim id id i = Sum.elim id id j := by + by_contra hn + have hh := hM.2.1 _ (hm _) _ (hm _) (hminj.ne hn) + exact Finset.disjoint_left.mp hh (hmem i) (by rw [h]; exact hmem j) + cases i <;> cases j <;> simp_all [e] + exact hv _ h.symm + refine ⟨e, hei, fun i => ?_, fun i j => ?_⟩ + · have h1 : v i ∈ m' i := by simp [he] + have h2 : w i ∈ m' i := by simp [he] + exact ((hM.1 _ (hm i)).2 h1 h2 (hv i)).2 + · by_cases h : i = j + · subst j; exact no_self_conflict _ _ + · obtain ⟨a,ha,b,hb,hadj⟩ := hM.2.2 _ (hm i) _ (hm j) (hminj.ne h) + have ha' : a = v i ∨ a = w i := by simpa [he] using ha + have hb' : b = v j ∨ b = w j := by simpa [he] using hb + intro hz + apply hadj.2 + rcases ha' with h1|h1 <;> rcases hb' with h2|h2 <;> rw [h1,h2] + · exact hz.1 + · exact hz.2.1 + · exact hz.2.2.1 + · exact hz.2.2.2 +end Holes +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ScalarStatusAlgebra.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ScalarStatusAlgebra.lean index 8e05f4d2626abce5c0a87175baa8da4672caba24..07b36d3f6da118243774ef99a7910f92668a17af 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ScalarStatusAlgebra.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ScalarStatusAlgebra.lean @@ -1,162 +1,162 @@ -import OAI.Combinatorics.HadwigerCounterexample.BasisConditioning - -namespace OAI - -/-! # Scalar Status Algebra -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Submodule Finset Function Module -open scoped BigOperators - -namespace StatusAnalysis -abbrev Nodes := Bool -abbrev Grid := Nodes × Nodes -abbrev Cell (d : ℕ) := Vec (Fin d) - -abbrev Par (d : ℕ) := F × Cell d -abbrev Whole (d : ℕ) := Par d × F - -abbrev Signal (d e : ℕ) := F × Whole d × Whole e -abbrev View (d e : ℕ) := F × Par d × Par e -abbrev Question (d e : ℕ) := F × F × Cell d × Cell e -variable {d e : ℕ} - -def view (d e : ℕ) : Signal d e→ₗ[F] View d e where - toFun x := (x.1,x.2.1.1,x.2.2.1) - map_add' _ _ := rfl - map_smul' _ _ := rfl -def testV (d e : ℕ) : View d e →ₗ[F] Question d e where - toFun x := (x.1,x.2.1.1 + x.2.2.1,x.2.1.2,x.2.2.2) - map_add' _ _ := Prod.ext rfl (Prod.ext (add_add_add_comm ..) rfl) - map_smul' _ _ := Prod.ext rfl (Prod.ext (mul_add _ _ _).symm rfl) -def want (d e : ℕ) := testV d e ∘ₗ view d e - -def couple (d : ℕ) : Whole d→ₗ[F] F where - toFun x := x.1.1+x.2 - map_add' _ _ := add_add_add_comm .. - map_smul' a _ := (mul_add a _ _).symm - -def coverBase (V : Space (Signal d e)) := Surjective (view d e ∘ₗ V.subtype) -theorem testV_surj (d e : ℕ) : Surjective (testV d e) := by - rintro ⟨a,b,x,y⟩ - exact ⟨(a,(b,x),(0,y)),Prod.ext rfl (Prod.ext (add_zero _) rfl)⟩ -theorem coversFull {V : Space (Signal d e)} (h : coverBase V) : Surjective (want d e ∘ₗ V.subtype) := - (testV_surj _ _).comp h - -abbrev Rates := Nodes→ℕ -abbrev Suite (A B : Rates) (i : Grid) := Signal (A i.1) (B i.2) -abbrev LedgerS (A B : Rates) (i : Grid) := Question (A i.1) (B i.2) -abbrev Cabinet (A B : Rates) := ∀ i, LedgerS A B i -abbrev Quota := Vec Nodes -abbrev Court (A B : Rates) := Cabinet A B × Quota × Quota -abbrev StatusSp (A B : Rates) := ∀ i,Space (Suite A B i) -variable {A B : Rates} - -def separate (A B : Rates) (i : Grid) : - Suite A B i →ₗ[F] Court A B := - (LinearMap.single F (LedgerS A B) i ∘ₗ want _ _).prod - ((LinearMap.single F (fun _ : Bool=>F) i.2 ∘ₗ - (couple (A i.1) ∘ₗ LinearMap.fst F _ _ ∘ₗ LinearMap.snd F _ _)).prod - (LinearMap.single F (fun _ : Bool=>F) i.1 ∘ₗ - (couple (B i.2) ∘ₗ LinearMap.snd F _ _ ∘ₗ LinearMap.snd F _ _))) - -def speak (A B : Rates) : - (∀ i,Suite A B i) →ₗ[F] Court A B := ∑ i:Grid,separate A B i ∘ₗ LinearMap.proj i - -theorem speak_solo (A B : Rates) (i : Grid) (x : Suite A B i) : - speak A B (Pi.single i x)=separate A B i x := by - classical - unfold speak; rw [LinearMap.sum_apply,sum_eq_single i] - · rw [LinearMap.comp_apply]; change separate _ _ _ ((Pi.single i x : ∀ i, Suite A B i) i)=_ - rw [Pi.single_eq_same] - · intro j _ hj; rw [LinearMap.comp_apply] - change separate _ _ _ ((Pi.single i x : ∀ i, Suite A B i) j)=_ - rw [Pi.single_eq_of_ne hj,map_zero] - simp - -def scorecard (V : StatusSp A B) (T : Cabinet A B) := - ∃ v : ∀ i,Suite A B i,(∀ i,v i∈V i) ∧ speak A B v=(T,0) - -structure Critic (A B : Rates) where - alf : ∀ i : Grid, LedgerS A B i →ₗ[F] F - altL : Quota - altR : Quota -def Counter (g : Critic A B) (V : StatusSp A B) := - ∀ i:Grid,∀ v∈V i, g.alf i (want _ _ v) = - g.altL i.2 * couple _ v.2.1 + g.altR i.1 * couple _ v.2.2 - -private theorem vanishes {M : Type} [AddCommGroup M] [Module F M] (V : Space M) {z} - (h : z∉ V) : - ∃ f:M→ₗ[F] F,f z ≠0 ∧ ∀ i∈V,f i=0 := by - have he : V.mkQ z ≠0 := fun hg=>h ((Submodule.Quotient.mk_eq_zero V).mp hg) - obtain ⟨f,hf⟩ := Module.Projective.exists_dual_ne_zero F he - exact ⟨f ∘ₗ V.mkQ,hf,fun i hi =>by rw [LinearMap.comp_apply,show V.mkQ i=0 from - (Submodule.Quotient.mk_eq_zero V).mpr hi,map_zero]⟩ - -set_option maxHeartbeats 800000 in -theorem counter_score (V : StatusSp A B) (T : Cabinet A B) - (h : ¬scorecard V T) : - ∃ g : Critic A B,Counter g V ∧ ∑ i,g.alf i (T i)≠0 := by - classical - let S := (Submodule.pi Set.univ V).map (speak A B) - have ht : (T,(0 : Quota × Quota))∉ S := by - rintro ⟨z,hz,he⟩ - exact h ⟨z,fun i => hz i (Set.mem_univ _),he⟩ - obtain ⟨f,hf,hx⟩ := vanishes S ht - let g : Critic A B := { - alf := fun i => f ∘ₗ LinearMap.inl F (Cabinet A B) _ ∘ₗ LinearMap.single F _ i - altL := fun i=> f (0,Pi.single i 1,0) - altR := fun i=> f (0,0,Pi.single i 1) } - refine ⟨g,fun i v hv => ?_,?_⟩ - · have hi : - f (separate A B i v)=0 := by - apply hx - refine ⟨Pi.single i v,?_,speak_solo A B i v⟩ - intro j _ - by_cases ht : j=i - · subst j; rwa [Pi.single_eq_same] - rw [Pi.single_eq_of_ne ht]; exact zero_mem _ - let a:= couple _ v.2.1 - let b:= couple _ v.2.2 - let Q:= want _ _ v - have hh (a:F) (i:Bool) : - (a • Pi.single i 1 : Quota)=Pi.single i a := by - ext j; by_cases he:j=i <;> simp [he] - have hz : - separate A B i v = - ( (Pi.single i Q : Cabinet A B),0) + (a • (0,Pi.single i.2 1,(0:Quota))+ - b • (0,(0:Quota),Pi.single i.1 1)) := by - change ((Pi.single i Q:Cabinet A B),(Pi.single i.2 a:Quota),(Pi.single i.1 b:Quota))=_ - apply Prod.ext; simp - apply Prod.ext <;> simp [hh] - rw [hz,map_add,map_add,map_smul,map_smul] at hi - change g.alf i Q+(a*g.altL i.2+b*g.altR i.1)=0 at hi - change _=g.altL _ * a+g.altR _ * b - rw [mul_comm _ a,mul_comm _ b] - exact add_right_cancel (hi.trans (char_two _).symm) - · have hh (i) : g.alf i (T i)=f ((Pi.single i (T i) : Cabinet A B),0) := rfl - have ht : ∑ i:Grid, ((Pi.single i (T i) : Cabinet A B),(0 : Quota × Quota))= - (T,0) := by - apply Prod.ext - · rw [Prod.fst_sum]; exact Finset.univ_sum_single _ - · simp only [Prod.snd_sum,Finset.sum_const_zero] - simp_rw [hh, ← map_sum,ht] - exact hf - -theorem critic_nz (V : StatusSp A B) (T : Cabinet A B) (hV : ∀ i,coverBase (V i)) (g : Critic A B) - (h : Counter g V) (hh : ∑ i,g.alf i (T i)≠0) : g.altL≠0 ∨ g.altR≠0 := by - classical - by_contra! hz - apply hh; apply Finset.sum_eq_zero - intro i _ - obtain ⟨⟨v,hv⟩,ht⟩ := coversFull (hV i) (T i) - simpa only [show want (A i.1) (B i.2) v=T i from ht,hz.1,hz.2,Pi.zero_apply,zero_mul,add_zero] - using h i v hv - -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BasisConditioning + +namespace OAI + +/-! # Scalar Status Algebra -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Submodule Finset Function Module +open scoped BigOperators + +namespace StatusAnalysis +abbrev Nodes := Bool +abbrev Grid := Nodes × Nodes +abbrev Cell (d : ℕ) := Vec (Fin d) + +abbrev Par (d : ℕ) := F × Cell d +abbrev Whole (d : ℕ) := Par d × F + +abbrev Signal (d e : ℕ) := F × Whole d × Whole e +abbrev View (d e : ℕ) := F × Par d × Par e +abbrev Question (d e : ℕ) := F × F × Cell d × Cell e +variable {d e : ℕ} + +def view (d e : ℕ) : Signal d e→ₗ[F] View d e where + toFun x := (x.1,x.2.1.1,x.2.2.1) + map_add' _ _ := rfl + map_smul' _ _ := rfl +def testV (d e : ℕ) : View d e →ₗ[F] Question d e where + toFun x := (x.1,x.2.1.1 + x.2.2.1,x.2.1.2,x.2.2.2) + map_add' _ _ := Prod.ext rfl (Prod.ext (add_add_add_comm ..) rfl) + map_smul' _ _ := Prod.ext rfl (Prod.ext (mul_add _ _ _).symm rfl) +def want (d e : ℕ) := testV d e ∘ₗ view d e + +def couple (d : ℕ) : Whole d→ₗ[F] F where + toFun x := x.1.1+x.2 + map_add' _ _ := add_add_add_comm .. + map_smul' a _ := (mul_add a _ _).symm + +def coverBase (V : Space (Signal d e)) := Surjective (view d e ∘ₗ V.subtype) +theorem testV_surj (d e : ℕ) : Surjective (testV d e) := by + rintro ⟨a,b,x,y⟩ + exact ⟨(a,(b,x),(0,y)),Prod.ext rfl (Prod.ext (add_zero _) rfl)⟩ +theorem coversFull {V : Space (Signal d e)} (h : coverBase V) : Surjective (want d e ∘ₗ V.subtype) := + (testV_surj _ _).comp h + +abbrev Rates := Nodes→ℕ +abbrev Suite (A B : Rates) (i : Grid) := Signal (A i.1) (B i.2) +abbrev LedgerS (A B : Rates) (i : Grid) := Question (A i.1) (B i.2) +abbrev Cabinet (A B : Rates) := ∀ i, LedgerS A B i +abbrev Quota := Vec Nodes +abbrev Court (A B : Rates) := Cabinet A B × Quota × Quota +abbrev StatusSp (A B : Rates) := ∀ i,Space (Suite A B i) +variable {A B : Rates} + +def separate (A B : Rates) (i : Grid) : + Suite A B i →ₗ[F] Court A B := + (LinearMap.single F (LedgerS A B) i ∘ₗ want _ _).prod + ((LinearMap.single F (fun _ : Bool=>F) i.2 ∘ₗ + (couple (A i.1) ∘ₗ LinearMap.fst F _ _ ∘ₗ LinearMap.snd F _ _)).prod + (LinearMap.single F (fun _ : Bool=>F) i.1 ∘ₗ + (couple (B i.2) ∘ₗ LinearMap.snd F _ _ ∘ₗ LinearMap.snd F _ _))) + +def speak (A B : Rates) : + (∀ i,Suite A B i) →ₗ[F] Court A B := ∑ i:Grid,separate A B i ∘ₗ LinearMap.proj i + +theorem speak_solo (A B : Rates) (i : Grid) (x : Suite A B i) : + speak A B (Pi.single i x)=separate A B i x := by + classical + unfold speak; rw [LinearMap.sum_apply,sum_eq_single i] + · rw [LinearMap.comp_apply]; change separate _ _ _ ((Pi.single i x : ∀ i, Suite A B i) i)=_ + rw [Pi.single_eq_same] + · intro j _ hj; rw [LinearMap.comp_apply] + change separate _ _ _ ((Pi.single i x : ∀ i, Suite A B i) j)=_ + rw [Pi.single_eq_of_ne hj,map_zero] + simp + +def scorecard (V : StatusSp A B) (T : Cabinet A B) := + ∃ v : ∀ i,Suite A B i,(∀ i,v i∈V i) ∧ speak A B v=(T,0) + +structure Critic (A B : Rates) where + alf : ∀ i : Grid, LedgerS A B i →ₗ[F] F + altL : Quota + altR : Quota +def Counter (g : Critic A B) (V : StatusSp A B) := + ∀ i:Grid,∀ v∈V i, g.alf i (want _ _ v) = + g.altL i.2 * couple _ v.2.1 + g.altR i.1 * couple _ v.2.2 + +private theorem vanishes {M : Type} [AddCommGroup M] [Module F M] (V : Space M) {z} + (h : z∉ V) : + ∃ f:M→ₗ[F] F,f z ≠0 ∧ ∀ i∈V,f i=0 := by + have he : V.mkQ z ≠0 := fun hg=>h ((Submodule.Quotient.mk_eq_zero V).mp hg) + obtain ⟨f,hf⟩ := Module.Projective.exists_dual_ne_zero F he + exact ⟨f ∘ₗ V.mkQ,hf,fun i hi =>by rw [LinearMap.comp_apply,show V.mkQ i=0 from + (Submodule.Quotient.mk_eq_zero V).mpr hi,map_zero]⟩ + +set_option maxHeartbeats 800000 in +theorem counter_score (V : StatusSp A B) (T : Cabinet A B) + (h : ¬scorecard V T) : + ∃ g : Critic A B,Counter g V ∧ ∑ i,g.alf i (T i)≠0 := by + classical + let S := (Submodule.pi Set.univ V).map (speak A B) + have ht : (T,(0 : Quota × Quota))∉ S := by + rintro ⟨z,hz,he⟩ + exact h ⟨z,fun i => hz i (Set.mem_univ _),he⟩ + obtain ⟨f,hf,hx⟩ := vanishes S ht + let g : Critic A B := { + alf := fun i => f ∘ₗ LinearMap.inl F (Cabinet A B) _ ∘ₗ LinearMap.single F _ i + altL := fun i=> f (0,Pi.single i 1,0) + altR := fun i=> f (0,0,Pi.single i 1) } + refine ⟨g,fun i v hv => ?_,?_⟩ + · have hi : + f (separate A B i v)=0 := by + apply hx + refine ⟨Pi.single i v,?_,speak_solo A B i v⟩ + intro j _ + by_cases ht : j=i + · subst j; rwa [Pi.single_eq_same] + rw [Pi.single_eq_of_ne ht]; exact zero_mem _ + let a:= couple _ v.2.1 + let b:= couple _ v.2.2 + let Q:= want _ _ v + have hh (a:F) (i:Bool) : + (a • Pi.single i 1 : Quota)=Pi.single i a := by + ext j; by_cases he:j=i <;> simp [he] + have hz : + separate A B i v = + ( (Pi.single i Q : Cabinet A B),0) + (a • (0,Pi.single i.2 1,(0:Quota))+ + b • (0,(0:Quota),Pi.single i.1 1)) := by + change ((Pi.single i Q:Cabinet A B),(Pi.single i.2 a:Quota),(Pi.single i.1 b:Quota))=_ + apply Prod.ext; simp + apply Prod.ext <;> simp [hh] + rw [hz,map_add,map_add,map_smul,map_smul] at hi + change g.alf i Q+(a*g.altL i.2+b*g.altR i.1)=0 at hi + change _=g.altL _ * a+g.altR _ * b + rw [mul_comm _ a,mul_comm _ b] + exact add_right_cancel (hi.trans (char_two _).symm) + · have hh (i) : g.alf i (T i)=f ((Pi.single i (T i) : Cabinet A B),0) := rfl + have ht : ∑ i:Grid, ((Pi.single i (T i) : Cabinet A B),(0 : Quota × Quota))= + (T,0) := by + apply Prod.ext + · rw [Prod.fst_sum]; exact Finset.univ_sum_single _ + · simp only [Prod.snd_sum,Finset.sum_const_zero] + simp_rw [hh, ← map_sum,ht] + exact hf + +theorem critic_nz (V : StatusSp A B) (T : Cabinet A B) (hV : ∀ i,coverBase (V i)) (g : Critic A B) + (h : Counter g V) (hh : ∑ i,g.alf i (T i)≠0) : g.altL≠0 ∨ g.altR≠0 := by + classical + by_contra! hz + apply hh; apply Finset.sum_eq_zero + intro i _ + obtain ⟨⟨v,hv⟩,ht⟩ := coversFull (hV i) (T i) + simpa only [show want (A i.1) (B i.2) v=T i from ht,hz.1,hz.2,Pi.zero_apply,zero_mul,add_zero] + using h i v hv + +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ScriptGramCorrespondence.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ScriptGramCorrespondence.lean index 68c5cd2c4b73c1a5e2d34610766a0d09f2770680..cbca623e96b115f16f945216a2d9b3b8835afff8 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ScriptGramCorrespondence.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ScriptGramCorrespondence.lean @@ -1,104 +1,104 @@ -import OAI.Combinatorics.HadwigerCounterexample.EndpointEvaluations - -namespace OAI - -/-! # Script Gram Correspondence -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix LinearMap Function -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] - -namespace Template -variable (v : Template p I) - -def lyrics (s : Script p I) (i : v.Chorus) : Vec (v.Abbey i) := - match i with - | .inl z => Sum.elim (fun j => if j.2 then s z.val.1 z.val.2 j.1 else s z.val.2 z.val.1 j.1) - (fun _ => 0) - | .inr _ => 0 -def performs (s : Script p I) (m : Mixer p n) (x : UnitType p n N) (z : Inputs p n I) := - listen v.choral (v.chime m x) z=v.lyrics s - -omit [DecidableEq I] in -theorem across_duet (v : Template p I) {i j} (h : i ≠ j) : - ∃ k : v.Chorus,v.verses k=(i,j)∨v.verses k=(j,i) := by - classical - let e := Fintype.equivFin I - by_cases hg : v.aim i=v.aim j - · rcases lt_or_gt_of_ne (e.injective.ne h) with hh|hh - · exact ⟨.inl ⟨⟨i,j⟩,hg,hh⟩,Or.inl rfl⟩ - exact ⟨.inl ⟨⟨j,i⟩,hg.symm,hh⟩,Or.inr rfl⟩ - cases hi : v.aim i <;> cases hj : v.aim j - · simp [hi,hj] at hg - · exact ⟨.inr ⟨⟨j,i⟩,hj,hi⟩,Or.inr rfl⟩ - · exact ⟨.inr ⟨⟨i,j⟩,hi,hj⟩,Or.inl rfl⟩ - simp [hi,hj] at hg - -def voices (v : Template p I) (x : Keys (p:=p) v.t N) (i j) (e : Comp p.g) (a : inc e (v.t i)) - (b : inc e (v.t j)) (q : Bool) := - dotProduct (x i ⟨e,a⟩ q) (x j ⟨e,b⟩ (!q)) - -omit [Fintype I] [DecidableEq I] in -theorem voice_note (v : Template p I) (x : UnitType p n N) (z : Inputs p n I) - (e : Comp p.g) (i j) (a : inc e (v.t i)) (b : inc e (v.t j)) (q : Bool) : - v.voices ((v.draw z).keys v.t x) i j e a b q=evmat - (duel p (onSide x (v.aim i) e) (onSide x (v.aim j) e) q) - (v.croon i (z i)) (v.croon j (z j)) := by - let P := primary (takeSign (p:=p) (onSide x (v.aim i) e) q) - let Q := primary (takeSign (p:=p) (onSide x (v.aim j) e) (!q)) - let u := v.croon i (z i); let t := v.croon j (z j) - change dotProduct (P *ᵥ u) (Q *ᵥ t)=dotProduct u ((Pᵀ *Q)*ᵥ t) - rw [← mulVec_mulVec,dotProduct_transpose_mulVec] - exact dotProduct_comm _ _ - -omit [Fintype I] [DecidableEq I] in -theorem voice_same (v : Template p I) (x : UnitType p n N) (z : Inputs p n I) - (m : Mixer p n) (hw : ∀ i,frameLaw m (onSide x i)) - (e : Comp p.g) (i j) (a : inc e (v.t i)) (b : inc e (v.t j)) - (h : v.aim i=v.aim j) (q : Bool) : - v.voices ((v.draw z).keys v.t x) i j e a b q=evmat - (eitherM q (selfM p n m.mixM)) (v.croon i (z i)) (v.croon j (z j)) := by - rw [voice_note,h] - let y := onSide x (v.aim j) e - have he : (primary y.1)ᵀ*primary y.2=selfM p n m.mixM := (hw (v.aim j) e).2.2.1 - congr 1 - unfold duel - cases q - · change (primary y.2)ᵀ*primary y.1=_ - rw [←he]; simp only [eitherM,Bool.false_eq_true,ite_false, transpose_mul,transpose_transpose] - exact he - -def verges (v : Template p I) (x : Keys (p:=p) v.t N) (i j) := - ∀ e a b q,v.voices x i j e a b q=0 -omit [Fintype I] [DecidableEq I] in -theorem verges_rev (v : Template p I) {x : Keys (p:=p) v.t N} {i j} - (h : v.verges x i j) : v.verges x j i := by - intro e a b q - have ht := h e b a (!q) - unfold voices at *; rw [dotProduct_comm]; rwa [Bool.not_not] at ht - -omit [Fintype I] [DecidableEq I] in -theorem voices_diag (v : Template p I) (m : Mixer p n) (x : UnitType p n N) - (w : Inputs p n I) (hw : ∀ i,frameLaw m (onSide x i)) (hj : 1≤p.j) (i : I) : - ownOne p (v.t i) (dialed p (v.t i) (v.f i) (w i)) - ((v.draw w).keys v.t x i) := by - intro e - let y := (v.draw w).par i - let A := mom p (v.s i) y - have h : A∈Wspace p n := Submodule.subset_span ⟨_,_,rfl⟩ - have he := v.voice_same x w m hw e.val i i e.property e.property rfl true - let E := selfM p n m.mixM - change v.voices _ i i e.val e.property e.property true=_ - rw [he] - change evmat E (point p _ y) (point p _ y)=_ - rw [← mpair_outer] - exact (selfM_pair p hj m.mixM h).trans (etaScan p (n:=n) (v.t i) (v.s i) _ (w i)).symm - -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.EndpointEvaluations + +namespace OAI + +/-! # Script Gram Correspondence -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix LinearMap Function +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] + +namespace Template +variable (v : Template p I) + +def lyrics (s : Script p I) (i : v.Chorus) : Vec (v.Abbey i) := + match i with + | .inl z => Sum.elim (fun j => if j.2 then s z.val.1 z.val.2 j.1 else s z.val.2 z.val.1 j.1) + (fun _ => 0) + | .inr _ => 0 +def performs (s : Script p I) (m : Mixer p n) (x : UnitType p n N) (z : Inputs p n I) := + listen v.choral (v.chime m x) z=v.lyrics s + +omit [DecidableEq I] in +theorem across_duet (v : Template p I) {i j} (h : i ≠ j) : + ∃ k : v.Chorus,v.verses k=(i,j)∨v.verses k=(j,i) := by + classical + let e := Fintype.equivFin I + by_cases hg : v.aim i=v.aim j + · rcases lt_or_gt_of_ne (e.injective.ne h) with hh|hh + · exact ⟨.inl ⟨⟨i,j⟩,hg,hh⟩,Or.inl rfl⟩ + exact ⟨.inl ⟨⟨j,i⟩,hg.symm,hh⟩,Or.inr rfl⟩ + cases hi : v.aim i <;> cases hj : v.aim j + · simp [hi,hj] at hg + · exact ⟨.inr ⟨⟨j,i⟩,hj,hi⟩,Or.inr rfl⟩ + · exact ⟨.inr ⟨⟨i,j⟩,hi,hj⟩,Or.inl rfl⟩ + simp [hi,hj] at hg + +def voices (v : Template p I) (x : Keys (p:=p) v.t N) (i j) (e : Comp p.g) (a : inc e (v.t i)) + (b : inc e (v.t j)) (q : Bool) := + dotProduct (x i ⟨e,a⟩ q) (x j ⟨e,b⟩ (!q)) + +omit [Fintype I] [DecidableEq I] in +theorem voice_note (v : Template p I) (x : UnitType p n N) (z : Inputs p n I) + (e : Comp p.g) (i j) (a : inc e (v.t i)) (b : inc e (v.t j)) (q : Bool) : + v.voices ((v.draw z).keys v.t x) i j e a b q=evmat + (duel p (onSide x (v.aim i) e) (onSide x (v.aim j) e) q) + (v.croon i (z i)) (v.croon j (z j)) := by + let P := primary (takeSign (p:=p) (onSide x (v.aim i) e) q) + let Q := primary (takeSign (p:=p) (onSide x (v.aim j) e) (!q)) + let u := v.croon i (z i); let t := v.croon j (z j) + change dotProduct (P *ᵥ u) (Q *ᵥ t)=dotProduct u ((Pᵀ *Q)*ᵥ t) + rw [← mulVec_mulVec,dotProduct_transpose_mulVec] + exact dotProduct_comm _ _ + +omit [Fintype I] [DecidableEq I] in +theorem voice_same (v : Template p I) (x : UnitType p n N) (z : Inputs p n I) + (m : Mixer p n) (hw : ∀ i,frameLaw m (onSide x i)) + (e : Comp p.g) (i j) (a : inc e (v.t i)) (b : inc e (v.t j)) + (h : v.aim i=v.aim j) (q : Bool) : + v.voices ((v.draw z).keys v.t x) i j e a b q=evmat + (eitherM q (selfM p n m.mixM)) (v.croon i (z i)) (v.croon j (z j)) := by + rw [voice_note,h] + let y := onSide x (v.aim j) e + have he : (primary y.1)ᵀ*primary y.2=selfM p n m.mixM := (hw (v.aim j) e).2.2.1 + congr 1 + unfold duel + cases q + · change (primary y.2)ᵀ*primary y.1=_ + rw [←he]; simp only [eitherM,Bool.false_eq_true,ite_false, transpose_mul,transpose_transpose] + exact he + +def verges (v : Template p I) (x : Keys (p:=p) v.t N) (i j) := + ∀ e a b q,v.voices x i j e a b q=0 +omit [Fintype I] [DecidableEq I] in +theorem verges_rev (v : Template p I) {x : Keys (p:=p) v.t N} {i j} + (h : v.verges x i j) : v.verges x j i := by + intro e a b q + have ht := h e b a (!q) + unfold voices at *; rw [dotProduct_comm]; rwa [Bool.not_not] at ht + +omit [Fintype I] [DecidableEq I] in +theorem voices_diag (v : Template p I) (m : Mixer p n) (x : UnitType p n N) + (w : Inputs p n I) (hw : ∀ i,frameLaw m (onSide x i)) (hj : 1≤p.j) (i : I) : + ownOne p (v.t i) (dialed p (v.t i) (v.f i) (w i)) + ((v.draw w).keys v.t x i) := by + intro e + let y := (v.draw w).par i + let A := mom p (v.s i) y + have h : A∈Wspace p n := Submodule.subset_span ⟨_,_,rfl⟩ + have he := v.voice_same x w m hw e.val i i e.property e.property rfl true + let E := selfM p n m.mixM + change v.voices _ i i e.val e.property e.property true=_ + rw [he] + change evmat E (point p _ y) (point p _ y)=_ + rw [← mpair_outer] + exact (selfM_pair p hj m.mixM h).trans (etaScan p (n:=n) (v.t i) (v.s i) _ (w i)).symm + +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SimultaneousProjection.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SimultaneousProjection.lean index c7f0efa5feb8ff97ebc43bf76fa452bc46384f43..2c75a4b007e2e76d20b6eda2726bb3956bb2350b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SimultaneousProjection.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SimultaneousProjection.lean @@ -1,142 +1,142 @@ -import OAI.Combinatorics.HadwigerCounterexample.AdaptiveProjectionBounds - -namespace OAI - -/-! # Simultaneous Projection -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix -open scoped BigOperators Topology -namespace StatusAnalysis -open Station PreparationParameters - -variable {p : Shape} {M s0 n N K : ℕ} {q:Format} {d e:Rates} - {l:Filter ℕ} {b:PreparationParameters} {m:cycleM p} {w:tale p M} {s:rhythms p M} - -def sparks (v : Stations p M b.pins s) (i:Scrip p b.pins) (m:cycleM p) (w:tale p M) - {r} (n:ℕ) (Y: Silhouette p (M*n) r) := - Station.stratum (v n) i.2.2 (m n) (w n) i.2.1 Y - -def bullseye (v: Stations p M K s) (m:cycleM p) (w:tale p M) (x:Typus p q d e) - (k : Fin (2^deckMax p K)) (ε : ℝ) {r : ℕ} (n : ℕ) (Y : Silhouette p (M*n) r) - (τ u:ℝ) := - ∀ (r':ℕ) (Y':Silhouette p (M*n) r'),refines Y' Y → - ∀ τ' δ:ℝ,τ'≤τ → - pr ((s n).sap (w n)) (fun i=>¬ gauze p τ' δ Y' (m n) K i) ≤u → - Station.stratum (v n) x (m n) (w n) k Y'≤ ε - -set_option maxHeartbeats 2400000 in -theorem glowLamp (v:Stations p M b.pins s) (h:veil p M b s0 l m s w) (x:Typus p q d e) - (k:Fin (2^deckMax p b.pins)) (hP:x.permission) (ε:ℝ) (he:0<ε) : - ∃ (r : ℕ) (τ u:ℝ), 0<τ∧0i*j; let r:=bouquet f - let τ:= min u v' - refine ⟨r,τ,a,lt_min hi hj,ha,?_⟩ - have hz:= (trend_sizes l h.timeL ht.hM).2 - filter_upwards [hX,h.upright,h.durableS.shape,h.durableS.mass.positive,h.moment, - hA.filter_mono h.timeL,hB.filter_mono h.timeL, - ((bp_nat_vanish hc).eventually (eventually_le_nhds ha)).filter_mono h.timeL, - ((bp_nat_vanish hC).eventually (eventually_le_nhds ha)).filter_mono h.timeL, - hz.eventually (eventually_ge_atTop (2*num (Messenger q×Toast p)+1))] - with n hn ha' hB' hW he' hA hB hM hV hG - let N:=M*n; let p0:=s n - obtain ⟨P,hP'⟩:=hn - let e k y:=ind (P y=k) - have heq k y : |e k y| ≤1 := by unfold e; rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ - choose X hF using fun i:Fin z=> hA (e i) (heq i) - choose Z hF' using fun i:Fin z=> hB (e i) (heq i) - let Y k:=duoY (X k) (Z k) - refine ⟨bundleY f Y,fun r Y' hR τ' δ hτ hpos=>?_⟩ - apply hP' r Y' - have hw:=he'.1.law - let hh:=hB'.1 - have hx' i : IsLaw (x.qA.policies x.t x.z n i) := - Appearance.witLaw (x.qA.allure_apt _ _ hP.2.1 _) ht.hR ha'.age - have hy' i : IsLaw (x.qB.policies x.t x.z n i) := - Appearance.witLaw (x.qB.allure_apt _ _ hP.2.2.1 _) ht.hR ha'.age - have hN:= show 2*num (Messenger q×Toast p)-(N:ℝ) ≤ -1 from by - change _ ≤ (N:ℝ) at hG; linarith only [hG] - have hp := nuLaw x.t x.z hN - have ht' : ∀ i:Fin z,refines Y' (Y i) := fun i=> refines_next hR (bundle_refines f Y i) - refine (projectSum (v n) x (m n) k (w n) Y' P hh.part hw (fun i hi=>(hh.leaf i hi).pos) - hW hx' hy' hp a u v' τ' a δ ha.le hP ⟨hτ.trans (min_le_left ..),hτ.trans (min_le_right ..)⟩ - hpos (fun i=>?_) (fun i=>?_)).trans ?_ - · exact (hF i _ Y' (refines_next (ht' i) (duo_good ..).1) _ _ ha').trans hM - · exact (hF' i _ Y' (refines_next (ht' i) (duo_good ..).2) _ _ ha').trans hV - have hi : 12*(z+1:ℝ)*a=η := by unfold a; field_simp - nlinarith only [hi,ha,(Nat.cast_nonneg z : 0≤(z:ℝ))] - -private theorem minimums {A:Type} [Fintype A] (x : Wgt A) (hx:∀ i,0 exact ⟨1,zero_lt_one,fun i=> (he.false i).elim⟩ - next he => - let f:= univ.image x - have hf : f.Nonempty := Finset.image_nonempty.mpr Finset.univ_nonempty - obtain ⟨i,hi,ht⟩:= mem_image.mp (Finset.min'_mem _ hf) - exact ⟨f.min' hf,ht ▸ hx i,fun i=>Finset.min'_le _ _ (mem_image_of_mem _ (mem_univ i))⟩ - -set_option maxHeartbeats 1400000 in -theorem twinkle (v:Stations p M b.pins s) (h:veil p M b s0 l m s w) - (ε:ℝ) (he:0<ε) : - ∃ (r : ℕ) (τ u:ℝ),0<τ∧0 show ∃ (r : ℕ) (τ u:ℝ),0<τ∧0 ?_)⟩ - obtain ⟨Y,hY⟩:=hi; exact ⟨Y,fun _=>hY⟩ - exact ⟨1,1,1,zero_lt_one,zero_lt_one,.of_forall (fun n=> ⟨fun _ _ _=>0,fun hi=>(hP hi).elim⟩)⟩) - obtain ⟨δ,hd,hd'⟩:=minimums q hr - obtain ⟨e,he,he'⟩:=minimums A hq - refine ⟨bouquet r,δ,e,hd,he,?_⟩ - filter_upwards [eventually_all.mpr hh] with n hn - choose F hF using hn - refine ⟨bundleY r F,fun i hi r' Y' hR τ' δ' hτ hp=> ?_⟩ - exact hF i hi r' Y' (refines_next hR (bundle_refines r F i)) _ _ (hτ.trans (hd' _)) (hp.trans (he' _)) - -set_option maxHeartbeats 1200000 in -theorem lateSilk (v:Stations p M b.pins s) (h:veil p M b s0 l m s w) - (ε η:ℝ) (he:0<ε) (hη:0<η) (L:ℕ) : - ∃ (r:ℕ) (δ:ℝ),0<δ ∧ (r+1:ℝ)*δ≤η ∧ ∀ᶠ n in l, - ∀ Y:Silhouette p (M*n) L,∃ X:Silhouette p (M*n) r, refines X Y ∧ - pr ((s n).sap (w n)) (fun i=>¬ gauze p δ δ X (m n) b.pins i)≤ η ∧ - ∀ i:Scrip p b.pins,i.2.2.permission → - sparks (b:=b) v i m w n X ≤ ε := by - classical - obtain ⟨r,τ,u,hτ,hu,hg⟩:= twinkle v h ε he - let d:=r*L - let a:= d+1; let δ := min τ (η/(a:ℝ)) - have hD : 0<(a:ℝ):=by unfold a; positivity - have hd : 0<δ:=lt_min hτ (by positivity) - have hb := gauzeCalendar p d M h.easel δ δ hd hd - refine ⟨d,δ,hd,?_,?_⟩ - · have hh := (le_div_iff₀ hD).mp (show δ ≤ η/(a:ℝ) from min_le_right ..) - rw [mul_comm]; simpa [a] using hh - filter_upwards [hg,hb.filter_mono h.timeL,h.upright,((bp_nat_vanish (by norm_num : - (0:ℝ)<1/100)).eventually (eventually_le_nhds (lt_min hu hη))).filter_mono h.timeL] - with n hn hb hc hz Y - obtain ⟨X,hX⟩:=hn - let Z:= duoY X Y - have hm := (hb _ _ hc Z).trans hz - exact ⟨Z,(duo_good X Y).2,hm.trans (min_le_right ..),fun i h=> hX i h d Z (duo_good X Y).1 - δ δ (min_le_left ..) (hm.trans (min_le_left ..))⟩ -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.AdaptiveProjectionBounds + +namespace OAI + +/-! # Simultaneous Projection -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix +open scoped BigOperators Topology +namespace StatusAnalysis +open Station PreparationParameters + +variable {p : Shape} {M s0 n N K : ℕ} {q:Format} {d e:Rates} + {l:Filter ℕ} {b:PreparationParameters} {m:cycleM p} {w:tale p M} {s:rhythms p M} + +def sparks (v : Stations p M b.pins s) (i:Scrip p b.pins) (m:cycleM p) (w:tale p M) + {r} (n:ℕ) (Y: Silhouette p (M*n) r) := + Station.stratum (v n) i.2.2 (m n) (w n) i.2.1 Y + +def bullseye (v: Stations p M K s) (m:cycleM p) (w:tale p M) (x:Typus p q d e) + (k : Fin (2^deckMax p K)) (ε : ℝ) {r : ℕ} (n : ℕ) (Y : Silhouette p (M*n) r) + (τ u:ℝ) := + ∀ (r':ℕ) (Y':Silhouette p (M*n) r'),refines Y' Y → + ∀ τ' δ:ℝ,τ'≤τ → + pr ((s n).sap (w n)) (fun i=>¬ gauze p τ' δ Y' (m n) K i) ≤u → + Station.stratum (v n) x (m n) (w n) k Y'≤ ε + +set_option maxHeartbeats 2400000 in +theorem glowLamp (v:Stations p M b.pins s) (h:veil p M b s0 l m s w) (x:Typus p q d e) + (k:Fin (2^deckMax p b.pins)) (hP:x.permission) (ε:ℝ) (he:0<ε) : + ∃ (r : ℕ) (τ u:ℝ), 0<τ∧0i*j; let r:=bouquet f + let τ:= min u v' + refine ⟨r,τ,a,lt_min hi hj,ha,?_⟩ + have hz:= (trend_sizes l h.timeL ht.hM).2 + filter_upwards [hX,h.upright,h.durableS.shape,h.durableS.mass.positive,h.moment, + hA.filter_mono h.timeL,hB.filter_mono h.timeL, + ((bp_nat_vanish hc).eventually (eventually_le_nhds ha)).filter_mono h.timeL, + ((bp_nat_vanish hC).eventually (eventually_le_nhds ha)).filter_mono h.timeL, + hz.eventually (eventually_ge_atTop (2*num (Messenger q×Toast p)+1))] + with n hn ha' hB' hW he' hA hB hM hV hG + let N:=M*n; let p0:=s n + obtain ⟨P,hP'⟩:=hn + let e k y:=ind (P y=k) + have heq k y : |e k y| ≤1 := by unfold e; rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ + choose X hF using fun i:Fin z=> hA (e i) (heq i) + choose Z hF' using fun i:Fin z=> hB (e i) (heq i) + let Y k:=duoY (X k) (Z k) + refine ⟨bundleY f Y,fun r Y' hR τ' δ hτ hpos=>?_⟩ + apply hP' r Y' + have hw:=he'.1.law + let hh:=hB'.1 + have hx' i : IsLaw (x.qA.policies x.t x.z n i) := + Appearance.witLaw (x.qA.allure_apt _ _ hP.2.1 _) ht.hR ha'.age + have hy' i : IsLaw (x.qB.policies x.t x.z n i) := + Appearance.witLaw (x.qB.allure_apt _ _ hP.2.2.1 _) ht.hR ha'.age + have hN:= show 2*num (Messenger q×Toast p)-(N:ℝ) ≤ -1 from by + change _ ≤ (N:ℝ) at hG; linarith only [hG] + have hp := nuLaw x.t x.z hN + have ht' : ∀ i:Fin z,refines Y' (Y i) := fun i=> refines_next hR (bundle_refines f Y i) + refine (projectSum (v n) x (m n) k (w n) Y' P hh.part hw (fun i hi=>(hh.leaf i hi).pos) + hW hx' hy' hp a u v' τ' a δ ha.le hP ⟨hτ.trans (min_le_left ..),hτ.trans (min_le_right ..)⟩ + hpos (fun i=>?_) (fun i=>?_)).trans ?_ + · exact (hF i _ Y' (refines_next (ht' i) (duo_good ..).1) _ _ ha').trans hM + · exact (hF' i _ Y' (refines_next (ht' i) (duo_good ..).2) _ _ ha').trans hV + have hi : 12*(z+1:ℝ)*a=η := by unfold a; field_simp + nlinarith only [hi,ha,(Nat.cast_nonneg z : 0≤(z:ℝ))] + +private theorem minimums {A:Type} [Fintype A] (x : Wgt A) (hx:∀ i,0 exact ⟨1,zero_lt_one,fun i=> (he.false i).elim⟩ + next he => + let f:= univ.image x + have hf : f.Nonempty := Finset.image_nonempty.mpr Finset.univ_nonempty + obtain ⟨i,hi,ht⟩:= mem_image.mp (Finset.min'_mem _ hf) + exact ⟨f.min' hf,ht ▸ hx i,fun i=>Finset.min'_le _ _ (mem_image_of_mem _ (mem_univ i))⟩ + +set_option maxHeartbeats 1400000 in +theorem twinkle (v:Stations p M b.pins s) (h:veil p M b s0 l m s w) + (ε:ℝ) (he:0<ε) : + ∃ (r : ℕ) (τ u:ℝ),0<τ∧0 show ∃ (r : ℕ) (τ u:ℝ),0<τ∧0 ?_)⟩ + obtain ⟨Y,hY⟩:=hi; exact ⟨Y,fun _=>hY⟩ + exact ⟨1,1,1,zero_lt_one,zero_lt_one,.of_forall (fun n=> ⟨fun _ _ _=>0,fun hi=>(hP hi).elim⟩)⟩) + obtain ⟨δ,hd,hd'⟩:=minimums q hr + obtain ⟨e,he,he'⟩:=minimums A hq + refine ⟨bouquet r,δ,e,hd,he,?_⟩ + filter_upwards [eventually_all.mpr hh] with n hn + choose F hF using hn + refine ⟨bundleY r F,fun i hi r' Y' hR τ' δ' hτ hp=> ?_⟩ + exact hF i hi r' Y' (refines_next hR (bundle_refines r F i)) _ _ (hτ.trans (hd' _)) (hp.trans (he' _)) + +set_option maxHeartbeats 1200000 in +theorem lateSilk (v:Stations p M b.pins s) (h:veil p M b s0 l m s w) + (ε η:ℝ) (he:0<ε) (hη:0<η) (L:ℕ) : + ∃ (r:ℕ) (δ:ℝ),0<δ ∧ (r+1:ℝ)*δ≤η ∧ ∀ᶠ n in l, + ∀ Y:Silhouette p (M*n) L,∃ X:Silhouette p (M*n) r, refines X Y ∧ + pr ((s n).sap (w n)) (fun i=>¬ gauze p δ δ X (m n) b.pins i)≤ η ∧ + ∀ i:Scrip p b.pins,i.2.2.permission → + sparks (b:=b) v i m w n X ≤ ε := by + classical + obtain ⟨r,τ,u,hτ,hu,hg⟩:= twinkle v h ε he + let d:=r*L + let a:= d+1; let δ := min τ (η/(a:ℝ)) + have hD : 0<(a:ℝ):=by unfold a; positivity + have hd : 0<δ:=lt_min hτ (by positivity) + have hb := gauzeCalendar p d M h.easel δ δ hd hd + refine ⟨d,δ,hd,?_,?_⟩ + · have hh := (le_div_iff₀ hD).mp (show δ ≤ η/(a:ℝ) from min_le_right ..) + rw [mul_comm]; simpa [a] using hh + filter_upwards [hg,hb.filter_mono h.timeL,h.upright,((bp_nat_vanish (by norm_num : + (0:ℝ)<1/100)).eventually (eventually_le_nhds (lt_min hu hη))).filter_mono h.timeL] + with n hn hb hc hz Y + obtain ⟨X,hX⟩:=hn + let Z:= duoY X Y + have hm := (hb _ _ hc Z).trans hz + exact ⟨Z,(duo_good X Y).2,hm.trans (min_le_right ..),fun i h=> hX i h d Z (duo_good X Y).1 + δ δ (min_le_left ..) (hm.trans (min_le_left ..))⟩ +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SinglePositionExpansion.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SinglePositionExpansion.lean index 9a37ae1e8dd3deb4de62ed22b840a0b0933d5fda..53b64ddafc39edc0f6e26bd1887ce55585d71dca 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SinglePositionExpansion.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SinglePositionExpansion.lean @@ -1,82 +1,82 @@ -import OAI.Combinatorics.HadwigerCounterexample.FourCornerViews -import OAI.Combinatorics.HadwigerCounterexample.ScriptGramCorrespondence - -namespace OAI - -/-! # Single Position Expansion -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Function Matrix -open scoped BigOperators -variable {I A B C : Type} [Fintype I] [DecidableEq I] -variable {p : Shape} {n N : ℕ} -variable {X : I → Type} - -abbrev Aside (i : I) := {j:I//j≠i} -def chair (X : I →Type) (i:I) := Equiv.piSplitAt i X - -theorem chair_split (p : ∀ i,Wgt (X i)) (x : ∀ i,X i) (a : I) : - prodW p x = p a (x a) * - prodW (fun i : Aside a=>p i.val) ((chair X a x).2) := by - exact Fintype.prod_eq_mul_prod_subtype_ne _ _ - -variable [∀ i,Fintype (X i)] -set_option maxHeartbeats 600000 in -theorem chair_weight (p : ∀ i,Wgt (X i)) (a : I) : - mapW (prodW p) (chair X a)= pairW (p a) - (prodW (fun i : Aside a=>p i.val)) := by - funext i - obtain ⟨i,rfl⟩ := (chair X a).surjective i - rw [mapW_equiv_val,Equiv.symm_apply_apply]; exact chair_split p i a - -def arm (i j : I) (x : Corn) := if j=i then x.1 else x.2 -omit [Fintype I] [∀ i,Fintype (X i)] in -theorem chair_arm (p : (∀ i,X i)×(∀ i,X i)) (i j : I) (x : Corn) : - criss (chair X i) p x j=(onSide p (arm i j x)) j := by - rcases x with ⟨a,b⟩ - have he := criss_pair p a b (chair X i) - by_cases h : j=i - · subst j - rw [arm,ite_eq_left rfl]; exact congrArg Prod.fst he - rw [arm,ite_eq_right h] - exact congr_fun (congrArg Prod.snd he) (⟨j,h⟩:Aside i) - -namespace Template -variable (v : Template p I) - -def beyond (v : Template p I) (i : I) : Template p (Aside i) := - collect p v Subtype.val -def chairK (v : Template p I) (i : I) (N : ℕ) : - Keys (p:=p) v.t N ≃ (AtomKey (p:=p) (v.t i) N × Keys (p:=p) (v.beyond i).t N) := - chair _ _ -def chairI (_ : Template p I) (i : I) (n : ℕ) : - Inputs p n I ≃ Knobs p.g n × Inputs p n (Aside i) := chair _ _ - -omit [Fintype I] in -theorem key_quoin (v : Template p I) (x : I) (o : UnitType p n N) - (p' : Inputs p n I× Inputs p n I) (c : Corn) : - criss (v.chairK x N) (Prod.map (v.resultKey o) (v.resultKey o) p') c= - v.resultKey o (criss (v.chairI x n) p' c) := by - classical - funext i; unfold resultKey - change criss (chair (fun i=>AtomKey (p:=p) (v.t i) N) x) _ _ i=keyOne p _ _ (lit _ _ (criss (chair (fun _=>Knobs p.g n) x) _ _ i)) _ - rw [chair_arm _ x,chair_arm _ x] - cases arm x i c <;> rfl - -omit [Fintype I] in -theorem key_split (v : Template p I) (x : I) (o : UnitType p n N) - (z : Inputs p n I) : - chairK v x N (v.resultKey o z) = (v.callOne x (z x) (onSide o (v.aim x)), - (v.beyond x).resultKey o (fun i=>z i.val)) := by - apply Prod.ext <;> rfl - -def earns (v : Template p I) (s : Script p I) (m : Mixer p n) (q : I→F) - (o : UnitType p n N) (x : Inputs p n I) := - (v.draw x).reads s m ∧ ownPart (p:=p) v.t q (v.resultKey o x) -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FourCornerViews +import OAI.Combinatorics.HadwigerCounterexample.ScriptGramCorrespondence + +namespace OAI + +/-! # Single Position Expansion -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Function Matrix +open scoped BigOperators +variable {I A B C : Type} [Fintype I] [DecidableEq I] +variable {p : Shape} {n N : ℕ} +variable {X : I → Type} + +abbrev Aside (i : I) := {j:I//j≠i} +def chair (X : I →Type) (i:I) := Equiv.piSplitAt i X + +theorem chair_split (p : ∀ i,Wgt (X i)) (x : ∀ i,X i) (a : I) : + prodW p x = p a (x a) * + prodW (fun i : Aside a=>p i.val) ((chair X a x).2) := by + exact Fintype.prod_eq_mul_prod_subtype_ne _ _ + +variable [∀ i,Fintype (X i)] +set_option maxHeartbeats 600000 in +theorem chair_weight (p : ∀ i,Wgt (X i)) (a : I) : + mapW (prodW p) (chair X a)= pairW (p a) + (prodW (fun i : Aside a=>p i.val)) := by + funext i + obtain ⟨i,rfl⟩ := (chair X a).surjective i + rw [mapW_equiv_val,Equiv.symm_apply_apply]; exact chair_split p i a + +def arm (i j : I) (x : Corn) := if j=i then x.1 else x.2 +omit [Fintype I] [∀ i,Fintype (X i)] in +theorem chair_arm (p : (∀ i,X i)×(∀ i,X i)) (i j : I) (x : Corn) : + criss (chair X i) p x j=(onSide p (arm i j x)) j := by + rcases x with ⟨a,b⟩ + have he := criss_pair p a b (chair X i) + by_cases h : j=i + · subst j + rw [arm,ite_eq_left rfl]; exact congrArg Prod.fst he + rw [arm,ite_eq_right h] + exact congr_fun (congrArg Prod.snd he) (⟨j,h⟩:Aside i) + +namespace Template +variable (v : Template p I) + +def beyond (v : Template p I) (i : I) : Template p (Aside i) := + collect p v Subtype.val +def chairK (v : Template p I) (i : I) (N : ℕ) : + Keys (p:=p) v.t N ≃ (AtomKey (p:=p) (v.t i) N × Keys (p:=p) (v.beyond i).t N) := + chair _ _ +def chairI (_ : Template p I) (i : I) (n : ℕ) : + Inputs p n I ≃ Knobs p.g n × Inputs p n (Aside i) := chair _ _ + +omit [Fintype I] in +theorem key_quoin (v : Template p I) (x : I) (o : UnitType p n N) + (p' : Inputs p n I× Inputs p n I) (c : Corn) : + criss (v.chairK x N) (Prod.map (v.resultKey o) (v.resultKey o) p') c= + v.resultKey o (criss (v.chairI x n) p' c) := by + classical + funext i; unfold resultKey + change criss (chair (fun i=>AtomKey (p:=p) (v.t i) N) x) _ _ i=keyOne p _ _ (lit _ _ (criss (chair (fun _=>Knobs p.g n) x) _ _ i)) _ + rw [chair_arm _ x,chair_arm _ x] + cases arm x i c <;> rfl + +omit [Fintype I] in +theorem key_split (v : Template p I) (x : I) (o : UnitType p n N) + (z : Inputs p n I) : + chairK v x N (v.resultKey o z) = (v.callOne x (z x) (onSide o (v.aim x)), + (v.beyond x).resultKey o (fun i=>z i.val)) := by + apply Prod.ext <;> rfl + +def earns (v : Template p I) (s : Script p I) (m : Mixer p n) (q : I→F) + (o : UnitType p n N) (x : Inputs p n I) := + (v.draw x).reads s m ∧ ownPart (p:=p) v.t q (v.resultKey o x) +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SingletonPhaseTests.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SingletonPhaseTests.lean index ba5ba80788047f231ebfb139220faa014c360070..5bd5f16e1ff665516f103ecf2af681730e828a97 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SingletonPhaseTests.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SingletonPhaseTests.lean @@ -1,135 +1,135 @@ -import OAI.Combinatorics.HadwigerCounterexample.OffsetFourierBounds - -namespace OAI - -/-! # Singleton Phase Tests -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Function Finset -open scoped BigOperators -variable {p : Shape} {n N r : ℕ} {T : Cov p N} {A : Type} [Fintype A] - -theorem avg_on_support {w f g : Wgt A} (h : ∀ x,0≤w x) - (he : ∀ x,w x≠0 → f x≤g x) : avg w f ≤ avg w g := - Finset.sum_le_sum (fun x _ => by - by_cases hh : w x=0 - · rw [hh,zero_mul,zero_mul] - exact mul_le_mul_of_nonneg_left (he x hh) (h x)) - -namespace Bazaar -variable (s : Bazaar p n r T) - -set_option maxHeartbeats 600000 in -theorem single_pitch {w : Wgt (UnitType p n N)} {Δ} - (hl : s.opened Δ w) (hv : IsLaw w) (i : Bool) (R : Party) - (m : Mixer p n) {ε H : ℝ} (hm : IsLaw (raw m N)) (he : initCap p N m ε) - (hH : 0 ≤ H) (hw : bySide p w m H) - (hp : selPrice p r n N H ε) (ht : num (Atlas p r T) ≤ bp (0.002*N)) - (hN : 2*num (Full p n)-N≤ -1) : - |pitch p Δ w (unary i) R|≤ glimpsesBill p r H+bp (-0.24*N) ∧ - ((∀ x,w x≠0 → ∀ y,w y≠0 → glimpse p y i (src (s.ix x))) → - |pitch p Δ w (unary i) R|≤bp (-0.24*N)) := by - classical - let C : Sales p n r T := fun M _ y => glimpse p y i (src M) - have hb M G (hh : standard M) (hh' : standard G) := - glimpse_prize m hH hm he hv.sub hw hl hp M G i hh hh' (C M G) (fun _ _ h => h) - have hf := beat_mix s hl hv (unary i) R i C (fun M => bag_rate m hH hm he hv.sub hw hl hp M i) - hb ht - have he : discard (s:=s) w C = avg w (fun x => - pr w (fun y => ¬ glimpse p y i (src (s.ix x)))) := pairW_avg .. - rw [he] at hf - constructor - · refine hf.trans (add_le_add_left ?_ _) - rw [← hv.avg_const (glimpsesBill p r H)] - apply avg_on_support hv.nz - intro x hx - have hX := (hl x hx).1 - exact glimpse_failure m hH hw hv.sub i hN _ r hX.2.2 (fun z => - Nat.lt_add_one_iff.mp ((s.ix x).1 z).isLt) - intro hh - have hW : avg w (fun x => pr w (fun y => ¬glimpse p y i (src (s.ix x))))=0 := by - rw [← hv.avg_const 0] - refine avg_congr (fun x hx => ?_) - rw [← hv.avg_const 0] - exact avg_congr fun y hy => ind_zero (by simp [hh x hx y hy]) - rwa [hW,zero_add] at hf - -def frequent (w : Wgt (UnitType p n N)) (S : Party) (j : Bool) - (M G : Atlas p r T) (y : UnitType p n N) := - prize p N (cells G) < mapW (s.chart w G) (s.pay M G j S) (s.pay M G j S y) - -theorem calm_pitch {w : Wgt (UnitType p n N)} {Δ} - (hl : s.opened Δ w) (hv : IsLaw w) (i : Bool) (R S : Party) - (m : Mixer p n) {ε H : ℝ} (hm : IsLaw (raw m N)) (he : initCap p N m ε) - (hH : 0 ≤ H) (hw : bySide p w m H) - (hp : selPrice p r n N H ε) (ht : num (Atlas p r T) ≤ bp (0.002*N)) : - |pitch p Δ w S R| ≤ pr (pairW w w) - (fun x => s.frequent w S i (s.ix x.1) (s.ix x.2) x.2) + bp (-0.24*N) := by - classical - let C : Sales p n r T := fun M G y => ¬ s.frequent w S i M G y - have hb (M G : Atlas p r T) (hh : standard M) (hh' : standard G) : - ∀ y,mapW (subW (s.chart w G) (C M G)) (s.pay M G i S) y ≤ prize p N (cells G) := by - let v := s.chart w G - let J := s.pay M G i S - have hw' : SubLaw v := subLaw_sub hv.sub _ - intro y - by_cases he : mapW v J y≤prize p N (cells G) - · exact (pr_mono_left (subW_le hw'.nz _) _).trans he - change pr (subW v (C M G)) (fun x => J x=y) ≤ _ - rw [pr_sub] - have hx : (fun x => C M G x ∧ J x=y)=(fun _ => False) := by - funext x - refine propext (iff_false_intro (fun ⟨h,h'⟩ => he ?_)) - rw [← h'] - exact le_of_not_gt h - rw [hx,pr_false]; exact (bp_pos _).le - have hf := beat_mix s hl hv S R i C (fun M => bag_rate m hH hm he hv.sub hw hl hp M i) hb ht - unfold discard C at hf; simpa only [not_not] using hf - -/-- fixed companion Z restrict frequent pair to this list of small Φ values -/ -def bids (w : Wgt (UnitType p n N)) (S : Party) (i : Bool) - (M G : Atlas p r T) (Z : Batch G N) : Finset (Batch M N) := - open scoped Classical in - Finset.univ.filter (fun x => prize p N (cells G) (f x).1 - have hh (x : Batch M N) : (fun y => f y=(x,Z))= - fun y => s.bag G i y=Z ∧ T y=x := by ext y; simp [Prod.mk.injEq,f,T,pay,and_comm] - simp only [mapW,hh,sum_pr_tag] - calc ↑B.card * P = ∑ x ∈ B,P := (by simp) - _ ≤ ∑ x∈B,mapW v f (x,Z) := Finset.sum_le_sum he - _ ≤ ∑ x : Batch M N,mapW v f (x,Z) := Finset.sum_le_sum_of_subset_of_nonneg - (Finset.subset_univ B) (fun i _ _ => pr_nonneg hv.nz) - _ ≤ loseA p N (cells G) 0 := hZ.trans_le (h Z) - refine (le_of_mul_le_mul_right (hg.trans_eq ?_) (bp_pos _ : 0 by + by_cases hh : w x=0 + · rw [hh,zero_mul,zero_mul] + exact mul_le_mul_of_nonneg_left (he x hh) (h x)) + +namespace Bazaar +variable (s : Bazaar p n r T) + +set_option maxHeartbeats 600000 in +theorem single_pitch {w : Wgt (UnitType p n N)} {Δ} + (hl : s.opened Δ w) (hv : IsLaw w) (i : Bool) (R : Party) + (m : Mixer p n) {ε H : ℝ} (hm : IsLaw (raw m N)) (he : initCap p N m ε) + (hH : 0 ≤ H) (hw : bySide p w m H) + (hp : selPrice p r n N H ε) (ht : num (Atlas p r T) ≤ bp (0.002*N)) + (hN : 2*num (Full p n)-N≤ -1) : + |pitch p Δ w (unary i) R|≤ glimpsesBill p r H+bp (-0.24*N) ∧ + ((∀ x,w x≠0 → ∀ y,w y≠0 → glimpse p y i (src (s.ix x))) → + |pitch p Δ w (unary i) R|≤bp (-0.24*N)) := by + classical + let C : Sales p n r T := fun M _ y => glimpse p y i (src M) + have hb M G (hh : standard M) (hh' : standard G) := + glimpse_prize m hH hm he hv.sub hw hl hp M G i hh hh' (C M G) (fun _ _ h => h) + have hf := beat_mix s hl hv (unary i) R i C (fun M => bag_rate m hH hm he hv.sub hw hl hp M i) + hb ht + have he : discard (s:=s) w C = avg w (fun x => + pr w (fun y => ¬ glimpse p y i (src (s.ix x)))) := pairW_avg .. + rw [he] at hf + constructor + · refine hf.trans (add_le_add_left ?_ _) + rw [← hv.avg_const (glimpsesBill p r H)] + apply avg_on_support hv.nz + intro x hx + have hX := (hl x hx).1 + exact glimpse_failure m hH hw hv.sub i hN _ r hX.2.2 (fun z => + Nat.lt_add_one_iff.mp ((s.ix x).1 z).isLt) + intro hh + have hW : avg w (fun x => pr w (fun y => ¬glimpse p y i (src (s.ix x))))=0 := by + rw [← hv.avg_const 0] + refine avg_congr (fun x hx => ?_) + rw [← hv.avg_const 0] + exact avg_congr fun y hy => ind_zero (by simp [hh x hx y hy]) + rwa [hW,zero_add] at hf + +def frequent (w : Wgt (UnitType p n N)) (S : Party) (j : Bool) + (M G : Atlas p r T) (y : UnitType p n N) := + prize p N (cells G) < mapW (s.chart w G) (s.pay M G j S) (s.pay M G j S y) + +theorem calm_pitch {w : Wgt (UnitType p n N)} {Δ} + (hl : s.opened Δ w) (hv : IsLaw w) (i : Bool) (R S : Party) + (m : Mixer p n) {ε H : ℝ} (hm : IsLaw (raw m N)) (he : initCap p N m ε) + (hH : 0 ≤ H) (hw : bySide p w m H) + (hp : selPrice p r n N H ε) (ht : num (Atlas p r T) ≤ bp (0.002*N)) : + |pitch p Δ w S R| ≤ pr (pairW w w) + (fun x => s.frequent w S i (s.ix x.1) (s.ix x.2) x.2) + bp (-0.24*N) := by + classical + let C : Sales p n r T := fun M G y => ¬ s.frequent w S i M G y + have hb (M G : Atlas p r T) (hh : standard M) (hh' : standard G) : + ∀ y,mapW (subW (s.chart w G) (C M G)) (s.pay M G i S) y ≤ prize p N (cells G) := by + let v := s.chart w G + let J := s.pay M G i S + have hw' : SubLaw v := subLaw_sub hv.sub _ + intro y + by_cases he : mapW v J y≤prize p N (cells G) + · exact (pr_mono_left (subW_le hw'.nz _) _).trans he + change pr (subW v (C M G)) (fun x => J x=y) ≤ _ + rw [pr_sub] + have hx : (fun x => C M G x ∧ J x=y)=(fun _ => False) := by + funext x + refine propext (iff_false_intro (fun ⟨h,h'⟩ => he ?_)) + rw [← h'] + exact le_of_not_gt h + rw [hx,pr_false]; exact (bp_pos _).le + have hf := beat_mix s hl hv S R i C (fun M => bag_rate m hH hm he hv.sub hw hl hp M i) hb ht + unfold discard C at hf; simpa only [not_not] using hf + +/-- fixed companion Z restrict frequent pair to this list of small Φ values -/ +def bids (w : Wgt (UnitType p n N)) (S : Party) (i : Bool) + (M G : Atlas p r T) (Z : Batch G N) : Finset (Batch M N) := + open scoped Classical in + Finset.univ.filter (fun x => prize p N (cells G) (f x).1 + have hh (x : Batch M N) : (fun y => f y=(x,Z))= + fun y => s.bag G i y=Z ∧ T y=x := by ext y; simp [Prod.mk.injEq,f,T,pay,and_comm] + simp only [mapW,hh,sum_pr_tag] + calc ↑B.card * P = ∑ x ∈ B,P := (by simp) + _ ≤ ∑ x∈B,mapW v f (x,Z) := Finset.sum_le_sum he + _ ≤ ∑ x : Batch M N,mapW v f (x,Z) := Finset.sum_le_sum_of_subset_of_nonneg + (Finset.subset_univ B) (fun i _ _ => pr_nonneg hv.nz) + _ ≤ loseA p N (cells G) 0 := hZ.trans_le (h Z) + refine (le_of_mul_le_mul_right (hg.trans_eq ?_) (bp_pos _ : 0 1 - -def cutDown (p : Shape) {n N} - (T : Cov p N) (Δ : UnitType p n N→ Ambient p N) (w : Wgt (UnitType p n N)) - (x : UnitType p n N) : coverX p T := - open scoped Classical in - if h : w x≠0 ∧ covered p T (Δ x) then ⟨_,h.2⟩ else 0 - -def juris (p : Shape) {n N} (T : Cov p N) (x : UnitType p n N) (S : Party) : - Module.Dual F (coverX p T) := - joinPhase p (listens p x) S ∘ₗ (coverX p T).subtype - -abbrev Daypair (p : Shape) {N} (T : Cov p N) := - coverX p T × (Bool → Module.Dual F (coverX p T)) - -def daypair (p : Shape) {n N} - (T : Cov p N) (Δ : UnitType p n N→ Ambient p N) (w : Wgt (UnitType p n N)) - (x : UnitType p n N) : Daypair p T := - (cutDown p T Δ w x,fun i => juris p T x (unary i)) - -def shadow (p : Shape) {n N} - (T : Cov p N) (Δ : UnitType p n N→ Ambient p N) (w : Wgt (UnitType p n N)) - (x y : UnitType p n N) (S : Party) := - juris p T y S (cutDown p T Δ w x) - -theorem shadow_valid (p : Shape) {n N} (T : Cov p N) - (Δ : UnitType p n N→Ambient p N) {w} - (h : ∀ x,w x≠0 → covered p T (Δ x)) (x y : UnitType p n N) (S) (hx : w x≠0) : - shadow p T Δ w x y S=tone p y S (Δ x) := by - classical - unfold shadow cutDown - rw [dite_eq_left ⟨hx,h x hx⟩]; rfl - -theorem tone_vec (p : Shape) {n N} (x : UnitType p n N) (S : Party) (Δ : Ambient p N) : - tone p x S Δ=dotProduct S (fun i => tone p x (unary i) Δ) := by - classical - have hg (i) : tone p x (unary i) Δ=uPhase p (onSide (listens p x) i) Δ := by - unfold tone joinPhase unary - rw [Finset.sum_eq_single i] - · rw [Pi.single_eq_same,one_smul] - · intro j _ hj; simp [hj] - simp - unfold dotProduct - simp_rw [hg] - unfold tone joinPhase - simp - -theorem shadow_day (p : Shape) {n N} (T : Cov p N) - (Δ : UnitType p n N→Ambient p N) (w : Wgt (UnitType p n N)) - (x y) (S : Party) : - shadow p T Δ w x y S = - dotProduct S (fun i => (daypair p T Δ w y).2 i (daypair p T Δ w x).1) := - tone_vec p y _ (cutDown p T Δ w x).val - -theorem day_named (p : Shape) {n N} (T : Cov p N) - (Δ : UnitType p n N→Ambient p N) - (w : Wgt (UnitType p n N)) (d : ℕ) (hT : cdim p T≤d) - (P : Daypair p T × Daypair p T → Prop) : - named (fun v => P (daypair p T Δ w v.1,daypair p T Δ w v.2)) (bp (3*d*(N:ℝ))) := by - classical - let A := (coverX p T) - let : Finite (Module.Dual F (coverX p T)) := Finite.of_injective _ DFunLike.coe_injective - let : Fintype (Module.Dual F (coverX p T)) := Fintype.ofFinite _ - have he : dim (Daypair p T) ≤ 3*d*N := by - unfold Daypair dim - rw [Module.finrank_prod, Module.finrank_pi_fintype,Fintype.sum_bool, - Subspace.dual_finrank_eq] - change dim A+(dim A+dim A)≤_ - have h : dim A≤N*d := (cover_dim p T).trans (Nat.mul_le_mul_left N hT) - nlinarith - refine named_at (fun y x => P (daypair p T Δ w x,y)) ?_ (fun y => ⟨daypair p T Δ w y,fun x => Iff.rfl⟩) - rw [card_space] - exact bp_le (by exact_mod_cast he) - -variable [AddCommGroup V] [Module F V] [FiniteDimensional F V] - -theorem dual_matrix_rank (f : A→ V) (g : B→Module.Dual F V) : - (Matrix.of (fun x : A => fun y : B => g y (f x))).rank ≤ dim V := by - classical - let M := Matrix.of (fun x : A => fun y : B => g y (f x)) - let L : V →ₗ[F] Vec B := LinearMap.pi g - have hi : colSp Mᵀ ≤ LinearMap.range L := by - rw [colSp, range_mulVecLin] - exact Submodule.span_le.mpr (Set.range_subset_iff.mpr fun x => ⟨f x,rfl⟩) - have he : dim (colSp Mᵀ) ≤ dim V := (Submodule.finrank_mono hi).trans - (LinearMap.finrank_range_le L) - rw [colSp_dim,Matrix.rank_transpose] at he - exact he - -def circus (p : Shape) {n N} - (T : Cov p N) (Δ : UnitType p n N→ Ambient p N) (w : Wgt (UnitType p n N)) : - Mat (UnitType p n N) (UnitType p n N) := - Matrix.of (fun x y => shadow p T Δ w x y allSide) - -theorem circus_rank (p : Shape) {n N} - (T : Cov p N) (Δ : UnitType p n N→ Ambient p N) (w : Wgt (UnitType p n N)) : - (circus p T Δ w).rank≤ N*cdim p T := (dual_matrix_rank (cutDown p T Δ w) - (fun y => juris p T y allSide)).trans (cover_dim p T) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RelativeInjectionBounds + +namespace OAI + +/-! # Small Cover Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Function Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {A B V : Type} [Fintype A] [Fintype B] + +def allSide : Party := fun _ => 1 + +def cutDown (p : Shape) {n N} + (T : Cov p N) (Δ : UnitType p n N→ Ambient p N) (w : Wgt (UnitType p n N)) + (x : UnitType p n N) : coverX p T := + open scoped Classical in + if h : w x≠0 ∧ covered p T (Δ x) then ⟨_,h.2⟩ else 0 + +def juris (p : Shape) {n N} (T : Cov p N) (x : UnitType p n N) (S : Party) : + Module.Dual F (coverX p T) := + joinPhase p (listens p x) S ∘ₗ (coverX p T).subtype + +abbrev Daypair (p : Shape) {N} (T : Cov p N) := + coverX p T × (Bool → Module.Dual F (coverX p T)) + +def daypair (p : Shape) {n N} + (T : Cov p N) (Δ : UnitType p n N→ Ambient p N) (w : Wgt (UnitType p n N)) + (x : UnitType p n N) : Daypair p T := + (cutDown p T Δ w x,fun i => juris p T x (unary i)) + +def shadow (p : Shape) {n N} + (T : Cov p N) (Δ : UnitType p n N→ Ambient p N) (w : Wgt (UnitType p n N)) + (x y : UnitType p n N) (S : Party) := + juris p T y S (cutDown p T Δ w x) + +theorem shadow_valid (p : Shape) {n N} (T : Cov p N) + (Δ : UnitType p n N→Ambient p N) {w} + (h : ∀ x,w x≠0 → covered p T (Δ x)) (x y : UnitType p n N) (S) (hx : w x≠0) : + shadow p T Δ w x y S=tone p y S (Δ x) := by + classical + unfold shadow cutDown + rw [dite_eq_left ⟨hx,h x hx⟩]; rfl + +theorem tone_vec (p : Shape) {n N} (x : UnitType p n N) (S : Party) (Δ : Ambient p N) : + tone p x S Δ=dotProduct S (fun i => tone p x (unary i) Δ) := by + classical + have hg (i) : tone p x (unary i) Δ=uPhase p (onSide (listens p x) i) Δ := by + unfold tone joinPhase unary + rw [Finset.sum_eq_single i] + · rw [Pi.single_eq_same,one_smul] + · intro j _ hj; simp [hj] + simp + unfold dotProduct + simp_rw [hg] + unfold tone joinPhase + simp + +theorem shadow_day (p : Shape) {n N} (T : Cov p N) + (Δ : UnitType p n N→Ambient p N) (w : Wgt (UnitType p n N)) + (x y) (S : Party) : + shadow p T Δ w x y S = + dotProduct S (fun i => (daypair p T Δ w y).2 i (daypair p T Δ w x).1) := + tone_vec p y _ (cutDown p T Δ w x).val + +theorem day_named (p : Shape) {n N} (T : Cov p N) + (Δ : UnitType p n N→Ambient p N) + (w : Wgt (UnitType p n N)) (d : ℕ) (hT : cdim p T≤d) + (P : Daypair p T × Daypair p T → Prop) : + named (fun v => P (daypair p T Δ w v.1,daypair p T Δ w v.2)) (bp (3*d*(N:ℝ))) := by + classical + let A := (coverX p T) + let : Finite (Module.Dual F (coverX p T)) := Finite.of_injective _ DFunLike.coe_injective + let : Fintype (Module.Dual F (coverX p T)) := Fintype.ofFinite _ + have he : dim (Daypair p T) ≤ 3*d*N := by + unfold Daypair dim + rw [Module.finrank_prod, Module.finrank_pi_fintype,Fintype.sum_bool, + Subspace.dual_finrank_eq] + change dim A+(dim A+dim A)≤_ + have h : dim A≤N*d := (cover_dim p T).trans (Nat.mul_le_mul_left N hT) + nlinarith + refine named_at (fun y x => P (daypair p T Δ w x,y)) ?_ (fun y => ⟨daypair p T Δ w y,fun x => Iff.rfl⟩) + rw [card_space] + exact bp_le (by exact_mod_cast he) + +variable [AddCommGroup V] [Module F V] [FiniteDimensional F V] + +theorem dual_matrix_rank (f : A→ V) (g : B→Module.Dual F V) : + (Matrix.of (fun x : A => fun y : B => g y (f x))).rank ≤ dim V := by + classical + let M := Matrix.of (fun x : A => fun y : B => g y (f x)) + let L : V →ₗ[F] Vec B := LinearMap.pi g + have hi : colSp Mᵀ ≤ LinearMap.range L := by + rw [colSp, range_mulVecLin] + exact Submodule.span_le.mpr (Set.range_subset_iff.mpr fun x => ⟨f x,rfl⟩) + have he : dim (colSp Mᵀ) ≤ dim V := (Submodule.finrank_mono hi).trans + (LinearMap.finrank_range_le L) + rw [colSp_dim,Matrix.rank_transpose] at he + exact he + +def circus (p : Shape) {n N} + (T : Cov p N) (Δ : UnitType p n N→ Ambient p N) (w : Wgt (UnitType p n N)) : + Mat (UnitType p n N) (UnitType p n N) := + Matrix.of (fun x y => shadow p T Δ w x y allSide) + +theorem circus_rank (p : Shape) {n N} + (T : Cov p N) (Δ : UnitType p n N→ Ambient p N) (w : Wgt (UnitType p n N)) : + (circus p T Δ w).rank≤ N*cdim p T := (dual_matrix_rank (cutDown p T Δ w) + (fun y => juris p T y allSide)).trans (cover_dim p T) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SpanDeficits.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SpanDeficits.lean index 470e97be8426bfc698da64ee3107107b3ae777f5..3cc5f6fbe6ac6b2307e59491b31ea21d0bb3f5ed 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SpanDeficits.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SpanDeficits.lean @@ -1,169 +1,169 @@ -import OAI.Combinatorics.HadwigerCounterexample.CoverSpaces - -namespace OAI - -/-! # Span Deficits -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Submodule Module Finset -open scoped BigOperators -variable {p : Shape} {N : ℕ} {I J K : Type} [Fintype I] [Fintype J] [Fintype K] - -/-- Loss of rank from overlapping mode spans. -/ -private theorem colsum_bound (A B : Mat I J) : - A.rank+B.rank ≤ (A+B).rank+dim (colSp A⊓colSp B : Submodule _ _)+ - dim (colSp Aᵀ ⊓ colSp Bᵀ : Submodule _ _) := by - classical - obtain ⟨X,Y,hX,hY,hA⟩ := rank_product A - obtain ⟨S,T,hS,hT,hB⟩ := rank_product B - have h := rank_ge_mul (fromCols X S) (fromRows Y T) - have he {I J U : Type} [Fintype I] [Fintype U] [Fintype J] (A : Mat I U) {B : Mat U J} - (h : Function.Surjective B.mulVec) : - colSp (A*B) = colSp A := by - rw [colSp,mulVecLin_mul,LinearMap.range_comp, - LinearMap.range_eq_top.mpr (show Function.Surjective B.mulVecLin from h),Submodule.map_top] - have hc := colSp_join X S - have hr := colSp_join Yᵀ Tᵀ - rw [← he X hY,← he S hT,hA,hB] at hc - rw [← he Yᵀ (transpose_surj_iff.mpr hX),←he Tᵀ (transpose_surj_iff.mpr hS),←transpose_mul, - ←transpose_mul,hA,hB] at hr - have h1 := finrank_sup_add_finrank_inf_eq (colSp A) (colSp B) - rw [←hc] at h1 - have h2 := finrank_sup_add_finrank_inf_eq (colSp Aᵀ) (colSp Bᵀ) - rw [←hr] at h2 - rw [fromCols_mul_fromRows,hA,hB,Fintype.card_sum,Fintype.card_fin,Fintype.card_fin, - ← Matrix.rank_transpose (fromRows _ _), transpose_fromRows] at h - change (fromCols X S).rank+dim (_ : Submodule _ _) = A.rank+B.rank at h1 - change (fromCols Yᵀ Tᵀ).rank+dim (_ : Submodule _ _)=Aᵀ.rank+Bᵀ.rank at h2 - rw [Matrix.rank_transpose,Matrix.rank_transpose] at h2 - omega - -theorem cdim_mono {a b : Cov p N} (h : a≤b) : cdim p a ≤ cdim p b := - Finset.sum_le_sum fun i _ => Submodule.finrank_mono (h i) -@[simp] theorem cdim_bot {p N} : cdim p (N:=N) ⊥=0 := by - unfold cdim - refine Finset.sum_eq_zero fun i _ => ?_ - exact finrank_bot _ _ - -theorem cdim_sup_inf (a b : Cov p N) : cdim p (a⊔b)+cdim p (a⊓b)=cdim p a+cdim p b := by - unfold cdim - rw [← Finset.sum_add_distrib, ← Finset.sum_add_distrib] - exact Finset.sum_congr rfl fun i _ => finrank_sup_add_finrank_inf_eq (a i) (b i) - -def tax (p : Shape) {N} (a b : Cov p N) := cdim p (a⊔b)-cdim p a - -theorem tax_before (a b : Cov p N) : cdim p a+tax p a b=cdim p (a⊔b) := - Nat.add_sub_of_le (cdim_mono (p:=p) le_sup_left) - -theorem tax_lost (a b : Cov p N) : tax p a b+cdim p (a⊓b)=cdim p b := by - have h := cdim_sup_inf (p:=p) a b; rw [←tax_before (p:=p)] at h - omega - -theorem tax_antitone (p : Shape) {N} (a b c : Cov p N) (h : a≤b) : - tax p b c≤ tax p a c := by - have he := cdim_mono (p:=p) (inf_le_inf h (show c≤c from le_rfl)) - have hg := tax_lost (p:=p) a c - have hh := tax_lost (p:=p) b c - omega - -theorem matter_pair {x y : Ambient p N} {a b : Cov p N} - (hx : matter p x ≤ a) (hy : matter p y ≤ b) : - matter p (x+y) ≤ a⊔b ∧ - epoch p x+ epoch p y+cdim p (a⊔b) ≤ epoch p (x+y)+cdim p a+cdim p b := by - classical - have h (i) : x i∈box (a (i,true)) (a (i,false)) := - (box_mem ..).mpr ⟨hx (i,true),hx (i,false)⟩ - have h' i : y i ∈box (b (i,true)) (b (i,false)) := - (box_mem ..).mpr ⟨hy (i,true),hy (i,false)⟩ - constructor - · intro i - let C := a⊔b - have he : x i.1 + y i.1∈box (C (i.1,true)) (C (i.1,false)) := - Submodule.add_mem _ ((box_le le_sup_left le_sup_left) (h _)) - ((box_le le_sup_right le_sup_right) (h' _)) - have hg := (box_mem ..).mp he - cases i with | mk i j => cases j; exact hg.2; exact hg.1 - · have hg (i) : (x i).rank+(y i).rank ≤ (x i+y i).rank+dim ((a⊓b) (i,true))+ - dim ((a⊓b) (i,false)) := by - refine (colsum_bound (x i) (y i)).trans ?_ - have he c := Submodule.finrank_mono (inf_le_inf (hx (i,c)) (hy (i,c))) - exact Nat.add_le_add (Nat.add_le_add_left (he true) _) (he false) - have he := cdim_sup_inf (p:=p) a b - have hh := (Finset.sum_le_sum (s:=Finset.univ) fun i _ => hg i) - simp only [Finset.sum_add_distrib] at hh - change epoch _ x+epoch _ y≤ epoch p (x+y)+cdSign p _ true+cdSign p _ false at hh - rw [Nat.add_assoc,← cdim_sign] at hh - omega - -def chopped (p : Shape) {N} (a b : Cov p N) : Cov p N := - fun z => chopSpace (a z) (b z) - -theorem matter_erased {a : Cov p N} (x : Ambient p N) : - matter p (erased p a x) ≤ chopped p a (matter p x) := by - intro z - let D := matter p x - have h : x z.1∈box (D (z.1,true)) (D (z.1,false)) := - (box_mem ..).mpr ⟨le_rfl,le_rfl⟩ - have he := (box_mem ..).mp (lift_mem_box (chop (a (z.1,true))) (chop (a (z.1,false))) h) - cases z with | mk e c => cases c; exact he.2; exact he.1 - -theorem cdim_chopped (p : Shape) {N} (a b : Cov p N) : - cdim p (chopped p a b)=tax p a b := by - have h := tax_before (p:=p) a b - have he : cdim p a+cdim p (chopped p a b)=cdim p (a⊔b) := by - unfold cdim - rw [← Finset.sum_add_distrib]; exact Finset.sum_congr rfl fun i _ => chopSpace_rank .. - exact Nat.add_left_cancel (he.trans h.symm) - -def arrange (p : Shape) {N J} (f : J→ Ambient p N) (r : Finset J) := r.sup (matter p ∘ f) - -theorem epoch_charge {J} (f : J→Ambient p N) (s : Cov p N) (r : Finset J) : - (matter p (∑ i∈r, erased p s (f i))) ≤ chopped p s (arrange p f r) ∧ - ((∑ i∈r,epoch p (erased p s (f i)))+tax p s (arrange p f r) ≤ - epoch p (∑ i∈r, erased p s (f i)) + ∑ i∈r,tax p s (matter p (f i))) := by - classical - induction r using Finset.induction with - | empty => - have he : matter p (N:=N) (0:Ambient p N)=⊥ := by funext i; simp [matter,colSp,Pi.bot_apply] - simp only [Finset.sum_empty,he,bot_le,true_and,zero_add,add_zero] - have hi : arrange p f ∅ = ⊥ := Finset.sup_empty - rw [hi,tax,sup_bot_eq,Nat.sub_self]; exact Nat.zero_le _ - | insert i r hr ih => - obtain ⟨hx,hh⟩ := matter_pair (matter_erased (a:=s) (f i)) ih.1 - simp only [Finset.sum_insert hr] - have he : arrange p f (insert i r)= matter p (f i)⊔arrange p f r := - Finset.sup_insert - have ht : chopped p s (arrange p f (insert i r)) = - chopped p s (matter p (f i))⊔chopped p s (arrange p f r) := by - rw [he] - funext z; exact Submodule.map_sup _ _ _ - rw [ht] - refine ⟨hx,?_⟩ - rw [← ht, cdim_chopped,cdim_chopped,cdim_chopped] at hh - have hi := ih.2 - omega - -theorem epoch_erased (s : Cov p N) (x : Ambient p N) : epoch p (erased p s x) ≤ epoch p x := - Finset.sum_le_sum fun i _ => rank_lift_le _ _ (x i) - -theorem epoch_eq_zero (x : Ambient p N) : epoch p x=0 ↔ x=0 := by - classical - constructor - · intro h - funext i - have he := Finset.single_le_sum (fun i _ => Nat.zero_le (x i).rank) - (Finset.mem_univ i) - have ht : (x i).rank=0 := Nat.eq_zero_of_le_zero (by simpa only [epoch] using h ▸ he) - obtain ⟨A,B,hA,hB,hZ⟩ := rank_product (x i) - have : IsEmpty (Fin (x i).rank) := ht ▸ Fin.isEmpty' - apply hZ.symm.trans - ext; simp [Matrix.mul_apply] - intro h - rw [h,epoch]; simp - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CoverSpaces + +namespace OAI + +/-! # Span Deficits -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Submodule Module Finset +open scoped BigOperators +variable {p : Shape} {N : ℕ} {I J K : Type} [Fintype I] [Fintype J] [Fintype K] + +/-- Loss of rank from overlapping mode spans. -/ +private theorem colsum_bound (A B : Mat I J) : + A.rank+B.rank ≤ (A+B).rank+dim (colSp A⊓colSp B : Submodule _ _)+ + dim (colSp Aᵀ ⊓ colSp Bᵀ : Submodule _ _) := by + classical + obtain ⟨X,Y,hX,hY,hA⟩ := rank_product A + obtain ⟨S,T,hS,hT,hB⟩ := rank_product B + have h := rank_ge_mul (fromCols X S) (fromRows Y T) + have he {I J U : Type} [Fintype I] [Fintype U] [Fintype J] (A : Mat I U) {B : Mat U J} + (h : Function.Surjective B.mulVec) : + colSp (A*B) = colSp A := by + rw [colSp,mulVecLin_mul,LinearMap.range_comp, + LinearMap.range_eq_top.mpr (show Function.Surjective B.mulVecLin from h),Submodule.map_top] + have hc := colSp_join X S + have hr := colSp_join Yᵀ Tᵀ + rw [← he X hY,← he S hT,hA,hB] at hc + rw [← he Yᵀ (transpose_surj_iff.mpr hX),←he Tᵀ (transpose_surj_iff.mpr hS),←transpose_mul, + ←transpose_mul,hA,hB] at hr + have h1 := finrank_sup_add_finrank_inf_eq (colSp A) (colSp B) + rw [←hc] at h1 + have h2 := finrank_sup_add_finrank_inf_eq (colSp Aᵀ) (colSp Bᵀ) + rw [←hr] at h2 + rw [fromCols_mul_fromRows,hA,hB,Fintype.card_sum,Fintype.card_fin,Fintype.card_fin, + ← Matrix.rank_transpose (fromRows _ _), transpose_fromRows] at h + change (fromCols X S).rank+dim (_ : Submodule _ _) = A.rank+B.rank at h1 + change (fromCols Yᵀ Tᵀ).rank+dim (_ : Submodule _ _)=Aᵀ.rank+Bᵀ.rank at h2 + rw [Matrix.rank_transpose,Matrix.rank_transpose] at h2 + omega + +theorem cdim_mono {a b : Cov p N} (h : a≤b) : cdim p a ≤ cdim p b := + Finset.sum_le_sum fun i _ => Submodule.finrank_mono (h i) +@[simp] theorem cdim_bot {p N} : cdim p (N:=N) ⊥=0 := by + unfold cdim + refine Finset.sum_eq_zero fun i _ => ?_ + exact finrank_bot _ _ + +theorem cdim_sup_inf (a b : Cov p N) : cdim p (a⊔b)+cdim p (a⊓b)=cdim p a+cdim p b := by + unfold cdim + rw [← Finset.sum_add_distrib, ← Finset.sum_add_distrib] + exact Finset.sum_congr rfl fun i _ => finrank_sup_add_finrank_inf_eq (a i) (b i) + +def tax (p : Shape) {N} (a b : Cov p N) := cdim p (a⊔b)-cdim p a + +theorem tax_before (a b : Cov p N) : cdim p a+tax p a b=cdim p (a⊔b) := + Nat.add_sub_of_le (cdim_mono (p:=p) le_sup_left) + +theorem tax_lost (a b : Cov p N) : tax p a b+cdim p (a⊓b)=cdim p b := by + have h := cdim_sup_inf (p:=p) a b; rw [←tax_before (p:=p)] at h + omega + +theorem tax_antitone (p : Shape) {N} (a b c : Cov p N) (h : a≤b) : + tax p b c≤ tax p a c := by + have he := cdim_mono (p:=p) (inf_le_inf h (show c≤c from le_rfl)) + have hg := tax_lost (p:=p) a c + have hh := tax_lost (p:=p) b c + omega + +theorem matter_pair {x y : Ambient p N} {a b : Cov p N} + (hx : matter p x ≤ a) (hy : matter p y ≤ b) : + matter p (x+y) ≤ a⊔b ∧ + epoch p x+ epoch p y+cdim p (a⊔b) ≤ epoch p (x+y)+cdim p a+cdim p b := by + classical + have h (i) : x i∈box (a (i,true)) (a (i,false)) := + (box_mem ..).mpr ⟨hx (i,true),hx (i,false)⟩ + have h' i : y i ∈box (b (i,true)) (b (i,false)) := + (box_mem ..).mpr ⟨hy (i,true),hy (i,false)⟩ + constructor + · intro i + let C := a⊔b + have he : x i.1 + y i.1∈box (C (i.1,true)) (C (i.1,false)) := + Submodule.add_mem _ ((box_le le_sup_left le_sup_left) (h _)) + ((box_le le_sup_right le_sup_right) (h' _)) + have hg := (box_mem ..).mp he + cases i with | mk i j => cases j; exact hg.2; exact hg.1 + · have hg (i) : (x i).rank+(y i).rank ≤ (x i+y i).rank+dim ((a⊓b) (i,true))+ + dim ((a⊓b) (i,false)) := by + refine (colsum_bound (x i) (y i)).trans ?_ + have he c := Submodule.finrank_mono (inf_le_inf (hx (i,c)) (hy (i,c))) + exact Nat.add_le_add (Nat.add_le_add_left (he true) _) (he false) + have he := cdim_sup_inf (p:=p) a b + have hh := (Finset.sum_le_sum (s:=Finset.univ) fun i _ => hg i) + simp only [Finset.sum_add_distrib] at hh + change epoch _ x+epoch _ y≤ epoch p (x+y)+cdSign p _ true+cdSign p _ false at hh + rw [Nat.add_assoc,← cdim_sign] at hh + omega + +def chopped (p : Shape) {N} (a b : Cov p N) : Cov p N := + fun z => chopSpace (a z) (b z) + +theorem matter_erased {a : Cov p N} (x : Ambient p N) : + matter p (erased p a x) ≤ chopped p a (matter p x) := by + intro z + let D := matter p x + have h : x z.1∈box (D (z.1,true)) (D (z.1,false)) := + (box_mem ..).mpr ⟨le_rfl,le_rfl⟩ + have he := (box_mem ..).mp (lift_mem_box (chop (a (z.1,true))) (chop (a (z.1,false))) h) + cases z with | mk e c => cases c; exact he.2; exact he.1 + +theorem cdim_chopped (p : Shape) {N} (a b : Cov p N) : + cdim p (chopped p a b)=tax p a b := by + have h := tax_before (p:=p) a b + have he : cdim p a+cdim p (chopped p a b)=cdim p (a⊔b) := by + unfold cdim + rw [← Finset.sum_add_distrib]; exact Finset.sum_congr rfl fun i _ => chopSpace_rank .. + exact Nat.add_left_cancel (he.trans h.symm) + +def arrange (p : Shape) {N J} (f : J→ Ambient p N) (r : Finset J) := r.sup (matter p ∘ f) + +theorem epoch_charge {J} (f : J→Ambient p N) (s : Cov p N) (r : Finset J) : + (matter p (∑ i∈r, erased p s (f i))) ≤ chopped p s (arrange p f r) ∧ + ((∑ i∈r,epoch p (erased p s (f i)))+tax p s (arrange p f r) ≤ + epoch p (∑ i∈r, erased p s (f i)) + ∑ i∈r,tax p s (matter p (f i))) := by + classical + induction r using Finset.induction with + | empty => + have he : matter p (N:=N) (0:Ambient p N)=⊥ := by funext i; simp [matter,colSp,Pi.bot_apply] + simp only [Finset.sum_empty,he,bot_le,true_and,zero_add,add_zero] + have hi : arrange p f ∅ = ⊥ := Finset.sup_empty + rw [hi,tax,sup_bot_eq,Nat.sub_self]; exact Nat.zero_le _ + | insert i r hr ih => + obtain ⟨hx,hh⟩ := matter_pair (matter_erased (a:=s) (f i)) ih.1 + simp only [Finset.sum_insert hr] + have he : arrange p f (insert i r)= matter p (f i)⊔arrange p f r := + Finset.sup_insert + have ht : chopped p s (arrange p f (insert i r)) = + chopped p s (matter p (f i))⊔chopped p s (arrange p f r) := by + rw [he] + funext z; exact Submodule.map_sup _ _ _ + rw [ht] + refine ⟨hx,?_⟩ + rw [← ht, cdim_chopped,cdim_chopped,cdim_chopped] at hh + have hi := ih.2 + omega + +theorem epoch_erased (s : Cov p N) (x : Ambient p N) : epoch p (erased p s x) ≤ epoch p x := + Finset.sum_le_sum fun i _ => rank_lift_le _ _ (x i) + +theorem epoch_eq_zero (x : Ambient p N) : epoch p x=0 ↔ x=0 := by + classical + constructor + · intro h + funext i + have he := Finset.single_le_sum (fun i _ => Nat.zero_le (x i).rank) + (Finset.mem_univ i) + have ht : (x i).rank=0 := Nat.eq_zero_of_le_zero (by simpa only [epoch] using h ▸ he) + obtain ⟨A,B,hA,hB,hZ⟩ := rank_product (x i) + have : IsEmpty (Fin (x i).rank) := ht ▸ Fin.isEmpty' + apply hZ.symm.trans + ext; simp [Matrix.mul_apply] + intro h + rw [h,epoch]; simp + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SparseCutProfiles.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SparseCutProfiles.lean index 61349dac7cacdd89095a2424046117645d0e5816..6258a3f0949e5af1eba9a53f1e102047eff02e4a 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SparseCutProfiles.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SparseCutProfiles.lean @@ -1,224 +1,224 @@ -import OAI.Combinatorics.HadwigerCounterexample.RawFrameLaws - -namespace OAI - -/-! # Sparse Cut Profiles -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix -open scoped BigOperators - -variable {p : Shape} {n : ℕ} - -theorem Wtag_disabled {l d : Tag p.g} (h : ¬allowed d l) (t : Tag p.g) (i : Fin n) - {m : Moment p n} (hm : m ∈ Wtag p n l) (s : SelIdx p.b p.j) (r : Row p n) : - m (s,some (Block.O d t,i)) r = 0 := by - unfold Wtag at hm - induction hm using Submodule.span_induction with - | mem m hm => - obtain ⟨s,z,hz,rfl⟩ := hm - change (selV _ _ _ * z _) * _ = 0 - rw [hz d t h,mul_zero,zero_mul] - | zero => rfl - | add x y _ _ hx hy => simp only [Matrix.add_apply,hx,hy,add_zero] - | smul a x _ h => simp only [Matrix.smul_apply,h,smul_zero] - -/-- Intersect W_l over a strict majority. Every O coordinate is forced -to zero and projecting onto the shared variables fixes the matrix. -/ -theorem Wtag_majority_star {I : Finset (Tag p.g)} - (hI : p.g < 2 * I.card) {m : Moment p n} (h : ∀ l ∈ I, m ∈ Wtag p n l) : - m ∈ Wstar p n := by - classical - obtain ⟨a,ha⟩ := Finset.card_pos.mp (show 0 < I.card by omega) - have hm : m ∈ Wspace p n := Wtag_le a (h a ha) - have hz (s : SelIdx p.b p.j) (i : Fin n) (d t : Tag p.g) (r : Row p n) : - m (s,some (Block.O d t,i)) r = 0 := by - obtain ⟨l,hl,hg⟩ : ∃ l ∈ I, ¬allowed d l := by - by_contra! he - have hi := @Finset.card_le_card _ I (Finset.univ.filter (allowed d)) (by - intro l hl; exact Finset.mem_filter.mpr ⟨Finset.mem_univ _,he _ hl⟩) - have hh := card_allowed d - rw [Fintype.card_subtype] at hh - have hi' := hi.trans_eq hh - omega - exact Wtag_disabled hg _ _ (h _ hl) _ _ - let kB : BaseIdx p.g n → F := fun i => i.1.elim (fun _ => 0) (fun _ => 1) - let k : Row p n → F := fun i => Option.elim' 1 kB i.2 - let D := Matrix.diagonal k - let L (z : Base p.g n) := fun i => kB i * z i - have hL (s z) : D *ᵥ point p s z = point p s (L z) := by - funext i - simp only [D,Matrix.mulVec_diagonal] - rcases i with ⟨s,i⟩ - rcases i with _|i - · change (1:F)*_ = _ - rw [one_mul]; rfl - change kB i * (selV _ _ _ * z i) = _ * (kB i * _); rw [mul_left_comm] - have hx : liftM D D m ∈ Wstar p n := by - clear h hz - unfold Wspace at hm - induction hm using Submodule.span_induction with - | mem m he => - obtain ⟨s,z,rfl⟩ := he - rw [mom,liftM_outer,hL] - exact Submodule.subset_span ⟨s,L z,fun d t i => by - change (0:F)*_=0 - rw [zero_mul],rfl⟩ - | zero => simp only [map_zero,Submodule.zero_mem] - | add i j _ _ h g => rw [map_add]; exact Submodule.add_mem _ h g - | smul _ _ _ h => rw [map_smul]; exact Submodule.smul_mem _ _ h - have hrow (i j) : k i*m i j = m i j := by - rcases i with ⟨s,_|⟨⟨d,t⟩|a,i⟩⟩ - · exact one_mul _ - · rw [hz] - simp - · exact one_mul _ - have hj : liftM D D m = m := by - ext i j - simp only [liftM_def,D,Matrix.diagonal_transpose,Matrix.mul_diagonal,Matrix.diagonal_mul,hrow] - rw [mul_comm] - have heq : m i j=m j i := congr_fun (congr_fun (Wspace_sym hm) j) i - rw [heq,hrow] - rwa [hj] at hx - -def totalRank (x : Profile p n) : ℕ := ∑ i, (x i).rank -def nonzeroTags (w : Tag p.g → Moment p n) : Finset (Tag p.g) := - by classical exact Finset.univ.filter (fun i => w i ≠ 0) - -theorem mem_nonzeroTags (i) (w : Tag p.g → Moment p n) : - i ∈ nonzeroTags w ↔ w i ≠ 0 := by classical simp [nonzeroTags] - -theorem cut_const (w : Tag p.g → Moment p n) (m : Moment p n) : - cut p n (fun i => w i+m) = cut p n w := by - funext i - change w _ + m + (w _ + m) = w _ + w _ - rw [add_add_add_comm, char_two,add_zero] - -theorem common_zero {w v : Tag p.g → Moment p n} - (h : 2*(nonzeroTags w).card < p.g) (g : 2*(nonzeroTags v).card < p.g) : - ∃ l, w l=0 ∧ v l=0 := by - classical - by_contra! hn - have hu : Finset.univ ⊆ nonzeroTags w ∪ nonzeroTags v := by - intro i hi - by_cases h : w i=0 - · exact Finset.mem_union_right _ ((mem_nonzeroTags _ _).mpr (hn i h)) - · exact Finset.mem_union_left _ ((mem_nonzeroTags _ _).mpr h) - have hx := (Finset.card_le_card hu).trans (Finset.card_union_le _ _) - simp only [Finset.card_univ, Tag, Fintype.card_fin] at hx - omega - -theorem small_cut_unique {w v : Tag p.g → Moment p n} - (h : 2*(nonzeroTags w).card < p.g) (g : 2*(nonzeroTags v).card < p.g) - (he : cut p n w = cut p n v) : w=v := by - obtain ⟨l,hl,hL⟩ := common_zero h g - funext i - have ha := getPair_cut w i l - rw [he, getPair_cut,hl,hL,add_zero,add_zero] at ha - exact ha.symm - -private theorem nz_rank {I J : Type} [Fintype I] [Fintype J] {M : Mat I J} - (h : M ≠ 0) : 1 ≤ M.rank := by - by_contra hg - have he : colSp M = ⊥ := Submodule.finrank_eq_zero.mp (by - rw [show Module.finrank F (colSp M)=M.rank from rfl]; omega) - have hm : M.mulVecLin = 0 := LinearMap.range_eq_bot.mp he - apply h - exact coe_mv_inj (J:=J) (show M.mulVecLin=Matrix.mulVecLin 0 by rw [hm,mulVecLin_zero]) - -theorem few_unequal {w : Tag p.g → Moment p n} : - ∑ l : Tag p.g, (nonzeroTags (fun d => w d+w l)).card ≤ 2*totalRank (cut p n w) := by - classical - let r := fun i => ((cut p n w) i).rank - have he (l) : - (nonzeroTags (fun d => w d+w l)).card ≤ - ∑ i : Comp p.g, if inc i l then r i else 0 := by - - let f (i : Tag p.g) := if w i+w l ≠ 0 then (1:ℕ) else 0 - have h : - (nonzeroTags (fun d => w d+w l)).card = ∑ i : {i : Tag p.g // l ≠ i}, f i := by - have hh : (nonzeroTags (fun d => w d+w l)).card = ∑ i, f i := by - unfold nonzeroTags f - rw [Finset.card_eq_sum_ones,Finset.sum_filter] - rw [hh,Fintype.sum_eq_add_sum_subtype_ne _ l] - have hz : f l=0 := by simp [f,char_two] - rw [hz,zero_add] - exact (Equiv.subtypeEquivRight (show ∀ x, (x ≠ l) ↔ (l ≠ x) from fun _ => ne_comm)).sum_comp - (fun x : {i : Tag p.g // l ≠ i} => f x) - rw [h] - have h' : - (∑ i : Comp p.g, if inc i l then r i else 0) = ∑ i : TagStar l, r i.val := by - rw [← Finset.sum_filter] - exact Finset.sum_subtype _ (by simp) _ - rw [h',← (starEquiv l).sum_comp] - refine Finset.sum_le_sum fun i _ => ?_ - unfold f - split - · rename_i hx - change 1 ≤ r (edge l i i.property) - apply nz_rank - have h0 := getPair_edge l i i.property (cut p n w) - rw [getPair_cut, add_comm] at h0 - rw [← h0] - exact hx - · exact Nat.zero_le _ - refine (Finset.sum_le_sum (fun i _ => he i)).trans_eq ?_ - unfold totalRank - rw [Finset.sum_comm, Finset.mul_sum] - refine Finset.sum_congr rfl fun i _ => ?_ - have hi : Finset.univ.filter (fun l => inc i l) = {i.val.1,i.val.2} := by - ext; simp [inc,eq_comm] - rw [← Finset.sum_filter,hi] - simp [i.property.ne, two_mul,r] - -/-- Sparse representatives: the bound here is g*(number of supported tags) -≤ 2*total rank (apply with total rank ≤ 2D). -/ -theorem sparse_rep {x : Profile p n} (h : x ∈ Xspace p n) - (hg : 4*totalRank x < p.g*p.g) : - ∃ w : Tag p.g → Moment p n, cut p n w=x ∧ - (∀ l,w l∈Wtag p n l) ∧ - p.g*(nonzeroTags w).card ≤ 2*totalRank x ∧ 2*(nonzeroTags w).card < p.g := by - classical - obtain ⟨w,hw,rfl⟩ := mem_X.mp h - let B := fun l => nonzeroTags (p:=p) (fun i => w i+w l) - let t := totalRank (cut p n w) - have hn : 0 < p.g := Nat.pos_of_ne_zero (fun he => by - have hi : p.g*p.g=0 := by rw [he] - omega) - have : NeZero p.g := ⟨hn.ne'⟩ - obtain ⟨l,hl⟩ : ∃ l : Tag p.g, p.g*(B l).card ≤ 2*t := by - by_contra! he - have he1 : - ∑ _l : Tag p.g, 2*t < ∑ l : Tag p.g, p.g*(B l).card := - Finset.sum_lt_sum (fun l _ => (he l).le) ⟨0,Finset.mem_univ _,he 0⟩ - simp only [Finset.sum_const,Finset.card_univ,Tag,Fintype.card_fin,nsmul_eq_mul] at he1 - rw [← Finset.mul_sum] at he1 - have hh : p.g*(∑ l, (B l).card) ≤ p.g*(2*t) := Nat.mul_le_mul_left _ few_unequal - exact Nat.not_lt_of_le hh he1 - let v := fun i => w i+w l - have hi : 2*(nonzeroTags v).card < p.g := by - change p.g*(nonzeroTags v).card ≤ _ at hl - by_contra h1 - have hh : p.g*p.g ≤ p.g*(2*(nonzeroTags v).card) := - Nat.mul_le_mul_left _ (Nat.le_of_not_lt h1) - change 4*t< p.g*p.g at hg - nlinarith - refine ⟨v,cut_const w _,fun i => ?_,hl,hi⟩ - refine Submodule.add_mem _ (hw i) ((Wstar_le_tag i) ?_) - apply Wtag_majority_star (I := (nonzeroTags v)ᶜ) - · rw [Finset.card_compl,show Fintype.card (Tag p.g)=p.g from Fintype.card_fin _] - omega - · intro j hj - have hh : w j+w l=0 := by - change v j=0 - have h := Finset.mem_compl.mp hj - rwa [mem_nonzeroTags, not_not] at h - have he : w j = w l := add_right_cancel (hh.trans (char_two _).symm) - rw [← he]; exact hw j - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.RawFrameLaws + +namespace OAI + +/-! # Sparse Cut Profiles -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix +open scoped BigOperators + +variable {p : Shape} {n : ℕ} + +theorem Wtag_disabled {l d : Tag p.g} (h : ¬allowed d l) (t : Tag p.g) (i : Fin n) + {m : Moment p n} (hm : m ∈ Wtag p n l) (s : SelIdx p.b p.j) (r : Row p n) : + m (s,some (Block.O d t,i)) r = 0 := by + unfold Wtag at hm + induction hm using Submodule.span_induction with + | mem m hm => + obtain ⟨s,z,hz,rfl⟩ := hm + change (selV _ _ _ * z _) * _ = 0 + rw [hz d t h,mul_zero,zero_mul] + | zero => rfl + | add x y _ _ hx hy => simp only [Matrix.add_apply,hx,hy,add_zero] + | smul a x _ h => simp only [Matrix.smul_apply,h,smul_zero] + +/-- Intersect W_l over a strict majority. Every O coordinate is forced +to zero and projecting onto the shared variables fixes the matrix. -/ +theorem Wtag_majority_star {I : Finset (Tag p.g)} + (hI : p.g < 2 * I.card) {m : Moment p n} (h : ∀ l ∈ I, m ∈ Wtag p n l) : + m ∈ Wstar p n := by + classical + obtain ⟨a,ha⟩ := Finset.card_pos.mp (show 0 < I.card by omega) + have hm : m ∈ Wspace p n := Wtag_le a (h a ha) + have hz (s : SelIdx p.b p.j) (i : Fin n) (d t : Tag p.g) (r : Row p n) : + m (s,some (Block.O d t,i)) r = 0 := by + obtain ⟨l,hl,hg⟩ : ∃ l ∈ I, ¬allowed d l := by + by_contra! he + have hi := @Finset.card_le_card _ I (Finset.univ.filter (allowed d)) (by + intro l hl; exact Finset.mem_filter.mpr ⟨Finset.mem_univ _,he _ hl⟩) + have hh := card_allowed d + rw [Fintype.card_subtype] at hh + have hi' := hi.trans_eq hh + omega + exact Wtag_disabled hg _ _ (h _ hl) _ _ + let kB : BaseIdx p.g n → F := fun i => i.1.elim (fun _ => 0) (fun _ => 1) + let k : Row p n → F := fun i => Option.elim' 1 kB i.2 + let D := Matrix.diagonal k + let L (z : Base p.g n) := fun i => kB i * z i + have hL (s z) : D *ᵥ point p s z = point p s (L z) := by + funext i + simp only [D,Matrix.mulVec_diagonal] + rcases i with ⟨s,i⟩ + rcases i with _|i + · change (1:F)*_ = _ + rw [one_mul]; rfl + change kB i * (selV _ _ _ * z i) = _ * (kB i * _); rw [mul_left_comm] + have hx : liftM D D m ∈ Wstar p n := by + clear h hz + unfold Wspace at hm + induction hm using Submodule.span_induction with + | mem m he => + obtain ⟨s,z,rfl⟩ := he + rw [mom,liftM_outer,hL] + exact Submodule.subset_span ⟨s,L z,fun d t i => by + change (0:F)*_=0 + rw [zero_mul],rfl⟩ + | zero => simp only [map_zero,Submodule.zero_mem] + | add i j _ _ h g => rw [map_add]; exact Submodule.add_mem _ h g + | smul _ _ _ h => rw [map_smul]; exact Submodule.smul_mem _ _ h + have hrow (i j) : k i*m i j = m i j := by + rcases i with ⟨s,_|⟨⟨d,t⟩|a,i⟩⟩ + · exact one_mul _ + · rw [hz] + simp + · exact one_mul _ + have hj : liftM D D m = m := by + ext i j + simp only [liftM_def,D,Matrix.diagonal_transpose,Matrix.mul_diagonal,Matrix.diagonal_mul,hrow] + rw [mul_comm] + have heq : m i j=m j i := congr_fun (congr_fun (Wspace_sym hm) j) i + rw [heq,hrow] + rwa [hj] at hx + +def totalRank (x : Profile p n) : ℕ := ∑ i, (x i).rank +def nonzeroTags (w : Tag p.g → Moment p n) : Finset (Tag p.g) := + by classical exact Finset.univ.filter (fun i => w i ≠ 0) + +theorem mem_nonzeroTags (i) (w : Tag p.g → Moment p n) : + i ∈ nonzeroTags w ↔ w i ≠ 0 := by classical simp [nonzeroTags] + +theorem cut_const (w : Tag p.g → Moment p n) (m : Moment p n) : + cut p n (fun i => w i+m) = cut p n w := by + funext i + change w _ + m + (w _ + m) = w _ + w _ + rw [add_add_add_comm, char_two,add_zero] + +theorem common_zero {w v : Tag p.g → Moment p n} + (h : 2*(nonzeroTags w).card < p.g) (g : 2*(nonzeroTags v).card < p.g) : + ∃ l, w l=0 ∧ v l=0 := by + classical + by_contra! hn + have hu : Finset.univ ⊆ nonzeroTags w ∪ nonzeroTags v := by + intro i hi + by_cases h : w i=0 + · exact Finset.mem_union_right _ ((mem_nonzeroTags _ _).mpr (hn i h)) + · exact Finset.mem_union_left _ ((mem_nonzeroTags _ _).mpr h) + have hx := (Finset.card_le_card hu).trans (Finset.card_union_le _ _) + simp only [Finset.card_univ, Tag, Fintype.card_fin] at hx + omega + +theorem small_cut_unique {w v : Tag p.g → Moment p n} + (h : 2*(nonzeroTags w).card < p.g) (g : 2*(nonzeroTags v).card < p.g) + (he : cut p n w = cut p n v) : w=v := by + obtain ⟨l,hl,hL⟩ := common_zero h g + funext i + have ha := getPair_cut w i l + rw [he, getPair_cut,hl,hL,add_zero,add_zero] at ha + exact ha.symm + +private theorem nz_rank {I J : Type} [Fintype I] [Fintype J] {M : Mat I J} + (h : M ≠ 0) : 1 ≤ M.rank := by + by_contra hg + have he : colSp M = ⊥ := Submodule.finrank_eq_zero.mp (by + rw [show Module.finrank F (colSp M)=M.rank from rfl]; omega) + have hm : M.mulVecLin = 0 := LinearMap.range_eq_bot.mp he + apply h + exact coe_mv_inj (J:=J) (show M.mulVecLin=Matrix.mulVecLin 0 by rw [hm,mulVecLin_zero]) + +theorem few_unequal {w : Tag p.g → Moment p n} : + ∑ l : Tag p.g, (nonzeroTags (fun d => w d+w l)).card ≤ 2*totalRank (cut p n w) := by + classical + let r := fun i => ((cut p n w) i).rank + have he (l) : + (nonzeroTags (fun d => w d+w l)).card ≤ + ∑ i : Comp p.g, if inc i l then r i else 0 := by + + let f (i : Tag p.g) := if w i+w l ≠ 0 then (1:ℕ) else 0 + have h : + (nonzeroTags (fun d => w d+w l)).card = ∑ i : {i : Tag p.g // l ≠ i}, f i := by + have hh : (nonzeroTags (fun d => w d+w l)).card = ∑ i, f i := by + unfold nonzeroTags f + rw [Finset.card_eq_sum_ones,Finset.sum_filter] + rw [hh,Fintype.sum_eq_add_sum_subtype_ne _ l] + have hz : f l=0 := by simp [f,char_two] + rw [hz,zero_add] + exact (Equiv.subtypeEquivRight (show ∀ x, (x ≠ l) ↔ (l ≠ x) from fun _ => ne_comm)).sum_comp + (fun x : {i : Tag p.g // l ≠ i} => f x) + rw [h] + have h' : + (∑ i : Comp p.g, if inc i l then r i else 0) = ∑ i : TagStar l, r i.val := by + rw [← Finset.sum_filter] + exact Finset.sum_subtype _ (by simp) _ + rw [h',← (starEquiv l).sum_comp] + refine Finset.sum_le_sum fun i _ => ?_ + unfold f + split + · rename_i hx + change 1 ≤ r (edge l i i.property) + apply nz_rank + have h0 := getPair_edge l i i.property (cut p n w) + rw [getPair_cut, add_comm] at h0 + rw [← h0] + exact hx + · exact Nat.zero_le _ + refine (Finset.sum_le_sum (fun i _ => he i)).trans_eq ?_ + unfold totalRank + rw [Finset.sum_comm, Finset.mul_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + have hi : Finset.univ.filter (fun l => inc i l) = {i.val.1,i.val.2} := by + ext; simp [inc,eq_comm] + rw [← Finset.sum_filter,hi] + simp [i.property.ne, two_mul,r] + +/-- Sparse representatives: the bound here is g*(number of supported tags) +≤ 2*total rank (apply with total rank ≤ 2D). -/ +theorem sparse_rep {x : Profile p n} (h : x ∈ Xspace p n) + (hg : 4*totalRank x < p.g*p.g) : + ∃ w : Tag p.g → Moment p n, cut p n w=x ∧ + (∀ l,w l∈Wtag p n l) ∧ + p.g*(nonzeroTags w).card ≤ 2*totalRank x ∧ 2*(nonzeroTags w).card < p.g := by + classical + obtain ⟨w,hw,rfl⟩ := mem_X.mp h + let B := fun l => nonzeroTags (p:=p) (fun i => w i+w l) + let t := totalRank (cut p n w) + have hn : 0 < p.g := Nat.pos_of_ne_zero (fun he => by + have hi : p.g*p.g=0 := by rw [he] + omega) + have : NeZero p.g := ⟨hn.ne'⟩ + obtain ⟨l,hl⟩ : ∃ l : Tag p.g, p.g*(B l).card ≤ 2*t := by + by_contra! he + have he1 : + ∑ _l : Tag p.g, 2*t < ∑ l : Tag p.g, p.g*(B l).card := + Finset.sum_lt_sum (fun l _ => (he l).le) ⟨0,Finset.mem_univ _,he 0⟩ + simp only [Finset.sum_const,Finset.card_univ,Tag,Fintype.card_fin,nsmul_eq_mul] at he1 + rw [← Finset.mul_sum] at he1 + have hh : p.g*(∑ l, (B l).card) ≤ p.g*(2*t) := Nat.mul_le_mul_left _ few_unequal + exact Nat.not_lt_of_le hh he1 + let v := fun i => w i+w l + have hi : 2*(nonzeroTags v).card < p.g := by + change p.g*(nonzeroTags v).card ≤ _ at hl + by_contra h1 + have hh : p.g*p.g ≤ p.g*(2*(nonzeroTags v).card) := + Nat.mul_le_mul_left _ (Nat.le_of_not_lt h1) + change 4*t< p.g*p.g at hg + nlinarith + refine ⟨v,cut_const w _,fun i => ?_,hl,hi⟩ + refine Submodule.add_mem _ (hw i) ((Wstar_le_tag i) ?_) + apply Wtag_majority_star (I := (nonzeroTags v)ᶜ) + · rw [Finset.card_compl,show Fintype.card (Tag p.g)=p.g from Fintype.card_fin _] + omega + · intro j hj + have hh : w j+w l=0 := by + change v j=0 + have h := Finset.mem_compl.mp hj + rwa [mem_nonzeroTags, not_not] at h + have he : w j = w l := add_right_cancel (hh.trans (char_two _).symm) + rw [← he]; exact hw j + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SparseLabelBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SparseLabelBounds.lean index 5220f572aab8eaa9a1e9fc5921c9d3d2f5bcf542..b91be099f5a58eac0892a09d8f4a86ddbb5ac343 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SparseLabelBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SparseLabelBounds.lean @@ -1,101 +1,101 @@ -import OAI.Combinatorics.HadwigerCounterexample.BooleanLabels - -namespace OAI - -/-! # Sparse Label Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Finset Submodule -variable {p : Shape} {n : ℕ} - -abbrev LabVals (p : Shape) (n : ℕ) := Label p.b → Vec (AIdx p.g n) - -def labcomb (p : Shape) (n : ℕ) (L : Finset (Label p.b)) : - LabVals p n →ₗ[F] Ray p n := - ∑ i∈L, putLab p n i ∘ₗ LinearMap.proj i - -theorem labcomb_eval (L : Finset (Label p.b)) (z : LabVals p n) : - labcomb p n L z= ∑ i∈L, putLab p n i (z i) := by simp [labcomb,LinearMap.sum_apply] - -def labV (p : Shape) (n : ℕ) (L : Finset (Label p.b)) : Space (Ray p n) := - LinearMap.range (labcomb p n L) - -def withinL (p : Shape) (L : Finset (Label p.b)) (z : LabVals p n) : LabVals p n := - fun i => if i ∈ L then z i else 0 - -theorem within_eq {L B : Finset (Label p.b)} (h : B ⊆ L) (z : LabVals p n) : - labcomb p n B z = labcomb p n L (withinL p B z) := by - classical - rw [labcomb_eval,labcomb_eval] - refine (sum_congr (g:=fun i => putLab p n i (withinL p B z i)) rfl fun i hi => ?_).trans - (sum_subset h fun i _ hi => ?_) - · simp [withinL,hi] - simp [withinL,hi] - -theorem labV_mono {L B : Finset (Label p.b)} (h : B ⊆ L) : labV p n B ≤ labV p n L := by - rintro x ⟨y,rfl⟩ - exact ⟨_,(within_eq h y).symm⟩ - -theorem labV_unique {L B : Finset (Label p.b)} {z : LabVals p n} - (h : labcomb p n B z∈labV p n L) (hj : (B∪L).card≤p.j+1) : - ∀ i∈B,i∉L → z i=0 := by - intro i hi hL - obtain ⟨x,hx⟩ := h - rw [within_eq (B:=L) (L:=B∪L) subset_union_right, - within_eq (B:=B) (L:=B∪L) subset_union_left] at hx - have he : - labcomb p n (B∪L) ((withinL p B z)-(withinL p L x))=0 := by rw [map_sub,hx,sub_self] - rw [labcomb_eval] at he - have hg := ray_indep _ _ hj he i (mem_union_left L hi) - simpa [withinL,hL,hi] using hg - -/-- L is the set excluded at this projected space. -/ -def protectedBy (p : Shape) {n} (S : Space (Ray p n)) (q : ℕ) (L : Finset (Label p.b)) := - ∀ (B : Finset (Label p.b)) (z : LabVals p n), - labcomb p n B z∈S → B.card≤q → ∀ i∈B,i∉L → z i=0 - -theorem protect_labels (p : Shape) {n} (S : Space (Ray p n)) (q : ℕ) - (hq : (dim S+1)*q≤p.j+1) : - ∃ L : Finset (Label p.b), L.card≤dim S * q ∧ protectedBy p S q L := by - classical - let T : Set ℕ := {t | ∃ (A : Space (Ray p n)) (L : Finset (Label p.b)), A ≤ S ∧ - A ≤ labV p n L ∧ L.card ≤ t*q ∧ t = dim A} - have he : BddAbove T := ⟨dim S, by - rintro x ⟨A,L, hA,hL,_,rfl⟩ - exact Submodule.finrank_mono hA⟩ - have hn : T.Nonempty := ⟨0, ⊥,∅, bot_le, bot_le, by simp, (finrank_bot ..).symm⟩ - obtain ⟨A,L,hA,hL,hsize,hd⟩ := (show sSup T∈T from Nat.sSup_mem hn he) - have hi := finrank_mono hA - rw [hd] at hsize - have hsc : L.card ≤ dim S*q := hsize.trans (Nat.mul_le_mul_right _ hi) - refine ⟨L,hsc,fun B z hz hB => ?_⟩ - have hh : (B∪L).card≤p.j+1 := by - refine (card_union_le _ _).trans ((add_le_add hB hsc).trans ?_) - simpa [Nat.add_mul, Nat.add_comm] using hq - let x := labcomb p n B z - apply labV_unique _ hh - by_cases hx : x∈A - · exact hL hx - let V : Space (Ray p n) := Submodule.span F ({x}:Set _) - have hv : dim A < dim (A⊔V : Submodule _ _) := by - apply Nat.lt_of_le_of_ne (Submodule.finrank_mono (show A≤A⊔V from le_sup_left)) (fun h => hx ?_) - have hh : A=A⊔V := Submodule.eq_of_le_of_finrank_eq le_sup_left h - exact (show V≤A from le_trans le_sup_right hh.symm.le) (show x ∈ V from - Submodule.subset_span (Set.mem_singleton _)) - have hk : dim (A⊔V : Submodule _ _)∈ T := by - refine ⟨A⊔V,B∪L,sup_le hA ((Submodule.span_singleton_le_iff_mem x S).mpr hz), - sup_le (hL.trans (labV_mono subset_union_right)) ?_, ?_,rfl⟩ - · refine le_trans ((Submodule.span_singleton_le_iff_mem x _).mpr (show x∈labV p n B from - ⟨z,rfl⟩)) (labV_mono subset_union_left) - exact (card_union_le _ _).trans ((Nat.add_le_add hB hsize).trans (by - simpa [Nat.add_mul,add_comm q] using Nat.mul_le_mul_right q hv)) - have hg := le_csSup he hk - exact (not_le_of_gt hv (by rwa [← hd])).elim - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BooleanLabels + +namespace OAI + +/-! # Sparse Label Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Finset Submodule +variable {p : Shape} {n : ℕ} + +abbrev LabVals (p : Shape) (n : ℕ) := Label p.b → Vec (AIdx p.g n) + +def labcomb (p : Shape) (n : ℕ) (L : Finset (Label p.b)) : + LabVals p n →ₗ[F] Ray p n := + ∑ i∈L, putLab p n i ∘ₗ LinearMap.proj i + +theorem labcomb_eval (L : Finset (Label p.b)) (z : LabVals p n) : + labcomb p n L z= ∑ i∈L, putLab p n i (z i) := by simp [labcomb,LinearMap.sum_apply] + +def labV (p : Shape) (n : ℕ) (L : Finset (Label p.b)) : Space (Ray p n) := + LinearMap.range (labcomb p n L) + +def withinL (p : Shape) (L : Finset (Label p.b)) (z : LabVals p n) : LabVals p n := + fun i => if i ∈ L then z i else 0 + +theorem within_eq {L B : Finset (Label p.b)} (h : B ⊆ L) (z : LabVals p n) : + labcomb p n B z = labcomb p n L (withinL p B z) := by + classical + rw [labcomb_eval,labcomb_eval] + refine (sum_congr (g:=fun i => putLab p n i (withinL p B z i)) rfl fun i hi => ?_).trans + (sum_subset h fun i _ hi => ?_) + · simp [withinL,hi] + simp [withinL,hi] + +theorem labV_mono {L B : Finset (Label p.b)} (h : B ⊆ L) : labV p n B ≤ labV p n L := by + rintro x ⟨y,rfl⟩ + exact ⟨_,(within_eq h y).symm⟩ + +theorem labV_unique {L B : Finset (Label p.b)} {z : LabVals p n} + (h : labcomb p n B z∈labV p n L) (hj : (B∪L).card≤p.j+1) : + ∀ i∈B,i∉L → z i=0 := by + intro i hi hL + obtain ⟨x,hx⟩ := h + rw [within_eq (B:=L) (L:=B∪L) subset_union_right, + within_eq (B:=B) (L:=B∪L) subset_union_left] at hx + have he : + labcomb p n (B∪L) ((withinL p B z)-(withinL p L x))=0 := by rw [map_sub,hx,sub_self] + rw [labcomb_eval] at he + have hg := ray_indep _ _ hj he i (mem_union_left L hi) + simpa [withinL,hL,hi] using hg + +/-- L is the set excluded at this projected space. -/ +def protectedBy (p : Shape) {n} (S : Space (Ray p n)) (q : ℕ) (L : Finset (Label p.b)) := + ∀ (B : Finset (Label p.b)) (z : LabVals p n), + labcomb p n B z∈S → B.card≤q → ∀ i∈B,i∉L → z i=0 + +theorem protect_labels (p : Shape) {n} (S : Space (Ray p n)) (q : ℕ) + (hq : (dim S+1)*q≤p.j+1) : + ∃ L : Finset (Label p.b), L.card≤dim S * q ∧ protectedBy p S q L := by + classical + let T : Set ℕ := {t | ∃ (A : Space (Ray p n)) (L : Finset (Label p.b)), A ≤ S ∧ + A ≤ labV p n L ∧ L.card ≤ t*q ∧ t = dim A} + have he : BddAbove T := ⟨dim S, by + rintro x ⟨A,L, hA,hL,_,rfl⟩ + exact Submodule.finrank_mono hA⟩ + have hn : T.Nonempty := ⟨0, ⊥,∅, bot_le, bot_le, by simp, (finrank_bot ..).symm⟩ + obtain ⟨A,L,hA,hL,hsize,hd⟩ := (show sSup T∈T from Nat.sSup_mem hn he) + have hi := finrank_mono hA + rw [hd] at hsize + have hsc : L.card ≤ dim S*q := hsize.trans (Nat.mul_le_mul_right _ hi) + refine ⟨L,hsc,fun B z hz hB => ?_⟩ + have hh : (B∪L).card≤p.j+1 := by + refine (card_union_le _ _).trans ((add_le_add hB hsc).trans ?_) + simpa [Nat.add_mul, Nat.add_comm] using hq + let x := labcomb p n B z + apply labV_unique _ hh + by_cases hx : x∈A + · exact hL hx + let V : Space (Ray p n) := Submodule.span F ({x}:Set _) + have hv : dim A < dim (A⊔V : Submodule _ _) := by + apply Nat.lt_of_le_of_ne (Submodule.finrank_mono (show A≤A⊔V from le_sup_left)) (fun h => hx ?_) + have hh : A=A⊔V := Submodule.eq_of_le_of_finrank_eq le_sup_left h + exact (show V≤A from le_trans le_sup_right hh.symm.le) (show x ∈ V from + Submodule.subset_span (Set.mem_singleton _)) + have hk : dim (A⊔V : Submodule _ _)∈ T := by + refine ⟨A⊔V,B∪L,sup_le hA ((Submodule.span_singleton_le_iff_mem x S).mpr hz), + sup_le (hL.trans (labV_mono subset_union_right)) ?_, ?_,rfl⟩ + · refine le_trans ((Submodule.span_singleton_le_iff_mem x _).mpr (show x∈labV p n B from + ⟨z,rfl⟩)) (labV_mono subset_union_left) + exact (card_union_le _ _).trans ((Nat.add_le_add hB hsize).trans (by + simpa [Nat.add_mul,add_comm q] using Nat.mul_le_mul_right q hv)) + have hg := le_csSup he hk + exact (not_le_of_gt hv (by rwa [← hd])).elim + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/StatusCharts.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/StatusCharts.lean index 478fc8d944eb4ef966412c6863c94614fecc681d..1aec85010152a83feddeb88bfdb1a789ce38747f 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/StatusCharts.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/StatusCharts.lean @@ -1,132 +1,132 @@ -import OAI.Combinatorics.HadwigerCounterexample.FourEdgeFamilies -import OAI.Combinatorics.HadwigerCounterexample.PredictionExactification - -namespace OAI - -/-! # Status Charts -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Function Module LinearMap Submodule -open scoped BigOperators - -namespace StatusAnalysis -abbrev Ax (p : Shape) (n : ℕ) (d : ℕ) := Cell d→ₗ[F] Profile p n -abbrev Charts (p : Shape) (n : ℕ) (d : Rates) := ∀ i, Ax p n (d i) -variable {p : Shape} {n N : ℕ} {d e : Rates} -def charted (v : Charts p n d) (w : Plan p n) := - ∀ i,LinearMap.range (v i)=effective w i ∧ Injective (v i) - -theorem chart_create (p : Shape) (n : ℕ) (w : Plan p n) : - let d:= fun i:Nodes=> dim (effective w i) - ∃ v : Charts p n d,charted v w := by - classical - intro d - have hh (i) : - ∃ f : Ax p n (d i),LinearMap.range f=effective w i ∧ Injective f := by - let S:= effective w i - let E : Cell (d i)≃ₗ[F] S := LinearEquiv.ofFinrankEq _ _ - (by change dim (Cell (d i))=d i; rw [dim_vec,Fintype.card_fin]) - refine ⟨S.subtype ∘ₗ E.toLinearMap,?_,Subtype.val_injective.comp E.injective⟩ - rw [LinearMap.range_comp,LinearMap.range_eq_top.mpr E.surjective,← LinearMap.range_eq_map, - Submodule.range_subtype S] - choose f h using hh - exact ⟨f,h⟩ - -abbrev Format := Grid→ℕ -abbrev Messenger (q : Format) := Σ i:Grid,Fin (q i) -def sendId (b : Bool) (i : Grid) := if b then i.1 else i.2 -def transit (b : Bool) (q : Grid) := if b then q else (q.2,q.1) -theorem sendPair (b : Bool) (x : Grid) : - (sendId b x,sendId (!b) x)=transit b x := by cases b <;> rfl -theorem transit_inv (b : Bool) (x : Grid) : transit b (transit b x)=x := by cases b <;> rfl - -def parcel (b : Bool) {q : Format} (x : Messenger q) := sendId b x.1 -def manager {q : Format} (b : Bool) (t : Tagging p (Messenger q)) (s : Messenger q→Label p.b) - (f : Messenger q→Flavor p.g) : Template p (Messenger q) := ⟨parcel b,t,s,f⟩ - -def roll {u : ℕ} (f : Ax p n u) (g : Pdual p n) : Cell u := fun i=>g (f (Pi.single i 1)) - -theorem roll_project {u : ℕ} (f : Ax p n u) (g : Pdual p n) (z : Cell u) : - g (f z)=dotProduct (roll f g) z := by - let h:=g ∘ₗ f - obtain ⟨x,hx⟩:=dotL_surj h - have hi (i:Fin u) : - roll f g i=x i := by - change h (Pi.single i 1)=_ - rw [hx]; change dotProduct x (Pi.single i 1)=x i - simp - rw [show roll f g=x from funext hi] - exact LinearMap.congr_fun hx z - -def targetMark (p : Shape) (v : Charts p n d) (M : Cross p n) (i j : Nodes) : Cell (d i) := - roll (v i) (contract p M i j + role p n) -def hailing (p : Shape) (v : Charts p n d) (z : Charts p n e) (M : Cross p n) : - Cabinet d e := - fun i => (1,1,targetMark p v M i.1 i.2,targetMark p z (reciprocal p M) i.2 i.1) - -abbrev Magazine (p : Shape) (d : ℕ) := Digest p.g × Whole d -def specify (p : Shape) {d : ℕ} (i : Nodes) (v : Ax p n d) - (m : Mixer p n) (o : UnitType p n N) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) - (x : Knobs p.g n) : Magazine p d := - let A:=useAtom p l s f x - (scan p l f x, (role p n A,roll v (Tsym m A)),innerP p o i A) - -variable {q : Format} - -def printed (b : Bool) (v : Charts p n d) (t : Tagging p (Messenger q)) - (s : Messenger q →Label p.b) (f : Messenger q → Flavor p.g) (m : Mixer p n) - (o : UnitType p n N) (x : Inputs p n (Messenger q)) := - fun i => specify p (parcel b i) (v (parcel b i)) m o (t i) (s i) (f i) (x i) -abbrev Amounts (p : Shape) (q : Format) (d : Rates) (b : Bool) := - ∀ i:Messenger q,Magazine p (d (parcel b i)) -def sendSum (u : Messenger q→F) (a : Amounts p q d true) (b : Amounts p q e false) : - ∀ i : Grid, Suite d e i := - fun i=> ∑ j:Fin (q i), (u ⟨i,j⟩,(a ⟨i,j⟩).2,(b ⟨i,j⟩).2) - -set_option maxHeartbeats 600000 in -theorem shooting_range (b : Bool) (v : Volley p n (Messenger q)) (x : Grid) - (h : v.obj = parcel b) : - v.shoots (parcel (!b)) (sendId b x) (sendId (!b) x) = - univ.image (fun i:Fin (q x)=> Sigma.mk x i) := by - classical - ext i; unfold Volley.shoots - rw [h]; rcases i with ⟨j,i⟩ - constructor - · intro hh - have he := (mem_filter.mp hh).2 - have ht : transit b j=transit b x := by - rw [←sendPair,←sendPair]; exact Prod.ext he.1 he.2 - have hh : j=x := by rw [←transit_inv b j,ht,transit_inv] - subst j; exact mem_image.mpr ⟨i,mem_univ _,rfl⟩ - intro h - obtain ⟨k,_,hh⟩:= mem_image.mp h - rw [← hh]; exact mem_filter.mpr ⟨mem_univ _,rfl,rfl⟩ - -variable {H : Type} [AddCommMonoid H] -theorem sum_shots (b : Bool) (v : Volley p n (Messenger q)) (x : Grid) - (h : v.obj=parcel b) (u : Messenger q→ H) : - (∑ j∈v.shoots (parcel (!b)) (sendId b x) (sendId (!b) x),u j) = - ∑ i:Fin (q x),u ⟨x,i⟩ := by - classical - rw [shooting_range b _ _ h,Finset.sum_image] - exact (fun x hx y hy e=> Sigma.mk.inj_iff.mp e |>.2 |> eq_of_heq) - -theorem shots_ok {q : Format} (b : Bool) (v : Volley p n (Messenger q)) - (h : v.obj=parcel b) (hh : ∀ i,1≤q i∧q i≤7) : - v.bounded (parcel (!b)) := by - intro x y - let i:= transit b (x,y) - have he : sendId b i=x := congrArg Prod.fst ((sendPair b i).trans (transit_inv b _)) - have hg : sendId (!b) i=y := congrArg Prod.snd ((sendPair b i).trans (transit_inv b _)) - have ht : (v.shoots (parcel (!b)) x y).card = q i := by - rw [←he,←hg,shooting_range b v i h, card_image_of_injective,card_univ,Fintype.card_fin] - exact fun i j he=> Sigma.mk.inj_iff.mp he |>.2 |> eq_of_heq - change 1≤_∧_≤7; rw [ht] - exact hh i -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FourEdgeFamilies +import OAI.Combinatorics.HadwigerCounterexample.PredictionExactification + +namespace OAI + +/-! # Status Charts -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Function Module LinearMap Submodule +open scoped BigOperators + +namespace StatusAnalysis +abbrev Ax (p : Shape) (n : ℕ) (d : ℕ) := Cell d→ₗ[F] Profile p n +abbrev Charts (p : Shape) (n : ℕ) (d : Rates) := ∀ i, Ax p n (d i) +variable {p : Shape} {n N : ℕ} {d e : Rates} +def charted (v : Charts p n d) (w : Plan p n) := + ∀ i,LinearMap.range (v i)=effective w i ∧ Injective (v i) + +theorem chart_create (p : Shape) (n : ℕ) (w : Plan p n) : + let d:= fun i:Nodes=> dim (effective w i) + ∃ v : Charts p n d,charted v w := by + classical + intro d + have hh (i) : + ∃ f : Ax p n (d i),LinearMap.range f=effective w i ∧ Injective f := by + let S:= effective w i + let E : Cell (d i)≃ₗ[F] S := LinearEquiv.ofFinrankEq _ _ + (by change dim (Cell (d i))=d i; rw [dim_vec,Fintype.card_fin]) + refine ⟨S.subtype ∘ₗ E.toLinearMap,?_,Subtype.val_injective.comp E.injective⟩ + rw [LinearMap.range_comp,LinearMap.range_eq_top.mpr E.surjective,← LinearMap.range_eq_map, + Submodule.range_subtype S] + choose f h using hh + exact ⟨f,h⟩ + +abbrev Format := Grid→ℕ +abbrev Messenger (q : Format) := Σ i:Grid,Fin (q i) +def sendId (b : Bool) (i : Grid) := if b then i.1 else i.2 +def transit (b : Bool) (q : Grid) := if b then q else (q.2,q.1) +theorem sendPair (b : Bool) (x : Grid) : + (sendId b x,sendId (!b) x)=transit b x := by cases b <;> rfl +theorem transit_inv (b : Bool) (x : Grid) : transit b (transit b x)=x := by cases b <;> rfl + +def parcel (b : Bool) {q : Format} (x : Messenger q) := sendId b x.1 +def manager {q : Format} (b : Bool) (t : Tagging p (Messenger q)) (s : Messenger q→Label p.b) + (f : Messenger q→Flavor p.g) : Template p (Messenger q) := ⟨parcel b,t,s,f⟩ + +def roll {u : ℕ} (f : Ax p n u) (g : Pdual p n) : Cell u := fun i=>g (f (Pi.single i 1)) + +theorem roll_project {u : ℕ} (f : Ax p n u) (g : Pdual p n) (z : Cell u) : + g (f z)=dotProduct (roll f g) z := by + let h:=g ∘ₗ f + obtain ⟨x,hx⟩:=dotL_surj h + have hi (i:Fin u) : + roll f g i=x i := by + change h (Pi.single i 1)=_ + rw [hx]; change dotProduct x (Pi.single i 1)=x i + simp + rw [show roll f g=x from funext hi] + exact LinearMap.congr_fun hx z + +def targetMark (p : Shape) (v : Charts p n d) (M : Cross p n) (i j : Nodes) : Cell (d i) := + roll (v i) (contract p M i j + role p n) +def hailing (p : Shape) (v : Charts p n d) (z : Charts p n e) (M : Cross p n) : + Cabinet d e := + fun i => (1,1,targetMark p v M i.1 i.2,targetMark p z (reciprocal p M) i.2 i.1) + +abbrev Magazine (p : Shape) (d : ℕ) := Digest p.g × Whole d +def specify (p : Shape) {d : ℕ} (i : Nodes) (v : Ax p n d) + (m : Mixer p n) (o : UnitType p n N) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) + (x : Knobs p.g n) : Magazine p d := + let A:=useAtom p l s f x + (scan p l f x, (role p n A,roll v (Tsym m A)),innerP p o i A) + +variable {q : Format} + +def printed (b : Bool) (v : Charts p n d) (t : Tagging p (Messenger q)) + (s : Messenger q →Label p.b) (f : Messenger q → Flavor p.g) (m : Mixer p n) + (o : UnitType p n N) (x : Inputs p n (Messenger q)) := + fun i => specify p (parcel b i) (v (parcel b i)) m o (t i) (s i) (f i) (x i) +abbrev Amounts (p : Shape) (q : Format) (d : Rates) (b : Bool) := + ∀ i:Messenger q,Magazine p (d (parcel b i)) +def sendSum (u : Messenger q→F) (a : Amounts p q d true) (b : Amounts p q e false) : + ∀ i : Grid, Suite d e i := + fun i=> ∑ j:Fin (q i), (u ⟨i,j⟩,(a ⟨i,j⟩).2,(b ⟨i,j⟩).2) + +set_option maxHeartbeats 600000 in +theorem shooting_range (b : Bool) (v : Volley p n (Messenger q)) (x : Grid) + (h : v.obj = parcel b) : + v.shoots (parcel (!b)) (sendId b x) (sendId (!b) x) = + univ.image (fun i:Fin (q x)=> Sigma.mk x i) := by + classical + ext i; unfold Volley.shoots + rw [h]; rcases i with ⟨j,i⟩ + constructor + · intro hh + have he := (mem_filter.mp hh).2 + have ht : transit b j=transit b x := by + rw [←sendPair,←sendPair]; exact Prod.ext he.1 he.2 + have hh : j=x := by rw [←transit_inv b j,ht,transit_inv] + subst j; exact mem_image.mpr ⟨i,mem_univ _,rfl⟩ + intro h + obtain ⟨k,_,hh⟩:= mem_image.mp h + rw [← hh]; exact mem_filter.mpr ⟨mem_univ _,rfl,rfl⟩ + +variable {H : Type} [AddCommMonoid H] +theorem sum_shots (b : Bool) (v : Volley p n (Messenger q)) (x : Grid) + (h : v.obj=parcel b) (u : Messenger q→ H) : + (∑ j∈v.shoots (parcel (!b)) (sendId b x) (sendId (!b) x),u j) = + ∑ i:Fin (q x),u ⟨x,i⟩ := by + classical + rw [shooting_range b _ _ h,Finset.sum_image] + exact (fun x hx y hy e=> Sigma.mk.inj_iff.mp e |>.2 |> eq_of_heq) + +theorem shots_ok {q : Format} (b : Bool) (v : Volley p n (Messenger q)) + (h : v.obj=parcel b) (hh : ∀ i,1≤q i∧q i≤7) : + v.bounded (parcel (!b)) := by + intro x y + let i:= transit b (x,y) + have he : sendId b i=x := congrArg Prod.fst ((sendPair b i).trans (transit_inv b _)) + have hg : sendId (!b) i=y := congrArg Prod.snd ((sendPair b i).trans (transit_inv b _)) + have ht : (v.shoots (parcel (!b)) x y).card = q i := by + rw [←he,←hg,shooting_range b v i h, card_image_of_injective,card_univ,Fintype.card_fin] + exact fun i j he=> Sigma.mk.inj_iff.mp he |>.2 |> eq_of_heq + change 1≤_∧_≤7; rw [ht] + exact hh i +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/StatusRecipes.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/StatusRecipes.lean index 8e7dfb50c33e15d1f3229f9d3c92e4408a4d1d8b..0388bafd8974e44ba1d5738bf144fa4bf5852703 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/StatusRecipes.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/StatusRecipes.lean @@ -1,102 +1,102 @@ -import OAI.Combinatorics.HadwigerCounterexample.ExplicitStatusEquations - -namespace OAI - -/-! # Status Recipes -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Function LinearMap Module Submodule -open scoped BigOperators -namespace StatusAnalysis -variable {p : Shape} {n N : ℕ} {q : Format} {d e : Rates} -def registers {i : ℕ} (p : Shape) (j : Nodes) (v : Ax p n i) (m : Mixer p n) - (x : UnitType p n N) : Profile p n→ₗ[F] Whole i where - toFun z := ((role p n z,roll v (Tsym m z)),innerP p x j z) - map_add' a b := by - rw [map_add,map_add,map_add]; congr 1 - map_smul' a b := by - rw [map_smul,map_smul,map_smul]; congr 1 -def unionAt {p : Shape} {q : Format} (f : Messenger q → Profile p n) (i : Grid) := - ∑ j:Fin (q i), f ⟨i,j⟩ - -theorem funds_reg (t : Tagging p (Messenger q)) (b : Bool) (v : Charts p n d) - (m : Mixer p n) (o : UnitType p n N) (l f x) (a : Amounts p q d b) - (h : printed b v t l f m o x=a) (i : Grid) : - let j := sendId b i - let w := (manager b t l f).draw x - funds a i = registers p j (v j) m o (unionAt (w.atomAt t) i) := by - rw [←h]; intro j w - unfold funds unionAt - rw [map_sum] - rfl - -theorem sumAtSend (b : Bool) (w : Volley p n (Messenger q)) (t : Tagging p (Messenger q)) - (i : Grid) (h : w.obj=parcel b) : - w.sumAt t (parcel (!b)) (sendId b i) (sendId (!b) i)=unionAt (w.atomAt t) i := - sum_shots b w _ h _ - -def owing (p : Shape) {q : Format} {d : Rates} - (b : Bool) (a : Amounts p q d b) (u : Messenger q→ F) := - ∀ i,(a i).1.sumBit=u i - -set_option maxHeartbeats 800000 in -theorem still_recipe (t : Tagging p (Messenger q)) (b : Bool) (S : Plan p n) - (M : Cross p n) (v : Charts p n d) (ha : charted v S) - (m : Mixer p n) (o : UnitType p n N) (l f x) (a : Amounts p q d b) - (h : printed b v t l f m o x=a) - (w : Volley p n (Messenger q)) (hw : w.obj=parcel (!b)) - (z : Messenger q→F) (hz : owing p b a z) (hq : ∀ i,fullq z i=1) - (hh : still b a v M) : - let u:=(manager b t l f).draw x - u.scalarRecipe w t m o S M := by - classical - intro u - have hi := funds_reg t b v m o l f x a h - have ho : u.obj=parcel b := rfl - have he (i j) (t : Grid) (h : t=transit b (i,j)) : sendId b t=i ∧ sendId (!b) t=j := by - have hh := (sendPair b t).trans (show transit b t=(i,j) by rw [h,transit_inv]) - exact ⟨congrArg Prod.fst hh,congrArg Prod.snd hh⟩ - have ht (i j) : u.sumAt t w.obj i j=unionAt (u.atomAt t) (transit b (i,j)) := by - obtain ⟨h1,h2⟩ := he i j _ rfl - rw [hw,←sumAtSend b u t _ ho,h1,h2] - have hd i j : - ((innerP p o i)+role p n) (u.sumAt t w.obj i j)= - couple _ (funds a (transit b (i,j))) := by - rw [ht,hi] - let W:= unionAt (u.atomAt t) (transit b (i,j)) - change innerP p o i W+role p n W=role p n W+innerP p o (sendId b _) W - rw [(he _ _ _ rfl).1,add_comm] - constructor - · have hu (i) : u.diagonalAt i=z i := - (etaScan p (t i) (l i) (f i) (x i)).symm.trans (by - rw [← h] at hz; exact hz i) - intro i j - obtain ⟨h1,h2⟩:= he i j _ rfl - let T:= transit b (i,j) - simp_rw [hu] - have hm:=sum_shots b u (transit b (i,j)) ho z - rw [h1,h2,←hw] at hm; exact hm.trans (hq T) - · intro j; rw [hd,hd, hh.2] - intro i j z hz - let Z := transit b (i,j) - obtain ⟨h1,h2⟩ : sendId b Z=i ∧ sendId (!b) Z=j := he _ _ _ rfl - let t':=sendId b Z - obtain ⟨y,hy⟩ : z ∈ LinearMap.range (v t') := by rw [(ha _).1]; rwa [show t'=i from h1] - have hg := hh.1 Z - rw [hi] at hg - let W:= unionAt (u.atomAt t) Z - have hh : Tsym m W z=contract p M i j z + role p n z := by - change roll (v t') (Tsym m W)=roll (v t') (contract p M t' (sendId (!b) Z) + _) at hg - have ht := congrArg (fun x=>dotProduct x y) hg - simp_rw [←roll_project,hy] at ht - change Tsym m W z=contract p M _ _ z+_ at ht - rwa [show t'=i from h1,h2] at ht - rw [ht,grad_val,hh,add_left_comm,char_two,add_zero] - -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ExplicitStatusEquations + +namespace OAI + +/-! # Status Recipes -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Function LinearMap Module Submodule +open scoped BigOperators +namespace StatusAnalysis +variable {p : Shape} {n N : ℕ} {q : Format} {d e : Rates} +def registers {i : ℕ} (p : Shape) (j : Nodes) (v : Ax p n i) (m : Mixer p n) + (x : UnitType p n N) : Profile p n→ₗ[F] Whole i where + toFun z := ((role p n z,roll v (Tsym m z)),innerP p x j z) + map_add' a b := by + rw [map_add,map_add,map_add]; congr 1 + map_smul' a b := by + rw [map_smul,map_smul,map_smul]; congr 1 +def unionAt {p : Shape} {q : Format} (f : Messenger q → Profile p n) (i : Grid) := + ∑ j:Fin (q i), f ⟨i,j⟩ + +theorem funds_reg (t : Tagging p (Messenger q)) (b : Bool) (v : Charts p n d) + (m : Mixer p n) (o : UnitType p n N) (l f x) (a : Amounts p q d b) + (h : printed b v t l f m o x=a) (i : Grid) : + let j := sendId b i + let w := (manager b t l f).draw x + funds a i = registers p j (v j) m o (unionAt (w.atomAt t) i) := by + rw [←h]; intro j w + unfold funds unionAt + rw [map_sum] + rfl + +theorem sumAtSend (b : Bool) (w : Volley p n (Messenger q)) (t : Tagging p (Messenger q)) + (i : Grid) (h : w.obj=parcel b) : + w.sumAt t (parcel (!b)) (sendId b i) (sendId (!b) i)=unionAt (w.atomAt t) i := + sum_shots b w _ h _ + +def owing (p : Shape) {q : Format} {d : Rates} + (b : Bool) (a : Amounts p q d b) (u : Messenger q→ F) := + ∀ i,(a i).1.sumBit=u i + +set_option maxHeartbeats 800000 in +theorem still_recipe (t : Tagging p (Messenger q)) (b : Bool) (S : Plan p n) + (M : Cross p n) (v : Charts p n d) (ha : charted v S) + (m : Mixer p n) (o : UnitType p n N) (l f x) (a : Amounts p q d b) + (h : printed b v t l f m o x=a) + (w : Volley p n (Messenger q)) (hw : w.obj=parcel (!b)) + (z : Messenger q→F) (hz : owing p b a z) (hq : ∀ i,fullq z i=1) + (hh : still b a v M) : + let u:=(manager b t l f).draw x + u.scalarRecipe w t m o S M := by + classical + intro u + have hi := funds_reg t b v m o l f x a h + have ho : u.obj=parcel b := rfl + have he (i j) (t : Grid) (h : t=transit b (i,j)) : sendId b t=i ∧ sendId (!b) t=j := by + have hh := (sendPair b t).trans (show transit b t=(i,j) by rw [h,transit_inv]) + exact ⟨congrArg Prod.fst hh,congrArg Prod.snd hh⟩ + have ht (i j) : u.sumAt t w.obj i j=unionAt (u.atomAt t) (transit b (i,j)) := by + obtain ⟨h1,h2⟩ := he i j _ rfl + rw [hw,←sumAtSend b u t _ ho,h1,h2] + have hd i j : + ((innerP p o i)+role p n) (u.sumAt t w.obj i j)= + couple _ (funds a (transit b (i,j))) := by + rw [ht,hi] + let W:= unionAt (u.atomAt t) (transit b (i,j)) + change innerP p o i W+role p n W=role p n W+innerP p o (sendId b _) W + rw [(he _ _ _ rfl).1,add_comm] + constructor + · have hu (i) : u.diagonalAt i=z i := + (etaScan p (t i) (l i) (f i) (x i)).symm.trans (by + rw [← h] at hz; exact hz i) + intro i j + obtain ⟨h1,h2⟩:= he i j _ rfl + let T:= transit b (i,j) + simp_rw [hu] + have hm:=sum_shots b u (transit b (i,j)) ho z + rw [h1,h2,←hw] at hm; exact hm.trans (hq T) + · intro j; rw [hd,hd, hh.2] + intro i j z hz + let Z := transit b (i,j) + obtain ⟨h1,h2⟩ : sendId b Z=i ∧ sendId (!b) Z=j := he _ _ _ rfl + let t':=sendId b Z + obtain ⟨y,hy⟩ : z ∈ LinearMap.range (v t') := by rw [(ha _).1]; rwa [show t'=i from h1] + have hg := hh.1 Z + rw [hi] at hg + let W:= unionAt (u.atomAt t) Z + have hh : Tsym m W z=contract p M i j z + role p n z := by + change roll (v t') (Tsym m W)=roll (v t') (contract p M t' (sendId (!b) Z) + _) at hg + have ht := congrArg (fun x=>dotProduct x y) hg + simp_rw [←roll_project,hy] at ht + change Tsym m W z=contract p M _ _ z+_ at ht + rwa [show t'=i from h1,h2] at ht + rw [ht,grad_val,hh,add_left_comm,char_two,add_zero] + +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SumRankBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SumRankBounds.lean index a2e1e700cdf2e614ce53e37e9d47d345ce6ff1d6..c96ee0d84b626976142350f048b69998f14b4d3c 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SumRankBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SumRankBounds.lean @@ -1,136 +1,136 @@ -import OAI.Combinatorics.HadwigerCounterexample.GreedyExposures - -namespace OAI - -/-! # Sum Rank Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Finset -variable {A I : Type} [Fintype A] [Fintype I] [DecidableEq I] - -def draws (I : Type) [Fintype I] (w : Wgt A) : Wgt (I→A) := prodW (fun _ : I => w) - -theorem draws_law {w : Wgt A} (h : IsLaw w) : - IsLaw (draws I w) := prodW_law (fun _ => h) - -def refresh (J : Finset I) (x y : I → A) : I → A := - fun i => if i∈J then y i else x i - -theorem fresh_avg (w : Wgt A) (hw : IsLaw w) (J : Finset I) (f : Wgt (I→A)) : - avg (draws I w) f = - avg (draws I w) (fun x => avg (draws I w) (fun y => f (refresh J x y))) := by - classical - let P := draws I w - have hP : IsLaw P := draws_law hw - let E := fun x : (I→A)×(I→A) => (refresh J x.1 x.2, refresh J x.2 x.1) - have hE x : E (E x)=x := by - apply Prod.ext - · funext i; change refresh _ _ _ _=_; by_cases h : i∈J <;> simp [refresh,E,h] - · funext i; change refresh _ _ _ _=_; by_cases h : i∈J <;> simp [refresh,E,h] - let e : (I→A)×(I→A) ≃ _ := ⟨E,E,hE,hE⟩ - have he x : pairW P P (E x)=pairW P P x := by - unfold pairW P draws prodW - rw [←Finset.prod_mul_distrib,←Finset.prod_mul_distrib] - refine Finset.prod_congr rfl fun i _ => ?_ - dsimp only [E,refresh] - split <;> ring - have ht := avg_bij e (pairW P P) (fun x => f x.1) - change avg (fun x => pairW P P (E x)) (fun x => f (E x).1)=_ at ht - simp_rw [he] at ht - rw [pairW_avg,pairW_avg] at ht - simp_rw [hP.avg_const] at ht - exact ht.symm - -private theorem draws_all (w : Wgt A) (hw : IsLaw w) (J : Finset I) (p : A → Prop) : - pr (draws I w) (fun x => ∀ i∈J,p (x i)) = pr w p ^ J.card := by - let v : Wgt (I→A) := prodW (fun _ => w) - have hh : pr v (fun x => ∀ i∈J,p (x i)) = - ∏ i:I, pr w (fun x => i∈J → p x) := prodW_pr (fun _ : I => w) (fun i x => i∈J → p x) - have ht (i : I) : - pr w (fun x => i∈J → p x)=if i∈J then pr w p else 1 := by - by_cases hi : i∈J <;> simp [hi,hw.total] - change pr v _=_ - rw [hh] - simp_rw [ht] - rw [← Finset.prod_filter] - simp - -variable {p : Shape} {N : ℕ} - -omit [Fintype A] [Fintype I] in -private theorem arrange_fresh (f : A→Ambient p N) (E J : Finset I) - (h : Disjoint E J) (x y : I → A) : - arrange p (f ∘ refresh J x y) E=arrange p (f ∘ x) E := by - classical - unfold arrange - apply Finset.sup_congr rfl - intro i hi - have he : i∉J := Finset.disjoint_left.mp h hi - simp [Function.comp_def,refresh,he] - -/-- With s=2^m*(2b), not requiring s itself to be a power -of two. -/ -theorem no_cover_rank (p : Shape) {N} (f : A→ Ambient p N) (w : Wgt A) - (hw : IsLaw w) (m b r : ℕ) (hb : 1 ≤ b) (hr : 16*r covered p S (f i)) ≤ c) : - let s := 2^m*(2*b) - pr (draws (Fin s) w) (fun x => 2*epoch p (∑ i,f (x i)) ≤ b) ≤ - ((2:ℝ)^s*(2:ℝ)^s)*c^b := by - classical - let s := 2^m*(2*b) - let T := draws (Fin s) w - have ht : IsLaw T := draws_law hw - let Q (X : Finset (Fin s) × Finset (Fin s)) (x : Fin s→A) := - Disjoint X.1 X.2 ∧ X.2.card=b ∧ ∀ i∈X.2, covered p (arrange p (f ∘ x) X.1) (f (x i)) - have hg (x : Fin s → A) (h : 2*epoch p (∑ i,f (x i)) ≤ b) : - ∃ X,Q X x := by - obtain ⟨E,J,_,_,hi,hj,hX⟩ := sparse_covered (p:=p) (f ∘ x) Finset.univ m b r - (by simp [s]) hb hr (fun i _ => hf _) h - exact ⟨(E,J),hi,hj,hX⟩ - have hq (X : Finset (Fin s) × Finset (Fin s)) : pr T (Q X) ≤ c^b := by - rcases X with ⟨E,J⟩ - by_cases h : Disjoint E J ∧ J.card=b - · let P (x : Fin s→A) := fun i => covered p (arrange p (f ∘ x) E) (f i) - have hp (x : Fin s→A) : pr w (P x) ≤ c := by - apply he; intro i - have hh := arrange_bound (p:=p) (f ∘ x) E r (fun _ _ => hf _) i - have hi : E.card ≤ s := by simpa using card_le_card (Finset.subset_univ E) - exact hh.trans ((Nat.mul_le_mul_right _ hi).trans_eq (Nat.mul_comm ..)) - unfold pr T - rw [fresh_avg w hw J] - refine ht.avg_le fun x => ?_ - have hx (y) : - Q (E,J) (refresh J x y) ↔ ∀ i∈J,P x (y i) := by - simp only [Q, h.1,h.2,true_and, arrange_fresh f E J h.1] - constructor - · intro hh i hi - specialize hh i hi - rwa [refresh,ite_eq_left hi] at hh - intro hh i hi - rw [refresh,ite_eq_left hi]; exact hh i hi - simp_rw [hx] - change pr T _ ≤ _ - rw [show pr T _ = pr w (P x)^J.card from draws_all w hw J _,h.2] - gcongr - · exact pr_nonneg hw.nz - · exact hp x - · have heq : Q (E,J) = fun _ => False := by - funext x - apply propext - exact iff_false_intro (fun he => h ⟨he.1,he.2.1⟩) - rw [heq,pr_false]; exact pow_nonneg hc _ - change pr T _ ≤ _ - refine ((pr_mono ht.nz hg).trans (pr_exists_le ht.nz Q)).trans ?_ - refine (Finset.sum_le_sum (g:=fun _ => c^b) fun i _ => hq i).trans_eq ?_ - simp [s] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.GreedyExposures + +namespace OAI + +/-! # Sum Rank Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Finset +variable {A I : Type} [Fintype A] [Fintype I] [DecidableEq I] + +def draws (I : Type) [Fintype I] (w : Wgt A) : Wgt (I→A) := prodW (fun _ : I => w) + +theorem draws_law {w : Wgt A} (h : IsLaw w) : + IsLaw (draws I w) := prodW_law (fun _ => h) + +def refresh (J : Finset I) (x y : I → A) : I → A := + fun i => if i∈J then y i else x i + +theorem fresh_avg (w : Wgt A) (hw : IsLaw w) (J : Finset I) (f : Wgt (I→A)) : + avg (draws I w) f = + avg (draws I w) (fun x => avg (draws I w) (fun y => f (refresh J x y))) := by + classical + let P := draws I w + have hP : IsLaw P := draws_law hw + let E := fun x : (I→A)×(I→A) => (refresh J x.1 x.2, refresh J x.2 x.1) + have hE x : E (E x)=x := by + apply Prod.ext + · funext i; change refresh _ _ _ _=_; by_cases h : i∈J <;> simp [refresh,E,h] + · funext i; change refresh _ _ _ _=_; by_cases h : i∈J <;> simp [refresh,E,h] + let e : (I→A)×(I→A) ≃ _ := ⟨E,E,hE,hE⟩ + have he x : pairW P P (E x)=pairW P P x := by + unfold pairW P draws prodW + rw [←Finset.prod_mul_distrib,←Finset.prod_mul_distrib] + refine Finset.prod_congr rfl fun i _ => ?_ + dsimp only [E,refresh] + split <;> ring + have ht := avg_bij e (pairW P P) (fun x => f x.1) + change avg (fun x => pairW P P (E x)) (fun x => f (E x).1)=_ at ht + simp_rw [he] at ht + rw [pairW_avg,pairW_avg] at ht + simp_rw [hP.avg_const] at ht + exact ht.symm + +private theorem draws_all (w : Wgt A) (hw : IsLaw w) (J : Finset I) (p : A → Prop) : + pr (draws I w) (fun x => ∀ i∈J,p (x i)) = pr w p ^ J.card := by + let v : Wgt (I→A) := prodW (fun _ => w) + have hh : pr v (fun x => ∀ i∈J,p (x i)) = + ∏ i:I, pr w (fun x => i∈J → p x) := prodW_pr (fun _ : I => w) (fun i x => i∈J → p x) + have ht (i : I) : + pr w (fun x => i∈J → p x)=if i∈J then pr w p else 1 := by + by_cases hi : i∈J <;> simp [hi,hw.total] + change pr v _=_ + rw [hh] + simp_rw [ht] + rw [← Finset.prod_filter] + simp + +variable {p : Shape} {N : ℕ} + +omit [Fintype A] [Fintype I] in +private theorem arrange_fresh (f : A→Ambient p N) (E J : Finset I) + (h : Disjoint E J) (x y : I → A) : + arrange p (f ∘ refresh J x y) E=arrange p (f ∘ x) E := by + classical + unfold arrange + apply Finset.sup_congr rfl + intro i hi + have he : i∉J := Finset.disjoint_left.mp h hi + simp [Function.comp_def,refresh,he] + +/-- With s=2^m*(2b), not requiring s itself to be a power +of two. -/ +theorem no_cover_rank (p : Shape) {N} (f : A→ Ambient p N) (w : Wgt A) + (hw : IsLaw w) (m b r : ℕ) (hb : 1 ≤ b) (hr : 16*r covered p S (f i)) ≤ c) : + let s := 2^m*(2*b) + pr (draws (Fin s) w) (fun x => 2*epoch p (∑ i,f (x i)) ≤ b) ≤ + ((2:ℝ)^s*(2:ℝ)^s)*c^b := by + classical + let s := 2^m*(2*b) + let T := draws (Fin s) w + have ht : IsLaw T := draws_law hw + let Q (X : Finset (Fin s) × Finset (Fin s)) (x : Fin s→A) := + Disjoint X.1 X.2 ∧ X.2.card=b ∧ ∀ i∈X.2, covered p (arrange p (f ∘ x) X.1) (f (x i)) + have hg (x : Fin s → A) (h : 2*epoch p (∑ i,f (x i)) ≤ b) : + ∃ X,Q X x := by + obtain ⟨E,J,_,_,hi,hj,hX⟩ := sparse_covered (p:=p) (f ∘ x) Finset.univ m b r + (by simp [s]) hb hr (fun i _ => hf _) h + exact ⟨(E,J),hi,hj,hX⟩ + have hq (X : Finset (Fin s) × Finset (Fin s)) : pr T (Q X) ≤ c^b := by + rcases X with ⟨E,J⟩ + by_cases h : Disjoint E J ∧ J.card=b + · let P (x : Fin s→A) := fun i => covered p (arrange p (f ∘ x) E) (f i) + have hp (x : Fin s→A) : pr w (P x) ≤ c := by + apply he; intro i + have hh := arrange_bound (p:=p) (f ∘ x) E r (fun _ _ => hf _) i + have hi : E.card ≤ s := by simpa using card_le_card (Finset.subset_univ E) + exact hh.trans ((Nat.mul_le_mul_right _ hi).trans_eq (Nat.mul_comm ..)) + unfold pr T + rw [fresh_avg w hw J] + refine ht.avg_le fun x => ?_ + have hx (y) : + Q (E,J) (refresh J x y) ↔ ∀ i∈J,P x (y i) := by + simp only [Q, h.1,h.2,true_and, arrange_fresh f E J h.1] + constructor + · intro hh i hi + specialize hh i hi + rwa [refresh,ite_eq_left hi] at hh + intro hh i hi + rw [refresh,ite_eq_left hi]; exact hh i hi + simp_rw [hx] + change pr T _ ≤ _ + rw [show pr T _ = pr w (P x)^J.card from draws_all w hw J _,h.2] + gcongr + · exact pr_nonneg hw.nz + · exact hp x + · have heq : Q (E,J) = fun _ => False := by + funext x + apply propext + exact iff_false_intro (fun he => h ⟨he.1,he.2.1⟩) + rw [heq,pr_false]; exact pow_nonneg hc _ + change pr T _ ≤ _ + refine ((pr_mono ht.nz hg).trans (pr_exists_le ht.nz Q)).trans ?_ + refine (Finset.sum_le_sum (g:=fun _ => c^b) fun i _ => hq i).trans_eq ?_ + simp [s] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SuperlevelBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SuperlevelBounds.lean index 2d85524c0df8d012dbc40b34cd30baa595e1b356..f614de27ab4eebe1df22b543a120a394c03eeecf 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SuperlevelBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SuperlevelBounds.lean @@ -1,99 +1,99 @@ -import OAI.Combinatorics.HadwigerCounterexample.LargeSetHits - -namespace OAI - -/-! # Superlevel Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix -open scoped BigOperators Topology -variable {A : Type} [Fintype A] - -def cliff (u f : Wgt A) (t:ℝ) (x : A) := 2*t*u x ≤ f x - -set_option maxHeartbeats 800000 in -theorem cliff_bounds (u f p : Wgt A) (t ε : ℝ) (ht : 0¬cliff u f t x)≤ 2*t+ε ∧ - pr u (fun x=> cliff u f t x ∧ p x < t*u x)≤ ε/t := by - classical - let W:=cliff u f t - let Q x:=¬ W x - let L x:=W x ∧ p x < t*u x - constructor - · have hi : pr f Q≤2*t := by - have hv i : f i * ind (Q i) ≤ u i*(2*t) := by - by_cases h:Q i - · rw [ind_one h,mul_one,mul_comm]; exact le_of_not_ge h - rw [ind_zero h,mul_zero]; exact mul_nonneg (hu.nz _) (by linarith) - exact (Finset.sum_le_sum (s:=univ) fun i _=>hv i).trans_eq (hu.avg_const _) - have hh: pr p Q-pr f Q ≤ ε:= (var_pr p f Q).trans h - linarith only [hh,hi] - · refine (le_div_iff₀ ht).mpr ((le_trans ?_ h)) - change pr u L*_ ≤_ - unfold pr avg varOne; rw [Finset.sum_mul] - apply Finset.sum_le_sum - intro i _ - dsimp only - by_cases he:L i - · rw [ind_one he,mul_one] - have hh : 2*t*u i≤ f i := he.1 - have hv := he.2 - linarith [(abs_sub_comm (f i) (p i)),le_abs_self (f i-p i)] - rw [ind_zero he,mul_zero,zero_mul]; exact abs_nonneg _ - -theorem cliff_thick (P: Wgt A→Prop) (x f u:Wgt A) - (hu:IsLaw u) (hp:P x) (t δ:ℝ) - (ht:0 W x ∧ ¬Q x - have he : pr x Q≤ K := h2 x h1 _ (cliff_bounds u f y t ε ht hu hf).2 - have hA : K≤ pr x F := by - have hf i (hi: W i): Q i∨ F i := by unfold F; tauto - have ha: pr x W≤pr x Q+pr x F:= (pr_mono hx.nz hf).trans (pr_or_le hx.nz) - linarith only [ha,h,he] - refine le_trans (mul_le_mul_of_nonneg_left hA ht.le) ?_ - unfold overlap pr avg; rw [Finset.mul_sum] - refine Finset.sum_le_sum fun i _=>?_ - dsimp only - have h i : 0≤density u x i*density u y i := mul_nonneg (div_nonneg (hx.nz _) (hu.nz _)) - (div_nonneg (hy.nz _) (hu.nz _)) - by_cases ha:x i=0 - · rw [ha,zero_mul,mul_zero] - exact mul_nonneg (hu.nz _) (h i) - by_cases hg:F i - · rw [ind_one hg,mul_one] - have hb:=lt_of_le_of_ne (hu.nz i) (Ne.symm (hz i ha)) - have hv : t ≤ density u y i := (le_div_iff₀ hb).mpr - (le_of_not_gt (fun h=>hg.2 ⟨hg.1,h⟩)) - calc - t*x i ≤ density u y i*x i :=mul_le_mul_of_nonneg_right hv (hx.nz _) - _ = _ := by unfold density; field_simp - rw [ind_zero hg,mul_zero,mul_zero] - exact mul_nonneg (hu.nz _) (h i) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.LargeSetHits + +namespace OAI + +/-! # Superlevel Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix +open scoped BigOperators Topology +variable {A : Type} [Fintype A] + +def cliff (u f : Wgt A) (t:ℝ) (x : A) := 2*t*u x ≤ f x + +set_option maxHeartbeats 800000 in +theorem cliff_bounds (u f p : Wgt A) (t ε : ℝ) (ht : 0¬cliff u f t x)≤ 2*t+ε ∧ + pr u (fun x=> cliff u f t x ∧ p x < t*u x)≤ ε/t := by + classical + let W:=cliff u f t + let Q x:=¬ W x + let L x:=W x ∧ p x < t*u x + constructor + · have hi : pr f Q≤2*t := by + have hv i : f i * ind (Q i) ≤ u i*(2*t) := by + by_cases h:Q i + · rw [ind_one h,mul_one,mul_comm]; exact le_of_not_ge h + rw [ind_zero h,mul_zero]; exact mul_nonneg (hu.nz _) (by linarith) + exact (Finset.sum_le_sum (s:=univ) fun i _=>hv i).trans_eq (hu.avg_const _) + have hh: pr p Q-pr f Q ≤ ε:= (var_pr p f Q).trans h + linarith only [hh,hi] + · refine (le_div_iff₀ ht).mpr ((le_trans ?_ h)) + change pr u L*_ ≤_ + unfold pr avg varOne; rw [Finset.sum_mul] + apply Finset.sum_le_sum + intro i _ + dsimp only + by_cases he:L i + · rw [ind_one he,mul_one] + have hh : 2*t*u i≤ f i := he.1 + have hv := he.2 + linarith [(abs_sub_comm (f i) (p i)),le_abs_self (f i-p i)] + rw [ind_zero he,mul_zero,zero_mul]; exact abs_nonneg _ + +theorem cliff_thick (P: Wgt A→Prop) (x f u:Wgt A) + (hu:IsLaw u) (hp:P x) (t δ:ℝ) + (ht:0 W x ∧ ¬Q x + have he : pr x Q≤ K := h2 x h1 _ (cliff_bounds u f y t ε ht hu hf).2 + have hA : K≤ pr x F := by + have hf i (hi: W i): Q i∨ F i := by unfold F; tauto + have ha: pr x W≤pr x Q+pr x F:= (pr_mono hx.nz hf).trans (pr_or_le hx.nz) + linarith only [ha,h,he] + refine le_trans (mul_le_mul_of_nonneg_left hA ht.le) ?_ + unfold overlap pr avg; rw [Finset.mul_sum] + refine Finset.sum_le_sum fun i _=>?_ + dsimp only + have h i : 0≤density u x i*density u y i := mul_nonneg (div_nonneg (hx.nz _) (hu.nz _)) + (div_nonneg (hy.nz _) (hu.nz _)) + by_cases ha:x i=0 + · rw [ha,zero_mul,mul_zero] + exact mul_nonneg (hu.nz _) (h i) + by_cases hg:F i + · rw [ind_one hg,mul_one] + have hb:=lt_of_le_of_ne (hu.nz i) (Ne.symm (hz i ha)) + have hv : t ≤ density u y i := (le_div_iff₀ hb).mpr + (le_of_not_gt (fun h=>hg.2 ⟨hg.1,h⟩)) + calc + t*x i ≤ density u y i*x i :=mul_le_mul_of_nonneg_right hv (hx.nz _) + _ = _ := by unfold density; field_simp + rw [ind_zero hg,mul_zero,mul_zero] + exact mul_nonneg (hu.nz _) (h i) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SupportedPhaseLaws.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SupportedPhaseLaws.lean index 6631241c526df8b810444b6b5f85b1851fcff37c..c81d375d460de89f7295b4d33d47e32973077ccd 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SupportedPhaseLaws.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SupportedPhaseLaws.lean @@ -1,167 +1,167 @@ -import OAI.Combinatorics.HadwigerCounterexample.FrameIntersectionCosts -import OAI.Combinatorics.HadwigerCounterexample.CellPruning - -namespace OAI - -/-! # Supported Phase Laws -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Function Finset -open scoped BigOperators -variable {p : Shape} {n N r : ℕ} {T : Cov p N} - -/-- Tables already fixed on population. bag M is total for convenience -but hypotheses on positive mass only apply on the indicated chart. -/ -structure Bazaar (p : Shape) {N} (n r : ℕ) (T : Cov p N) where - ix : UnitType p n N → Atlas p r T - bag : (M : Atlas p r T) → Bool → UnitType p n N → Batch M N - -namespace Bazaar - -variable (s : Bazaar p n r T) - -def opened (Δ : UnitType p n N → Ambient p N) (w : Wgt (UnitType p n N)) := - ∀ x,w x≠0 → standard (s.ix x) ∧ ∀ i,compFor (s.ix x) - (s.bag (s.ix x) i x) (imageP p x i) (Δ x) - -def chart (w : Wgt (UnitType p n N)) (M : Atlas p r T) := - subW w (fun x => s.ix x=M) - -theorem active {Δ : UnitType p n N→Ambient p N} {w} {M} - (h : s.opened Δ w) (x) (hx : s.chart w M x≠0) : - s.ix x=M ∧ standard M ∧ ∀ i,compFor M (s.bag M i x) (imageP p x i) (Δ x) := by - have h' : s.ix x=M := Classical.byContradiction fun he => hx (subW_carried w _ _ he) - refine ⟨h',?_⟩ - subst M; exact h x (left_ne_zero_of_mul hx) - -def pay (M G : Atlas p r T) (j : Bool) (S : Party) - (y : UnitType p n N) : Batch M N × Batch G N := - (thermal p y S (src M),s.bag G j y) - -end Bazaar - -def loseA (_ : Shape) (N x y : ℕ) := bp (-((x:ℝ)+y)*N+0.01*N) -def prize (_ : Shape) (N x : ℕ) := bp (- ((x:ℝ)+0.5)*N) -def beat (N : ℕ) := bp (-0.245*N) -def selPrice (p : Shape) (r n N : ℕ) (H ε : ℝ) := - ∀ x y : ℕ,x≤2*r → y≤2*r → H*heatRate p n N ε x y≤loseA p N x y - -namespace Bazaar -variable {s : Bazaar p n r T} - -theorem bag_rate (m : Mixer p n) {H : ℝ} (hH : 0≤H) - {w : Wgt (UnitType p n N)} {Δ} {ε : ℝ} (hm : IsLaw (raw m N)) (he : initCap p N m ε) - (hv : SubLaw w) (hw : bySide p w m H) - (hl : s.opened Δ w) (hp : selPrice p r n N H ε) - (M : Atlas p r T) (i : Bool) : - ∀ x, mapW (s.chart w M) (s.bag M i) x ≤ loseA p N (cells M) 0 := by - classical - intro x - let v := s.chart w M - have hV : SubLaw v := subLaw_sub hv _ - by_cases hx : standard M - · refine le_trans (pr_on_mono hV.nz (P:=fun y => s.bag M i y=x) - (Q:=fun y => basisFrom p y i x) (fun z hz hg => ?_)) ?_ - · subst x - exact ((active s hl z hz).2.2 i).1 - refine (pr_mono_left (subW_le hv.nz _) _).trans ?_ - exact (heat_none i x hH m hm he hw).trans (hp (cells M) 0 hx.2.1 (Nat.zero_le _)) - have h : v=(fun _ => 0) := - funext fun x => Classical.byContradiction fun h => hx (active s hl x h).2.1 - change mapW v _ _≤_ - rw [h] - simp only [mapW,pr,avg,zero_mul,Finset.sum_const_zero] - exact (bp_pos _).le - -theorem glimpse_prize (m : Mixer p n) {H : ℝ} (hH : 0≤H) - {w : Wgt (UnitType p n N)} {Δ} {ε : ℝ} - (hm : IsLaw (raw m N)) (he : initCap p N m ε) (hv : SubLaw w) - (hw : bySide p w m H) (h : s.opened Δ w) (hp : selPrice p r n N H ε) - (M G : Atlas p r T) (i : Bool) (hh : standard M) (hh' : standard G) - (P : UnitType p n N → Prop) - (hf : ∀ x, s.chart w G x≠0 → P x → glimpse p x i (src M)) : - ∀ x, mapW (subW (s.chart w G) P) (s.pay M G i (unary i)) x≤ prize p N (cells G) := by - classical - rintro ⟨x,y⟩ - let v := s.chart w G - have hv' : SubLaw v := subLaw_sub hv _ - change pr (subW v P) _ ≤ _ - rw [pr_sub] - refine (pr_on_mono hv'.nz (Q:=fun z => - basisFrom p z i y ∧ glimpse p z i (src M) ∧ thermal p z (unary i) (src M)=x) ?_).trans ?_ - · rintro z hz ⟨he,hx⟩ - have h1 : s.bag G i z=y := congrArg Prod.snd hx - exact ⟨h1 ▸ ((active s h z hz).2.2 i).1,hf z hz he,congrArg Prod.fst hx⟩ - refine (pr_mono_left (subW_le hv.nz _) _).trans ?_ - apply (heat_one i (src M) x y hH m hm he hw).trans - refine (hp (cells G) (cells M) hh'.2.1 hh.2.1).trans ?_ - unfold prize loseA - apply bp_le - have ht : (1:ℝ)≤cells M := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr hh.1 - rw [← add_mul]; apply mul_le_mul_of_nonneg_right _ (Nat.cast_nonneg _) - linarith - -end Bazaar - -variable {A B V : Type} [Fintype A] [Fintype B] [Fintype V] - -private theorem write_weight (g : Wgt A) (w : Wgt A) (hw : SubLaw w) (f : A→B) - (h : ∀ x, |g x|≤1) : - ∃ t : Wgt B, (∀ x,|t x|≤1) ∧ - ∀ s : Wgt B, avg w (fun x => g x*s (f x))=avg (mapW w f) (fun y => t y*s y) := by - classical - let V (y : B) := onW w (fun x => f x=y) - have hv (y) : SubLaw (V y) := normW_subLaw (subW_nonneg hw.nz _) - let T (y) := avg (V y) g - refine ⟨T,fun y => (abs_avg_le (hv y).nz).trans ((hv y).avg_le zero_le_one h),fun s => ?_⟩ - calc avg w (fun x => g x*s (f x)) - _ = avg (mixW (mapW w f) V) (fun x => g x*s (f x)) := - congrArg (avg · (fun x => g x*s (f x))) (disintegrate hw.nz f) - _ = _ := by - rw [mixW_avg]; refine avg_congr (fun x _ => ?_) - calc _ = avg (V x) (fun y => g y*s x) := avg_congr (fun y hy => by - have h : f y=x := Classical.byContradiction fun h => hy - (normW_carried (subW_carried w (fun v => f v=x)) y h) - rw [h]) - _ = _ := avg_mul .. - -theorem mapW_sub (f : A→B) {w : Wgt A} (hw : SubLaw w) : SubLaw (mapW w f) := by - refine ⟨fun _ => pr_nonneg hw.nz,?_⟩ - have he := mapW_avg w f (fun _ => 1) - rw [avg_const,avg_const,mul_one,mul_one] at he - rw [he]; exact hw.total - -variable [AddCommGroup V] [Module F V] - -/-- Walsh bound on pushforward tuples with arbitrary separate -query weights. -/ -theorem walsh_weighted (b : V →ₗ[F] V →ₗ[F] F) (hb : Function.Injective b) - (w : Wgt A) (v : Wgt B) (hw : SubLaw w) (hv : SubLaw v) - (f : A→V) (g : B→V) (S : Wgt A) (T : Wgt B) {p q : ℝ} - (hs : ∀ x,|S x|≤1) (ht : ∀ x, |T x| ≤1) - (hp : ∀ x, mapW w f x ≤ p) (hq : ∀ x,mapW v g x ≤ q) : - (avg (pairW w v) (fun x => S x.1*T x.2 * wsign (b (f x.1) (g x.2))))^2 ≤ num V*p*q := by - obtain ⟨Y,hY,hA⟩ := write_weight S w hw f hs - obtain ⟨X,hX,hB⟩ := write_weight T v hv g ht - have he : - avg (pairW w v) (fun x => S x.1*T x.2*wsign (b (f x.1) (g x.2)))= - avg (mapW v g) (fun y => X y* avg (mapW w f) (fun x => - Y x*wsign (b x y))) := by - rw [pairW_avg,avg_avg] - have he y : - avg w (fun x => S x*T y* wsign (b (f x) (g y))) = - T y * avg (mapW w f) (fun x => Y x*wsign (b x (g y))) := by - have hh := hA (fun v => wsign (b v (g y))) - simp_rw [mul_comm (S _) (T y),mul_assoc,avg_mul'] - rw [hh] - simp_rw [he] - exact hB (fun y => avg _ (fun x => Y x*wsign (b x y))) - rw [he] - exact walsh_mass b hb (mapW w f) (mapW v g) Y X hY hX (mapW_sub f hw) (mapW_sub g hv) hp hq - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FrameIntersectionCosts +import OAI.Combinatorics.HadwigerCounterexample.CellPruning + +namespace OAI + +/-! # Supported Phase Laws -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Function Finset +open scoped BigOperators +variable {p : Shape} {n N r : ℕ} {T : Cov p N} + +/-- Tables already fixed on population. bag M is total for convenience +but hypotheses on positive mass only apply on the indicated chart. -/ +structure Bazaar (p : Shape) {N} (n r : ℕ) (T : Cov p N) where + ix : UnitType p n N → Atlas p r T + bag : (M : Atlas p r T) → Bool → UnitType p n N → Batch M N + +namespace Bazaar + +variable (s : Bazaar p n r T) + +def opened (Δ : UnitType p n N → Ambient p N) (w : Wgt (UnitType p n N)) := + ∀ x,w x≠0 → standard (s.ix x) ∧ ∀ i,compFor (s.ix x) + (s.bag (s.ix x) i x) (imageP p x i) (Δ x) + +def chart (w : Wgt (UnitType p n N)) (M : Atlas p r T) := + subW w (fun x => s.ix x=M) + +theorem active {Δ : UnitType p n N→Ambient p N} {w} {M} + (h : s.opened Δ w) (x) (hx : s.chart w M x≠0) : + s.ix x=M ∧ standard M ∧ ∀ i,compFor M (s.bag M i x) (imageP p x i) (Δ x) := by + have h' : s.ix x=M := Classical.byContradiction fun he => hx (subW_carried w _ _ he) + refine ⟨h',?_⟩ + subst M; exact h x (left_ne_zero_of_mul hx) + +def pay (M G : Atlas p r T) (j : Bool) (S : Party) + (y : UnitType p n N) : Batch M N × Batch G N := + (thermal p y S (src M),s.bag G j y) + +end Bazaar + +def loseA (_ : Shape) (N x y : ℕ) := bp (-((x:ℝ)+y)*N+0.01*N) +def prize (_ : Shape) (N x : ℕ) := bp (- ((x:ℝ)+0.5)*N) +def beat (N : ℕ) := bp (-0.245*N) +def selPrice (p : Shape) (r n N : ℕ) (H ε : ℝ) := + ∀ x y : ℕ,x≤2*r → y≤2*r → H*heatRate p n N ε x y≤loseA p N x y + +namespace Bazaar +variable {s : Bazaar p n r T} + +theorem bag_rate (m : Mixer p n) {H : ℝ} (hH : 0≤H) + {w : Wgt (UnitType p n N)} {Δ} {ε : ℝ} (hm : IsLaw (raw m N)) (he : initCap p N m ε) + (hv : SubLaw w) (hw : bySide p w m H) + (hl : s.opened Δ w) (hp : selPrice p r n N H ε) + (M : Atlas p r T) (i : Bool) : + ∀ x, mapW (s.chart w M) (s.bag M i) x ≤ loseA p N (cells M) 0 := by + classical + intro x + let v := s.chart w M + have hV : SubLaw v := subLaw_sub hv _ + by_cases hx : standard M + · refine le_trans (pr_on_mono hV.nz (P:=fun y => s.bag M i y=x) + (Q:=fun y => basisFrom p y i x) (fun z hz hg => ?_)) ?_ + · subst x + exact ((active s hl z hz).2.2 i).1 + refine (pr_mono_left (subW_le hv.nz _) _).trans ?_ + exact (heat_none i x hH m hm he hw).trans (hp (cells M) 0 hx.2.1 (Nat.zero_le _)) + have h : v=(fun _ => 0) := + funext fun x => Classical.byContradiction fun h => hx (active s hl x h).2.1 + change mapW v _ _≤_ + rw [h] + simp only [mapW,pr,avg,zero_mul,Finset.sum_const_zero] + exact (bp_pos _).le + +theorem glimpse_prize (m : Mixer p n) {H : ℝ} (hH : 0≤H) + {w : Wgt (UnitType p n N)} {Δ} {ε : ℝ} + (hm : IsLaw (raw m N)) (he : initCap p N m ε) (hv : SubLaw w) + (hw : bySide p w m H) (h : s.opened Δ w) (hp : selPrice p r n N H ε) + (M G : Atlas p r T) (i : Bool) (hh : standard M) (hh' : standard G) + (P : UnitType p n N → Prop) + (hf : ∀ x, s.chart w G x≠0 → P x → glimpse p x i (src M)) : + ∀ x, mapW (subW (s.chart w G) P) (s.pay M G i (unary i)) x≤ prize p N (cells G) := by + classical + rintro ⟨x,y⟩ + let v := s.chart w G + have hv' : SubLaw v := subLaw_sub hv _ + change pr (subW v P) _ ≤ _ + rw [pr_sub] + refine (pr_on_mono hv'.nz (Q:=fun z => + basisFrom p z i y ∧ glimpse p z i (src M) ∧ thermal p z (unary i) (src M)=x) ?_).trans ?_ + · rintro z hz ⟨he,hx⟩ + have h1 : s.bag G i z=y := congrArg Prod.snd hx + exact ⟨h1 ▸ ((active s h z hz).2.2 i).1,hf z hz he,congrArg Prod.fst hx⟩ + refine (pr_mono_left (subW_le hv.nz _) _).trans ?_ + apply (heat_one i (src M) x y hH m hm he hw).trans + refine (hp (cells G) (cells M) hh'.2.1 hh.2.1).trans ?_ + unfold prize loseA + apply bp_le + have ht : (1:ℝ)≤cells M := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr hh.1 + rw [← add_mul]; apply mul_le_mul_of_nonneg_right _ (Nat.cast_nonneg _) + linarith + +end Bazaar + +variable {A B V : Type} [Fintype A] [Fintype B] [Fintype V] + +private theorem write_weight (g : Wgt A) (w : Wgt A) (hw : SubLaw w) (f : A→B) + (h : ∀ x, |g x|≤1) : + ∃ t : Wgt B, (∀ x,|t x|≤1) ∧ + ∀ s : Wgt B, avg w (fun x => g x*s (f x))=avg (mapW w f) (fun y => t y*s y) := by + classical + let V (y : B) := onW w (fun x => f x=y) + have hv (y) : SubLaw (V y) := normW_subLaw (subW_nonneg hw.nz _) + let T (y) := avg (V y) g + refine ⟨T,fun y => (abs_avg_le (hv y).nz).trans ((hv y).avg_le zero_le_one h),fun s => ?_⟩ + calc avg w (fun x => g x*s (f x)) + _ = avg (mixW (mapW w f) V) (fun x => g x*s (f x)) := + congrArg (avg · (fun x => g x*s (f x))) (disintegrate hw.nz f) + _ = _ := by + rw [mixW_avg]; refine avg_congr (fun x _ => ?_) + calc _ = avg (V x) (fun y => g y*s x) := avg_congr (fun y hy => by + have h : f y=x := Classical.byContradiction fun h => hy + (normW_carried (subW_carried w (fun v => f v=x)) y h) + rw [h]) + _ = _ := avg_mul .. + +theorem mapW_sub (f : A→B) {w : Wgt A} (hw : SubLaw w) : SubLaw (mapW w f) := by + refine ⟨fun _ => pr_nonneg hw.nz,?_⟩ + have he := mapW_avg w f (fun _ => 1) + rw [avg_const,avg_const,mul_one,mul_one] at he + rw [he]; exact hw.total + +variable [AddCommGroup V] [Module F V] + +/-- Walsh bound on pushforward tuples with arbitrary separate +query weights. -/ +theorem walsh_weighted (b : V →ₗ[F] V →ₗ[F] F) (hb : Function.Injective b) + (w : Wgt A) (v : Wgt B) (hw : SubLaw w) (hv : SubLaw v) + (f : A→V) (g : B→V) (S : Wgt A) (T : Wgt B) {p q : ℝ} + (hs : ∀ x,|S x|≤1) (ht : ∀ x, |T x| ≤1) + (hp : ∀ x, mapW w f x ≤ p) (hq : ∀ x,mapW v g x ≤ q) : + (avg (pairW w v) (fun x => S x.1*T x.2 * wsign (b (f x.1) (g x.2))))^2 ≤ num V*p*q := by + obtain ⟨Y,hY,hA⟩ := write_weight S w hw f hs + obtain ⟨X,hX,hB⟩ := write_weight T v hv g ht + have he : + avg (pairW w v) (fun x => S x.1*T x.2*wsign (b (f x.1) (g x.2)))= + avg (mapW v g) (fun y => X y* avg (mapW w f) (fun x => + Y x*wsign (b x y))) := by + rw [pairW_avg,avg_avg] + have he y : + avg w (fun x => S x*T y* wsign (b (f x) (g y))) = + T y * avg (mapW w f) (fun x => Y x*wsign (b x (g y))) := by + have hh := hA (fun v => wsign (b v (g y))) + simp_rw [mul_comm (S _) (T y),mul_assoc,avg_mul'] + rw [hh] + simp_rw [he] + exact hB (fun y => avg _ (fun x => Y x*wsign (b x y))) + rw [he] + exact walsh_mass b hb (mapW w f) (mapW v g) Y X hY hX (mapW_sub f hw) (mapW_sub g hv) hp hq + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateAggregation.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateAggregation.lean index 772a195e51731ec21c2f4562aa1634953b10d741..9ff80787c725c8c45018a70f04e94fdbcd73a724 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateAggregation.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateAggregation.lean @@ -1,134 +1,134 @@ -import OAI.Combinatorics.HadwigerCounterexample.UniformSideComparisons -import OAI.Combinatorics.HadwigerCounterexample.ProjectedSurrogates - -namespace OAI - -/-! # Surrogate Aggregation -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module LinearMap Filter Function -open scoped BigOperators Topology -open Template -namespace StatusAnalysis -variable {p : Shape} {n N K M r : ℕ} -variable {q:Format} {d e : Rates} {b:Bool} - -namespace Quill -variable (w:Quill p q d b) (t: Tagging p (Messenger q)) - (z : Messenger q→F) (μ:Wgt (UnitType p n N)) (P:UnitType p n N→Prop) - (m:Mixer p n) (s:Charts p n d) (Y: Silhouette p N r) -def showcase := fun x=> avg μ (fun i=> ind (P i)*w.mirror t z i m s Y x) - -theorem bower_case (hw:IsLaw μ) (h:∀ i,IsLaw (w.policies t z n i)) : - bower (w.showcase t z μ P m s Y) := by - let f i := w.mirror t z i m s Y - have he i x := mirror_floor w t z i m s Y h x - constructor - · intro i; exact avg_nonneg hw.nz fun j=>mul_nonneg (ind_nonneg _) (he j i).1 - intro i; exact hw.avg_le fun j=>(mul_le_mul (ind_le_one (P j)) (he j i).2 (he j i).1 - zero_le_one).trans_eq (one_mul _) -def displayMass := fun x=>lawNu p N t z x*w.showcase t z μ P m s Y x - -theorem display_mean (W : Wgt (Keys (p:=p) t N)) : - avg (w.displayMass t z μ P m s Y) W=avg μ (fun o=>ind (P o)*w.sheen t z o m s Y W) := by - unfold sheen displayMass showcase - simp only [avg,mul_assoc] - simp only [Finset.sum_mul, Finset.mul_sum] - rw [Finset.sum_comm] - exact Finset.sum_congr rfl fun i _=>Finset.sum_congr rfl fun j _ => by ring - -set_option maxHeartbeats 900000 in -theorem display_test (H : Keys (p:=p) t N→ Prop) - (hw:IsLaw μ) (h:∀ i,IsLaw (w.policies t z n i)) (hn:IsLaw (lawNu p N t z)) - (Z : UnitType p n N→Prop) - {ε : ℝ} (he:0≤ε) - (hg : ∀ x,P x → |w.prowl s t z m x (fun x=>ind (H x))-w.sheen t z x m s Y - (fun x=>ind (H x))| > ε → Z x) : - |pr (w.displayMass t z μ P m s Y) H- pr (w.sales t z μ P m s) H| ≤ ε+2*pr μ Z := by - classical - let W := fun x=>ind (H x) - let f x:=w.prowl s t z m x W; let g x:=w.sheen t z x m s Y W - have heq x : - |ind (P x)*g x-ind (P x)*f x|≤ ε+ 2*ind (Z x) := by - rw [←mul_sub,abs_mul,abs_of_nonneg (ind_nonneg _)] - have hh (x): |ind (Z x)|≤1:=by rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ - by_cases hP:P x - · rw [ind_one hP,one_mul] - by_cases h0 : Z x - · have hh (x'): |W x'|≤1 := by unfold W; rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ - have h1 : |f x|≤1 := by - let F:=w.pen t - have hv : IsLaw (F.state z n):=prodW_law h - unfold f prowl; refine (abs_avg_le hv.nz).trans (hv.avg_le fun j=>?_) - rw [abs_mul,abs_of_nonneg (ind_nonneg _)] - exact (mul_le_mul (ind_le_one _) (hh _) (abs_nonneg _) zero_le_one).trans_eq (one_mul _) - have h2 : |g x|≤1 := by - unfold g sheen; refine (abs_avg_le hn.nz).trans (hn.avg_le fun j=>?_) - have hm:=mirror_floor w t z x m s Y h j - rw [abs_mul,abs_of_nonneg hm.1] - exact (mul_le_mul hm.2 (hh _) (abs_nonneg _) zero_le_one).trans_eq (one_mul _) - rw [ind_one h0] - have hi := abs_sub (g x) (f x) - linarith only [hi,h1,h2,he] - rw [ind_zero h0,abs_sub_comm,mul_zero,add_zero] - exact le_of_not_gt (fun h=> h0 (hg x hP h)) - rw [ind_zero hP,zero_mul] - exact add_nonneg he (mul_nonneg (by norm_num) (ind_nonneg _)) - unfold pr; rw [sales_mean,display_mean,← avg_sub] - exact (abs_avg_le hw.nz).trans ((avg_mono hw.nz heq).trans_eq (by rw [avg_add, - avg_mul',hw.avg_const])) - -end Quill - -namespace Typus -variable (w: Typus p q d e) (o o' : UnitType p n N) (s:Charts p n d) (t:Charts p n e) - (m : Mixer p n) (Y:Silhouette p N r) - -/-- Per-position beta status overlap at fixed orientation pair. -/ -def chimera (i:Messenger q) := - let l:=w.t i; let z:=w.z i - let f:=w.qA.seraph w.t w.z o m s Y i; let g:=w.qB.seraph w.t w.z o' m t Y i - dip (lawOmega p N l z) f g -def momus := (w.qA.pen w.t).kappa*(w.qB.pen w.t).kappa -def constellation := w.momus*(∏ i:Messenger q, w.chimera o o' s t m Y i) - -set_option maxHeartbeats 900000 in -theorem shine_match (ha:∀ i,IsLaw (w.qA.policies w.t w.z n i)) - (hb:∀ i,IsLaw (w.qB.policies w.t w.z n i)) - (hN: 2*num ((Messenger q)×Toast p)-(N:ℝ)≤ -1) : - let L:=w.qA.mirror w.t w.z o m s Y - let R:=w.qB.mirror w.t w.z o' m t Y - |w.constellation o o' s t m Y - dip (lawNu p N w.t w.z) L R| ≤ - 2*netFact (trayPort p w.t) * bp (-(N:ℝ)/2) := by - classical - intro L R - let μ:= lawNu p N w.t w.z - let Z:=w.momus - let A:=w.qA.seraph w.t w.z o m s Y; let B:=w.qB.seraph w.t w.z o' m t Y - let C (i:Messenger q):=fun z=> A i z*B i z - have hh : dip μ L R=Z*avg μ (prodW C) := by - unfold dip; rw [←avg_mul']; refine avg_congr fun i hi=>?_ - unfold L R Z Quill.mirror momus prodW C - rw [Finset.prod_mul_distrib]; unfold A B; ring - have hC (i: Messenger q) (j): |C i j|≤1 := by - have hm:= w.qA.seraphFloor w.t w.z o m s Y i (ha i) j - have hn:= w.qB.seraphFloor w.t w.z o' m t Y i (hb i) j - unfold C A B; rw [abs_mul,abs_of_nonneg hm.1,abs_of_nonneg hn.1] - exact (mul_le_mul hm.2 hn.2 hn.1 zero_le_one).trans_eq (one_mul _) - have hf := reference_product w.t w.z C hC hN - change |Z*_ - dip μ L R|≤ _ - rw [hh,abs_sub_comm,←mul_sub,abs_mul] - have hZ : |Z|≤1:= by - unfold Z momus - rw [abs_mul,abs_of_pos (kappa_pos _),abs_of_pos (kappa_pos _)] - exact (mul_le_mul (w.qA.kappaTop _) (w.qB.kappaTop _) (kappa_pos _).le zero_le_one).trans_eq - (one_mul _) - exact (mul_le_mul hZ hf (abs_nonneg _) zero_le_one).trans_eq (one_mul _) -end Typus -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.UniformSideComparisons +import OAI.Combinatorics.HadwigerCounterexample.ProjectedSurrogates + +namespace OAI + +/-! # Surrogate Aggregation -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module LinearMap Filter Function +open scoped BigOperators Topology +open Template +namespace StatusAnalysis +variable {p : Shape} {n N K M r : ℕ} +variable {q:Format} {d e : Rates} {b:Bool} + +namespace Quill +variable (w:Quill p q d b) (t: Tagging p (Messenger q)) + (z : Messenger q→F) (μ:Wgt (UnitType p n N)) (P:UnitType p n N→Prop) + (m:Mixer p n) (s:Charts p n d) (Y: Silhouette p N r) +def showcase := fun x=> avg μ (fun i=> ind (P i)*w.mirror t z i m s Y x) + +theorem bower_case (hw:IsLaw μ) (h:∀ i,IsLaw (w.policies t z n i)) : + bower (w.showcase t z μ P m s Y) := by + let f i := w.mirror t z i m s Y + have he i x := mirror_floor w t z i m s Y h x + constructor + · intro i; exact avg_nonneg hw.nz fun j=>mul_nonneg (ind_nonneg _) (he j i).1 + intro i; exact hw.avg_le fun j=>(mul_le_mul (ind_le_one (P j)) (he j i).2 (he j i).1 + zero_le_one).trans_eq (one_mul _) +def displayMass := fun x=>lawNu p N t z x*w.showcase t z μ P m s Y x + +theorem display_mean (W : Wgt (Keys (p:=p) t N)) : + avg (w.displayMass t z μ P m s Y) W=avg μ (fun o=>ind (P o)*w.sheen t z o m s Y W) := by + unfold sheen displayMass showcase + simp only [avg,mul_assoc] + simp only [Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + exact Finset.sum_congr rfl fun i _=>Finset.sum_congr rfl fun j _ => by ring + +set_option maxHeartbeats 900000 in +theorem display_test (H : Keys (p:=p) t N→ Prop) + (hw:IsLaw μ) (h:∀ i,IsLaw (w.policies t z n i)) (hn:IsLaw (lawNu p N t z)) + (Z : UnitType p n N→Prop) + {ε : ℝ} (he:0≤ε) + (hg : ∀ x,P x → |w.prowl s t z m x (fun x=>ind (H x))-w.sheen t z x m s Y + (fun x=>ind (H x))| > ε → Z x) : + |pr (w.displayMass t z μ P m s Y) H- pr (w.sales t z μ P m s) H| ≤ ε+2*pr μ Z := by + classical + let W := fun x=>ind (H x) + let f x:=w.prowl s t z m x W; let g x:=w.sheen t z x m s Y W + have heq x : + |ind (P x)*g x-ind (P x)*f x|≤ ε+ 2*ind (Z x) := by + rw [←mul_sub,abs_mul,abs_of_nonneg (ind_nonneg _)] + have hh (x): |ind (Z x)|≤1:=by rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ + by_cases hP:P x + · rw [ind_one hP,one_mul] + by_cases h0 : Z x + · have hh (x'): |W x'|≤1 := by unfold W; rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ + have h1 : |f x|≤1 := by + let F:=w.pen t + have hv : IsLaw (F.state z n):=prodW_law h + unfold f prowl; refine (abs_avg_le hv.nz).trans (hv.avg_le fun j=>?_) + rw [abs_mul,abs_of_nonneg (ind_nonneg _)] + exact (mul_le_mul (ind_le_one _) (hh _) (abs_nonneg _) zero_le_one).trans_eq (one_mul _) + have h2 : |g x|≤1 := by + unfold g sheen; refine (abs_avg_le hn.nz).trans (hn.avg_le fun j=>?_) + have hm:=mirror_floor w t z x m s Y h j + rw [abs_mul,abs_of_nonneg hm.1] + exact (mul_le_mul hm.2 (hh _) (abs_nonneg _) zero_le_one).trans_eq (one_mul _) + rw [ind_one h0] + have hi := abs_sub (g x) (f x) + linarith only [hi,h1,h2,he] + rw [ind_zero h0,abs_sub_comm,mul_zero,add_zero] + exact le_of_not_gt (fun h=> h0 (hg x hP h)) + rw [ind_zero hP,zero_mul] + exact add_nonneg he (mul_nonneg (by norm_num) (ind_nonneg _)) + unfold pr; rw [sales_mean,display_mean,← avg_sub] + exact (abs_avg_le hw.nz).trans ((avg_mono hw.nz heq).trans_eq (by rw [avg_add, + avg_mul',hw.avg_const])) + +end Quill + +namespace Typus +variable (w: Typus p q d e) (o o' : UnitType p n N) (s:Charts p n d) (t:Charts p n e) + (m : Mixer p n) (Y:Silhouette p N r) + +/-- Per-position beta status overlap at fixed orientation pair. -/ +def chimera (i:Messenger q) := + let l:=w.t i; let z:=w.z i + let f:=w.qA.seraph w.t w.z o m s Y i; let g:=w.qB.seraph w.t w.z o' m t Y i + dip (lawOmega p N l z) f g +def momus := (w.qA.pen w.t).kappa*(w.qB.pen w.t).kappa +def constellation := w.momus*(∏ i:Messenger q, w.chimera o o' s t m Y i) + +set_option maxHeartbeats 900000 in +theorem shine_match (ha:∀ i,IsLaw (w.qA.policies w.t w.z n i)) + (hb:∀ i,IsLaw (w.qB.policies w.t w.z n i)) + (hN: 2*num ((Messenger q)×Toast p)-(N:ℝ)≤ -1) : + let L:=w.qA.mirror w.t w.z o m s Y + let R:=w.qB.mirror w.t w.z o' m t Y + |w.constellation o o' s t m Y - dip (lawNu p N w.t w.z) L R| ≤ + 2*netFact (trayPort p w.t) * bp (-(N:ℝ)/2) := by + classical + intro L R + let μ:= lawNu p N w.t w.z + let Z:=w.momus + let A:=w.qA.seraph w.t w.z o m s Y; let B:=w.qB.seraph w.t w.z o' m t Y + let C (i:Messenger q):=fun z=> A i z*B i z + have hh : dip μ L R=Z*avg μ (prodW C) := by + unfold dip; rw [←avg_mul']; refine avg_congr fun i hi=>?_ + unfold L R Z Quill.mirror momus prodW C + rw [Finset.prod_mul_distrib]; unfold A B; ring + have hC (i: Messenger q) (j): |C i j|≤1 := by + have hm:= w.qA.seraphFloor w.t w.z o m s Y i (ha i) j + have hn:= w.qB.seraphFloor w.t w.z o' m t Y i (hb i) j + unfold C A B; rw [abs_mul,abs_of_nonneg hm.1,abs_of_nonneg hn.1] + exact (mul_le_mul hm.2 hn.2 hn.1 zero_le_one).trans_eq (one_mul _) + have hf := reference_product w.t w.z C hC hN + change |Z*_ - dip μ L R|≤ _ + rw [hh,abs_sub_comm,←mul_sub,abs_mul] + have hZ : |Z|≤1:= by + unfold Z momus + rw [abs_mul,abs_of_pos (kappa_pos _),abs_of_pos (kappa_pos _)] + exact (mul_le_mul (w.qA.kappaTop _) (w.qB.kappaTop _) (kappa_pos _).le zero_le_one).trans_eq + (one_mul _) + exact (mul_le_mul hZ hf (abs_nonneg _) zero_le_one).trans_eq (one_mul _) +end Typus +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateProductBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateProductBounds.lean index f0898ebd1c543d7dae53eacea8ef09c08235ef7c..dd57c8435f5ab0d9335c187d43140ac37908f5c1 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateProductBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateProductBounds.lean @@ -1,162 +1,162 @@ -import OAI.Combinatorics.HadwigerCounterexample.SurrogateQueryScores - -namespace OAI - -/-! # Surrogate Product Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix Function -open scoped BigOperators Topology -variable {p:Shape} {n N K r:ℕ} {A:Type} [Fintype A] -open Template -namespace StatusAnalysis - -omit [Fintype A] in -theorem cottonError (s : Finset A) (p q : Wgt A) (ε:ℝ) - (hp : ∀ x,|p x|≤1) (hq : ∀ x,|q x|≤1) - (hh : ∀ x,|p x-q x|≤ε) : - |(∏ x∈s,p x) - (∏ x∈s,q x)|≤s.card*ε := by - classical - have ht (s : Finset A) : |∏ i∈s, q i| ≤1 := by - rw [Finset.abs_prod] - refine (Finset.prod_le_prod₀ (g:=fun _=>1) (fun i _=>abs_nonneg _) (fun i _=>hq i)).trans_eq (by simp) - induction s using Finset.induction_on with - | empty => simp - | insert x s h ih => - let Q:= ∏ i∈s,q i - let P:= ∏ i∈s,p i - rw [Finset.prod_insert h,Finset.prod_insert h,Finset.card_insert_of_notMem h] - have he : p x*P-q x*Q=p x*(P-Q)+(p x-q x)*Q:=by ring - push_cast; rw [he] - have hf : |p x*(P-Q)|≤ (s.card:ℝ)*ε := by rw [abs_mul]; exact - (mul_le_mul (hp _) ih (abs_nonneg _) zero_le_one).trans_eq (one_mul _) - have hg : |(p x-q x)*Q|≤ ε := by - rw [abs_mul] - exact (mul_le_mul (hh x) (ht s) (abs_nonneg Q) ((abs_nonneg _).trans (hh x))).trans_eq (mul_one _) - refine ((abs_add_le _ _).trans (add_le_add hf hg)).trans_eq (by ring) - -def pigments {q : Template p A} (z : A→F) (Y : Silhouette p N r) (F : Paint q N) := - ∀ i:A, ∃ H : Fin r → Prop,∀ x,F.flies i x ↔ H (Y (q.t i) (z i) x) - -namespace Quill -variable {q : Format} {d : Rates} {b : Bool} (w : Quill p q d b) - (t : Tagging p (Messenger q)) (z : Messenger q→F) - (o : UnitType p n N) (m:Mixer p n) - -def suede (s:Charts p n d) (f : Paint (w.pen t) N) (i : Messenger q) (x : Knobs p.g n) := - w.stencil t z o s m i x* - ind (f.flies i ((w.allure t z i).face (onSide o (parcel b i)) x)) - -def insidePaint (s : Charts p n d) (Y:Silhouette p N r) (f : Paint (w.pen t) N) - (i : Messenger q) : Wgt (AtomKey (p:=p) (t i) N) := - fun x=> ind (f.flies i x) * seraph w t z o m s Y i x - -theorem suedeFloor (s f i x) : - |w.suede t z o m s f i x| ≤ 1 := by - unfold suede - rw [abs_mul,abs_of_nonneg (ind_nonneg _)] - exact (mul_le_mul (w.stencil_floor t z o s m i x) (ind_le_one _) (ind_nonneg _) zero_le_one).trans_eq - (one_mul _) - -theorem paintFloor (s Y) (f:Paint (w.pen t) N) (i x) - (hw : IsLaw (w.policies t z n i)) : - |insidePaint w t z o m s (r:=r) Y f i x|≤1 := by - unfold insidePaint; have hh:= w.seraphFloor t z o m s Y i hw x - rw [abs_mul,abs_of_nonneg (ind_nonneg _),abs_of_nonneg hh.1] - exact (mul_le_mul (ind_le_one _) hh.2 hh.1 zero_le_one).trans_eq (one_mul _) - -set_option maxHeartbeats 700000 in -theorem surrogate_close (s :Charts p n d) (Y:Silhouette p N r) (f: Paint (w.pen t) N) - (hf : pigments z Y f) (i:Messenger q) (hw:IsLaw (w.policies t z n i)) - {ε:ℝ} (h : (w.allure t z i).close Y (onSide o (parcel b i)) ε) : - |avg (lawOmega p N (t i) (z i)) (w.insidePaint t z o m s Y f i)- - avg (w.policies t z n i) (w.suede t z o m s f i)|≤ε := by - classical - let l:=w.allure t z i; let I:=parcel b i - obtain ⟨H,hf⟩:=hf i - let u (x : Fin r) (a:Magazine p (d I)) := ind (H x)*ind (a=w.amp i) - have hu x i : |u x i|≤1 := by unfold u; rw [←ind_and,abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ - have hh:= l.close_expect Y I o m (s I) hw u hu h - let Ω:= lawOmega p N l.l l.q - let E x:= avg (l.reflected Y I o m (s I) x) (u x) - have he : avg (l.reference Y) E=avg Ω (insidePaint w t z o m s Y f i) := by - unfold Appearance.reference - rw [mapW_avg]; refine avg_congr fun k _=>?_ - have hx : f.flies i k ↔ H (Y l.l l.q k) := hf k - let G:= l.reflected Y I o m (s I) (Y l.l l.q k) - change avg G _=ind (f.flies i k)* G (w.amp i) - rw [hx]; unfold u; rw [avg_mul']; change _*pr _ _=_; rw [pr_point'] - have hc (x:Knobs p.g n) : - u (l.showTag Y (onSide o I) x) (l.profile I o m (s I) x)=w.suede t z o m s f i x := by - let k : AtomKey (p:=p) ((w.pen t).t i) N := l.face (onSide o I) x - change ind (H (Y ((w.pen t).t i) (z i) k)) * - ind (l.profile I o m (s I) x=w.amp i) = - ind (l.profile I o m (s I) x=w.amp i) * ind (f.flies i k) - rw [hf]; exact mul_comm _ _ - change |avg (l.reference Y) E- _| ≤ _ at hh - rw [he] at hh; simp_rw [hc] at hh; exact hh - -set_option maxHeartbeats 800000 in -theorem score_sheen (s : Charts p n d) (Y:Silhouette p N r) - (f : Paint (w.pen t) N) : - w.sheen t z o m s Y f.cost= - f.coeff*((w.pen t).kappa * avg (lawNu p N t z) (prodW (w.insidePaint t z o m s Y f))) := by - classical - let cost : Wgt (Keys (p:=p) t N) := f.cost - let flies : ∀ i : Messenger q, AtomKey (p:=p) (t i) N → Prop := f.flies - change w.sheen t z o m s Y cost = _ - rw [sheen_sun] - let v:= w.pen t - let h x := prodW (w.insidePaint t z o m s Y f) x - let F := w.seraph t z o m s Y - have hf (x: Keys (p:=p) t N) : cost x * prodW F x = f.coeff*h x := by - change f.coeff * (∏ i : Messenger q, ind (flies i (x i))) * - (∏ i : Messenger q, F i (x i)) = - f.coeff * (∏ i : Messenger q, ind (flies i (x i)) * F i (x i)) - rw [Finset.prod_mul_distrib, mul_assoc] - change v.kappa * avg _ _=_ - let μ:=lawNu p N t z - calc - _ = v.kappa * (f.coeff * avg μ h) := congrArg (fun x=>v.kappa*x) ((avg_congr (w:=μ) - (fun i _=>hf i)).trans (avg_mul' ..)) - _ = _ := mul_left_comm _ _ _ - -set_option maxHeartbeats 800000 in -theorem score_prowl (s : Charts p n d) (f : Paint (w.pen t) N) - (hh : ∀ i,frameLaw m (onSide o i)) (hg : 2≤p.g) (hj : 1≤p.j) : - w.prowl s t z m o f.cost= - f.coeff*avg (prodW (w.policies t z n)) (fun x => ind ((w.pen t).performs w.script m o x)* - prodW (w.suede t z o m s f) x) := by - classical - let cost : Wgt (Keys (p:=p) t N) := f.cost - change w.prowl s t z m o cost = _ - rw [prowl_astonish] - let v:=w.pen t; let x:=w.policies t z n - let μ:=prodW x - let Q (y:Inputs p n (Messenger q)):= v.resultKey o y - have heq := astonish_val v z f.cost w.script m x (w.stencil t z o s m) o - change astonish v z f.cost w.script m x (w.stencil t z o s m) o=_ - rw [heq, ← avg_mul']; apply avg_congr - intro y hy - have he (i:Messenger q) : dialed p (v.t i) (v.f i) (y i)=z i := by - have hf i : x i (y i) ≠ 0 := (Finset.prod_ne_zero_iff.mp hy _ (mem_univ i)) - exact (onW_ne (hf i)).1 - let a:= w.stencil t z o s m - let W i:= ind (f.flies i ((w.allure t z i).face (onSide o (parcel b i)) (y i))) - have hq : f.cost (Q y)= f.coeff*(∏ i,W i) := rfl - change ind (v.earns w.script m z o y)* f.cost (Q y)*prodW a y=_ - have hs : (v.performs w.script m o y) ↔ v.earns w.script m z o y := - v.performs_own w.script m o y hh hg hj z he - have hx : prodW (w.suede t z o m s f) y=prodW a y* (∏ i,W i) := by - change (∏ i, a i (y i) * W i) = (∏ i, a i (y i)) * (∏ i,W i) - rw [Finset.prod_mul_distrib] - rw [hs,hq,hx]; ring - -end Quill -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SurrogateQueryScores + +namespace OAI + +/-! # Surrogate Product Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix Function +open scoped BigOperators Topology +variable {p:Shape} {n N K r:ℕ} {A:Type} [Fintype A] +open Template +namespace StatusAnalysis + +omit [Fintype A] in +theorem cottonError (s : Finset A) (p q : Wgt A) (ε:ℝ) + (hp : ∀ x,|p x|≤1) (hq : ∀ x,|q x|≤1) + (hh : ∀ x,|p x-q x|≤ε) : + |(∏ x∈s,p x) - (∏ x∈s,q x)|≤s.card*ε := by + classical + have ht (s : Finset A) : |∏ i∈s, q i| ≤1 := by + rw [Finset.abs_prod] + refine (Finset.prod_le_prod₀ (g:=fun _=>1) (fun i _=>abs_nonneg _) (fun i _=>hq i)).trans_eq (by simp) + induction s using Finset.induction_on with + | empty => simp + | insert x s h ih => + let Q:= ∏ i∈s,q i + let P:= ∏ i∈s,p i + rw [Finset.prod_insert h,Finset.prod_insert h,Finset.card_insert_of_notMem h] + have he : p x*P-q x*Q=p x*(P-Q)+(p x-q x)*Q:=by ring + push_cast; rw [he] + have hf : |p x*(P-Q)|≤ (s.card:ℝ)*ε := by rw [abs_mul]; exact + (mul_le_mul (hp _) ih (abs_nonneg _) zero_le_one).trans_eq (one_mul _) + have hg : |(p x-q x)*Q|≤ ε := by + rw [abs_mul] + exact (mul_le_mul (hh x) (ht s) (abs_nonneg Q) ((abs_nonneg _).trans (hh x))).trans_eq (mul_one _) + refine ((abs_add_le _ _).trans (add_le_add hf hg)).trans_eq (by ring) + +def pigments {q : Template p A} (z : A→F) (Y : Silhouette p N r) (F : Paint q N) := + ∀ i:A, ∃ H : Fin r → Prop,∀ x,F.flies i x ↔ H (Y (q.t i) (z i) x) + +namespace Quill +variable {q : Format} {d : Rates} {b : Bool} (w : Quill p q d b) + (t : Tagging p (Messenger q)) (z : Messenger q→F) + (o : UnitType p n N) (m:Mixer p n) + +def suede (s:Charts p n d) (f : Paint (w.pen t) N) (i : Messenger q) (x : Knobs p.g n) := + w.stencil t z o s m i x* + ind (f.flies i ((w.allure t z i).face (onSide o (parcel b i)) x)) + +def insidePaint (s : Charts p n d) (Y:Silhouette p N r) (f : Paint (w.pen t) N) + (i : Messenger q) : Wgt (AtomKey (p:=p) (t i) N) := + fun x=> ind (f.flies i x) * seraph w t z o m s Y i x + +theorem suedeFloor (s f i x) : + |w.suede t z o m s f i x| ≤ 1 := by + unfold suede + rw [abs_mul,abs_of_nonneg (ind_nonneg _)] + exact (mul_le_mul (w.stencil_floor t z o s m i x) (ind_le_one _) (ind_nonneg _) zero_le_one).trans_eq + (one_mul _) + +theorem paintFloor (s Y) (f:Paint (w.pen t) N) (i x) + (hw : IsLaw (w.policies t z n i)) : + |insidePaint w t z o m s (r:=r) Y f i x|≤1 := by + unfold insidePaint; have hh:= w.seraphFloor t z o m s Y i hw x + rw [abs_mul,abs_of_nonneg (ind_nonneg _),abs_of_nonneg hh.1] + exact (mul_le_mul (ind_le_one _) hh.2 hh.1 zero_le_one).trans_eq (one_mul _) + +set_option maxHeartbeats 700000 in +theorem surrogate_close (s :Charts p n d) (Y:Silhouette p N r) (f: Paint (w.pen t) N) + (hf : pigments z Y f) (i:Messenger q) (hw:IsLaw (w.policies t z n i)) + {ε:ℝ} (h : (w.allure t z i).close Y (onSide o (parcel b i)) ε) : + |avg (lawOmega p N (t i) (z i)) (w.insidePaint t z o m s Y f i)- + avg (w.policies t z n i) (w.suede t z o m s f i)|≤ε := by + classical + let l:=w.allure t z i; let I:=parcel b i + obtain ⟨H,hf⟩:=hf i + let u (x : Fin r) (a:Magazine p (d I)) := ind (H x)*ind (a=w.amp i) + have hu x i : |u x i|≤1 := by unfold u; rw [←ind_and,abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ + have hh:= l.close_expect Y I o m (s I) hw u hu h + let Ω:= lawOmega p N l.l l.q + let E x:= avg (l.reflected Y I o m (s I) x) (u x) + have he : avg (l.reference Y) E=avg Ω (insidePaint w t z o m s Y f i) := by + unfold Appearance.reference + rw [mapW_avg]; refine avg_congr fun k _=>?_ + have hx : f.flies i k ↔ H (Y l.l l.q k) := hf k + let G:= l.reflected Y I o m (s I) (Y l.l l.q k) + change avg G _=ind (f.flies i k)* G (w.amp i) + rw [hx]; unfold u; rw [avg_mul']; change _*pr _ _=_; rw [pr_point'] + have hc (x:Knobs p.g n) : + u (l.showTag Y (onSide o I) x) (l.profile I o m (s I) x)=w.suede t z o m s f i x := by + let k : AtomKey (p:=p) ((w.pen t).t i) N := l.face (onSide o I) x + change ind (H (Y ((w.pen t).t i) (z i) k)) * + ind (l.profile I o m (s I) x=w.amp i) = + ind (l.profile I o m (s I) x=w.amp i) * ind (f.flies i k) + rw [hf]; exact mul_comm _ _ + change |avg (l.reference Y) E- _| ≤ _ at hh + rw [he] at hh; simp_rw [hc] at hh; exact hh + +set_option maxHeartbeats 800000 in +theorem score_sheen (s : Charts p n d) (Y:Silhouette p N r) + (f : Paint (w.pen t) N) : + w.sheen t z o m s Y f.cost= + f.coeff*((w.pen t).kappa * avg (lawNu p N t z) (prodW (w.insidePaint t z o m s Y f))) := by + classical + let cost : Wgt (Keys (p:=p) t N) := f.cost + let flies : ∀ i : Messenger q, AtomKey (p:=p) (t i) N → Prop := f.flies + change w.sheen t z o m s Y cost = _ + rw [sheen_sun] + let v:= w.pen t + let h x := prodW (w.insidePaint t z o m s Y f) x + let F := w.seraph t z o m s Y + have hf (x: Keys (p:=p) t N) : cost x * prodW F x = f.coeff*h x := by + change f.coeff * (∏ i : Messenger q, ind (flies i (x i))) * + (∏ i : Messenger q, F i (x i)) = + f.coeff * (∏ i : Messenger q, ind (flies i (x i)) * F i (x i)) + rw [Finset.prod_mul_distrib, mul_assoc] + change v.kappa * avg _ _=_ + let μ:=lawNu p N t z + calc + _ = v.kappa * (f.coeff * avg μ h) := congrArg (fun x=>v.kappa*x) ((avg_congr (w:=μ) + (fun i _=>hf i)).trans (avg_mul' ..)) + _ = _ := mul_left_comm _ _ _ + +set_option maxHeartbeats 800000 in +theorem score_prowl (s : Charts p n d) (f : Paint (w.pen t) N) + (hh : ∀ i,frameLaw m (onSide o i)) (hg : 2≤p.g) (hj : 1≤p.j) : + w.prowl s t z m o f.cost= + f.coeff*avg (prodW (w.policies t z n)) (fun x => ind ((w.pen t).performs w.script m o x)* + prodW (w.suede t z o m s f) x) := by + classical + let cost : Wgt (Keys (p:=p) t N) := f.cost + change w.prowl s t z m o cost = _ + rw [prowl_astonish] + let v:=w.pen t; let x:=w.policies t z n + let μ:=prodW x + let Q (y:Inputs p n (Messenger q)):= v.resultKey o y + have heq := astonish_val v z f.cost w.script m x (w.stencil t z o s m) o + change astonish v z f.cost w.script m x (w.stencil t z o s m) o=_ + rw [heq, ← avg_mul']; apply avg_congr + intro y hy + have he (i:Messenger q) : dialed p (v.t i) (v.f i) (y i)=z i := by + have hf i : x i (y i) ≠ 0 := (Finset.prod_ne_zero_iff.mp hy _ (mem_univ i)) + exact (onW_ne (hf i)).1 + let a:= w.stencil t z o s m + let W i:= ind (f.flies i ((w.allure t z i).face (onSide o (parcel b i)) (y i))) + have hq : f.cost (Q y)= f.coeff*(∏ i,W i) := rfl + change ind (v.earns w.script m z o y)* f.cost (Q y)*prodW a y=_ + have hs : (v.performs w.script m o y) ↔ v.earns w.script m z o y := + v.performs_own w.script m o y hh hg hj z he + have hx : prodW (w.suede t z o m s f) y=prodW a y* (∏ i,W i) := by + change (∏ i, a i (y i) * W i) = (∏ i, a i (y i)) * (∏ i,W i) + rw [Finset.prod_mul_distrib] + rw [hs,hq,hx]; ring + +end Quill +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateQueryScores.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateQueryScores.lean index d2943977dc0862a2623f1dbc713645acf2cc1b57..07a89e4caf2b041de97df31c3846d46400db00dc 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateQueryScores.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateQueryScores.lean @@ -1,109 +1,109 @@ -import OAI.Combinatorics.HadwigerCounterexample.ConditionalSignaturePositivity -import OAI.Combinatorics.HadwigerCounterexample.WeakProductComparison -import OAI.Combinatorics.HadwigerCounterexample.BinaryMixingBounds - -namespace OAI - -/-! # Surrogate Query Scores -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix Function -open scoped BigOperators Topology -open Template -variable {p : Shape} {n N K M r : ℕ} -namespace StatusAnalysis -variable {q:Format} {d : Rates} {b:Bool} -namespace Quill - -variable (w : Quill p q d b) (t : Tagging p (Messenger q)) (z : Messenger q → F) - -def allure (i : Messenger q) : Appearance p := ⟨t i,w.sel i,w.flav i,z i⟩ -theorem allure_apt (h : w.moral t z) (i : Messenger q) : - (w.allure t z i).apt := canDraw t z h i - -def policies (n:ℕ) := fun i => (w.allure t z i).wit n -variable (o : UnitType p n N) -def stencil (s : Charts p n d) (m : Mixer p n) (i : Messenger q) (v : Knobs p.g n) := - let j:=parcel b i - ind ((w.allure t z i).profile j o m (s j) v=w.amp i) - -theorem stencil_floor (s : Charts p n d) (m : Mixer p n) (i v) : - |w.stencil t z o s m i v|≤1 := by - unfold stencil; dsimp only; rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ - -variable (m : Mixer p n) -def seraph (s : Charts p n d) (Y:Silhouette p N r) (i:Messenger q) : Wgt (AtomKey (p:=p) (t i) N) := - let j:=parcel b i - fun h=> (w.allure t z i).reflected Y j o m (s j) (Y (t i) (z i) h) (w.amp i) -def mirror (s : Charts p n d) (Y:Silhouette p N r) := fun x:Keys (p:=p) t N=> - (w.pen t).kappa*prodW (w.seraph t z o m s Y) x - -theorem seraphFloor (s : Charts p n d) (Y:Silhouette p N r) (i:Messenger q) - (hw : IsLaw (w.policies t z n i)) (x) : - 0≤ seraph w t z o m s Y i x ∧ seraph w t z o m s Y i x≤1 := - let h:= Appearance.reflectedLaw (w.allure t z i) Y hw (parcel b i) o m _ (Y _ (z i) x) - - ⟨h.nz _,(weight_le_tot h.nz _).trans h.total.le⟩ - -theorem kappaTop : (w.pen t).kappa ≤1 := by - unfold kappa wavelength - classical - have hh : IsLaw (prism (w.pen t).Abbey) := prodW_law (fun _ => unif_law) - exact (weight_le_tot hh.nz _).trans hh.total.le - -theorem mirror_floor (s : Charts p n d) (Y:Silhouette p N r) - (hw : ∀ i,IsLaw (w.policies t z n i)) - (x:Keys (p:=p) t N) : - 0≤ w.mirror t z o m s Y x ∧ w.mirror t z o m s Y x≤1 := by - let f:= w.seraph t z o m s Y - let v:= w.pen t - have hh i:= seraphFloor w t z o m s Y i (hw i) (x i) - have h0 : 0 ≤ prodW f x:= prodW_nonneg (fun i y=> (seraphFloor w t z o m s Y i (hw i) y).1) _ - have h1 : prodW f x≤1 := (Finset.prod_le_prod₀ (s:=Finset.univ) - (g:=fun i: Messenger q=> (1:ℝ)) (fun i _=> (hh i).1) (fun i _=> (hh i).2)).trans_eq - (by simp) - exact ⟨mul_nonneg v.kappa_pos.le h0,(mul_le_mul (kappaTop w t) h1 h0 zero_le_one).trans_eq - (one_mul _)⟩ - -def sheen (s : Charts p n d) (Y:Silhouette p N r) (W:Wgt (Keys (p:=p) t N)) := - avg (lawNu p N t z) (fun x=>w.mirror t z o m s Y x*W x) - -theorem painted (s : Charts p n d) - (x:Inputs p n (Messenger q)) : - prodW (w.stencil t z o s m) x= - ind (printed b s t w.sel w.flav m o x=w.amp) := by - classical - rw [funext_iff,ind_all]; rfl - -theorem prowl_astonish (s : Charts p n d) (W : Wgt (Keys (p:=p) t N)) : - w.prowl s t z m o W=astonish (w.pen t) z W w.script m (w.policies t z n) - (w.stencil t z o s m) o := by - classical - - let v:=w.pen t - have ht : astonish v z W w.script m (w.policies t z n) (w.stencil t z o s m) o= - avg (v.state z n) (fun x=> ind (earns v w.script m z o x)*W (v.resultKey o x)*prodW - (w.stencil t z o s m) x) := astonish_val v z _ _ m _ _ _ - rw [ht]; unfold prowl; apply avg_congr - intro i _ - rw [painted] - simp_rw [deposit, earns,ind_and] - let a:=ind (printed b s t w.sel w.flav m o i=w.amp); let b0:=ind ((v.draw i).reads w.script m) - let x:= v.resultKey o i; let c:= ind (ownPart v.t z x) - change a*(b0*c)*W x= (b0*c)*W x*a - ring - -theorem sheen_sun (s : Charts p n d) (Y:Silhouette p N r) (W:Wgt (Keys (p:=p) t N)) : - w.sheen t z o m s Y W= - (w.pen t).kappa * avg (lawNu p N t z) (fun x=>W x*prodW (w.seraph t z o m s Y) x) := by - unfold sheen mirror; rw [←avg_mul'] - apply avg_congr; intro i _; ring - -end Quill -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ConditionalSignaturePositivity +import OAI.Combinatorics.HadwigerCounterexample.WeakProductComparison +import OAI.Combinatorics.HadwigerCounterexample.BinaryMixingBounds + +namespace OAI + +/-! # Surrogate Query Scores -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix Function +open scoped BigOperators Topology +open Template +variable {p : Shape} {n N K M r : ℕ} +namespace StatusAnalysis +variable {q:Format} {d : Rates} {b:Bool} +namespace Quill + +variable (w : Quill p q d b) (t : Tagging p (Messenger q)) (z : Messenger q → F) + +def allure (i : Messenger q) : Appearance p := ⟨t i,w.sel i,w.flav i,z i⟩ +theorem allure_apt (h : w.moral t z) (i : Messenger q) : + (w.allure t z i).apt := canDraw t z h i + +def policies (n:ℕ) := fun i => (w.allure t z i).wit n +variable (o : UnitType p n N) +def stencil (s : Charts p n d) (m : Mixer p n) (i : Messenger q) (v : Knobs p.g n) := + let j:=parcel b i + ind ((w.allure t z i).profile j o m (s j) v=w.amp i) + +theorem stencil_floor (s : Charts p n d) (m : Mixer p n) (i v) : + |w.stencil t z o s m i v|≤1 := by + unfold stencil; dsimp only; rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _ + +variable (m : Mixer p n) +def seraph (s : Charts p n d) (Y:Silhouette p N r) (i:Messenger q) : Wgt (AtomKey (p:=p) (t i) N) := + let j:=parcel b i + fun h=> (w.allure t z i).reflected Y j o m (s j) (Y (t i) (z i) h) (w.amp i) +def mirror (s : Charts p n d) (Y:Silhouette p N r) := fun x:Keys (p:=p) t N=> + (w.pen t).kappa*prodW (w.seraph t z o m s Y) x + +theorem seraphFloor (s : Charts p n d) (Y:Silhouette p N r) (i:Messenger q) + (hw : IsLaw (w.policies t z n i)) (x) : + 0≤ seraph w t z o m s Y i x ∧ seraph w t z o m s Y i x≤1 := + let h:= Appearance.reflectedLaw (w.allure t z i) Y hw (parcel b i) o m _ (Y _ (z i) x) + + ⟨h.nz _,(weight_le_tot h.nz _).trans h.total.le⟩ + +theorem kappaTop : (w.pen t).kappa ≤1 := by + unfold kappa wavelength + classical + have hh : IsLaw (prism (w.pen t).Abbey) := prodW_law (fun _ => unif_law) + exact (weight_le_tot hh.nz _).trans hh.total.le + +theorem mirror_floor (s : Charts p n d) (Y:Silhouette p N r) + (hw : ∀ i,IsLaw (w.policies t z n i)) + (x:Keys (p:=p) t N) : + 0≤ w.mirror t z o m s Y x ∧ w.mirror t z o m s Y x≤1 := by + let f:= w.seraph t z o m s Y + let v:= w.pen t + have hh i:= seraphFloor w t z o m s Y i (hw i) (x i) + have h0 : 0 ≤ prodW f x:= prodW_nonneg (fun i y=> (seraphFloor w t z o m s Y i (hw i) y).1) _ + have h1 : prodW f x≤1 := (Finset.prod_le_prod₀ (s:=Finset.univ) + (g:=fun i: Messenger q=> (1:ℝ)) (fun i _=> (hh i).1) (fun i _=> (hh i).2)).trans_eq + (by simp) + exact ⟨mul_nonneg v.kappa_pos.le h0,(mul_le_mul (kappaTop w t) h1 h0 zero_le_one).trans_eq + (one_mul _)⟩ + +def sheen (s : Charts p n d) (Y:Silhouette p N r) (W:Wgt (Keys (p:=p) t N)) := + avg (lawNu p N t z) (fun x=>w.mirror t z o m s Y x*W x) + +theorem painted (s : Charts p n d) + (x:Inputs p n (Messenger q)) : + prodW (w.stencil t z o s m) x= + ind (printed b s t w.sel w.flav m o x=w.amp) := by + classical + rw [funext_iff,ind_all]; rfl + +theorem prowl_astonish (s : Charts p n d) (W : Wgt (Keys (p:=p) t N)) : + w.prowl s t z m o W=astonish (w.pen t) z W w.script m (w.policies t z n) + (w.stencil t z o s m) o := by + classical + + let v:=w.pen t + have ht : astonish v z W w.script m (w.policies t z n) (w.stencil t z o s m) o= + avg (v.state z n) (fun x=> ind (earns v w.script m z o x)*W (v.resultKey o x)*prodW + (w.stencil t z o s m) x) := astonish_val v z _ _ m _ _ _ + rw [ht]; unfold prowl; apply avg_congr + intro i _ + rw [painted] + simp_rw [deposit, earns,ind_and] + let a:=ind (printed b s t w.sel w.flav m o i=w.amp); let b0:=ind ((v.draw i).reads w.script m) + let x:= v.resultKey o i; let c:= ind (ownPart v.t z x) + change a*(b0*c)*W x= (b0*c)*W x*a + ring + +theorem sheen_sun (s : Charts p n d) (Y:Silhouette p N r) (W:Wgt (Keys (p:=p) t N)) : + w.sheen t z o m s Y W= + (w.pen t).kappa * avg (lawNu p N t z) (fun x=>W x*prodW (w.seraph t z o m s Y) x) := by + unfold sheen mirror; rw [←avg_mul'] + apply avg_congr; intro i _; ring + +end Quill +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateStatusLaws.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateStatusLaws.lean index 19fe4e61b8ca3c7c7e745fe113f36e4dcb4862ed..b0163581d2fc83be26f08f23099cdcb7191a6588 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateStatusLaws.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SurrogateStatusLaws.lean @@ -1,144 +1,144 @@ -import OAI.Combinatorics.HadwigerCounterexample.AnalyticParameters - -namespace OAI - -/-! # Surrogate Status Laws -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix Function -open scoped BigOperators Topology - -variable {A B C H : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype H] -variable {p : Shape} {n N K M r : ℕ} -abbrev Silhouette (p : Shape) (N r : ℕ) := - ∀ t : Tag p.g,F→AtomKey (p:=p) t N→Fin r - -namespace StatusAnalysis -structure Appearance (p : Shape) where - l : Tag p.g - s : Label p.b - f : Flavor p.g - q : F - -instance : Fintype (Appearance p) := by - classical - let A := Tag p.g × Label p.b × Flavor p.g × F - let E : A ≃ Appearance p := { - toFun x:=⟨x.1,x.2.1,x.2.2.1,x.2.2.2⟩ - invFun x:=(x.l,x.s,x.f,x.q) - left_inv _:=rfl - right_inv _:=rfl } - exact Fintype.ofEquiv _ E - -namespace Appearance -variable (x : Appearance p) -def apt := canDial p x.l x.f x.q -def trot := Template.solo p x.l x.s x.f -def wit (x : Appearance p) (n : ℕ) := scopedBit p n x.l x.f x.q -def face (o : Orient p n N) (w : Knobs p.g n) : AtomKey (p:=p) x.l N := - x.trot.desc w o -def profile {d : ℕ} (i : Nodes) (o : UnitType p n N) (m : Mixer p n) (v : Ax p n d) - (z : Knobs p.g n) : Magazine p d := - specify p i v m o x.l x.s x.f z -theorem witLaw {x : Appearance p} (h : x.apt) (hq : 1≤p.r) (hn : 2*p.r≤n) : - IsLaw (x.wit n) := dial_law _ _ _ _ _ hq hn h - -variable (Y : Silhouette p N r) -def showTag (o : Orient p n N) := fun w=>Y x.l x.q (x.face o w) - -def reference := mapW (lawOmega p N x.l x.q) (Y x.l x.q) -def empirical (o : Orient p n N) := mapW (x.wit n) (x.showTag Y o) - -variable {d : ℕ} -def reflected (i : Nodes) (o : UnitType p n N) (m : Mixer p n) (v : Ax p n d) (a : Fin r) := - mapW (stained (x.wit n) (x.showTag Y (onSide o i)) a) (x.profile i o m v) - -theorem reflectedLaw (h : IsLaw (x.wit n)) (i : Nodes) - (o : UnitType p n N) (m : Mixer p n) (v : Ax p n d) - (a : Fin r) : IsLaw (x.reflected Y i o m v a) := - mapW_law (stained_law _ h _) _ - -def close (o : Orient p n N) (ε : ℝ) := - varOne (x.reference Y) (x.empirical Y o) ≤ ε -end Appearance - -omit [Fintype B] in -private theorem stained_except (w : Wgt A) (f : A→B) (x : B) - (hx : mapW w f x ≠0) : - carried (stained w f x) (fun i=> f i=x) := by - unfold stained; rw [ite_eq_left hx] - exact normW_carried (subW_carried w _) - -theorem inside_color (w : Wgt A) (hw : IsLaw w) (f : A→B) (r : A→C) - (u : B→C→ℝ) : - avg w (fun i=> u (f i) (r i)) = avg (mapW w f) (fun i=>avg (mapW (stained w f i) r) (u i)) := by - classical - let d i:= u (f i) (r i) - calc avg w d = avg (mixW (mapW w f) (stained w f)) d := congrArg (fun w=>avg w d) - (stain_inputs f hw) - _ = _ := by - rw [mixW_avg] - refine avg_congr fun i hi=> ?_ - rw [mapW_avg] - refine avg_congr fun j hj=> ?_ - have he : f j=i := not_not.mp (fun h=>hj (stained_except w f i hi j h)) - unfold d; rw [he] - -theorem varError (w v : Wgt A) (f : A→ℝ) (h : ∀ i, |f i|≤1) : - |avg w f-avg v f| ≤ varOne w v := by - unfold avg varOne - rw [←sum_sub_distrib] - refine (abs_sum_le_sum_abs ..).trans (Finset.sum_le_sum fun i _=> ?_) - rw [← sub_mul,abs_mul]; exact (mul_le_mul_of_nonneg_left (h _) (abs_nonneg _)).trans_eq (mul_one _) - -namespace Appearance -variable (x : Appearance p) (Y : Silhouette p N r) -variable {d : ℕ} - -theorem close_expect (i : Nodes) (o : UnitType p n N) (m : Mixer p n) (v : Ax p n d) - (hw : IsLaw (x.wit n)) (u : Fin r → Magazine p d→ ℝ) (hu : ∀ i j, |u i j| ≤ 1) - {ε : ℝ} (h : x.close Y (onSide o i) ε) : - |avg (x.reference Y) (fun a=> avg (x.reflected Y i o m v a) (u a))- - avg (x.wit n) (fun a=>u (x.showTag Y (onSide o i) a) (x.profile i o m v a))|≤ ε := by - rw [inside_color _ hw] - refine le_trans (varError (x.reference Y) (x.empirical Y (onSide o i)) _ (fun j=>?_)) h - let w := x.reflected Y i o m v j - have he : IsLaw w:= x.reflectedLaw Y hw i o m v j - exact (abs_avg_le he.nz).trans ((avg_mono he.nz (hu j)).trans_eq (he.avg_const _)) - -theorem show_pr (i : Nodes) (o : UnitType p n N) (m : Mixer p n) (v : Ax p n d) - (hw : IsLaw (x.wit n)) (j : Fin r) (U : Magazine p d→Prop) : - pr (x.wit n) (fun y => x.showTag Y (onSide o i) y=j∧ U (x.profile i o m v y))= - x.empirical Y (onSide o i) j * pr (x.reflected Y i o m v j) U := by - classical - rw [pr_of_on hw.nz] - unfold reflected empirical - rw [mapW_pr] - let f:=x.showTag Y (onSide o i) - let w:= x.wit n - by_cases h : mapW w f j ≠0 - · unfold stained; rw [ite_eq_left h]; rfl - have hh : pr w (fun y=> f y=j)=0 := not_not.mp h - change pr w _*_=pr w _ * _ - rw [hh,zero_mul,zero_mul] - -theorem reflection_exact (i : Nodes) (o : UnitType p n N) (m : Mixer p n) (v : Ax p n d) - (j : Fin r) (P : Magazine p d→Prop) - (hw : carried (x.wit n) (P ∘ x.profile i o m v)) : - carried (x.reflected Y i o m v j) P := by - unfold reflected - let f := P∘x.profile i o m v - refine mapW_carried (p:=f) ?_ (fun _ hh=>hh) - unfold stained; split - next h => - refine normW_carried ?_; intro a ha - unfold subW; rw [hw a ha,zero_mul] - next => exact hw -end Appearance -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.AnalyticParameters + +namespace OAI + +/-! # Surrogate Status Laws -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix Function +open scoped BigOperators Topology + +variable {A B C H : Type} [Fintype A] [Fintype B] [Fintype C] [Fintype H] +variable {p : Shape} {n N K M r : ℕ} +abbrev Silhouette (p : Shape) (N r : ℕ) := + ∀ t : Tag p.g,F→AtomKey (p:=p) t N→Fin r + +namespace StatusAnalysis +structure Appearance (p : Shape) where + l : Tag p.g + s : Label p.b + f : Flavor p.g + q : F + +instance : Fintype (Appearance p) := by + classical + let A := Tag p.g × Label p.b × Flavor p.g × F + let E : A ≃ Appearance p := { + toFun x:=⟨x.1,x.2.1,x.2.2.1,x.2.2.2⟩ + invFun x:=(x.l,x.s,x.f,x.q) + left_inv _:=rfl + right_inv _:=rfl } + exact Fintype.ofEquiv _ E + +namespace Appearance +variable (x : Appearance p) +def apt := canDial p x.l x.f x.q +def trot := Template.solo p x.l x.s x.f +def wit (x : Appearance p) (n : ℕ) := scopedBit p n x.l x.f x.q +def face (o : Orient p n N) (w : Knobs p.g n) : AtomKey (p:=p) x.l N := + x.trot.desc w o +def profile {d : ℕ} (i : Nodes) (o : UnitType p n N) (m : Mixer p n) (v : Ax p n d) + (z : Knobs p.g n) : Magazine p d := + specify p i v m o x.l x.s x.f z +theorem witLaw {x : Appearance p} (h : x.apt) (hq : 1≤p.r) (hn : 2*p.r≤n) : + IsLaw (x.wit n) := dial_law _ _ _ _ _ hq hn h + +variable (Y : Silhouette p N r) +def showTag (o : Orient p n N) := fun w=>Y x.l x.q (x.face o w) + +def reference := mapW (lawOmega p N x.l x.q) (Y x.l x.q) +def empirical (o : Orient p n N) := mapW (x.wit n) (x.showTag Y o) + +variable {d : ℕ} +def reflected (i : Nodes) (o : UnitType p n N) (m : Mixer p n) (v : Ax p n d) (a : Fin r) := + mapW (stained (x.wit n) (x.showTag Y (onSide o i)) a) (x.profile i o m v) + +theorem reflectedLaw (h : IsLaw (x.wit n)) (i : Nodes) + (o : UnitType p n N) (m : Mixer p n) (v : Ax p n d) + (a : Fin r) : IsLaw (x.reflected Y i o m v a) := + mapW_law (stained_law _ h _) _ + +def close (o : Orient p n N) (ε : ℝ) := + varOne (x.reference Y) (x.empirical Y o) ≤ ε +end Appearance + +omit [Fintype B] in +private theorem stained_except (w : Wgt A) (f : A→B) (x : B) + (hx : mapW w f x ≠0) : + carried (stained w f x) (fun i=> f i=x) := by + unfold stained; rw [ite_eq_left hx] + exact normW_carried (subW_carried w _) + +theorem inside_color (w : Wgt A) (hw : IsLaw w) (f : A→B) (r : A→C) + (u : B→C→ℝ) : + avg w (fun i=> u (f i) (r i)) = avg (mapW w f) (fun i=>avg (mapW (stained w f i) r) (u i)) := by + classical + let d i:= u (f i) (r i) + calc avg w d = avg (mixW (mapW w f) (stained w f)) d := congrArg (fun w=>avg w d) + (stain_inputs f hw) + _ = _ := by + rw [mixW_avg] + refine avg_congr fun i hi=> ?_ + rw [mapW_avg] + refine avg_congr fun j hj=> ?_ + have he : f j=i := not_not.mp (fun h=>hj (stained_except w f i hi j h)) + unfold d; rw [he] + +theorem varError (w v : Wgt A) (f : A→ℝ) (h : ∀ i, |f i|≤1) : + |avg w f-avg v f| ≤ varOne w v := by + unfold avg varOne + rw [←sum_sub_distrib] + refine (abs_sum_le_sum_abs ..).trans (Finset.sum_le_sum fun i _=> ?_) + rw [← sub_mul,abs_mul]; exact (mul_le_mul_of_nonneg_left (h _) (abs_nonneg _)).trans_eq (mul_one _) + +namespace Appearance +variable (x : Appearance p) (Y : Silhouette p N r) +variable {d : ℕ} + +theorem close_expect (i : Nodes) (o : UnitType p n N) (m : Mixer p n) (v : Ax p n d) + (hw : IsLaw (x.wit n)) (u : Fin r → Magazine p d→ ℝ) (hu : ∀ i j, |u i j| ≤ 1) + {ε : ℝ} (h : x.close Y (onSide o i) ε) : + |avg (x.reference Y) (fun a=> avg (x.reflected Y i o m v a) (u a))- + avg (x.wit n) (fun a=>u (x.showTag Y (onSide o i) a) (x.profile i o m v a))|≤ ε := by + rw [inside_color _ hw] + refine le_trans (varError (x.reference Y) (x.empirical Y (onSide o i)) _ (fun j=>?_)) h + let w := x.reflected Y i o m v j + have he : IsLaw w:= x.reflectedLaw Y hw i o m v j + exact (abs_avg_le he.nz).trans ((avg_mono he.nz (hu j)).trans_eq (he.avg_const _)) + +theorem show_pr (i : Nodes) (o : UnitType p n N) (m : Mixer p n) (v : Ax p n d) + (hw : IsLaw (x.wit n)) (j : Fin r) (U : Magazine p d→Prop) : + pr (x.wit n) (fun y => x.showTag Y (onSide o i) y=j∧ U (x.profile i o m v y))= + x.empirical Y (onSide o i) j * pr (x.reflected Y i o m v j) U := by + classical + rw [pr_of_on hw.nz] + unfold reflected empirical + rw [mapW_pr] + let f:=x.showTag Y (onSide o i) + let w:= x.wit n + by_cases h : mapW w f j ≠0 + · unfold stained; rw [ite_eq_left h]; rfl + have hh : pr w (fun y=> f y=j)=0 := not_not.mp h + change pr w _*_=pr w _ * _ + rw [hh,zero_mul,zero_mul] + +theorem reflection_exact (i : Nodes) (o : UnitType p n N) (m : Mixer p n) (v : Ax p n d) + (j : Fin r) (P : Magazine p d→Prop) + (hw : carried (x.wit n) (P ∘ x.profile i o m v)) : + carried (x.reflected Y i o m v j) P := by + unfold reflected + let f := P∘x.profile i o m v + refine mapW_carried (p:=f) ?_ (fun _ hh=>hh) + unfold stained; split + next h => + refine normW_carried ?_; intro a ha + unfold subW; rw [hw a ha,zero_mul] + next => exact hw +end Appearance +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticArraySlices.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticArraySlices.lean index 5c0dc9605123001b4e64e7c52d65442e25d2a825..2ba04ab4336be7bf95de846ea6e5c3827f258163 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticArraySlices.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticArraySlices.lean @@ -1,120 +1,120 @@ -import OAI.Combinatorics.HadwigerCounterexample.SyntheticParity -import OAI.Combinatorics.HadwigerCounterexample.RankSubrectangles - -namespace OAI - -/-! # Synthetic Array Slices -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module Function LinearMap -open scoped BigOperators -variable {p : Shape} {d e n N : ℕ} -variable {I J : Type} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] - -def exhibit (p : Shape) (A : Mat I J) (x : Display p I N) : Display p J N := - fun i => ((x i).1*A,(x i).2*A) - -theorem exhibit_law (p : Shape) (A : Mat I J) (G : Mat I I) - (h : Injective A.mulVec) (hn : 2*num I-(N:ℝ) ≤ -1) : - mapW (displayLaw p I N G) (exhibit p A)=displayLaw p J N (pullM A A G) := by - classical - let C := fun x:Mat I I=> x=G - have he : gramGood (U:=Fin N) G = FramesAt C := rfl - have hl : 2*num Ihi ▸ rfl) - have ht:=mapW_repeat (fun _ : Comp p.g=> unifOn (gramGood G)) (fun _ => observe (U:=Fin N) A A) - rw [hv] at ht; exact ht - -omit [DecidableEq I] [DecidableEq J] in -theorem exhibit_color (p : Shape) (A : Mat I J) (u : Vec J) (x : Display p I N) (l : Tag p.g) : - libColor p l u (exhibit p A x)=libColor p l (A *ᵥ u) x := by - funext i j; cases j - · exact (Matrix.mulVec_mulVec ..).symm - exact (Matrix.mulVec_mulVec ..).symm - -abbrev Sextant (d e : ℕ) := (Fin d ↪ Fin e) × (Fin d↪Fin e) -def reflectSextant (f : Sextant d e) : Hue d ↪ Hue e where - toFun x := x.map (fun i=> (i.1,(onSide f i.1) i.2)) - inj' := by - rintro (_|⟨a,b⟩) (_|⟨c,d⟩) h - · rfl - · cases h - · cases h - have he : (a,(onSide f a) b)=(c,(onSide f c) d) := Option.some.inj h - have hh : a=c := congrArg Prod.fst he - subst c; rw [(onSide f a).injective (congrArg Prod.snd he)] -def cartM (f : Sextant d e) := embedMat (reflectSextant f) - -theorem cart_target (f : Sextant d e) : - pullM (cartM f) (cartM f) (beamMap e) = - (beamMap e).submatrix (reflectSextant f) (reflectSextant f) := by - rw [cartM,pullM_def,embedMat_mul,mul_embedMat]; rfl - -theorem cart_cross (p : Shape) (f : Sextant d e) (l : Tag p.g) (s : Augur p N) - (x : Display p (Hue e) N) : - let Z:= arches (libAug p l s (beamMap e) x) - arches (libAug p l s (pullM (cartM f) (cartM f) (beamMap e)) (exhibit p (cartM f) x)) - = Z.submatrix f.1 f.2 := by - classical - intro Z - let A:= cartM f - have hu (i : Hue d) : A*ᵥjet i=jet (reflectSextant f i) := by - funext j; simp only [jet,Matrix.mulVec_single_one,col_apply,A,cartM,embedMat, - Matrix.of_apply] - by_cases h : j= reflectSextant f i <;> simp [h] - have hx (u : Vec (Hue d)) : - libAug p l s (pullM A A (beamMap e)) (exhibit p A x) u = - libAug p l s (beamMap e) x (A*ᵥu) := by unfold libAug libPredict; rw [evmat_pull,exhibit_color] - ext i j - change arches (libAug p l s (pullM A A (beamMap e)) (exhibit p A x)) i j=Z (f.1 i) (f.2 j) - unfold arches Z; dsimp only - simp_rw [hx,mulVec_add,hu] - rfl - -omit [Fintype I] [DecidableEq I] in -theorem col_flag {K : Type} [Fintype K] {M : Mat K I} {f : J → I} - (h : Injective (M.submatrix _root_.id f).mulVec) : Injective f := by - classical - intro i j hi - let X:=M.submatrix _root_.id f - have he : jet i=jet j := h (by - rw [jet,jet,mulVec_single_one,mulVec_single_one] - funext k; simp only [col_apply,Matrix.submatrix_apply,hi]) - by_contra! hg - have hf := congr_fun he i - simp only [jet,Pi.single_eq_same,Pi.single_eq_of_ne hg] at hf - exact one_ne_zero hf - -set_option maxHeartbeats 600000 in -theorem rank_torpedo (M : Mat (Fin e) (Fin e)) (d : ℕ) - (h : ∀ f : Sextant d e,(M.submatrix f.1 f.2).rank ((x i).1*A,(x i).2*A) + +theorem exhibit_law (p : Shape) (A : Mat I J) (G : Mat I I) + (h : Injective A.mulVec) (hn : 2*num I-(N:ℝ) ≤ -1) : + mapW (displayLaw p I N G) (exhibit p A)=displayLaw p J N (pullM A A G) := by + classical + let C := fun x:Mat I I=> x=G + have he : gramGood (U:=Fin N) G = FramesAt C := rfl + have hl : 2*num Ihi ▸ rfl) + have ht:=mapW_repeat (fun _ : Comp p.g=> unifOn (gramGood G)) (fun _ => observe (U:=Fin N) A A) + rw [hv] at ht; exact ht + +omit [DecidableEq I] [DecidableEq J] in +theorem exhibit_color (p : Shape) (A : Mat I J) (u : Vec J) (x : Display p I N) (l : Tag p.g) : + libColor p l u (exhibit p A x)=libColor p l (A *ᵥ u) x := by + funext i j; cases j + · exact (Matrix.mulVec_mulVec ..).symm + exact (Matrix.mulVec_mulVec ..).symm + +abbrev Sextant (d e : ℕ) := (Fin d ↪ Fin e) × (Fin d↪Fin e) +def reflectSextant (f : Sextant d e) : Hue d ↪ Hue e where + toFun x := x.map (fun i=> (i.1,(onSide f i.1) i.2)) + inj' := by + rintro (_|⟨a,b⟩) (_|⟨c,d⟩) h + · rfl + · cases h + · cases h + have he : (a,(onSide f a) b)=(c,(onSide f c) d) := Option.some.inj h + have hh : a=c := congrArg Prod.fst he + subst c; rw [(onSide f a).injective (congrArg Prod.snd he)] +def cartM (f : Sextant d e) := embedMat (reflectSextant f) + +theorem cart_target (f : Sextant d e) : + pullM (cartM f) (cartM f) (beamMap e) = + (beamMap e).submatrix (reflectSextant f) (reflectSextant f) := by + rw [cartM,pullM_def,embedMat_mul,mul_embedMat]; rfl + +theorem cart_cross (p : Shape) (f : Sextant d e) (l : Tag p.g) (s : Augur p N) + (x : Display p (Hue e) N) : + let Z:= arches (libAug p l s (beamMap e) x) + arches (libAug p l s (pullM (cartM f) (cartM f) (beamMap e)) (exhibit p (cartM f) x)) + = Z.submatrix f.1 f.2 := by + classical + intro Z + let A:= cartM f + have hu (i : Hue d) : A*ᵥjet i=jet (reflectSextant f i) := by + funext j; simp only [jet,Matrix.mulVec_single_one,col_apply,A,cartM,embedMat, + Matrix.of_apply] + by_cases h : j= reflectSextant f i <;> simp [h] + have hx (u : Vec (Hue d)) : + libAug p l s (pullM A A (beamMap e)) (exhibit p A x) u = + libAug p l s (beamMap e) x (A*ᵥu) := by unfold libAug libPredict; rw [evmat_pull,exhibit_color] + ext i j + change arches (libAug p l s (pullM A A (beamMap e)) (exhibit p A x)) i j=Z (f.1 i) (f.2 j) + unfold arches Z; dsimp only + simp_rw [hx,mulVec_add,hu] + rfl + +omit [Fintype I] [DecidableEq I] in +theorem col_flag {K : Type} [Fintype K] {M : Mat K I} {f : J → I} + (h : Injective (M.submatrix _root_.id f).mulVec) : Injective f := by + classical + intro i j hi + let X:=M.submatrix _root_.id f + have he : jet i=jet j := h (by + rw [jet,jet,mulVec_single_one,mulVec_single_one] + funext k; simp only [col_apply,Matrix.submatrix_apply,hi]) + by_contra! hg + have hf := congr_fun he i + simp only [jet,Pi.single_eq_same,Pi.single_eq_of_ne hg] at hf + exact one_ne_zero hf + +set_option maxHeartbeats 600000 in +theorem rank_torpedo (M : Mat (Fin e) (Fin e)) (d : ℕ) + (h : ∀ f : Sextant d e,(M.submatrix f.1 f.2).rank ?_ - by_cases hi : w i=0 - · rw [hi,zero_mul,zero_mul] - exact mul_le_mul_of_nonneg_left (ind_mono (h i hi)) (hw i) - -def fiddleRate (p : Shape) (I : Type) [Fintype I] [DecidableEq I] := - num (Vec I)* (labFee p I)⁻¹ - -theorem fiddle_bound (p : Shape) (S : Knobs p.g n → Prop) (w : I→ Tickets p) - (h : 2*p.r≤n) (ε : ℝ) (hS : pr (spins p n) S≤ ε) : - pr (sketchLaw p n w) (fun i=> ∃ x,weightsAff x ∧ S (compound p i x)) - ≤ fiddleRate p I * ε := by - classical - let P (x : Vec I) := fun i : I → Knobs p.g n=> weightsAff x ∧ S (compound p i x) - have hw := sketch_law p n w h - have hi (i:Vec I) : - pr (sketchLaw p n w) (P i) ≤ (labFee p I)⁻¹*ε := by - have hg : 0 < labFee p I := labFee_pos .. - by_cases he : weightsAff i - · unfold P; simp only [he,true_and]; exact - (sketch_point p n w h i he S).trans (mul_le_mul_of_nonneg_left hS (by positivity)) - have he' := (pr_nonneg (spins_law p n).nz).trans hS - simp only [P,he,false_and,pr_false]; positivity - exact (pr_exists_le hw.nz P).trans ((Finset.sum_le_sum (fun i _ => hi i)).trans_eq - (by simp only [fiddleRate,num,Finset.sum_const,card_univ,nsmul_eq_mul,mul_assoc])) - -def havoc (p : Shape) (l : Tag p.g) (g : Augur p N) (G : Mat (Hue d) (Hue d)) - (r : ℕ) (x : Display p (Hue d) N) := 2*r<(arches (libAug p l g G x)).rank - -set_option maxHeartbeats 800000 in -theorem havoc_rate (p : Shape) (l : Tag p.g) (o : Orient p n N) (g : Augur p N) (E : Finset (Tag p.g)) - (s : Label p.b) (r : ℕ) (m : Mixer p n) (ε : ℝ) - (a : Hue d → Tickets p) (hj : 1≤p.j) (hn : 2*p.r≤n) - (hx : screen p o s E r g ε) : - let f:= creed p E - magazine p l s f (havoc p l g (labGram p l f a) r) a o ≤ fiddleRate p (Hue d)*ε := by - classical - intro f - let G:= labGram p l f a - obtain ⟨w,h1,h2⟩:=hx - obtain ⟨M,hM,h⟩:=h2 l - let P:= mismatch p g w l s f o - let v:=sketchLaw p n a - apply le_trans _ (fiddle_bound p P a hn ε (h1 l f)) - change pr v _≤ pr v _ - refine pr_mono_support v (sketch_law p n a hn).nz fun x hx hh=>?_ - by_contra! he - let A:= incision p l s f x - let T:=pullM A A M; let F:=libAug p l g G (drill p A o) - have hi : pullM A A (selfM p n m.mixM) = G := sketch_matrix p l s f m a hj x hx - have hz (y : Vec (Hue d)) (hy : weightsAff y) : - F y=evmat T y y := by - let t:=compound p x y - have ht : ¬ P t := he y hy - have heq : g l (evmat G y y) (libColor p l y (drill p A o))= - dialed p l f t+evmat T y y := by - rw [←hi,inc_diag _ l s f m x y hy hj,lib_see p l s f x y hy o] - have he := Eq.symm (not_ne_iff.mp ht) - refine he.trans ((h t).trans ?_) - unfold T; rw [evmat_pull,inc_compound p l s f x y hy] - unfold F libAug libPredict - rw [heq,←hi,inc_diag _ l s f m x y hy hj] - change dialed p l f t+_ + dialed p l f t=_ - rw [add_right_comm,char_two,zero_add] - have hl := (arches_rank F T hz).trans (Nat.mul_le_mul_left 2 ((rank_lift_le ..).trans hM)) - exact Nat.not_lt_of_ge hl hh - -def mute (p : Shape) (g : Augur p N) (G : Mat Unit Unit) (x : Display p Unit N) := - (∑ i:Tag p.g,libPredict p i g G x (jet ()))≠0 - -theorem common_lit (p : Shape) (j l : Tag p.g) (x : Knobs p.g n) : - lit Flavor.sharedOnly j x=lit Flavor.sharedOnly l x := by - classical - funext i - rcases i with ⟨x|x,i⟩ - · simp [lit,Flavor.keeps] - simp [lit,Flavor.keeps] -theorem common_dial (p : Shape) (j l : Tag p.g) (x : Knobs p.g n) : - dialed p j Flavor.sharedOnly x=dialed p l Flavor.sharedOnly x := by - have hj := etaScan p j (0:Label p.b) Flavor.sharedOnly x - have hl := etaScan p l (0:Label p.b) Flavor.sharedOnly x - rw [common_lit p j l x] at hj; exact hj.trans hl.symm - -set_option maxHeartbeats 800000 in -theorem mute_rate (p : Shape) (l : Tag p.g) (o : Orient p n N) (g : Augur p N) (E : Finset (Tag p.g)) - (s : Label p.b) (r : ℕ) (m : Mixer p n) (ε : ℝ) - (a : Unit→ Tickets p) (hj : 1≤p.j) (hn : 2*p.r≤n) - (hx : screen p o s E r g ε) : - let f:= Flavor.sharedOnly - magazine p l s f (mute p g (labGram p l f a)) a o ≤ p.g*fiddleRate p Unit*ε := by - classical - intro f; let G:=labGram p l f a - obtain ⟨w,h1,h2⟩:=hx - let P (i:Tag p.g):= mismatch p g w i s f o - let Q := fun x=>∃ i,P i x - let W:=sketchLaw p n a - have he : pr (spins p n) Q≤p.g*ε := by - refine (pr_exists_le (spins_law p n).nz P).trans ((sum_le_sum - (fun i _=> h1 i f)).trans_eq ?_) - simp only [Finset.sum_const,nsmul_eq_mul,card_univ,Tag,Fintype.card_fin] - apply le_trans _ ((fiddle_bound p Q a hn (p.g*ε) he).trans_eq (by ring)) - change pr W _ ≤ pr W _ - refine pr_mono_support W (sketch_law p n a hn).nz fun x hx hh=>?_ - by_contra! H - let A:= incision p l s f x - let u:= jet () - have hu : weightsAff u := by simp [weightsAff,u,jet] - let t:= compound p x u - have ht : ∀ i,¬ P i t := not_exists.mp (H u hu) - have hZ : pullM A A (selfM p n m.mixM) = G := sketch_matrix p l s f m a hj x hx - have heq i : - libPredict p i g G (drill p A o) u = w (atom p i s (lit f l t)) := by - have hq : evmat G u u=dialed p i f t := by rw [←hZ,inc_diag _ l s f m x u hu hj]; - exact common_dial p l i t - have hg : A=incision p i s f x := by - ext y j; unfold A incision - simp only [Matrix.of_apply,spring, f] - rw [common_lit p l i] - unfold libPredict; rw [hq,hg,lib_see p i s f x u hu o] - rw [show lit f l t=lit f i t from common_lit p l i t] - exact Eq.symm (not_ne_iff.mp (ht i)) - apply hh; change ∑ i:Tag p.g,libPredict p i g G (drill p A o) u=_ - simp_rw [heq,←map_sum,atom_union,map_zero] -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ZeroDiscrepancyPrediction + +namespace OAI + +/-! # Synthetic Failure Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module LinearMap Function Filter Real +open scoped BigOperators +variable {p : Shape} {I A : Type} [Fintype I] [DecidableEq I] [Fintype A] {n N d : ℕ} + +theorem pr_mono_support (w : Wgt A) (hw : ∀ i, 0≤w i) {P Q : A→Prop} + (h : ∀ i, w i≠0→P i→Q i) : + pr w P ≤ pr w Q := by + change ∑ i,w i*ind (P i) ≤ ∑ i,w i*ind (Q i) + refine Finset.sum_le_sum fun i _=> ?_ + by_cases hi : w i=0 + · rw [hi,zero_mul,zero_mul] + exact mul_le_mul_of_nonneg_left (ind_mono (h i hi)) (hw i) + +def fiddleRate (p : Shape) (I : Type) [Fintype I] [DecidableEq I] := + num (Vec I)* (labFee p I)⁻¹ + +theorem fiddle_bound (p : Shape) (S : Knobs p.g n → Prop) (w : I→ Tickets p) + (h : 2*p.r≤n) (ε : ℝ) (hS : pr (spins p n) S≤ ε) : + pr (sketchLaw p n w) (fun i=> ∃ x,weightsAff x ∧ S (compound p i x)) + ≤ fiddleRate p I * ε := by + classical + let P (x : Vec I) := fun i : I → Knobs p.g n=> weightsAff x ∧ S (compound p i x) + have hw := sketch_law p n w h + have hi (i:Vec I) : + pr (sketchLaw p n w) (P i) ≤ (labFee p I)⁻¹*ε := by + have hg : 0 < labFee p I := labFee_pos .. + by_cases he : weightsAff i + · unfold P; simp only [he,true_and]; exact + (sketch_point p n w h i he S).trans (mul_le_mul_of_nonneg_left hS (by positivity)) + have he' := (pr_nonneg (spins_law p n).nz).trans hS + simp only [P,he,false_and,pr_false]; positivity + exact (pr_exists_le hw.nz P).trans ((Finset.sum_le_sum (fun i _ => hi i)).trans_eq + (by simp only [fiddleRate,num,Finset.sum_const,card_univ,nsmul_eq_mul,mul_assoc])) + +def havoc (p : Shape) (l : Tag p.g) (g : Augur p N) (G : Mat (Hue d) (Hue d)) + (r : ℕ) (x : Display p (Hue d) N) := 2*r<(arches (libAug p l g G x)).rank + +set_option maxHeartbeats 800000 in +theorem havoc_rate (p : Shape) (l : Tag p.g) (o : Orient p n N) (g : Augur p N) (E : Finset (Tag p.g)) + (s : Label p.b) (r : ℕ) (m : Mixer p n) (ε : ℝ) + (a : Hue d → Tickets p) (hj : 1≤p.j) (hn : 2*p.r≤n) + (hx : screen p o s E r g ε) : + let f:= creed p E + magazine p l s f (havoc p l g (labGram p l f a) r) a o ≤ fiddleRate p (Hue d)*ε := by + classical + intro f + let G:= labGram p l f a + obtain ⟨w,h1,h2⟩:=hx + obtain ⟨M,hM,h⟩:=h2 l + let P:= mismatch p g w l s f o + let v:=sketchLaw p n a + apply le_trans _ (fiddle_bound p P a hn ε (h1 l f)) + change pr v _≤ pr v _ + refine pr_mono_support v (sketch_law p n a hn).nz fun x hx hh=>?_ + by_contra! he + let A:= incision p l s f x + let T:=pullM A A M; let F:=libAug p l g G (drill p A o) + have hi : pullM A A (selfM p n m.mixM) = G := sketch_matrix p l s f m a hj x hx + have hz (y : Vec (Hue d)) (hy : weightsAff y) : + F y=evmat T y y := by + let t:=compound p x y + have ht : ¬ P t := he y hy + have heq : g l (evmat G y y) (libColor p l y (drill p A o))= + dialed p l f t+evmat T y y := by + rw [←hi,inc_diag _ l s f m x y hy hj,lib_see p l s f x y hy o] + have he := Eq.symm (not_ne_iff.mp ht) + refine he.trans ((h t).trans ?_) + unfold T; rw [evmat_pull,inc_compound p l s f x y hy] + unfold F libAug libPredict + rw [heq,←hi,inc_diag _ l s f m x y hy hj] + change dialed p l f t+_ + dialed p l f t=_ + rw [add_right_comm,char_two,zero_add] + have hl := (arches_rank F T hz).trans (Nat.mul_le_mul_left 2 ((rank_lift_le ..).trans hM)) + exact Nat.not_lt_of_ge hl hh + +def mute (p : Shape) (g : Augur p N) (G : Mat Unit Unit) (x : Display p Unit N) := + (∑ i:Tag p.g,libPredict p i g G x (jet ()))≠0 + +theorem common_lit (p : Shape) (j l : Tag p.g) (x : Knobs p.g n) : + lit Flavor.sharedOnly j x=lit Flavor.sharedOnly l x := by + classical + funext i + rcases i with ⟨x|x,i⟩ + · simp [lit,Flavor.keeps] + simp [lit,Flavor.keeps] +theorem common_dial (p : Shape) (j l : Tag p.g) (x : Knobs p.g n) : + dialed p j Flavor.sharedOnly x=dialed p l Flavor.sharedOnly x := by + have hj := etaScan p j (0:Label p.b) Flavor.sharedOnly x + have hl := etaScan p l (0:Label p.b) Flavor.sharedOnly x + rw [common_lit p j l x] at hj; exact hj.trans hl.symm + +set_option maxHeartbeats 800000 in +theorem mute_rate (p : Shape) (l : Tag p.g) (o : Orient p n N) (g : Augur p N) (E : Finset (Tag p.g)) + (s : Label p.b) (r : ℕ) (m : Mixer p n) (ε : ℝ) + (a : Unit→ Tickets p) (hj : 1≤p.j) (hn : 2*p.r≤n) + (hx : screen p o s E r g ε) : + let f:= Flavor.sharedOnly + magazine p l s f (mute p g (labGram p l f a)) a o ≤ p.g*fiddleRate p Unit*ε := by + classical + intro f; let G:=labGram p l f a + obtain ⟨w,h1,h2⟩:=hx + let P (i:Tag p.g):= mismatch p g w i s f o + let Q := fun x=>∃ i,P i x + let W:=sketchLaw p n a + have he : pr (spins p n) Q≤p.g*ε := by + refine (pr_exists_le (spins_law p n).nz P).trans ((sum_le_sum + (fun i _=> h1 i f)).trans_eq ?_) + simp only [Finset.sum_const,nsmul_eq_mul,card_univ,Tag,Fintype.card_fin] + apply le_trans _ ((fiddle_bound p Q a hn (p.g*ε) he).trans_eq (by ring)) + change pr W _ ≤ pr W _ + refine pr_mono_support W (sketch_law p n a hn).nz fun x hx hh=>?_ + by_contra! H + let A:= incision p l s f x + let u:= jet () + have hu : weightsAff u := by simp [weightsAff,u,jet] + let t:= compound p x u + have ht : ∀ i,¬ P i t := not_exists.mp (H u hu) + have hZ : pullM A A (selfM p n m.mixM) = G := sketch_matrix p l s f m a hj x hx + have heq i : + libPredict p i g G (drill p A o) u = w (atom p i s (lit f l t)) := by + have hq : evmat G u u=dialed p i f t := by rw [←hZ,inc_diag _ l s f m x u hu hj]; + exact common_dial p l i t + have hg : A=incision p i s f x := by + ext y j; unfold A incision + simp only [Matrix.of_apply,spring, f] + rw [common_lit p l i] + unfold libPredict; rw [hq,hg,lib_see p i s f x u hu o] + rw [show lit f l t=lit f i t from common_lit p l i t] + exact Eq.symm (not_ne_iff.mp (ht i)) + apply hh; change ∑ i:Tag p.g,libPredict p i g G (drill p A o) u=_ + simp_rw [heq,←map_sum,atom_union,map_zero] +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticParity.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticParity.lean index 39e3869e2e06e6e422dcaaaab0db80823a42d8d3..9282800ea294b03ad2df7e956e8040600f56da8f 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticParity.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticParity.lean @@ -1,104 +1,104 @@ -import OAI.Combinatorics.HadwigerCounterexample.SyntheticTolerances - -namespace OAI - -/-! # Synthetic Parity -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Submodule Function Finset -open scoped BigOperators -variable {p : Shape} {I J : Type} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] -variable {d e n N : ℕ} - -abbrev Hue (d : ℕ) := Option (Bool × Fin d) -def beamMap (d : ℕ) : Mat (Hue d) (Hue d) := - Matrix.of (fun i j => - i.elim 0 (fun x=> j.elim 0 (fun y=> if x.1=true∧y.1=false∧x.2=y.2 then 1 else 0))) -def jet (i : I) := (Pi.single i 1 : Vec I) -abbrev incarn {d : ℕ} (x : Fin d) (b : Bool) : Hue d := some (b,x) -def plumeDiff (d : ℕ) (b : Bool) : Mat (Hue d) (Fin d) := - Matrix.of (fun i j => jet none i + jet (incarn j b) i) - -def arches (F : Vec (Hue d) → F) : Mat (Fin d) (Fin d) := - Matrix.of (fun i j => - let x:=jet (incarn i true) - let y:=jet (incarn j false) - let z:=jet (none : Hue d) - F (z+x+y)+F x+(F y+F z)) - -omit [DecidableEq I] in -theorem quad_cross_gen (Q : Mat I I) (x y z : Vec I) : - evmat Q (z+x+y) (z+x+y)+evmat Q x x+(evmat Q y y+evmat Q z z)= - evmat (Q+Qᵀ) (z+x) (z+y) := by - rw [evmat_addM,evmat_transpose] - unfold evmat; simp only [mulVec_add,add_dotProduct,dotProduct_add] - ring_nf - simp only [mul_two,char_two,zero_add,add_zero] - -theorem arches_from (F : Vec (Hue d) → F) (Q : Mat (Hue d) (Hue d)) - (h : ∀ x,weightsAff x → F x=evmat Q x x) : - arches F = pullM (plumeDiff d true) (plumeDiff d false) (Q+Qᵀ) := by - classical - ext i j - let x:=jet (incarn i true); let y:=jet (incarn j false) - let z:=jet (none : Hue d) - have hj (x : Hue d) : weightsAff (jet x) := by simp [weightsAff,jet] - have hz : weightsAff (z+x+y) := by - unfold weightsAff - simp only [Finset.sum_add_distrib,Pi.add_apply] - rw [show ∑ i,z i=1 from hj _,show ∑ i,x i=1 from hj _,show ∑ i,y i=1 from hj _,char_two,zero_add] - change F (z+x+y)+F x+(F y+F z)=_ - rw [h _ hz,h _ (hj _),h _ (hj _),h _ (hj _),quad_cross_gen] - rw [pullM_def,Matrix.mul_assoc] - rfl - -theorem arches_rank (F : Vec (Hue d) → F) (Q : Mat (Hue d) (Hue d)) - (h : ∀ x,weightsAff x → F x=evmat Q x x) : - (arches F).rank≤2*Q.rank := by - rw [arches_from F Q h] - refine le_trans (rank_lift_le ..) ?_ - rw [two_mul] - exact (mrk_add_le ..).trans (by rw [Matrix.rank_transpose]) - -theorem arches_beam (d : ℕ) : - arches (fun x => evmat (beamMap d) x x)= (1:Mat (Fin d) (Fin d)) := by - classical - ext i j - have he (a b : Hue d) : - evmat (beamMap d) (jet a) (jet b)=beamMap d a b := by simp [evmat,jet] - - let x:=jet (incarn i true); let y:=jet (incarn j false); let z:=jet (none:Hue d) - change evmat _ (z+x+y) (z+x+y)+_+_=_ - rw [quad_cross_gen,evmat_addM,evmat_transpose] - have h1 (a b c e : Hue d) : evmat (beamMap d) (jet a+jet b) (jet c+jet e)= - beamMap d a c+beamMap d b c+(beamMap d a e+beamMap d b e) := by - simp_rw [← he]; unfold evmat; rw [Matrix.mulVec_add,dotProduct_add,add_dotProduct,add_dotProduct] - rw [h1,h1] - simp [beamMap,Matrix.one_apply] - -def libColor (p : Shape) (l : Tag p.g) (u : Vec I) (x : Display p I N) : - AtomKey (p:=p) l N := - fun i b=> if b then (x i.val).1 *ᵥ u else (x i.val).2 *ᵥ u -def libPredict (p : Shape) (l : Tag p.g) (s : Augur p N) (G : Mat I I) (x : Display p I N) - (u : Vec I) := s l (evmat G u u) (libColor p l u x) -def libAug (p : Shape) (l : Tag p.g) (s : Augur p N) (G : Mat I I) (x : Display p I N) (u : Vec I) := - libPredict p l s G x u+evmat G u u - -omit [DecidableEq I] in -theorem lib_see (p : Shape) (l s f) (x : I →Knobs p.g n) - (u : Vec I) (h : weightsAff u) (o : Orient p n N) : - let A := incision p l s f x - let y := compound p x u - libColor p l u (drill p A o) = keyOne p l s (lit f l y) o := by - intro A y; funext i b - cases b - · change (primary _* A) *ᵥ u=primary _*ᵥ spring _ _ _ _ _ - rw [←Matrix.mulVec_mulVec,inc_compound p l s f x u h]; rfl - change (primary _ * A)*ᵥ u=primary _*ᵥ spring _ _ _ _ _ - rw [← Matrix.mulVec_mulVec,inc_compound p l s f x u h]; rfl -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SyntheticTolerances + +namespace OAI + +/-! # Synthetic Parity -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Submodule Function Finset +open scoped BigOperators +variable {p : Shape} {I J : Type} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] +variable {d e n N : ℕ} + +abbrev Hue (d : ℕ) := Option (Bool × Fin d) +def beamMap (d : ℕ) : Mat (Hue d) (Hue d) := + Matrix.of (fun i j => + i.elim 0 (fun x=> j.elim 0 (fun y=> if x.1=true∧y.1=false∧x.2=y.2 then 1 else 0))) +def jet (i : I) := (Pi.single i 1 : Vec I) +abbrev incarn {d : ℕ} (x : Fin d) (b : Bool) : Hue d := some (b,x) +def plumeDiff (d : ℕ) (b : Bool) : Mat (Hue d) (Fin d) := + Matrix.of (fun i j => jet none i + jet (incarn j b) i) + +def arches (F : Vec (Hue d) → F) : Mat (Fin d) (Fin d) := + Matrix.of (fun i j => + let x:=jet (incarn i true) + let y:=jet (incarn j false) + let z:=jet (none : Hue d) + F (z+x+y)+F x+(F y+F z)) + +omit [DecidableEq I] in +theorem quad_cross_gen (Q : Mat I I) (x y z : Vec I) : + evmat Q (z+x+y) (z+x+y)+evmat Q x x+(evmat Q y y+evmat Q z z)= + evmat (Q+Qᵀ) (z+x) (z+y) := by + rw [evmat_addM,evmat_transpose] + unfold evmat; simp only [mulVec_add,add_dotProduct,dotProduct_add] + ring_nf + simp only [mul_two,char_two,zero_add,add_zero] + +theorem arches_from (F : Vec (Hue d) → F) (Q : Mat (Hue d) (Hue d)) + (h : ∀ x,weightsAff x → F x=evmat Q x x) : + arches F = pullM (plumeDiff d true) (plumeDiff d false) (Q+Qᵀ) := by + classical + ext i j + let x:=jet (incarn i true); let y:=jet (incarn j false) + let z:=jet (none : Hue d) + have hj (x : Hue d) : weightsAff (jet x) := by simp [weightsAff,jet] + have hz : weightsAff (z+x+y) := by + unfold weightsAff + simp only [Finset.sum_add_distrib,Pi.add_apply] + rw [show ∑ i,z i=1 from hj _,show ∑ i,x i=1 from hj _,show ∑ i,y i=1 from hj _,char_two,zero_add] + change F (z+x+y)+F x+(F y+F z)=_ + rw [h _ hz,h _ (hj _),h _ (hj _),h _ (hj _),quad_cross_gen] + rw [pullM_def,Matrix.mul_assoc] + rfl + +theorem arches_rank (F : Vec (Hue d) → F) (Q : Mat (Hue d) (Hue d)) + (h : ∀ x,weightsAff x → F x=evmat Q x x) : + (arches F).rank≤2*Q.rank := by + rw [arches_from F Q h] + refine le_trans (rank_lift_le ..) ?_ + rw [two_mul] + exact (mrk_add_le ..).trans (by rw [Matrix.rank_transpose]) + +theorem arches_beam (d : ℕ) : + arches (fun x => evmat (beamMap d) x x)= (1:Mat (Fin d) (Fin d)) := by + classical + ext i j + have he (a b : Hue d) : + evmat (beamMap d) (jet a) (jet b)=beamMap d a b := by simp [evmat,jet] + + let x:=jet (incarn i true); let y:=jet (incarn j false); let z:=jet (none:Hue d) + change evmat _ (z+x+y) (z+x+y)+_+_=_ + rw [quad_cross_gen,evmat_addM,evmat_transpose] + have h1 (a b c e : Hue d) : evmat (beamMap d) (jet a+jet b) (jet c+jet e)= + beamMap d a c+beamMap d b c+(beamMap d a e+beamMap d b e) := by + simp_rw [← he]; unfold evmat; rw [Matrix.mulVec_add,dotProduct_add,add_dotProduct,add_dotProduct] + rw [h1,h1] + simp [beamMap,Matrix.one_apply] + +def libColor (p : Shape) (l : Tag p.g) (u : Vec I) (x : Display p I N) : + AtomKey (p:=p) l N := + fun i b=> if b then (x i.val).1 *ᵥ u else (x i.val).2 *ᵥ u +def libPredict (p : Shape) (l : Tag p.g) (s : Augur p N) (G : Mat I I) (x : Display p I N) + (u : Vec I) := s l (evmat G u u) (libColor p l u x) +def libAug (p : Shape) (l : Tag p.g) (s : Augur p N) (G : Mat I I) (x : Display p I N) (u : Vec I) := + libPredict p l s G x u+evmat G u u + +omit [DecidableEq I] in +theorem lib_see (p : Shape) (l s f) (x : I →Knobs p.g n) + (u : Vec I) (h : weightsAff u) (o : Orient p n N) : + let A := incision p l s f x + let y := compound p x u + libColor p l u (drill p A o) = keyOne p l s (lit f l y) o := by + intro A y; funext i b + cases b + · change (primary _* A) *ᵥ u=primary _*ᵥ spring _ _ _ _ _ + rw [←Matrix.mulVec_mulVec,inc_compound p l s f x u h]; rfl + change (primary _ * A)*ᵥ u=primary _*ᵥ spring _ _ _ _ _ + rw [← Matrix.mulVec_mulVec,inc_compound p l s f x u h]; rfl +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticSliceComparison.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticSliceComparison.lean index 359cb1ed5362205b7f7044cf5355e49f0edb7e8a..34e3ef075a8aafaebb79e5d392d9c72e571f6c63 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticSliceComparison.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticSliceComparison.lean @@ -1,91 +1,91 @@ -import OAI.Combinatorics.HadwigerCounterexample.NominalPointArrays - -namespace OAI - -/-! # Synthetic Slice Comparison -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module LinearMap Function Finset -open scoped BigOperators -variable {p : Shape} {I J : Type} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] -variable {n N : ℕ} - -abbrev Display (p : Shape) (I : Type) (N : ℕ) := Comp p.g → Rack I N -def displayLaw (p : Shape) (I : Type) [Fintype I] [DecidableEq I] (N : ℕ) (G : Mat I I) : - Wgt (Display p I N) := prodW (fun (_:Comp p.g) => unifOn (gramGood G)) - -theorem display_law (p : Shape) (G : Mat I I) (N : ℕ) (hN : 2*num I-(N:ℝ)≤ -1) : - IsLaw (displayLaw p I N G) := by - have hU : num I + num I-num (Fin N) ≤ -1 := by - rw [← two_mul]; simpa only [num,Fintype.card_fin] using hN - have hh := gram_norm_quarter G hU - have ht : IsLaw (unifOn (gramGood G (U:=Fin N))) := by - rw [←on_unif]; exact on_law unif_law.nz ((div_pos (bp_pos _) (by norm_num : 0<(4:ℝ))).trans_le hh) - exact prodW_law (fun i : Comp p.g => ht) - -def drill (p : Shape) (A : Mat (Row p n) I) (o : Orient p n N) : Display p I N := - fun i => peer p A A (o i) - -theorem drill_law (p : Shape) {A : Mat (Row p n) I} (h : Injective A.mulVec) - (m : Mixer p n) (hN : 2*num (Full p n)w) (fun i=>peer p A A (N:=N)) - rw [peer_cap _ _ hN h h] at hh - exact hh - -def drStage (p : Shape) (I : Type) : Route (Comp p.g × I) (Comp p.g) := Prod.fst - -def drQuery (A : Mat (Row p n) I) : NomQuery p n (drStage p I) := - fun j => A.submatrix _root_.id (fun i : Port (drStage p I) j => i.val.2) - -omit [DecidableEq I] in -theorem drill_view (p : Shape) {A : Mat (Row p n) I} (o : Orient p n N) : - drill p A o= relay (Comp p.g) I N - (peekR p (drStage p I) (drQuery A) (drQuery A) o) := by - funext i; apply Prod.ext <;> rfl - -theorem bloom_incision (p : Shape) (n : ℕ) (x : J→I→ Knobs p.g n) - (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) - (h : bloom p x) (a : J) : - Injective (incision p l s f (x a)).mulVec := by - classical - let M := incision p l s f (x a); let T:= freeNet p x - let g := Prod.mk a (β:=I) - have he (i : I) (j) : M (emptySel,some (Block.Z,j)) i=T j (g i) := by - change point _ _ _ _=_ - rw [point_base_eval] - exact ite_eq_left (Flavor.keepZ ..) - intro y z hy - refine inject_column_slice T h (show Injective g from fun i j h=>congrArg Prod.snd h) ?_ - funext i - have hh:= congr_fun hy (emptySel,some (Block.Z,i)) - change ∑ j:I,M _ _*_=∑ j:I, M _ _*_ at hh - simp_rw [he] at hh; exact hh -theorem bloom_drill (p : Shape) (n : ℕ) (x : J→I→ Knobs p.g n) - (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) - (h : bloom p x) (i : Comp p.g) : - Injective (pooled (fun j=> drQuery (incision p l s f (x j))) i).mulVec := by - classical - let r := fun y : J×(Comp p.g × I)=> (y.1,y.2.2) - let T := tied (drStage p I) J - have hr : Injective (fun a : Port T i=> r a.val) := by - rintro ⟨⟨j,a,c⟩,ha⟩ ⟨⟨j',b,d⟩,hb⟩ hh - change (j,c)=(j',d) at hh - cases hh - cases ha; cases hb; rfl - refine ray_bloom (b:=r) _ _ h hr ?_ - intro j k - change point p s (lit f l (x (r j.val).1 (r j.val).2)) (emptySel,some (Block.Z,k))=freeNet p x k (r j.val) - rw [point_base_eval]; exact ite_eq_left (Flavor.keepZ ..) - -def labGram (p : Shape) (l : Tag p.g) (s : Flavor p.g) (a : I→ Tickets p) : Mat I I := - Matrix.of (fun i j => tabGram p l s (a i) (a j)) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.NominalPointArrays + +namespace OAI + +/-! # Synthetic Slice Comparison -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module LinearMap Function Finset +open scoped BigOperators +variable {p : Shape} {I J : Type} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] +variable {n N : ℕ} + +abbrev Display (p : Shape) (I : Type) (N : ℕ) := Comp p.g → Rack I N +def displayLaw (p : Shape) (I : Type) [Fintype I] [DecidableEq I] (N : ℕ) (G : Mat I I) : + Wgt (Display p I N) := prodW (fun (_:Comp p.g) => unifOn (gramGood G)) + +theorem display_law (p : Shape) (G : Mat I I) (N : ℕ) (hN : 2*num I-(N:ℝ)≤ -1) : + IsLaw (displayLaw p I N G) := by + have hU : num I + num I-num (Fin N) ≤ -1 := by + rw [← two_mul]; simpa only [num,Fintype.card_fin] using hN + have hh := gram_norm_quarter G hU + have ht : IsLaw (unifOn (gramGood G (U:=Fin N))) := by + rw [←on_unif]; exact on_law unif_law.nz ((div_pos (bp_pos _) (by norm_num : 0<(4:ℝ))).trans_le hh) + exact prodW_law (fun i : Comp p.g => ht) + +def drill (p : Shape) (A : Mat (Row p n) I) (o : Orient p n N) : Display p I N := + fun i => peer p A A (o i) + +theorem drill_law (p : Shape) {A : Mat (Row p n) I} (h : Injective A.mulVec) + (m : Mixer p n) (hN : 2*num (Full p n)w) (fun i=>peer p A A (N:=N)) + rw [peer_cap _ _ hN h h] at hh + exact hh + +def drStage (p : Shape) (I : Type) : Route (Comp p.g × I) (Comp p.g) := Prod.fst + +def drQuery (A : Mat (Row p n) I) : NomQuery p n (drStage p I) := + fun j => A.submatrix _root_.id (fun i : Port (drStage p I) j => i.val.2) + +omit [DecidableEq I] in +theorem drill_view (p : Shape) {A : Mat (Row p n) I} (o : Orient p n N) : + drill p A o= relay (Comp p.g) I N + (peekR p (drStage p I) (drQuery A) (drQuery A) o) := by + funext i; apply Prod.ext <;> rfl + +theorem bloom_incision (p : Shape) (n : ℕ) (x : J→I→ Knobs p.g n) + (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) + (h : bloom p x) (a : J) : + Injective (incision p l s f (x a)).mulVec := by + classical + let M := incision p l s f (x a); let T:= freeNet p x + let g := Prod.mk a (β:=I) + have he (i : I) (j) : M (emptySel,some (Block.Z,j)) i=T j (g i) := by + change point _ _ _ _=_ + rw [point_base_eval] + exact ite_eq_left (Flavor.keepZ ..) + intro y z hy + refine inject_column_slice T h (show Injective g from fun i j h=>congrArg Prod.snd h) ?_ + funext i + have hh:= congr_fun hy (emptySel,some (Block.Z,i)) + change ∑ j:I,M _ _*_=∑ j:I, M _ _*_ at hh + simp_rw [he] at hh; exact hh +theorem bloom_drill (p : Shape) (n : ℕ) (x : J→I→ Knobs p.g n) + (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) + (h : bloom p x) (i : Comp p.g) : + Injective (pooled (fun j=> drQuery (incision p l s f (x j))) i).mulVec := by + classical + let r := fun y : J×(Comp p.g × I)=> (y.1,y.2.2) + let T := tied (drStage p I) J + have hr : Injective (fun a : Port T i=> r a.val) := by + rintro ⟨⟨j,a,c⟩,ha⟩ ⟨⟨j',b,d⟩,hb⟩ hh + change (j,c)=(j',d) at hh + cases hh + cases ha; cases hb; rfl + refine ray_bloom (b:=r) _ _ h hr ?_ + intro j k + change point p s (lit f l (x (r j.val).1 (r j.val).2)) (emptySel,some (Block.Z,k))=freeNet p x k (r j.val) + rw [point_base_eval]; exact ite_eq_left (Flavor.keepZ ..) + +def labGram (p : Shape) (l : Tag p.g) (s : Flavor p.g) (a : I→ Tickets p) : Mat I I := + Matrix.of (fun i j => tabGram p l s (a i) (a j)) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticSliceExperiments.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticSliceExperiments.lean index 59d0a9085ca51008dc2298aba0a3512c541ecf53..37d7c8a687e8b147e9fcf4d83cc2c74a2b4f86ff 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticSliceExperiments.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticSliceExperiments.lean @@ -1,120 +1,120 @@ -import OAI.Combinatorics.HadwigerCounterexample.CommonPredictions - -namespace OAI - -/-! # Synthetic Slice Experiments -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module Function Finset -open scoped BigOperators -variable {p : Shape} {n : ℕ} - -abbrev Punch (p : Shape) := ProbeIdx p.g × Fin p.r -abbrev Gauge (p : Shape) := Punch p × Bool -def gaugeAddr (p : Shape) (i : Gauge p) := if i.2 then 2*i.1.2.val else 2*i.1.2.val+1 -def usesPunch (p : Shape) (l : Tag p.g) (f : Flavor p.g) (i : Punch p) := f.keeps l - (asBlock i.1) -instance (p : Shape) (l f i) : Decidable (usesPunch p l f i) := Classical.propDecidable _ - -abbrev Tickets (p : Shape) := Vec (Gauge p) -def punchField (p : Shape) (x : Knobs p.g n) : Tickets p := - fun i => zget (x (asBlock i.1.1)) (gaugeAddr p i) -def issued (p : Shape) (w : Tickets p) (x : Knobs p.g n) := punchField p x=w - -def rung (p : Shape) (n : ℕ) (w : Tickets p) : Wgt (Knobs p.g n) := - onW (spins p n) (issued p w) -def ticketsFee (p : Shape) := (1/2:ℝ)^Fintype.card (Gauge p) -theorem ticketsFee_pos (p : Shape) : 0 simp only [gaugeAddr] - all_goals - simp - omega - let g : Gauge p → BaseIdx p.g n := fun i => (asBlock i.1.1,⟨gaugeAddr p i,he i⟩) - have hi : Injective g := by - rintro ⟨⟨i,j⟩,c⟩ ⟨⟨k,l⟩,d⟩ hh - obtain rfl : i=k := asBlock_inj (congrArg Prod.fst hh) - have hh := congrArg (fun x : BaseIdx p.g n=>x.2.val) hh - cases c <;> cases d - all_goals - simp only [g,gaugeAddr,Bool.false_eq_true, ↓reduceIte] at hh - first - | solve | omega - | solve | simp [Fin.ext (show j.val=l.val from by omega)] - let e : Base p.g n≃Knobs p.g n := ⟨curry,uncurry,fun _=>rfl,fun _=>rfl⟩ - have hh (x : Base p.g n) : issued p w (e x)↔ ∀ i,x (g i)=w i := by - unfold issued - rw [funext_iff] - simp only [punchField,zget,dite_eq_left (he _)] - rfl - rw [spins,←draws_unif,← unif_equiv e,mapW_pr] - simp_rw [hh]; rw [draws_unif] - change pr (prodW (fun (_ : BaseIdx p.g n)=>unif)) _= _ - rw [prodW_pr_inj hi (fun _=>unif_law) (fun i y=>y=w i)] - simp only [pr_point',unif_apply,F,ZMod.card,ticketsFee] - simp - -theorem ticketLaw (n : ℕ) (w : Tickets p) (h : 2*p.r≤n) : IsLaw (rung p n w) := - on_law (spins_law p n).nz ((ticketsFee_pos p).trans_eq (rungPrice n w h).symm) -theorem ticketFlow (n : ℕ) (w : Tickets p) (h : 2*p.r≤n) : - mapW (rung p n w) (freePart p)=unif := by - refine fresh_Z p n (issued p w) (fun x y=>?_) (ticketLaw n w h) - have hi : punchField p (x+Pi.single Block.Z y)=punchField p x := by - classical - funext i - have hh : asBlock i.1.1≠Block.Z := by - rcases i with ⟨⟨⟨i,j⟩|⟨⟩,b⟩,c⟩ <;> simp [asBlock,Block.O,Block.S,Block.Z] - unfold punchField; simp only [Pi.add_apply,Pi.single_eq_of_ne hh,add_zero] - unfold issued; rw [hi] -theorem ticketCap (n : ℕ) (w : Tickets p) (h : 2*p.r≤n) : - ∀ x,rung p n w x≤(ticketsFee p)⁻¹ * spins p n x := - on_mon (spins_law p n).nz (ticketsFee_pos p) (le_of_eq (Eq.symm (rungPrice n w h))) - -def tabGram (p : Shape) (l : Tag p.g) (f : Flavor p.g) (x y : Tickets p) := - ∑ i:Punch p, if usesPunch p l f i then x (i,true)*y (i,false) else 0 - -theorem tabGram_sound (p : Shape) (n : ℕ) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) - (x y : Knobs p.g n) (m : Mixer p n) (hj : 1 ≤ p.j) : - let E:=selfM p n m.mixM - evmat E (spring p l s f x) (spring p l s f y)=tabGram p l f (punchField p x) - (punchField p y) := by - classical - intro E - let z (x : Knobs p.g n) := lit f l x - let A (B : Block p.g) := test p n B (z x) (z y) - let h i := usesPunch p l f i - have hX (i : ProbeIdx p.g) : - A (asBlock i) = ∑ j : Fin p.r, (fun t:Punch p => if usesPunch p l f t then - punchField p x (t,true)*punchField p y (t,false) else 0) (i,j) := by - unfold A test z; refine Finset.sum_congr rfl fun j _=>?_ - let B := asBlock i - have he (u : Knobs p.g n) (k) : - readBit (lit f l u) B k=if f.keeps l B then zget (u B) k else 0 := by - by_cases hh : k simp [lit,zget,readBit,hh] - by_cases ht : f.keeps l B - · rw [he,he,ite_eq_left ht,ite_eq_left ht] - exact Eq.symm (ite_eq_left (show usesPunch p l f (i,j) from ht)) - rw [he,he,ite_eq_right ht,ite_eq_right ht,zero_mul] - exact Eq.symm (ite_eq_right (show ¬usesPunch p l f (i,j) from ht)) - rw [←mpair_outer]; unfold E spring selfM; simp_rw [mpair_add,mpair_sum] - rw [sharpM_point _ hj]; simp only [char_two,zero_mul,sum_const_zero,add_zero] - unfold tabGram - rw [Fintype.sum_prod_type,Fintype.sum_sum_type,Fintype.sum_prod_type] - simp only [Fintype.sum_unique] - - congr 1 - · refine Finset.sum_congr rfl fun i _=>Finset.sum_congr rfl fun j _=> ?_ - exact (etab_point p (Block.O i j) ..).trans (hX (.inl (i,j))) - exact (etab_point p Block.S ..).trans (hX (.inr ())) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CommonPredictions + +namespace OAI + +/-! # Synthetic Slice Experiments -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module Function Finset +open scoped BigOperators +variable {p : Shape} {n : ℕ} + +abbrev Punch (p : Shape) := ProbeIdx p.g × Fin p.r +abbrev Gauge (p : Shape) := Punch p × Bool +def gaugeAddr (p : Shape) (i : Gauge p) := if i.2 then 2*i.1.2.val else 2*i.1.2.val+1 +def usesPunch (p : Shape) (l : Tag p.g) (f : Flavor p.g) (i : Punch p) := f.keeps l + (asBlock i.1) +instance (p : Shape) (l f i) : Decidable (usesPunch p l f i) := Classical.propDecidable _ + +abbrev Tickets (p : Shape) := Vec (Gauge p) +def punchField (p : Shape) (x : Knobs p.g n) : Tickets p := + fun i => zget (x (asBlock i.1.1)) (gaugeAddr p i) +def issued (p : Shape) (w : Tickets p) (x : Knobs p.g n) := punchField p x=w + +def rung (p : Shape) (n : ℕ) (w : Tickets p) : Wgt (Knobs p.g n) := + onW (spins p n) (issued p w) +def ticketsFee (p : Shape) := (1/2:ℝ)^Fintype.card (Gauge p) +theorem ticketsFee_pos (p : Shape) : 0 simp only [gaugeAddr] + all_goals + simp + omega + let g : Gauge p → BaseIdx p.g n := fun i => (asBlock i.1.1,⟨gaugeAddr p i,he i⟩) + have hi : Injective g := by + rintro ⟨⟨i,j⟩,c⟩ ⟨⟨k,l⟩,d⟩ hh + obtain rfl : i=k := asBlock_inj (congrArg Prod.fst hh) + have hh := congrArg (fun x : BaseIdx p.g n=>x.2.val) hh + cases c <;> cases d + all_goals + simp only [g,gaugeAddr,Bool.false_eq_true, ↓reduceIte] at hh + first + | solve | omega + | solve | simp [Fin.ext (show j.val=l.val from by omega)] + let e : Base p.g n≃Knobs p.g n := ⟨curry,uncurry,fun _=>rfl,fun _=>rfl⟩ + have hh (x : Base p.g n) : issued p w (e x)↔ ∀ i,x (g i)=w i := by + unfold issued + rw [funext_iff] + simp only [punchField,zget,dite_eq_left (he _)] + rfl + rw [spins,←draws_unif,← unif_equiv e,mapW_pr] + simp_rw [hh]; rw [draws_unif] + change pr (prodW (fun (_ : BaseIdx p.g n)=>unif)) _= _ + rw [prodW_pr_inj hi (fun _=>unif_law) (fun i y=>y=w i)] + simp only [pr_point',unif_apply,F,ZMod.card,ticketsFee] + simp + +theorem ticketLaw (n : ℕ) (w : Tickets p) (h : 2*p.r≤n) : IsLaw (rung p n w) := + on_law (spins_law p n).nz ((ticketsFee_pos p).trans_eq (rungPrice n w h).symm) +theorem ticketFlow (n : ℕ) (w : Tickets p) (h : 2*p.r≤n) : + mapW (rung p n w) (freePart p)=unif := by + refine fresh_Z p n (issued p w) (fun x y=>?_) (ticketLaw n w h) + have hi : punchField p (x+Pi.single Block.Z y)=punchField p x := by + classical + funext i + have hh : asBlock i.1.1≠Block.Z := by + rcases i with ⟨⟨⟨i,j⟩|⟨⟩,b⟩,c⟩ <;> simp [asBlock,Block.O,Block.S,Block.Z] + unfold punchField; simp only [Pi.add_apply,Pi.single_eq_of_ne hh,add_zero] + unfold issued; rw [hi] +theorem ticketCap (n : ℕ) (w : Tickets p) (h : 2*p.r≤n) : + ∀ x,rung p n w x≤(ticketsFee p)⁻¹ * spins p n x := + on_mon (spins_law p n).nz (ticketsFee_pos p) (le_of_eq (Eq.symm (rungPrice n w h))) + +def tabGram (p : Shape) (l : Tag p.g) (f : Flavor p.g) (x y : Tickets p) := + ∑ i:Punch p, if usesPunch p l f i then x (i,true)*y (i,false) else 0 + +theorem tabGram_sound (p : Shape) (n : ℕ) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) + (x y : Knobs p.g n) (m : Mixer p n) (hj : 1 ≤ p.j) : + let E:=selfM p n m.mixM + evmat E (spring p l s f x) (spring p l s f y)=tabGram p l f (punchField p x) + (punchField p y) := by + classical + intro E + let z (x : Knobs p.g n) := lit f l x + let A (B : Block p.g) := test p n B (z x) (z y) + let h i := usesPunch p l f i + have hX (i : ProbeIdx p.g) : + A (asBlock i) = ∑ j : Fin p.r, (fun t:Punch p => if usesPunch p l f t then + punchField p x (t,true)*punchField p y (t,false) else 0) (i,j) := by + unfold A test z; refine Finset.sum_congr rfl fun j _=>?_ + let B := asBlock i + have he (u : Knobs p.g n) (k) : + readBit (lit f l u) B k=if f.keeps l B then zget (u B) k else 0 := by + by_cases hh : k simp [lit,zget,readBit,hh] + by_cases ht : f.keeps l B + · rw [he,he,ite_eq_left ht,ite_eq_left ht] + exact Eq.symm (ite_eq_left (show usesPunch p l f (i,j) from ht)) + rw [he,he,ite_eq_right ht,ite_eq_right ht,zero_mul] + exact Eq.symm (ite_eq_right (show ¬usesPunch p l f (i,j) from ht)) + rw [←mpair_outer]; unfold E spring selfM; simp_rw [mpair_add,mpair_sum] + rw [sharpM_point _ hj]; simp only [char_two,zero_mul,sum_const_zero,add_zero] + unfold tabGram + rw [Fintype.sum_prod_type,Fintype.sum_sum_type,Fintype.sum_prod_type] + simp only [Fintype.sum_unique] + + congr 1 + · refine Finset.sum_congr rfl fun i _=>Finset.sum_congr rfl fun j _=> ?_ + exact (etab_point p (Block.O i j) ..).trans (hX (.inl (i,j))) + exact (etab_point p Block.S ..).trans (hX (.inr ())) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticTolerances.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticTolerances.lean index 959a89ae39cb1a9b2ba6d59dc88a8c5812c603d6..9b41fef03f8db13617d370faa2b44022690244e7 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticTolerances.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/SyntheticTolerances.lean @@ -1,73 +1,73 @@ -import OAI.Combinatorics.HadwigerCounterexample.GramArrayConcentration - -namespace OAI - -/-! # Synthetic Tolerances -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Function Filter Real -open scoped BigOperators Topology -variable {p : Shape} {I : Type} [Fintype I] [DecidableEq I] {n N : ℕ} - -theorem magazine_calendar (p : Shape) (I : Type) [Fintype I] [DecidableEq I] - (M : ℕ) (hM : 1≤M) (hj : 1≤p.j) (L ε : ℝ) (hL : 0≤L) (hε : 0<ε) : - ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ l s f, ∀ m : Mixer p n,2*num (Full p n)L*C n) atTop (𝓝 0) := by - have hh {N:ℕ→ℝ} (h : Tendsto N atTop atTop) (i : ℝ) (b : ℝ) (hb : 0 bp (i-b*N n)) atTop (𝓝 0) := by - simp_rw [sub_eq_add_neg,bp_add,←neg_mul] - simpa using ((bp_tendsto_zero hb).comp h).const_mul (bp i) - have hN := cast_tops M hM - have h1 := (hh hN k 1 (by norm_num)) - have h2 : Tendsto (fun n:ℕ => bp (-(↑(M*n):ℝ)/2)) atTop (𝓝 0) := by - refine (tendsto_congr' ?_).mp (hh hN 0 (1/2) (by norm_num)) - exact .of_forall (fun x => by ring_nf) - have h3 := hh (tendsto_natCast_atTop_atTop (R:=ℝ)) (num Bool*num I) 1 (by norm_num) - have hv := (((((h1.const_mul 2).const_mul (num (Comp p.g))).add h2).const_mul - (2*netFact g)).add h3).const_mul L - simpa only [C,twinkle,mul_zero,zero_add,add_zero,one_mul] using hv - let b:= ε/2 - have hb : 0sq_nonneg (u i - F)) he).trans ?_ - apply le_trans ?_ (mul_le_mul_of_nonneg_left hh hL) - simp only [X,avg,mul_assoc,Finset.mul_sum] - exact le_rfl - exact not_lt_of_ge (hB.trans hX) hn -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.GramArrayConcentration + +namespace OAI + +/-! # Synthetic Tolerances -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Function Filter Real +open scoped BigOperators Topology +variable {p : Shape} {I : Type} [Fintype I] [DecidableEq I] {n N : ℕ} + +theorem magazine_calendar (p : Shape) (I : Type) [Fintype I] [DecidableEq I] + (M : ℕ) (hM : 1≤M) (hj : 1≤p.j) (L ε : ℝ) (hL : 0≤L) (hε : 0<ε) : + ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ l s f, ∀ m : Mixer p n,2*num (Full p n)L*C n) atTop (𝓝 0) := by + have hh {N:ℕ→ℝ} (h : Tendsto N atTop atTop) (i : ℝ) (b : ℝ) (hb : 0 bp (i-b*N n)) atTop (𝓝 0) := by + simp_rw [sub_eq_add_neg,bp_add,←neg_mul] + simpa using ((bp_tendsto_zero hb).comp h).const_mul (bp i) + have hN := cast_tops M hM + have h1 := (hh hN k 1 (by norm_num)) + have h2 : Tendsto (fun n:ℕ => bp (-(↑(M*n):ℝ)/2)) atTop (𝓝 0) := by + refine (tendsto_congr' ?_).mp (hh hN 0 (1/2) (by norm_num)) + exact .of_forall (fun x => by ring_nf) + have h3 := hh (tendsto_natCast_atTop_atTop (R:=ℝ)) (num Bool*num I) 1 (by norm_num) + have hv := (((((h1.const_mul 2).const_mul (num (Comp p.g))).add h2).const_mul + (2*netFact g)).add h3).const_mul L + simpa only [C,twinkle,mul_zero,zero_add,add_zero,one_mul] using hv + let b:= ε/2 + have hb : 0sq_nonneg (u i - F)) he).trans ?_ + apply le_trans ?_ (mul_le_mul_of_nonneg_left hh hL) + simp only [X,avg,mul_assoc,Finset.mul_sum] + exact le_rfl + exact not_lt_of_ge (hB.trans hX) hn +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/TableInjectionTransfer.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/TableInjectionTransfer.lean index 86d147d3dbd08be72d58829e41f7ce7a34d458be..d5c0c8b562398f56a05347dd1620d1e38b8d1b8e 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/TableInjectionTransfer.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/TableInjectionTransfer.lean @@ -1,167 +1,167 @@ -import OAI.Combinatorics.HadwigerCounterexample.InjectionWitnesses - -namespace OAI - -/-! # Table Injection Transfer -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Submodule Function Finset -open scoped BigOperators -variable {p : Shape} {n N : ℕ} -variable {A B : Type} - -def named (P : A×A → Prop) (C : ℝ) := - ∃ k : ℕ,(k:ℝ) ≤ C ∧ ∃ S : Fin k → A → Prop,∀ y,∃ i,∀ x,P (x,y)↔S i x - -theorem named_at [Fintype B] {P : A×A → Prop} {C : ℝ} - (S : B → A → Prop) (h : (Fintype.card B:ℝ) ≤ C) - (he : ∀ y,∃ i,∀ x,P (x,y) ↔ S i x) : - named P C := by - classical - let e := Fintype.equivFin B - refine ⟨Fintype.card B,h,fun i => S (e.symm i),fun y => ?_⟩ - obtain ⟨i,hi⟩ := he y - exact ⟨e i,by simpa using hi⟩ - -theorem named_true {A : Type} {C : ℝ} (h : 1 ≤ C) : - named (fun _ : A×A => True) C := - ⟨1,(by simpa using h),fun _ _ => True,fun _ => ⟨0,fun _ => Iff.rfl⟩⟩ - -theorem pair_each [Fintype A] (w : Wgt A) (P : A×A→Prop) : - pr (pairW w w) P = avg w (fun y => pr w (fun x => P (x,y))) := by - unfold pr - rw [pairW_avg]; exact avg_avg w w _ - -set_option maxHeartbeats 600000 in -private theorem named_fans {P : UnitType p n N × UnitType p n N → Prop} - {C U L l : ℝ} (hP : named P C) (hu : 0 P x ∧ fans b z i j x.1 x.2) ≤ - 3*l* pr (pairW w w) P + U+ C*(fireBill p k K L/(pushCost l K)^k) := by - classical - obtain ⟨t,hC,S,hS⟩ := hP - let v := onW w - let f := fans b z i j - let event (y : UnitType p n N) := - ∃ a : Fin t,U≤pr w (S a) ∧ 3*l≤pr (v (S a)) (fun x => f x y) - let R := fireBill p k K L/(pushCost l K)^k - have hR : 0 ≤ R := by - refine div_nonneg ?_ (pow_nonneg (div_pos hℓ (bp_pos _)).le _) - exact mul_nonneg (by positivity) (bp_pos _).le - have he : pr w event ≤ C * R := by - let Q (a : Fin t) := fun y => U ≤ pr w (S a) ∧ 3*l≤pr (v (S a)) (fun x => f x y) - have h a : pr w (Q a) ≤ R := by - by_cases ht : U≤pr w (S a) - · have hv := on_law hw.nz (lt_of_lt_of_le hu ht) - have hk := bySide_on m hw.nz hm (S a) (show 0<2*U by positivity) (by linarith) - simp only [Q,ht,true_and] - exact cannon K k hb z i j (v (S a)) w hv hw hℓ m (by unfold rhUp; positivity) - hl hk hm hN hf - simp only [Q,ht,false_and,pr_false]; exact hR - refine (pr_exists_le hw.nz Q).trans ?_ - refine (Finset.sum_le_sum fun i _ => h i).trans ?_ - rw [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] - exact mul_le_mul_of_nonneg_right hC hR - have hU (y : UnitType p n N) : - pr w (fun x => P (x,y) ∧ f x y) ≤ 3*l*pr w (fun x => P (x,y)) + U + ind (event y) := by - obtain ⟨a,ha⟩ := hS y - simp_rw [ha] - have h1 := pr_nonneg (p:=S a) hw.nz - have hr := mul_nonneg (show 0≤3*l by linarith) h1 - by_cases h : U≤pr w (S a) - · by_cases ht : 3*l ≤ pr (v (S a)) (fun x => f x y) - · rw [ind_one (show event y from ⟨a,h,ht⟩)] - exact ((pr_le_tot hw.nz).trans hw.total.le).trans (by linarith only [hr,hu]) - rw [pr_of_on hw.nz] - have hj := mul_le_mul_of_nonneg_left (le_of_not_ge ht) h1 - have hi := ind_nonneg (event y) - refine hj.trans ?_ - linarith only [hi,hu] - have hh := (pr_mono hw.nz (p:=fun x => S a x∧ f x y) (q:=S a) fun x h => h.1).trans - (le_of_not_ge h) - refine hh.trans ?_ - linarith only [hr,ind_nonneg (event y)] - rw [pair_each,pair_each] - apply (avg_mono hw.nz hU).trans - rw [avg_add,avg_add,avg_mul',hw.avg_const] - exact add_le_add_right he _ - -def acceptsInj (p : Shape) {n N} (b : Fpins p n N) (x : UnitType p n N×UnitType p n N) := - tableInj (b x.1) (b x.2) (actual p x.1 x.2) - -set_option maxHeartbeats 800000 in -theorem secure_one {P : UnitType p n N × UnitType p n N → Prop} - {C U L l : ℝ} (hP : named P C) (hu : 0 P x ∧ ¬ acceptsInj p b x) ≤ - (4*num (Place p))*(3*l* pr (pairW w w) P + U+ C*(fireBill p k K L/(pushCost l K)^k)) := by - classical - let J := Place p × Bool × Bool - let Q := fun (u : Place p × Bool × Bool) (x : UnitType p n N × _) => - P x ∧ fans b u.1 u.2.1 u.2.2 x.1 x.2 - let v := pairW w w - have hh x (h : v x≠0) (hf : P x ∧ ¬ acceptsInj p b x) : ∃ i,Q i x := by - obtain ⟨z,i,j,hf₀⟩ := fans_of_not_inj b _ _ m (hx x.1 (left_ne_zero_of_mul h)) hf.2 - exact ⟨(z,i,j),⟨hf.1,hf₀⟩⟩ - have hv := (pairW_law hw hw).nz - refine ((pr_on_mono hv hh).trans (pr_exists_le hv Q)).trans ?_ - refine (Finset.sum_le_sum fun i _ => named_fans hP hu hl hℓ w b K k hb hw m hm i.2.1 i.2.2 i.1 - hN hf).trans_eq ?_ - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,Fintype.card_prod,num,Fintype.card_bool] - push_cast - ring - -theorem perm_pair_prob [Fintype A] (w : Wgt A) (P : A × A→ Prop) : - pr (pairW w w) (P ∘ Prod.swap)=pr (pairW w w) P := by - rw [pair_each] - unfold pr; rw [pairW_avg]; rfl - -def secureAt (p : Shape) {n N} (b : Fpins p n N) (x : UnitType p n N×UnitType p n N) := - acceptsInj p b x ∧ acceptsInj p b x.swap - -theorem secure_bound {P : UnitType p n N × UnitType p n N → Prop} - {C U L l : ℝ} (hP : named P C) (hq : named (P ∘ Prod.swap) C) - (hu : 0 P x ∧ ¬ secureAt p b x) ≤ - 8*num (Place p)*(3*l*pr (pairW w w) P+U+C*(fireBill p k K L/(pushCost l K)^k)) := by - classical - let Q := acceptsInj p b - let v := pairW w w - have he := secure_one hP hu hl hℓ w b K k hb hw m hm hx hN hf - have ht : - pr v (fun x => P x∧¬ Q x.swap)≤ - 4*num (Place p)*(3*l*pr v P+U+C*(fireBill p k K L/(pushCost l K)^k)) := by - rw [←perm_pair_prob w (fun x => P x∧¬Q x.swap),←perm_pair_prob w P] - have h : (fun x => P x∧¬Q x.swap) ∘ Prod.swap = fun x => P x.swap∧¬ Q x := by - funext x; rw [Function.comp_apply,Prod.swap_swap] - rw [h]; exact secure_one hq hu hl hℓ w b K k hb hw m hm hx hN hf - have hx x : P x ∧ ¬secureAt p b x → (P x∧¬Q x)∨ (P x ∧¬Q x.swap) := by - intro h - have hh : P x∧¬ (Q x∧Q x.swap) := h - tauto - have hv := (pairW_law hw hw).nz - refine ((pr_mono hv hx).trans ((pr_or_le hv).trans (add_le_add he ht))).trans_eq ?_ - unfold v - ring - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.InjectionWitnesses + +namespace OAI + +/-! # Table Injection Transfer -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Function Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} +variable {A B : Type} + +def named (P : A×A → Prop) (C : ℝ) := + ∃ k : ℕ,(k:ℝ) ≤ C ∧ ∃ S : Fin k → A → Prop,∀ y,∃ i,∀ x,P (x,y)↔S i x + +theorem named_at [Fintype B] {P : A×A → Prop} {C : ℝ} + (S : B → A → Prop) (h : (Fintype.card B:ℝ) ≤ C) + (he : ∀ y,∃ i,∀ x,P (x,y) ↔ S i x) : + named P C := by + classical + let e := Fintype.equivFin B + refine ⟨Fintype.card B,h,fun i => S (e.symm i),fun y => ?_⟩ + obtain ⟨i,hi⟩ := he y + exact ⟨e i,by simpa using hi⟩ + +theorem named_true {A : Type} {C : ℝ} (h : 1 ≤ C) : + named (fun _ : A×A => True) C := + ⟨1,(by simpa using h),fun _ _ => True,fun _ => ⟨0,fun _ => Iff.rfl⟩⟩ + +theorem pair_each [Fintype A] (w : Wgt A) (P : A×A→Prop) : + pr (pairW w w) P = avg w (fun y => pr w (fun x => P (x,y))) := by + unfold pr + rw [pairW_avg]; exact avg_avg w w _ + +set_option maxHeartbeats 600000 in +private theorem named_fans {P : UnitType p n N × UnitType p n N → Prop} + {C U L l : ℝ} (hP : named P C) (hu : 0 P x ∧ fans b z i j x.1 x.2) ≤ + 3*l* pr (pairW w w) P + U+ C*(fireBill p k K L/(pushCost l K)^k) := by + classical + obtain ⟨t,hC,S,hS⟩ := hP + let v := onW w + let f := fans b z i j + let event (y : UnitType p n N) := + ∃ a : Fin t,U≤pr w (S a) ∧ 3*l≤pr (v (S a)) (fun x => f x y) + let R := fireBill p k K L/(pushCost l K)^k + have hR : 0 ≤ R := by + refine div_nonneg ?_ (pow_nonneg (div_pos hℓ (bp_pos _)).le _) + exact mul_nonneg (by positivity) (bp_pos _).le + have he : pr w event ≤ C * R := by + let Q (a : Fin t) := fun y => U ≤ pr w (S a) ∧ 3*l≤pr (v (S a)) (fun x => f x y) + have h a : pr w (Q a) ≤ R := by + by_cases ht : U≤pr w (S a) + · have hv := on_law hw.nz (lt_of_lt_of_le hu ht) + have hk := bySide_on m hw.nz hm (S a) (show 0<2*U by positivity) (by linarith) + simp only [Q,ht,true_and] + exact cannon K k hb z i j (v (S a)) w hv hw hℓ m (by unfold rhUp; positivity) + hl hk hm hN hf + simp only [Q,ht,false_and,pr_false]; exact hR + refine (pr_exists_le hw.nz Q).trans ?_ + refine (Finset.sum_le_sum fun i _ => h i).trans ?_ + rw [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + exact mul_le_mul_of_nonneg_right hC hR + have hU (y : UnitType p n N) : + pr w (fun x => P (x,y) ∧ f x y) ≤ 3*l*pr w (fun x => P (x,y)) + U + ind (event y) := by + obtain ⟨a,ha⟩ := hS y + simp_rw [ha] + have h1 := pr_nonneg (p:=S a) hw.nz + have hr := mul_nonneg (show 0≤3*l by linarith) h1 + by_cases h : U≤pr w (S a) + · by_cases ht : 3*l ≤ pr (v (S a)) (fun x => f x y) + · rw [ind_one (show event y from ⟨a,h,ht⟩)] + exact ((pr_le_tot hw.nz).trans hw.total.le).trans (by linarith only [hr,hu]) + rw [pr_of_on hw.nz] + have hj := mul_le_mul_of_nonneg_left (le_of_not_ge ht) h1 + have hi := ind_nonneg (event y) + refine hj.trans ?_ + linarith only [hi,hu] + have hh := (pr_mono hw.nz (p:=fun x => S a x∧ f x y) (q:=S a) fun x h => h.1).trans + (le_of_not_ge h) + refine hh.trans ?_ + linarith only [hr,ind_nonneg (event y)] + rw [pair_each,pair_each] + apply (avg_mono hw.nz hU).trans + rw [avg_add,avg_add,avg_mul',hw.avg_const] + exact add_le_add_right he _ + +def acceptsInj (p : Shape) {n N} (b : Fpins p n N) (x : UnitType p n N×UnitType p n N) := + tableInj (b x.1) (b x.2) (actual p x.1 x.2) + +set_option maxHeartbeats 800000 in +theorem secure_one {P : UnitType p n N × UnitType p n N → Prop} + {C U L l : ℝ} (hP : named P C) (hu : 0 P x ∧ ¬ acceptsInj p b x) ≤ + (4*num (Place p))*(3*l* pr (pairW w w) P + U+ C*(fireBill p k K L/(pushCost l K)^k)) := by + classical + let J := Place p × Bool × Bool + let Q := fun (u : Place p × Bool × Bool) (x : UnitType p n N × _) => + P x ∧ fans b u.1 u.2.1 u.2.2 x.1 x.2 + let v := pairW w w + have hh x (h : v x≠0) (hf : P x ∧ ¬ acceptsInj p b x) : ∃ i,Q i x := by + obtain ⟨z,i,j,hf₀⟩ := fans_of_not_inj b _ _ m (hx x.1 (left_ne_zero_of_mul h)) hf.2 + exact ⟨(z,i,j),⟨hf.1,hf₀⟩⟩ + have hv := (pairW_law hw hw).nz + refine ((pr_on_mono hv hh).trans (pr_exists_le hv Q)).trans ?_ + refine (Finset.sum_le_sum fun i _ => named_fans hP hu hl hℓ w b K k hb hw m hm i.2.1 i.2.2 i.1 + hN hf).trans_eq ?_ + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,Fintype.card_prod,num,Fintype.card_bool] + push_cast + ring + +theorem perm_pair_prob [Fintype A] (w : Wgt A) (P : A × A→ Prop) : + pr (pairW w w) (P ∘ Prod.swap)=pr (pairW w w) P := by + rw [pair_each] + unfold pr; rw [pairW_avg]; rfl + +def secureAt (p : Shape) {n N} (b : Fpins p n N) (x : UnitType p n N×UnitType p n N) := + acceptsInj p b x ∧ acceptsInj p b x.swap + +theorem secure_bound {P : UnitType p n N × UnitType p n N → Prop} + {C U L l : ℝ} (hP : named P C) (hq : named (P ∘ Prod.swap) C) + (hu : 0 P x ∧ ¬ secureAt p b x) ≤ + 8*num (Place p)*(3*l*pr (pairW w w) P+U+C*(fireBill p k K L/(pushCost l K)^k)) := by + classical + let Q := acceptsInj p b + let v := pairW w w + have he := secure_one hP hu hl hℓ w b K k hb hw m hm hx hN hf + have ht : + pr v (fun x => P x∧¬ Q x.swap)≤ + 4*num (Place p)*(3*l*pr v P+U+C*(fireBill p k K L/(pushCost l K)^k)) := by + rw [←perm_pair_prob w (fun x => P x∧¬Q x.swap),←perm_pair_prob w P] + have h : (fun x => P x∧¬Q x.swap) ∘ Prod.swap = fun x => P x.swap∧¬ Q x := by + funext x; rw [Function.comp_apply,Prod.swap_swap] + rw [h]; exact secure_one hq hu hl hℓ w b K k hb hw m hm hx hN hf + have hx x : P x ∧ ¬secureAt p b x → (P x∧¬Q x)∨ (P x ∧¬Q x.swap) := by + intro h + have hh : P x∧¬ (Q x∧Q x.swap) := h + tauto + have hv := (pairW_law hw hw).nz + refine ((pr_mono hv hx).trans ((pr_or_le hv).trans (add_le_add he ht))).trans_eq ?_ + unfold v + ring + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/TemplateTypicality.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/TemplateTypicality.lean index f273c1e1fd6d270b681d2dd762eff3b02ccb6c9c..7d668a4c932e938f666b1405824ed00466dad8f1 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/TemplateTypicality.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/TemplateTypicality.lean @@ -1,126 +1,126 @@ -import OAI.Combinatorics.HadwigerCounterexample.PairedTemplateConcentration - -namespace OAI - -/-! # Template Typicality -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Real Finset Matrix Function -open scoped BigOperators -variable {p : Shape} {M n N : ℕ} -variable {I J G : Type} [Fintype I] [DecidableEq I] - -theorem fork_law {a : I → Type} [∀ i,Fintype (a i)] - (p : I→Prop) [DecidablePred p] (w : ∀ i,Wgt (a i)) : - let E := Equiv.piEquivPiSubtypeProd p a - mapW (prodW w) E=pairW (prodW (fun i:{i // p i} => w i.val)) - (prodW (fun i:{i // ¬p i} => w i.val)) := by - intro E - funext x - obtain ⟨y,rfl⟩ := E.surjective x - rw [mapW_equiv_val,Equiv.symm_apply_apply] - exact (Fintype.prod_subtype_mul_prod_subtype p (fun i => w i (y i))).symm - -namespace Template -variable (v : Template p I) - -def collect (p : Shape) (v : Template p I) (f : J→I) : Template p J := - ⟨v.aim ∘ f, v.t ∘ f, v.s ∘ f,v.f ∘ f⟩ - -abbrev PosA (v : Template p I) := {i:I//v.aim i} -abbrev PosB (v : Template p I) := {i:I//¬v.aim i} -def atA := collect p v (Subtype.val : v.PosA→I) -def atB := collect p v (Subtype.val : v.PosB→I) - -def forkI (n : ℕ) : Inputs p n I ≃ Inputs p n v.PosA × Inputs p n v.PosB := - Equiv.piEquivPiSubtypeProd (fun i:I => v.aim i) (fun _ => _) -def forkK (N : ℕ) : Keys (p:=p) v.t N ≃ Keys (p:=p) v.atA.t N × Keys (p:=p) v.atB.t N := - Equiv.piEquivPiSubtypeProd (fun i:I => v.aim i) (fun i => AtomKey (p:=p) (v.t i) N) - -def sampleAll (u : I→Wgt (Knobs p.g n)) - (T : Inputs p n I → Keys (p:=p) v.t N → ℝ) - (x : UnitType p n N) := - avg (prodW u) (fun i => T i ((v.draw i).keys v.t x)) - -def connectT (T : Inputs p n I → Keys (p:=p) v.t N → ℝ) - (x : v.atA.Datum n N × v.atB.Datum n N) := - T ((v.forkI n).symm (x.1.1,x.2.1)) - ((v.forkK N).symm ((scatter v.atA.t N).symm x.1.2,(scatter v.atB.t N).symm x.2.2)) - -set_option maxHeartbeats 800000 in -theorem connect_avg (u : I→Wgt (Knobs p.g n)) - (T : Inputs p n I → Keys (p:=p) v.t N → ℝ) - (x : UnitType p n N) : - let a := fun i : v.PosA => u i.val - let b := fun i : v.PosB => u i.val - v.sampleAll u T x = avg - (pairW ((v.atA.singleP n).makeData (prodW a) x.1) - ((v.atB.singleP n).makeData (prodW b) x.2)) (v.connectT T) := by - classical - intro a b - let s (i : Inputs p n v.PosA) : v.atA.Datum n N := - (i,(v.atA.singleP n).showKey i x.1) - let t (i : Inputs p n v.PosB) : v.atB.Datum n N := - (i,(v.atB.singleP n).showKey i x.2) - have hi (i : Inputs p n I) : - T i ((v.draw i).keys v.t x) = - v.connectT T (s ((v.forkI n i).1), t ((v.forkI n i).2)) := by - let y := (v.draw i).keys v.t x - let Y := v.forkK N y - have hA : - (scatter v.atA.t N).symm ((v.atA.singleP n).showKey ((v.forkI n i).1) x.1)=Y.1 := by - rw [single_show,Equiv.symm_apply_apply]; funext j - - change keyOne p (v.t j.val) _ _ x.1=keyOne p _ _ _ (onSide x (v.aim j.val)) - rw [j.property]; rfl - have hB : - (scatter v.atB.t N).symm ((v.atB.singleP n).showKey ((v.forkI n i).2) x.2)=Y.2 := by - rw [single_show,Equiv.symm_apply_apply]; funext j - change keyOne p (v.t j.val) _ _ x.2=keyOne p _ _ _ (onSide x (v.aim j.val)) - rw [Bool.eq_false_iff.mpr j.property]; rfl - unfold connectT s t - rw [hA,hB] - simp [Y,Equiv.symm_apply_apply,y] - let Q (j : Inputs p n v.PosA × Inputs p n v.PosB) := v.connectT T (s j.1, t j.2) - calc _ = avg (mapW (prodW u) (v.forkI n)) Q := by - rw [mapW_avg,sampleAll]; simp_rw [hi]; rfl - _ = avg (pairW (prodW a) (prodW b)) Q := congrArg (fun w => avg w Q) - (fork_law (fun i => v.aim i) u) - _ = _ := by - rw [pairW_avg,pairW_avg,Program.makeData,Program.makeData,mapW_avg] - simp_rw [mapW_avg]; rfl - -theorem typical_calendar (v : Template p I) (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) ε≤ |f x-avg ρ f|) ≤ bp (-(1/16:ℝ)*n) := by - classical - filter_upwards [twinned v.atA v.atB M hM C ε hε] - with n hn N m w hw μ ρ H hA hB hw' hN u hu hz T hT f - let a := u ∘ (Subtype.val : v.PosA→I) - let b := u ∘ (Subtype.val : v.PosB→I) - have h := hn m w hw hA hB hw' hN a b - (fun i => hu _) (fun i => hz _) (fun i => hu _) (fun i => hz _) - (connectT v T) (fun x => hT _ _) - have he : f = fun x : UnitType p n N => avg - (pairW ((v.atA.singleP n).makeData (prodW a) x.1) - ((v.atB.singleP n).makeData (prodW b) x.2)) (v.connectT T) := - funext fun x => connect_avg v u T x - rw [he]; exact h - -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PairedTemplateConcentration + +namespace OAI + +/-! # Template Typicality -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Real Finset Matrix Function +open scoped BigOperators +variable {p : Shape} {M n N : ℕ} +variable {I J G : Type} [Fintype I] [DecidableEq I] + +theorem fork_law {a : I → Type} [∀ i,Fintype (a i)] + (p : I→Prop) [DecidablePred p] (w : ∀ i,Wgt (a i)) : + let E := Equiv.piEquivPiSubtypeProd p a + mapW (prodW w) E=pairW (prodW (fun i:{i // p i} => w i.val)) + (prodW (fun i:{i // ¬p i} => w i.val)) := by + intro E + funext x + obtain ⟨y,rfl⟩ := E.surjective x + rw [mapW_equiv_val,Equiv.symm_apply_apply] + exact (Fintype.prod_subtype_mul_prod_subtype p (fun i => w i (y i))).symm + +namespace Template +variable (v : Template p I) + +def collect (p : Shape) (v : Template p I) (f : J→I) : Template p J := + ⟨v.aim ∘ f, v.t ∘ f, v.s ∘ f,v.f ∘ f⟩ + +abbrev PosA (v : Template p I) := {i:I//v.aim i} +abbrev PosB (v : Template p I) := {i:I//¬v.aim i} +def atA := collect p v (Subtype.val : v.PosA→I) +def atB := collect p v (Subtype.val : v.PosB→I) + +def forkI (n : ℕ) : Inputs p n I ≃ Inputs p n v.PosA × Inputs p n v.PosB := + Equiv.piEquivPiSubtypeProd (fun i:I => v.aim i) (fun _ => _) +def forkK (N : ℕ) : Keys (p:=p) v.t N ≃ Keys (p:=p) v.atA.t N × Keys (p:=p) v.atB.t N := + Equiv.piEquivPiSubtypeProd (fun i:I => v.aim i) (fun i => AtomKey (p:=p) (v.t i) N) + +def sampleAll (u : I→Wgt (Knobs p.g n)) + (T : Inputs p n I → Keys (p:=p) v.t N → ℝ) + (x : UnitType p n N) := + avg (prodW u) (fun i => T i ((v.draw i).keys v.t x)) + +def connectT (T : Inputs p n I → Keys (p:=p) v.t N → ℝ) + (x : v.atA.Datum n N × v.atB.Datum n N) := + T ((v.forkI n).symm (x.1.1,x.2.1)) + ((v.forkK N).symm ((scatter v.atA.t N).symm x.1.2,(scatter v.atB.t N).symm x.2.2)) + +set_option maxHeartbeats 800000 in +theorem connect_avg (u : I→Wgt (Knobs p.g n)) + (T : Inputs p n I → Keys (p:=p) v.t N → ℝ) + (x : UnitType p n N) : + let a := fun i : v.PosA => u i.val + let b := fun i : v.PosB => u i.val + v.sampleAll u T x = avg + (pairW ((v.atA.singleP n).makeData (prodW a) x.1) + ((v.atB.singleP n).makeData (prodW b) x.2)) (v.connectT T) := by + classical + intro a b + let s (i : Inputs p n v.PosA) : v.atA.Datum n N := + (i,(v.atA.singleP n).showKey i x.1) + let t (i : Inputs p n v.PosB) : v.atB.Datum n N := + (i,(v.atB.singleP n).showKey i x.2) + have hi (i : Inputs p n I) : + T i ((v.draw i).keys v.t x) = + v.connectT T (s ((v.forkI n i).1), t ((v.forkI n i).2)) := by + let y := (v.draw i).keys v.t x + let Y := v.forkK N y + have hA : + (scatter v.atA.t N).symm ((v.atA.singleP n).showKey ((v.forkI n i).1) x.1)=Y.1 := by + rw [single_show,Equiv.symm_apply_apply]; funext j + + change keyOne p (v.t j.val) _ _ x.1=keyOne p _ _ _ (onSide x (v.aim j.val)) + rw [j.property]; rfl + have hB : + (scatter v.atB.t N).symm ((v.atB.singleP n).showKey ((v.forkI n i).2) x.2)=Y.2 := by + rw [single_show,Equiv.symm_apply_apply]; funext j + change keyOne p (v.t j.val) _ _ x.2=keyOne p _ _ _ (onSide x (v.aim j.val)) + rw [Bool.eq_false_iff.mpr j.property]; rfl + unfold connectT s t + rw [hA,hB] + simp [Y,Equiv.symm_apply_apply,y] + let Q (j : Inputs p n v.PosA × Inputs p n v.PosB) := v.connectT T (s j.1, t j.2) + calc _ = avg (mapW (prodW u) (v.forkI n)) Q := by + rw [mapW_avg,sampleAll]; simp_rw [hi]; rfl + _ = avg (pairW (prodW a) (prodW b)) Q := congrArg (fun w => avg w Q) + (fork_law (fun i => v.aim i) u) + _ = _ := by + rw [pairW_avg,pairW_avg,Program.makeData,Program.makeData,mapW_avg] + simp_rw [mapW_avg]; rfl + +theorem typical_calendar (v : Template p I) (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) ε≤ |f x-avg ρ f|) ≤ bp (-(1/16:ℝ)*n) := by + classical + filter_upwards [twinned v.atA v.atB M hM C ε hε] + with n hn N m w hw μ ρ H hA hB hw' hN u hu hz T hT f + let a := u ∘ (Subtype.val : v.PosA→I) + let b := u ∘ (Subtype.val : v.PosB→I) + have h := hn m w hw hA hB hw' hN a b + (fun i => hu _) (fun i => hz _) (fun i => hu _) (fun i => hz _) + (connectT v T) (fun x => hT _ _) + have he : f = fun x : UnitType p n N => avg + (pairW ((v.atA.singleP n).makeData (prodW a) x.1) + ((v.atB.singleP n).makeData (prodW b) x.2)) (v.connectT T) := + funext fun x => connect_avg v u T x + rw [he]; exact h + +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/TensorIntersections.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/TensorIntersections.lean index f5698b91e9bb8f1143604d00901d305f0360a239..1c275366128fd513fc56a04bf89f4356d0bb0816 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/TensorIntersections.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/TensorIntersections.lean @@ -1,137 +1,137 @@ -import OAI.Combinatorics.HadwigerCounterexample.SparseCutProfiles - -namespace OAI - -/-! # Tensor Intersections -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Submodule -open scoped BigOperators - -variable {p : Shape} {n N : ℕ} - -section Rank -variable {U I J L : Type} [Fintype I] [Fintype J] [Fintype U] [Fintype L] - -omit [Fintype U] in -theorem colSp_join (A : Mat U I) (B : Mat U J) : - colSp (fromCols A B) = colSp A ⊔ colSp B := by - apply le_antisymm - · rintro _ ⟨x,rfl⟩ - rw [mulVecLin_apply,fromCols_mulVec] - exact add_mem_sup (show A *ᵥ _ ∈ colSp A from ⟨_,rfl⟩) - (show B *ᵥ _ ∈ colSp B from ⟨_,rfl⟩) - refine sup_le ?_ ?_ - · rintro _ ⟨x,rfl⟩ - refine ⟨Sum.elim x 0,?_⟩ - simp only [mulVecLin_apply,fromCols_mulVec_sumElim,Matrix.mulVec_zero,add_zero] - · rintro _ ⟨x,rfl⟩ - refine ⟨Sum.elim 0 x,?_⟩ - simp only [mulVecLin_apply,fromCols_mulVec_sumElim,Matrix.mulVec_zero,zero_add] - -omit [Fintype U] in -theorem colSp_primary (A : Mat U (I⊕J)) : colSp (primary A) ≤ colSp A := - calc colSp (primary A) ≤ colSp (primary A) ⊔ colSp (channel A) := le_sup_left - _ = colSp A := by rw [← colSp_join,fromCols_frame] - -omit [Fintype U] in -theorem join_kernel {A : Mat U I} {B : Mat U J} - (ha : Function.Injective A.mulVec) (hb : Function.Injective B.mulVec) : - dim (colSp A ⊓ colSp B : Submodule _ _) = dim (ker (fromCols A B).mulVecLin) := by - have h := finrank_sup_add_finrank_inf_eq (colSp A) (colSp B) - have h' := (fromCols A B).mulVecLin.finrank_range_add_finrank_ker - rw [← colSp_join] at h - change dim (colSp _) + dim _ = dim _+dim _ at h - change dim (colSp _) + dim _ = dim _ at h' - rw [colSp_dim A,colSp_dim B,mrk_inj.mp ha,mrk_inj.mp hb] at h - rw [dim_vec, Fintype.card_sum] at h' - omega - -omit [Fintype U] in -theorem colSp_lift_le (P : Mat U I) (Q : Mat L J) (A : Mat I J) : - colSp (liftM P Q A) ≤ colSp P := by - rw [liftM_def,Matrix.mul_assoc,colSp, Matrix.mulVecLin_mul] - exact LinearMap.range_comp_le_range _ _ - -omit [Fintype U] in -theorem rank_lift_le (P : Mat U I) (Q : Mat L J) (A : Mat I J) : - (liftM P Q A).rank ≤ A.rank := - (Matrix.rank_mul_le_left _ _).trans (Matrix.rank_mul_le_right _ _) - -theorem rank_lift_eq {P : Mat U I} {Q : Mat L J} (hP : Function.Injective P.mulVec) - (hQ : Function.Injective Q.mulVec) (A : Mat I J) : - (liftM P Q A).rank = A.rank := by - classical - obtain ⟨P',h1⟩ := mat_left_inv hP - obtain ⟨Q',h2⟩ := mat_left_inv hQ - refine le_antisymm (rank_lift_le P Q A) ?_ - have h := rank_lift_le P' Q' (liftM P Q A) - rw [liftM_comp,h1,h2,liftM_def,Matrix.one_mul,Matrix.transpose_one,Matrix.mul_one] at h - exact h - -end Rank - -/-- Sum of dimensions of the kernel of the combined plus maps at each component. -This bounds (in fact equals) the sum of intersection dimensions of full plus -frames when the frames are valid. -/ -def joins (x : UnitType p n N) : ℕ := - ∑ i : Comp p.g, dim (ker (images x (i,true)).mulVecLin) - -theorem totalRank_shared {m : Mixer p n} {x y : Orient p n N} - (hx : frameLaw m x) (hy : frameLaw m y) {v w : Profile p n} - (h : Uembed x v = Uembed y w) : - totalRank v = totalRank w ∧ totalRank v ≤ joins (x,y) := by - have he (x : Orient p n N) (hx : frameLaw m x) (a : Profile p n) (i) : - (Uembed x a i).rank = (a i).rank := - rank_lift_eq (primary_inj (hx i).1) (primary_inj (hx i).2.1) (a i) - have hf i : (v i).rank=(w i).rank := by rw [← he x hx,← he y hy,h] - refine ⟨Finset.sum_congr rfl fun i _ => hf i, Finset.sum_le_sum fun i _ => ?_⟩ - let A := (x i).1 - let B := (y i).1 - have hi (x : Orient p n N) (v) : - colSp (Uembed x v i) ≤ colSp (x i).1 := - (colSp_lift_le _ _ _).trans (colSp_primary _) - have hh : colSp (Uembed x v i) ≤ colSp A ⊓ colSp B := - le_inf (hi x v) (by rw [h]; exact hi y w) - change (v i).rank ≤ dim (ker (images _ _).mulVecLin) - rw [← he x hx,← colSp_dim] - apply le_trans (Submodule.finrank_mono hh) - exact (join_kernel (hx i).1 (hy i).1).le - -theorem eta_share {m : Mixer p n} {x : Orient p n N} {v : Profile p n} (hj : 1 ≤ p.j) - (hx : frameLaw m x) (hv : v ∈ Xspace p n) (i) : - mpair (1:Mat (Fin N) (Fin N)) (Uembed x v i) = eta p n (v i) := by - let P := primary (x i).1 - let Q := primary (x i).2 - have hi : v i ∈ Wspace p n := by - obtain ⟨w,hw,rfl⟩ := mem_X.mp hv - exact Submodule.add_mem _ (Wtag_le _ (hw _)) (Wtag_le _ (hw _)) - change mpair _ (liftM P Q (v i)) = _ - rw [mpair_liftM,liftM_def,transpose_transpose, Matrix.mul_one, - show Pᵀ*Q=selfM p n m.mixM from (hx i).2.2.1,selfM_pair _ hj _ hi] - -def parityW (w : Tag p.g → Moment p n) := ∑ i, eta p n (w i) - -theorem parityW_shared {m : Mixer p n} (hj : 1 ≤ p.j) {x y : Orient p n N} - (hx : frameLaw m x) (hy : frameLaw m y) {v w : Tag p.g → Moment p n} - (hv : ∀ l, v l∈ Wtag p n l) (hw : ∀ l, w l∈ Wtag p n l) - (h : Uembed x (cut p n v) = Uembed y (cut p n w)) - (hv' : 2 * (nonzeroTags v).card < p.g) - (hw' : 2 * (nonzeroTags w).card < p.g) : parityW v = parityW w := by - have he i : eta p n (cut p n v i) = eta p n (cut p n w i) := by - rw [← eta_share hj hx (mem_X.mpr ⟨v,hv,rfl⟩),← eta_share hj hy (mem_X.mpr ⟨w,hw,rfl⟩),h] - obtain ⟨l,hl,hL⟩ := common_zero hv' hw' - refine Finset.sum_congr rfl fun t _ => ?_ - by_cases htl : l=t - · subst t; rw [hl,hL] - have hf (w : Tag p.g → Moment p n) (h : w l=0) : - cut p n w (edge l t htl) = w t := by - rw [← getPair_edge l t htl (cut p n w), getPair_cut,h,zero_add] - exact (by simpa only [hf v hl,hf w hL] using he (edge l t htl)) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.SparseCutProfiles + +namespace OAI + +/-! # Tensor Intersections -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Submodule +open scoped BigOperators + +variable {p : Shape} {n N : ℕ} + +section Rank +variable {U I J L : Type} [Fintype I] [Fintype J] [Fintype U] [Fintype L] + +omit [Fintype U] in +theorem colSp_join (A : Mat U I) (B : Mat U J) : + colSp (fromCols A B) = colSp A ⊔ colSp B := by + apply le_antisymm + · rintro _ ⟨x,rfl⟩ + rw [mulVecLin_apply,fromCols_mulVec] + exact add_mem_sup (show A *ᵥ _ ∈ colSp A from ⟨_,rfl⟩) + (show B *ᵥ _ ∈ colSp B from ⟨_,rfl⟩) + refine sup_le ?_ ?_ + · rintro _ ⟨x,rfl⟩ + refine ⟨Sum.elim x 0,?_⟩ + simp only [mulVecLin_apply,fromCols_mulVec_sumElim,Matrix.mulVec_zero,add_zero] + · rintro _ ⟨x,rfl⟩ + refine ⟨Sum.elim 0 x,?_⟩ + simp only [mulVecLin_apply,fromCols_mulVec_sumElim,Matrix.mulVec_zero,zero_add] + +omit [Fintype U] in +theorem colSp_primary (A : Mat U (I⊕J)) : colSp (primary A) ≤ colSp A := + calc colSp (primary A) ≤ colSp (primary A) ⊔ colSp (channel A) := le_sup_left + _ = colSp A := by rw [← colSp_join,fromCols_frame] + +omit [Fintype U] in +theorem join_kernel {A : Mat U I} {B : Mat U J} + (ha : Function.Injective A.mulVec) (hb : Function.Injective B.mulVec) : + dim (colSp A ⊓ colSp B : Submodule _ _) = dim (ker (fromCols A B).mulVecLin) := by + have h := finrank_sup_add_finrank_inf_eq (colSp A) (colSp B) + have h' := (fromCols A B).mulVecLin.finrank_range_add_finrank_ker + rw [← colSp_join] at h + change dim (colSp _) + dim _ = dim _+dim _ at h + change dim (colSp _) + dim _ = dim _ at h' + rw [colSp_dim A,colSp_dim B,mrk_inj.mp ha,mrk_inj.mp hb] at h + rw [dim_vec, Fintype.card_sum] at h' + omega + +omit [Fintype U] in +theorem colSp_lift_le (P : Mat U I) (Q : Mat L J) (A : Mat I J) : + colSp (liftM P Q A) ≤ colSp P := by + rw [liftM_def,Matrix.mul_assoc,colSp, Matrix.mulVecLin_mul] + exact LinearMap.range_comp_le_range _ _ + +omit [Fintype U] in +theorem rank_lift_le (P : Mat U I) (Q : Mat L J) (A : Mat I J) : + (liftM P Q A).rank ≤ A.rank := + (Matrix.rank_mul_le_left _ _).trans (Matrix.rank_mul_le_right _ _) + +theorem rank_lift_eq {P : Mat U I} {Q : Mat L J} (hP : Function.Injective P.mulVec) + (hQ : Function.Injective Q.mulVec) (A : Mat I J) : + (liftM P Q A).rank = A.rank := by + classical + obtain ⟨P',h1⟩ := mat_left_inv hP + obtain ⟨Q',h2⟩ := mat_left_inv hQ + refine le_antisymm (rank_lift_le P Q A) ?_ + have h := rank_lift_le P' Q' (liftM P Q A) + rw [liftM_comp,h1,h2,liftM_def,Matrix.one_mul,Matrix.transpose_one,Matrix.mul_one] at h + exact h + +end Rank + +/-- Sum of dimensions of the kernel of the combined plus maps at each component. +This bounds (in fact equals) the sum of intersection dimensions of full plus +frames when the frames are valid. -/ +def joins (x : UnitType p n N) : ℕ := + ∑ i : Comp p.g, dim (ker (images x (i,true)).mulVecLin) + +theorem totalRank_shared {m : Mixer p n} {x y : Orient p n N} + (hx : frameLaw m x) (hy : frameLaw m y) {v w : Profile p n} + (h : Uembed x v = Uembed y w) : + totalRank v = totalRank w ∧ totalRank v ≤ joins (x,y) := by + have he (x : Orient p n N) (hx : frameLaw m x) (a : Profile p n) (i) : + (Uembed x a i).rank = (a i).rank := + rank_lift_eq (primary_inj (hx i).1) (primary_inj (hx i).2.1) (a i) + have hf i : (v i).rank=(w i).rank := by rw [← he x hx,← he y hy,h] + refine ⟨Finset.sum_congr rfl fun i _ => hf i, Finset.sum_le_sum fun i _ => ?_⟩ + let A := (x i).1 + let B := (y i).1 + have hi (x : Orient p n N) (v) : + colSp (Uembed x v i) ≤ colSp (x i).1 := + (colSp_lift_le _ _ _).trans (colSp_primary _) + have hh : colSp (Uembed x v i) ≤ colSp A ⊓ colSp B := + le_inf (hi x v) (by rw [h]; exact hi y w) + change (v i).rank ≤ dim (ker (images _ _).mulVecLin) + rw [← he x hx,← colSp_dim] + apply le_trans (Submodule.finrank_mono hh) + exact (join_kernel (hx i).1 (hy i).1).le + +theorem eta_share {m : Mixer p n} {x : Orient p n N} {v : Profile p n} (hj : 1 ≤ p.j) + (hx : frameLaw m x) (hv : v ∈ Xspace p n) (i) : + mpair (1:Mat (Fin N) (Fin N)) (Uembed x v i) = eta p n (v i) := by + let P := primary (x i).1 + let Q := primary (x i).2 + have hi : v i ∈ Wspace p n := by + obtain ⟨w,hw,rfl⟩ := mem_X.mp hv + exact Submodule.add_mem _ (Wtag_le _ (hw _)) (Wtag_le _ (hw _)) + change mpair _ (liftM P Q (v i)) = _ + rw [mpair_liftM,liftM_def,transpose_transpose, Matrix.mul_one, + show Pᵀ*Q=selfM p n m.mixM from (hx i).2.2.1,selfM_pair _ hj _ hi] + +def parityW (w : Tag p.g → Moment p n) := ∑ i, eta p n (w i) + +theorem parityW_shared {m : Mixer p n} (hj : 1 ≤ p.j) {x y : Orient p n N} + (hx : frameLaw m x) (hy : frameLaw m y) {v w : Tag p.g → Moment p n} + (hv : ∀ l, v l∈ Wtag p n l) (hw : ∀ l, w l∈ Wtag p n l) + (h : Uembed x (cut p n v) = Uembed y (cut p n w)) + (hv' : 2 * (nonzeroTags v).card < p.g) + (hw' : 2 * (nonzeroTags w).card < p.g) : parityW v = parityW w := by + have he i : eta p n (cut p n v i) = eta p n (cut p n w i) := by + rw [← eta_share hj hx (mem_X.mpr ⟨v,hv,rfl⟩),← eta_share hj hy (mem_X.mpr ⟨w,hw,rfl⟩),h] + obtain ⟨l,hl,hL⟩ := common_zero hv' hw' + refine Finset.sum_congr rfl fun t _ => ?_ + by_cases htl : l=t + · subst t; rw [hl,hL] + have hf (w : Tag p.g → Moment p n) (h : w l=0) : + cut p n w (edge l t htl) = w t := by + rw [← getPair_edge l t htl (cut p n w), getPair_cut,h,zero_add] + exact (by simpa only [hf v hl,hf w hL] using he (edge l t htl)) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/TerminalCut.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/TerminalCut.lean index bc9fc6bacb974b752de2fac7bbea12126ffc3f5f..56e7433cfe8199705e6c495d447378beb594152b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/TerminalCut.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/TerminalCut.lean @@ -1,179 +1,179 @@ -import OAI.Combinatorics.HadwigerCounterexample.EntropyContainers - -namespace OAI - -/-! # Terminal Cut -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators - -variable {α : Type*} [Fintype α] - -/-- Individual marginal caps (mapW denotes the actual marginals) and a joint cap. -/ -def pairCaps (μ : Wgt α) (m d : ℝ) (w : Wgt (α × α)) := - (∀ x, mapW w Prod.fst x ≤ m * μ x) ∧ - (∀ x, mapW w Prod.snd x ≤ m * μ x) ∧ - (∀ p, w p ≤ d * pairW μ μ p) - -theorem closed_pairCaps (μ : Wgt α) (m d : ℝ) : - IsClosed {w : Wgt (α × α) | pairCaps μ m d w} := by - have e : - {w : Wgt (α × α) | pairCaps μ m d w} = - (⋂ x, {w | mapW w Prod.fst x ≤ m * μ x}) ∩ - ((⋂ x, {w | mapW w Prod.snd x ≤ m * μ x}) ∩ - (⋂ p, {w | w p ≤ d * pairW μ μ p})) := by ext; simp [pairCaps] - rw [e] - exact (isClosed_iInter fun _ => isClosed_le (pr_continuous _) continuous_const).inter - ((isClosed_iInter fun _ => isClosed_le (pr_continuous _) continuous_const).inter - (isClosed_iInter fun _ => isClosed_le (continuous_apply _) continuous_const)) - -theorem mid_pairCaps {μ : Wgt α} {m d : ℝ} {w v : Wgt (α × α)} - (hw : pairCaps μ m d w) (hv : pairCaps μ m d v) : - pairCaps μ m d (midLaw w v) := by - have h1 (f : α × α → α) (x : α) : - mapW (midLaw w v) f x = (mapW w f x + mapW v f x) * 2⁻¹ := midLaw_pr w v _ - constructor - · intro x - rw [h1] - linarith only [hw.1 x, hv.1 x] - refine ⟨fun x => ?_, fun p => ?_⟩ - · rw [h1] - linarith only [hw.2.1 x, hv.2.1 x] - · unfold midLaw - linarith only [hw.2.2 p, hv.2.2 p] - -theorem compact_subLaw : IsCompact {w : Wgt α | SubLaw w} := by - refine IsCompact.of_isClosed_subset (s:=Set.Icc (0 : Wgt α) 1) isCompact_Icc ?_ ?_ - · have he : - {w : Wgt α | SubLaw w} = - (⋂ x, {w | 0 ≤ w x}) ∩ {w : Wgt α | tot w ≤ 1} := by - ext w - have : SubLaw w ↔ (∀ x, 0 ≤ w x) ∧ tot w ≤ 1 := - ⟨fun h => ⟨h.nz,h.total⟩, fun ⟨h,g⟩ => ⟨h,g⟩⟩ - simp [this] - rw [he] - exact (isClosed_iInter fun _ => isClosed_le continuous_const (continuous_apply _)).inter - (isClosed_le tot_continuous continuous_const) - · intro w hw - exact ⟨hw.nz,hw.weight_le_one⟩ - -private def incW (w : Wgt α) (p : α) (b : ℝ) : Wgt α := - fun x => w x + b * ind (x = p) - -private theorem incW_tot (w : Wgt α) (p : α) (b : ℝ) : - tot (incW w p b) = tot w + b := by - classical simp [tot, incW, ind, Finset.sum_add_distrib] - -private theorem incW_pr (w : Wgt α) (p : α) (b : ℝ) (q : α → Prop) : - pr (incW w p b) q = pr w q + b * ind (q p) := by - classical - simp only [pr, avg, incW, add_mul, Finset.sum_add_distrib, add_right_inj] - rw [Finset.sum_eq_single p] - · simp [ind] - · intro x _ h; simp [ind,h] - · simp - -private theorem sat_le_tot {u v : Wgt α} (hu : ∀ x, 0 ≤ u x) (b : ℝ) : - b * pr v (fun x => u x = b * v x) ≤ tot u := by - have e : - b * pr v (fun x => u x = b * v x) = pr u (fun x => u x = b * v x) := by - unfold pr avg - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro x _ - by_cases h : u x = b * v x <;> simp [ind, h] - rw [e]; exact pr_le_tot hu - -private theorem mapW_tot' {β : Type*} [Fintype β] (w : Wgt α) (f : α → β) : - tot (mapW w f) = tot w := by simpa using mapW_pr w f (fun _ => True) - -theorem terminal {μ : Wgt α} (hu : ∀ x, 0 ≤ μ x) - {m d : ℝ} (hm : 0 < m) (hd : 0 < d) (R : α × α → Prop) - (hR : ¬∃ w : Wgt (α × α), IsLaw w ∧ pairCaps μ m d w ∧ carried w R) : - ∃ (S : α → Prop) (E : α × α → Prop), - m * pr μ S < 2 ∧ d * pr (pairW μ μ) E < 1 ∧ - ∀ x : α × α, R x → S x.1 ∨ S x.2 ∨ E x := by - let T := {w : Wgt (α × α) | SubLaw w} ∩ - ({w | pairCaps μ m d w} ∩ {w | carried w R}) - have hc : IsCompact T := compact_subLaw.inter_right - ((closed_pairCaps _ _ _).inter (closed_carried _)) - have ht : T.Nonempty := by - refine ⟨(fun _ => 0), ⟨?_,?_⟩, ⟨fun x => ?_, fun x => ?_, fun p => ?_⟩, fun _ _ => rfl⟩ - · exact fun _ => le_rfl - · simp [tot] - · simpa [mapW,pr,avg] using mul_nonneg hm.le (hu x) - · simpa [mapW,pr,avg] using mul_nonneg hm.le (hu x) - · exact mul_nonneg hd.le (mul_nonneg (hu _) (hu _)) - obtain ⟨w,hw,hwmax⟩ := hc.exists_isMaxOn ht tot_continuous.continuousOn - have hwL : SubLaw w := hw.1 - have hwC : pairCaps μ m d w := hw.2.1 - have hw' : tot w < 1 := lt_of_le_of_ne hwL.total (fun he => - hR ⟨w,⟨hwL.nz,he⟩,hwC,hw.2.2⟩) - let hit (f : α × α → α) (x : α) := mapW w f x = m * μ x - let EH (p : α × α) := w p = d * pairW μ μ p - refine ⟨fun x => hit Prod.fst x ∨ hit Prod.snd x, EH, ?_, ?_, ?_⟩ - · have hh (f : α × α → α) : m * pr μ (hit f) < 1 := by - apply lt_of_le_of_lt _ hw' - rw [← mapW_tot' w f] - exact sat_le_tot (fun _ => pr_nonneg hwL.nz) m - have h := mul_le_mul_of_nonneg_left - (pr_or_le (p:=hit Prod.fst) (q:=hit Prod.snd) hu) hm.le - linarith only [h, hh Prod.fst, hh Prod.snd] - · exact lt_of_le_of_lt (sat_le_tot hwL.nz d) hw' - intro x hx - by_contra hn - push Not at hn - have hg : 0 < m * μ x.1 - mapW w Prod.fst x.1 := - sub_pos.mpr (lt_of_le_of_ne (hwC.1 _) hn.1.1) - have hi : 0 < m * μ x.2 - mapW w Prod.snd x.2 := - sub_pos.mpr (lt_of_le_of_ne (hwC.2.1 _) hn.2.1.2) - have hj : 0 < d * pairW μ μ x - w x := sub_pos.mpr - (lt_of_le_of_ne (hwC.2.2 _) hn.2.2) - obtain ⟨b,hb,h1,h2,h3,h4⟩ : ∃ b : ℝ, 0 < b ∧ b ≤ 1 - tot w ∧ - b ≤ m * μ x.1 - mapW w Prod.fst x.1 ∧ - b ≤ m * μ x.2 - mapW w Prod.snd x.2 ∧ b ≤ d * pairW μ μ x - w x := by - let b := min (min (1 - tot w) (m * μ x.1 - mapW w Prod.fst x.1)) - (min (m * μ x.2 - mapW w Prod.snd x.2) (d * pairW μ μ x - w x)) - refine ⟨b, lt_min (lt_min (sub_pos.mpr hw') hg) (lt_min hi hj), ?_,?_,?_,?_⟩ - · exact le_trans (min_le_left _ _) (min_le_left _ _) - · exact le_trans (min_le_left _ _) (min_le_right _ _) - · exact le_trans (min_le_right _ _) (min_le_left _ _) - · exact le_trans (min_le_right _ _) (min_le_right _ _) - have hmap (f : α × α → α) (y : α) : mapW (incW w x b) f y = - mapW w f y + b * ind (f x = y) := incW_pr w x b _ - have hm : incW w x b ∈ T := by - refine ⟨⟨fun _ => add_nonneg (hwL.nz _) (mul_nonneg hb.le (ind_nonneg _)),?_⟩, - ⟨fun y => ?_, fun y => ?_, fun p => ?_⟩, fun y hy => ?_⟩ - · rw [incW_tot]; linarith only [h1] - · by_cases h : x.1 = y - · subst y - rw [hmap] - simp only [ind_true, mul_one] - linarith only [h2] - · rw [hmap, ind_zero h, mul_zero, add_zero] - exact hwC.1 y - · by_cases h : x.2 = y - · subst y - rw [hmap] - simp only [ind_true, mul_one] - linarith only [h3] - · rw [hmap, ind_zero h, mul_zero, add_zero] - exact hwC.2.1 y - · by_cases h : p = x - · subst p - simp only [incW, ind_true, mul_one] - linarith only [h4] - · rw [incW, ind_zero h, mul_zero, add_zero] - exact hwC.2.2 p - · have h : y ≠ x := fun he => hy (he.symm ▸ hx) - rw [incW, hw.2.2 y hy, ind_zero h, mul_zero, add_zero] - have hle : tot (incW w x b) ≤ tot w := hwmax hm - rw [incW_tot] at hle - linarith only [hb, hle] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.EntropyContainers + +namespace OAI + +/-! # Terminal Cut -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators + +variable {α : Type*} [Fintype α] + +/-- Individual marginal caps (mapW denotes the actual marginals) and a joint cap. -/ +def pairCaps (μ : Wgt α) (m d : ℝ) (w : Wgt (α × α)) := + (∀ x, mapW w Prod.fst x ≤ m * μ x) ∧ + (∀ x, mapW w Prod.snd x ≤ m * μ x) ∧ + (∀ p, w p ≤ d * pairW μ μ p) + +theorem closed_pairCaps (μ : Wgt α) (m d : ℝ) : + IsClosed {w : Wgt (α × α) | pairCaps μ m d w} := by + have e : + {w : Wgt (α × α) | pairCaps μ m d w} = + (⋂ x, {w | mapW w Prod.fst x ≤ m * μ x}) ∩ + ((⋂ x, {w | mapW w Prod.snd x ≤ m * μ x}) ∩ + (⋂ p, {w | w p ≤ d * pairW μ μ p})) := by ext; simp [pairCaps] + rw [e] + exact (isClosed_iInter fun _ => isClosed_le (pr_continuous _) continuous_const).inter + ((isClosed_iInter fun _ => isClosed_le (pr_continuous _) continuous_const).inter + (isClosed_iInter fun _ => isClosed_le (continuous_apply _) continuous_const)) + +theorem mid_pairCaps {μ : Wgt α} {m d : ℝ} {w v : Wgt (α × α)} + (hw : pairCaps μ m d w) (hv : pairCaps μ m d v) : + pairCaps μ m d (midLaw w v) := by + have h1 (f : α × α → α) (x : α) : + mapW (midLaw w v) f x = (mapW w f x + mapW v f x) * 2⁻¹ := midLaw_pr w v _ + constructor + · intro x + rw [h1] + linarith only [hw.1 x, hv.1 x] + refine ⟨fun x => ?_, fun p => ?_⟩ + · rw [h1] + linarith only [hw.2.1 x, hv.2.1 x] + · unfold midLaw + linarith only [hw.2.2 p, hv.2.2 p] + +theorem compact_subLaw : IsCompact {w : Wgt α | SubLaw w} := by + refine IsCompact.of_isClosed_subset (s:=Set.Icc (0 : Wgt α) 1) isCompact_Icc ?_ ?_ + · have he : + {w : Wgt α | SubLaw w} = + (⋂ x, {w | 0 ≤ w x}) ∩ {w : Wgt α | tot w ≤ 1} := by + ext w + have : SubLaw w ↔ (∀ x, 0 ≤ w x) ∧ tot w ≤ 1 := + ⟨fun h => ⟨h.nz,h.total⟩, fun ⟨h,g⟩ => ⟨h,g⟩⟩ + simp [this] + rw [he] + exact (isClosed_iInter fun _ => isClosed_le continuous_const (continuous_apply _)).inter + (isClosed_le tot_continuous continuous_const) + · intro w hw + exact ⟨hw.nz,hw.weight_le_one⟩ + +private def incW (w : Wgt α) (p : α) (b : ℝ) : Wgt α := + fun x => w x + b * ind (x = p) + +private theorem incW_tot (w : Wgt α) (p : α) (b : ℝ) : + tot (incW w p b) = tot w + b := by + classical simp [tot, incW, ind, Finset.sum_add_distrib] + +private theorem incW_pr (w : Wgt α) (p : α) (b : ℝ) (q : α → Prop) : + pr (incW w p b) q = pr w q + b * ind (q p) := by + classical + simp only [pr, avg, incW, add_mul, Finset.sum_add_distrib, add_right_inj] + rw [Finset.sum_eq_single p] + · simp [ind] + · intro x _ h; simp [ind,h] + · simp + +private theorem sat_le_tot {u v : Wgt α} (hu : ∀ x, 0 ≤ u x) (b : ℝ) : + b * pr v (fun x => u x = b * v x) ≤ tot u := by + have e : + b * pr v (fun x => u x = b * v x) = pr u (fun x => u x = b * v x) := by + unfold pr avg + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + by_cases h : u x = b * v x <;> simp [ind, h] + rw [e]; exact pr_le_tot hu + +private theorem mapW_tot' {β : Type*} [Fintype β] (w : Wgt α) (f : α → β) : + tot (mapW w f) = tot w := by simpa using mapW_pr w f (fun _ => True) + +theorem terminal {μ : Wgt α} (hu : ∀ x, 0 ≤ μ x) + {m d : ℝ} (hm : 0 < m) (hd : 0 < d) (R : α × α → Prop) + (hR : ¬∃ w : Wgt (α × α), IsLaw w ∧ pairCaps μ m d w ∧ carried w R) : + ∃ (S : α → Prop) (E : α × α → Prop), + m * pr μ S < 2 ∧ d * pr (pairW μ μ) E < 1 ∧ + ∀ x : α × α, R x → S x.1 ∨ S x.2 ∨ E x := by + let T := {w : Wgt (α × α) | SubLaw w} ∩ + ({w | pairCaps μ m d w} ∩ {w | carried w R}) + have hc : IsCompact T := compact_subLaw.inter_right + ((closed_pairCaps _ _ _).inter (closed_carried _)) + have ht : T.Nonempty := by + refine ⟨(fun _ => 0), ⟨?_,?_⟩, ⟨fun x => ?_, fun x => ?_, fun p => ?_⟩, fun _ _ => rfl⟩ + · exact fun _ => le_rfl + · simp [tot] + · simpa [mapW,pr,avg] using mul_nonneg hm.le (hu x) + · simpa [mapW,pr,avg] using mul_nonneg hm.le (hu x) + · exact mul_nonneg hd.le (mul_nonneg (hu _) (hu _)) + obtain ⟨w,hw,hwmax⟩ := hc.exists_isMaxOn ht tot_continuous.continuousOn + have hwL : SubLaw w := hw.1 + have hwC : pairCaps μ m d w := hw.2.1 + have hw' : tot w < 1 := lt_of_le_of_ne hwL.total (fun he => + hR ⟨w,⟨hwL.nz,he⟩,hwC,hw.2.2⟩) + let hit (f : α × α → α) (x : α) := mapW w f x = m * μ x + let EH (p : α × α) := w p = d * pairW μ μ p + refine ⟨fun x => hit Prod.fst x ∨ hit Prod.snd x, EH, ?_, ?_, ?_⟩ + · have hh (f : α × α → α) : m * pr μ (hit f) < 1 := by + apply lt_of_le_of_lt _ hw' + rw [← mapW_tot' w f] + exact sat_le_tot (fun _ => pr_nonneg hwL.nz) m + have h := mul_le_mul_of_nonneg_left + (pr_or_le (p:=hit Prod.fst) (q:=hit Prod.snd) hu) hm.le + linarith only [h, hh Prod.fst, hh Prod.snd] + · exact lt_of_le_of_lt (sat_le_tot hwL.nz d) hw' + intro x hx + by_contra hn + push Not at hn + have hg : 0 < m * μ x.1 - mapW w Prod.fst x.1 := + sub_pos.mpr (lt_of_le_of_ne (hwC.1 _) hn.1.1) + have hi : 0 < m * μ x.2 - mapW w Prod.snd x.2 := + sub_pos.mpr (lt_of_le_of_ne (hwC.2.1 _) hn.2.1.2) + have hj : 0 < d * pairW μ μ x - w x := sub_pos.mpr + (lt_of_le_of_ne (hwC.2.2 _) hn.2.2) + obtain ⟨b,hb,h1,h2,h3,h4⟩ : ∃ b : ℝ, 0 < b ∧ b ≤ 1 - tot w ∧ + b ≤ m * μ x.1 - mapW w Prod.fst x.1 ∧ + b ≤ m * μ x.2 - mapW w Prod.snd x.2 ∧ b ≤ d * pairW μ μ x - w x := by + let b := min (min (1 - tot w) (m * μ x.1 - mapW w Prod.fst x.1)) + (min (m * μ x.2 - mapW w Prod.snd x.2) (d * pairW μ μ x - w x)) + refine ⟨b, lt_min (lt_min (sub_pos.mpr hw') hg) (lt_min hi hj), ?_,?_,?_,?_⟩ + · exact le_trans (min_le_left _ _) (min_le_left _ _) + · exact le_trans (min_le_left _ _) (min_le_right _ _) + · exact le_trans (min_le_right _ _) (min_le_left _ _) + · exact le_trans (min_le_right _ _) (min_le_right _ _) + have hmap (f : α × α → α) (y : α) : mapW (incW w x b) f y = + mapW w f y + b * ind (f x = y) := incW_pr w x b _ + have hm : incW w x b ∈ T := by + refine ⟨⟨fun _ => add_nonneg (hwL.nz _) (mul_nonneg hb.le (ind_nonneg _)),?_⟩, + ⟨fun y => ?_, fun y => ?_, fun p => ?_⟩, fun y hy => ?_⟩ + · rw [incW_tot]; linarith only [h1] + · by_cases h : x.1 = y + · subst y + rw [hmap] + simp only [ind_true, mul_one] + linarith only [h2] + · rw [hmap, ind_zero h, mul_zero, add_zero] + exact hwC.1 y + · by_cases h : x.2 = y + · subst y + rw [hmap] + simp only [ind_true, mul_one] + linarith only [h3] + · rw [hmap, ind_zero h, mul_zero, add_zero] + exact hwC.2.1 y + · by_cases h : p = x + · subst p + simp only [incW, ind_true, mul_one] + linarith only [h4] + · rw [incW, ind_zero h, mul_zero, add_zero] + exact hwC.2.2 p + · have h : y ≠ x := fun he => hy (he.symm ▸ hx) + rw [incW, hw.2.2 y hy, ind_zero h, mul_zero, add_zero] + have hle : tot (incW w x b) ≤ tot w := hwmax hm + rw [incW_tot] at hle + linarith only [hb, hle] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/TesterFourierSupport.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/TesterFourierSupport.lean index 850bb79e86171efe4219ee7714ee7f58ef7e9335..c2e0dadbfa5defa34ea3854970a963568dd543b6 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/TesterFourierSupport.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/TesterFourierSupport.lean @@ -1,147 +1,147 @@ -import OAI.Combinatorics.HadwigerCounterexample.QuadraticFourier - -namespace OAI - -/-! # Tester Fourier Support -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module Submodule Function LinearMap Finset -open scoped BigOperators -variable {p : Shape} {n : ℕ} - -theorem roleT_scan (p : Shape) (i l : Tag p.g) (s : Label p.b) (f : Flavor p.g) - (x : Knobs p.g n) : - roleT p n i (useAtom p l s f x) = ∑ d:Tag p.g,scan p l f x (.inl (d,i)) := by - classical - unfold useAtom atom - let M := mom p s (lit f l x) - have h (t : Tag p.g) : (Pi.single l M : Tag p.g→ Moment p n) t ∈Wtag p n t := by - by_cases ht : t=l - · subst t; rw [Pi.single_eq_same]; exact Submodule.subset_span ⟨_,_,lit_allows f l x,rfl⟩ - simp [ht] - rw [roleT_cut p i _ h,Finset.sum_eq_single l,Pi.single_eq_same] - · simp_rw [scan_is p l s]; rfl - · intro i _ hi; simp [hi] - simp - -theorem sharedT_scan (p : Shape) (hg : Odd p.g) (i l : Tag p.g) (s : Label p.b) (f : Flavor p.g) - (x : Knobs p.g n) : - let r := scan p l f x (.inr ()) - sharedT p n i (useAtom p l s f x)= r+(if l=i then r else 0) := by - classical - intro r - unfold r useAtom atom - rw [sharedT_cut _ hg,Finset.sum_eq_single l] - · rw [Pi.single_eq_same,scan_is p l s f]; by_cases h : i=l <;> simp [h,asBlock,Ne.symm] - · intro i _ hi; simp [hi] - simp - -theorem T0_scanZ (p : Shape) (hg : Odd p.g) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) - (x : Profile p n) (u : Knobs p.g n) (y) : - T0 p n x (useAtom p l s f (update u Block.Z y))=T0 p n x (useAtom p l s f u) := by - simp_rw [T0_val,role_scan,roleT_scan] - have h i : sharedT p n i (useAtom p l s f (update u Block.Z y))=sharedT p n i - (useAtom p l s f u) := by rw [sharedT_scan p hg i,sharedT_scan p hg i]; simp only [scannedZ] - simp_rw [h,scannedZ] - -namespace Template - -variable (v : Solo p) -def shanty (v : Solo p) (m : Mixer p n) (x : Profile p n) (t : Knobs p.g n) := - wsign (Tsym m x (useAtom p (v.t ()) (v.s ()) (v.f ()) t)) -def stave (v : Solo p) (n : ℕ) := blockRay p n (v.s ()) Block.Z -def slash (v : Solo p) (m : Mixer p n) (x : Profile p n) := qmix m x (v.t ()) - -def scroll (v : Solo p) (m : Mixer p n) (x : Profile p n) := - let P:=stave v n; let M := slash v m x - colSp (Pᵀ*M) ⊔ colSp (Pᵀ*Mᵀ) - -theorem scroll_dim (v : Solo p) (m : Mixer p n) (x : Profile p n) : - dim (scroll v m x) ≤ 2*(p.J*(p.g-1)*(2*totalRank x)) := by - let P:=stave v n; let M:=slash v m x; let k:=p.J*(p.g-1)*(2*totalRank x) - have hm : M.rank ≤ k := qmix_rank .. - have h1 : dim (colSp (Pᵀ*M)) ≤ k := (Matrix.rank_mul_le_right ..).trans hm - have h2 : dim (colSp (Pᵀ*Mᵀ)) ≤ k := - (Matrix.rank_mul_le_right ..).trans ((Matrix.rank_transpose _).le.trans hm) - exact (Submodule.finrank_add_le_finrank_add_finrank ..).trans - ((Nat.add_le_add h1 h2).trans_eq (two_mul _).symm) - -theorem shanty_arc (v : Solo p) (m : Mixer p n) (x : Profile p n) - (hg : Odd p.g) (u : Knobs p.g n) : - let P := v.stave n; let M:= v.slash m x - ∃ a : Ray p n,∃ b : F,∀ y, - v.shanty m x (update u Block.Z y)= - wsign (b + evmat M (P *ᵥ y+a) (P *ᵥ y+a)) := by - intro P M - let l := v.t (); let s := v.s (); let f := v.f () - let A := spring p l s f (update u Block.Z (0 : Vec (Fin n))) - let b := T0 p n x (useAtom p l s f u) - refine ⟨A,b,fun y => ?_⟩ - let t := update u Block.Z y - let k := useAtom p l s f t - have hx : Tsym m x k = T0 p n x k + evmat M (spring p l s f t) (spring p l s f t) := by - unfold Tsym k useAtom; rw [LinearMap.add_apply,LinearMap.add_apply,Tmix_atom] - exact congrArg (_ + ·) (mpair_outer ..) - have ht : spring p l s f t=P *ᵥ y+A := (spring_update _ _ _ _ _ _ (Flavor.keepZ ..) _).trans - (add_comm _ _) - change wsign (Tsym m x k)=_ - rw [hx,ht]; unfold k t b - rw [T0_scanZ p hg] - -set_option maxHeartbeats 600000 in -theorem shanty_cap (v : Solo p) (m : Mixer p n) (x : Profile p n) - (K s : ℕ) (hg : Odd p.g) (hm : unaryGood m K s) (hK : totalRank x≤K) - (hx : 0 (bit_cases _).resolve_right (h _ hj)) - obtain ⟨t,ht,he⟩ := hh - let W y := v.shanty m x (update u Block.Z y) - let C := P *ᵥ t - have hz (y) : W (y+t)=W y := by - obtain ⟨a,b,hQ⟩ := shanty_arc v m x hg u - have hh (M : Moment p n) (h : colSp (Pᵀ*M)≤S) (i : Ray p n) : - dotProduct C (M *ᵥ i)=0 := by - have h1 := (annih_mem ..).mp ht _ (h (show (Pᵀ*M)*ᵥi∈_ from ⟨i,rfl⟩)) - rw [← mulVec_mulVec,dotProduct_transpose_mulVec] at h1; rw [dotProduct_comm]; exact h1 - let B := fun y => P *ᵥ y+a - unfold W; simp_rw [hQ] - change wsign (b+evmat M (B (y+t)) (B (y+t)))=_ - rw [show B (y+t)=B y+C by unfold B C; rw [mulVec_add]; ac_rfl] - have h1 z : evmat M C z=0 := hh M le_sup_left z - have h2 z : evmat M z C=0 := (evmat_transpose M _ _).symm.trans (hh Mᵀ le_sup_right z) - unfold evmat at * - simp_rw [mulVec_add,dotProduct_add,add_dotProduct,h1,h2] - simp only [add_zero,B,P,M,mulVec_add,dotProduct_add,add_dotProduct] - unfold zhat - let Q (y) := vectorPhase i y*W y - have hq (y) : - Q (y+t) = Q y * (-1) := by unfold Q vectorPhase; rw [hz,dotProduct_add,wsign_add,he,wsign_one]; ring - change avg unif Q=0 - have hh := phase_trans t Q - simp_rw [hq] at hh; rw [avg_mul] at hh; linarith -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.QuadraticFourier + +namespace OAI + +/-! # Tester Fourier Support -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module Submodule Function LinearMap Finset +open scoped BigOperators +variable {p : Shape} {n : ℕ} + +theorem roleT_scan (p : Shape) (i l : Tag p.g) (s : Label p.b) (f : Flavor p.g) + (x : Knobs p.g n) : + roleT p n i (useAtom p l s f x) = ∑ d:Tag p.g,scan p l f x (.inl (d,i)) := by + classical + unfold useAtom atom + let M := mom p s (lit f l x) + have h (t : Tag p.g) : (Pi.single l M : Tag p.g→ Moment p n) t ∈Wtag p n t := by + by_cases ht : t=l + · subst t; rw [Pi.single_eq_same]; exact Submodule.subset_span ⟨_,_,lit_allows f l x,rfl⟩ + simp [ht] + rw [roleT_cut p i _ h,Finset.sum_eq_single l,Pi.single_eq_same] + · simp_rw [scan_is p l s]; rfl + · intro i _ hi; simp [hi] + simp + +theorem sharedT_scan (p : Shape) (hg : Odd p.g) (i l : Tag p.g) (s : Label p.b) (f : Flavor p.g) + (x : Knobs p.g n) : + let r := scan p l f x (.inr ()) + sharedT p n i (useAtom p l s f x)= r+(if l=i then r else 0) := by + classical + intro r + unfold r useAtom atom + rw [sharedT_cut _ hg,Finset.sum_eq_single l] + · rw [Pi.single_eq_same,scan_is p l s f]; by_cases h : i=l <;> simp [h,asBlock,Ne.symm] + · intro i _ hi; simp [hi] + simp + +theorem T0_scanZ (p : Shape) (hg : Odd p.g) (l : Tag p.g) (s : Label p.b) (f : Flavor p.g) + (x : Profile p n) (u : Knobs p.g n) (y) : + T0 p n x (useAtom p l s f (update u Block.Z y))=T0 p n x (useAtom p l s f u) := by + simp_rw [T0_val,role_scan,roleT_scan] + have h i : sharedT p n i (useAtom p l s f (update u Block.Z y))=sharedT p n i + (useAtom p l s f u) := by rw [sharedT_scan p hg i,sharedT_scan p hg i]; simp only [scannedZ] + simp_rw [h,scannedZ] + +namespace Template + +variable (v : Solo p) +def shanty (v : Solo p) (m : Mixer p n) (x : Profile p n) (t : Knobs p.g n) := + wsign (Tsym m x (useAtom p (v.t ()) (v.s ()) (v.f ()) t)) +def stave (v : Solo p) (n : ℕ) := blockRay p n (v.s ()) Block.Z +def slash (v : Solo p) (m : Mixer p n) (x : Profile p n) := qmix m x (v.t ()) + +def scroll (v : Solo p) (m : Mixer p n) (x : Profile p n) := + let P:=stave v n; let M := slash v m x + colSp (Pᵀ*M) ⊔ colSp (Pᵀ*Mᵀ) + +theorem scroll_dim (v : Solo p) (m : Mixer p n) (x : Profile p n) : + dim (scroll v m x) ≤ 2*(p.J*(p.g-1)*(2*totalRank x)) := by + let P:=stave v n; let M:=slash v m x; let k:=p.J*(p.g-1)*(2*totalRank x) + have hm : M.rank ≤ k := qmix_rank .. + have h1 : dim (colSp (Pᵀ*M)) ≤ k := (Matrix.rank_mul_le_right ..).trans hm + have h2 : dim (colSp (Pᵀ*Mᵀ)) ≤ k := + (Matrix.rank_mul_le_right ..).trans ((Matrix.rank_transpose _).le.trans hm) + exact (Submodule.finrank_add_le_finrank_add_finrank ..).trans + ((Nat.add_le_add h1 h2).trans_eq (two_mul _).symm) + +theorem shanty_arc (v : Solo p) (m : Mixer p n) (x : Profile p n) + (hg : Odd p.g) (u : Knobs p.g n) : + let P := v.stave n; let M:= v.slash m x + ∃ a : Ray p n,∃ b : F,∀ y, + v.shanty m x (update u Block.Z y)= + wsign (b + evmat M (P *ᵥ y+a) (P *ᵥ y+a)) := by + intro P M + let l := v.t (); let s := v.s (); let f := v.f () + let A := spring p l s f (update u Block.Z (0 : Vec (Fin n))) + let b := T0 p n x (useAtom p l s f u) + refine ⟨A,b,fun y => ?_⟩ + let t := update u Block.Z y + let k := useAtom p l s f t + have hx : Tsym m x k = T0 p n x k + evmat M (spring p l s f t) (spring p l s f t) := by + unfold Tsym k useAtom; rw [LinearMap.add_apply,LinearMap.add_apply,Tmix_atom] + exact congrArg (_ + ·) (mpair_outer ..) + have ht : spring p l s f t=P *ᵥ y+A := (spring_update _ _ _ _ _ _ (Flavor.keepZ ..) _).trans + (add_comm _ _) + change wsign (Tsym m x k)=_ + rw [hx,ht]; unfold k t b + rw [T0_scanZ p hg] + +set_option maxHeartbeats 600000 in +theorem shanty_cap (v : Solo p) (m : Mixer p n) (x : Profile p n) + (K s : ℕ) (hg : Odd p.g) (hm : unaryGood m K s) (hK : totalRank x≤K) + (hx : 0 (bit_cases _).resolve_right (h _ hj)) + obtain ⟨t,ht,he⟩ := hh + let W y := v.shanty m x (update u Block.Z y) + let C := P *ᵥ t + have hz (y) : W (y+t)=W y := by + obtain ⟨a,b,hQ⟩ := shanty_arc v m x hg u + have hh (M : Moment p n) (h : colSp (Pᵀ*M)≤S) (i : Ray p n) : + dotProduct C (M *ᵥ i)=0 := by + have h1 := (annih_mem ..).mp ht _ (h (show (Pᵀ*M)*ᵥi∈_ from ⟨i,rfl⟩)) + rw [← mulVec_mulVec,dotProduct_transpose_mulVec] at h1; rw [dotProduct_comm]; exact h1 + let B := fun y => P *ᵥ y+a + unfold W; simp_rw [hQ] + change wsign (b+evmat M (B (y+t)) (B (y+t)))=_ + rw [show B (y+t)=B y+C by unfold B C; rw [mulVec_add]; ac_rfl] + have h1 z : evmat M C z=0 := hh M le_sup_left z + have h2 z : evmat M z C=0 := (evmat_transpose M _ _).symm.trans (hh Mᵀ le_sup_right z) + unfold evmat at * + simp_rw [mulVec_add,dotProduct_add,add_dotProduct,h1,h2] + simp only [add_zero,B,P,M,mulVec_add,dotProduct_add,add_dotProduct] + unfold zhat + let Q (y) := vectorPhase i y*W y + have hq (y) : + Q (y+t) = Q y * (-1) := by unfold Q vectorPhase; rw [hz,dotProduct_add,wsign_add,he,wsign_one]; ring + change avg unif Q=0 + have hh := phase_trans t Q + simp_rw [hq] at hh; rw [avg_mul] at hh; linarith +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/TesterSummaryMass.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/TesterSummaryMass.lean index 487ffc74249b89410bc9ae46e0ad03ec6eadce2d..42570c618f2c44369a0de0f6f28fd45e6400a7f6 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/TesterSummaryMass.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/TesterSummaryMass.lean @@ -1,143 +1,143 @@ -import OAI.Combinatorics.HadwigerCounterexample.AtomFlavors -import OAI.Combinatorics.HadwigerCounterexample.PhaseAlternativeSupport - -namespace OAI - -/-! # Tester Summary Mass -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix LinearMap Module Finset Function -open scoped BigOperators -variable {p : Shape} {r n : ℕ} {A I : Type} [Fintype A] [Fintype I] -variable [DecidableEq I] - -theorem draws_unif : - unif (α:=I → A)=draws I (unif : Wgt A) := by - classical funext i - simp [draws,prodW,unif_apply] - -set_option maxHeartbeats 600000 in -theorem tested_fraction (r n : ℕ) (hr : 1≤r) (hn : 2*r≤n) (q : F) : - 1/4 ≤ pr unif (fun x : Vec (Fin n) => tested r x=q) := by - classical - let w := draws (Fin n) (unif (α:=F)) - let a : Fin n := ⟨0,by omega⟩ - let b : Fin n := ⟨1,by omega⟩ - let Z : Finset (Fin n) := {a,b} - have hh : pr unif (fun x : Vec (Fin n) => tested r x=q) = - avg w (fun x => pr w (fun y => tested r (refresh Z x y)=q)) := by - unfold pr; rw [draws_unif] - exact fresh_avg _ unif_law _ _ - rw [hh] - refine (draws_law unif_law).le_avg (fun v => ?_) - let i0 : Fin r := ⟨0,hr⟩ - let S : Finset (Fin r) := Finset.univ.erase i0 - let h (y : Vec (Fin n)) (i : Fin r) := zget y (2*i.val)*zget y (2*i.val+1) - let t := ∑ i∈S,h v i - have hg (y) (ha : y a=1) (hb : y b=q-t) : - tested r (refresh Z v y) = q := by - have hu (i : Fin r) (hh : i∈ S) : h (refresh Z v y) i=h v i := by - have hi := (mem_erase.mp hh).1 - have hi' : i.val ≠ 0 := fun h => hi (Fin.ext h) - have heq (j : ℕ) (h : 1 cases j <;> simp [f,a,b] - have hi : pr w (fun x => ∀ i,P i (x (f i)))=1/4 := by - change pr (prodW _) _ = _ - rw [prodW_pr_inj he (fun _ => unif_law) P] - simp only [Fintype.prod_bool,P,pr_point',unif_apply,F] - norm_num [ZMod.card] - rw [←hi] - exact pr_mono (draws_law unif_law).nz (fun y h => hg _ (h true) (h false)) - -def scanPrice (p : Shape) : ℝ := (1/4)^Fintype.card (ProbeIdx p.g) - -theorem scan_fraction (l : Tag p.g) (f : Flavor p.g) (x : Digest p.g) - (hr : 1 ≤ p.r) (hn : 2*p.r ≤ n) (hx : x.feasible l f) : - scanPrice p ≤ pr (spins p n) (fun y => scan p l f y=x) := by - classical - let P (i : ProbeIdx p.g) (v : Vec (Fin n)) := - (if f.keeps l (asBlock i) then tested p.r v else 0)=x i - have h (i) : 1/4 ≤ pr unif (P i) := by - by_cases h : f.keeps l (asBlock i) - · simpa only [P,h,ite_true] using tested_fraction _ _ hr hn (x i) - simp [P,h,hx _ h,unif_law.total]; norm_num - have hi y : scan p l f y=x ↔ ∀ i,P i (y (asBlock i)) := funext_iff - change _ ≤ pr (draws _ _) _ - simp_rw [hi] - rw [draws,prodW_pr_inj asBlock_inj (fun _ => unif_law) P] - refine le_trans ?_ (Finset.prod_le_prod₀ (fun i _ => ?_) fun i _ => h i) - · simp [scanPrice] - norm_num - -def canDial (p : Shape) (l : Tag p.g) (f : Flavor p.g) (q : F) := - ∃ v : Digest p.g, v.feasible l f ∧ v.sumBit=q - -theorem dial_fraction (p : Shape) (n : ℕ) (l) (f : Flavor p.g) (x : F) - (hr : 1 ≤ p.r) (hn : 2*p.r ≤ n) (hx : canDial p l f x) : - scanPrice p ≤ pr (spins p n) (fun y => dialed p l f y=x) := by - obtain ⟨v,hv,h⟩ := hx - exact (scan_fraction l f v hr hn hv).trans - (pr_mono (spins_law p n).nz fun i hi => (congrArg Digest.sumBit hi).trans h) - -theorem scanPrice_pos (p : Shape) : 0 q-y) - have hf : v.diagO=y := by - unfold Digest.diagO; rw [Finset.sum_eq_single i] - · rw [Finset.sum_eq_single l] - · simp [v] - · intro k _ hk; simp [v,hk] - simp - · intro k _ hk; simp [v,hk] - simp - refine ⟨v,?_,?_,hf⟩ - · rintro (⟨j,t⟩|_) hj - · have h : (j,t) ≠ (i,l) := by - rintro hk - obtain rfl : j=i := congrArg Prod.fst hk - exact hj hi - exact Pi.single_eq_of_ne h _ - exact (hj trivial).elim - unfold Digest.sumBit - rw [hf]; change y+(q-y)=q - rw [add_sub_cancel] - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.AtomFlavors +import OAI.Combinatorics.HadwigerCounterexample.PhaseAlternativeSupport + +namespace OAI + +/-! # Tester Summary Mass -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Finset Function +open scoped BigOperators +variable {p : Shape} {r n : ℕ} {A I : Type} [Fintype A] [Fintype I] +variable [DecidableEq I] + +theorem draws_unif : + unif (α:=I → A)=draws I (unif : Wgt A) := by + classical funext i + simp [draws,prodW,unif_apply] + +set_option maxHeartbeats 600000 in +theorem tested_fraction (r n : ℕ) (hr : 1≤r) (hn : 2*r≤n) (q : F) : + 1/4 ≤ pr unif (fun x : Vec (Fin n) => tested r x=q) := by + classical + let w := draws (Fin n) (unif (α:=F)) + let a : Fin n := ⟨0,by omega⟩ + let b : Fin n := ⟨1,by omega⟩ + let Z : Finset (Fin n) := {a,b} + have hh : pr unif (fun x : Vec (Fin n) => tested r x=q) = + avg w (fun x => pr w (fun y => tested r (refresh Z x y)=q)) := by + unfold pr; rw [draws_unif] + exact fresh_avg _ unif_law _ _ + rw [hh] + refine (draws_law unif_law).le_avg (fun v => ?_) + let i0 : Fin r := ⟨0,hr⟩ + let S : Finset (Fin r) := Finset.univ.erase i0 + let h (y : Vec (Fin n)) (i : Fin r) := zget y (2*i.val)*zget y (2*i.val+1) + let t := ∑ i∈S,h v i + have hg (y) (ha : y a=1) (hb : y b=q-t) : + tested r (refresh Z v y) = q := by + have hu (i : Fin r) (hh : i∈ S) : h (refresh Z v y) i=h v i := by + have hi := (mem_erase.mp hh).1 + have hi' : i.val ≠ 0 := fun h => hi (Fin.ext h) + have heq (j : ℕ) (h : 1 cases j <;> simp [f,a,b] + have hi : pr w (fun x => ∀ i,P i (x (f i)))=1/4 := by + change pr (prodW _) _ = _ + rw [prodW_pr_inj he (fun _ => unif_law) P] + simp only [Fintype.prod_bool,P,pr_point',unif_apply,F] + norm_num [ZMod.card] + rw [←hi] + exact pr_mono (draws_law unif_law).nz (fun y h => hg _ (h true) (h false)) + +def scanPrice (p : Shape) : ℝ := (1/4)^Fintype.card (ProbeIdx p.g) + +theorem scan_fraction (l : Tag p.g) (f : Flavor p.g) (x : Digest p.g) + (hr : 1 ≤ p.r) (hn : 2*p.r ≤ n) (hx : x.feasible l f) : + scanPrice p ≤ pr (spins p n) (fun y => scan p l f y=x) := by + classical + let P (i : ProbeIdx p.g) (v : Vec (Fin n)) := + (if f.keeps l (asBlock i) then tested p.r v else 0)=x i + have h (i) : 1/4 ≤ pr unif (P i) := by + by_cases h : f.keeps l (asBlock i) + · simpa only [P,h,ite_true] using tested_fraction _ _ hr hn (x i) + simp [P,h,hx _ h,unif_law.total]; norm_num + have hi y : scan p l f y=x ↔ ∀ i,P i (y (asBlock i)) := funext_iff + change _ ≤ pr (draws _ _) _ + simp_rw [hi] + rw [draws,prodW_pr_inj asBlock_inj (fun _ => unif_law) P] + refine le_trans ?_ (Finset.prod_le_prod₀ (fun i _ => ?_) fun i _ => h i) + · simp [scanPrice] + norm_num + +def canDial (p : Shape) (l : Tag p.g) (f : Flavor p.g) (q : F) := + ∃ v : Digest p.g, v.feasible l f ∧ v.sumBit=q + +theorem dial_fraction (p : Shape) (n : ℕ) (l) (f : Flavor p.g) (x : F) + (hr : 1 ≤ p.r) (hn : 2*p.r ≤ n) (hx : canDial p l f x) : + scanPrice p ≤ pr (spins p n) (fun y => dialed p l f y=x) := by + obtain ⟨v,hv,h⟩ := hx + exact (scan_fraction l f v hr hn hv).trans + (pr_mono (spins_law p n).nz fun i hi => (congrArg Digest.sumBit hi).trans h) + +theorem scanPrice_pos (p : Shape) : 0 q-y) + have hf : v.diagO=y := by + unfold Digest.diagO; rw [Finset.sum_eq_single i] + · rw [Finset.sum_eq_single l] + · simp [v] + · intro k _ hk; simp [v,hk] + simp + · intro k _ hk; simp [v,hk] + simp + refine ⟨v,?_,?_,hf⟩ + · rintro (⟨j,t⟩|_) hj + · have h : (j,t) ≠ (i,l) := by + rintro hk + obtain rfl : j=i := congrArg Prod.fst hk + exact hj hi + exact Pi.single_eq_of_ne h _ + exact (hj trivial).elim + unfold Digest.sumBit + rw [hf]; change y+(q-y)=q + rw [add_sub_cancel] + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/UltrafilterRates.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/UltrafilterRates.lean index b75a88f5bcac3196a48dc590444cc8579359858a..841b8cff45b369bc55a7317838d20c485684a4a7 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/UltrafilterRates.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/UltrafilterRates.lean @@ -1,119 +1,119 @@ -import OAI.Combinatorics.HadwigerCounterexample.ExponentialRates -import Mathlib.Order.Filter.Ultrafilter.Basic - -namespace OAI - -/-! # Ultrafilter Rates -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Real Finset -open scoped Topology - -variable {A B : Type} {l : Filter A} {U : Ultrafilter A} {x y z v a : A → ℝ} - -/-- Upper target thresholds, without claiming nonnegativity. -/ -def slight (l : Filter A) (x : A→ℝ) := ∀ δ:ℝ,0<δ→∀ᶠ n in l,x n≤δ - -theorem slight_gap : - slight (U : Filter A) x ∨ ∃ δ:ℝ,0<δ∧∀ᶠ n in U, δ < x n := by - by_cases h : slight (U : Filter A) x - · exact Or.inl h - right - unfold slight at h - - push Not at h - obtain ⟨δ,hd,h⟩:=h - exact ⟨δ,hd,h⟩ - -/-- At least subexponential mass. -/ -def warm (l : Filter A) (z x : A→ℝ) := - ∀ ε:ℝ,0<ε → ∀ᶠ i in l,bp (-ε * z i) ≤ x i - -namespace warm - -theorem const (hz : Tendsto z l atTop) {a : ℝ} (ha : 0a) := by - intro ε he - exact (((bp_tendsto_zero he).comp hz).eventually (gt_mem_nhds ha)).mono (fun _ h=> h.le) -theorem mono (h : warm l z x) (hg : ∀ᶠ i in l,x i≤ y i) : warm l z y := fun ε he=> - (h ε he).mp (hg.mono fun _ hi h=>h.trans hi) -theorem positive (h : warm l z x) : ∀ᶠ i in l,0 (bp_pos _).trans_le hi) - -theorem mul (h : warm l z x) (hg : warm l z y) : warm l z (fun i=> x i*y i) := by - intro ε he - filter_upwards [h (ε/2) (half_pos he),hg (ε/2) (half_pos he)] with i hi hj - rw [show -ε*z i= -(ε/2)*z i + -(ε/2)*z i from by ring,bp_add] - exact mul_le_mul hi hj (bp_pos _).le ((bp_pos _).le.trans hi) -theorem inv_cap (h : warm l z x) : ExpO l z (fun i=> (x i)⁻¹) := by - intro c hc - filter_upwards [h c hc] with i hi - rw [abs_of_nonneg (inv_nonneg.mpr ((bp_pos _).le.trans hi))] - exact le_trans (inv_anti₀ (bp_pos _) hi) (le_of_eq (by rw [neg_mul,bp_neg,inv_inv])) - -theorem survive (hz : Tendsto z l atTop) (h : warm l z x) (hg : ExpSmall l z y) : - warm l z (fun i=> x i - y i) := by - have he := (hg.mul h.inv_cap).lim hz - refine ((const hz (by norm_num : 0<(1/2:ℝ))).mul h).mono ?_ - filter_upwards [h.positive,he.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1/2))] - with i hi hg - change y i*(x i)⁻¹<1/2 at hg - rw [←div_eq_mul_inv] at hg - linarith only [(div_lt_iff₀ hi).mp hg] -end warm - -namespace ExpSmall -theorem bp_n {c : ℝ} (hc : 0bp (-c*z n)) := - ⟨_,hc,.of_forall (fun _ => (abs_of_pos (bp_pos _)).le)⟩ - -theorem poly (hz : Tendsto z l atTop) (hx : ExpSmall l z x) (k : ℕ) : - ExpSmall l z (fun n=>x n*(z n)^k) := by - refine hx.mul (fun ε he => ?_) - have hp : ∀ᶠ n in l, 1*(z n)^(k:ℝ)< bp (ε*z n) := - hz.eventually (bp_poly_dom he _ _) - filter_upwards [hp,hz.eventually (eventually_ge_atTop 0)] with n hn h - rw [abs_of_nonneg (pow_nonneg h _),←Real.rpow_natCast] - simpa only [one_mul] using hn.le - -end ExpSmall - -theorem taking {X : A→ Type*} [∀ n,Nonempty (X n)] - {P : ∀ n,X n→Prop} (h : ∀ᶠ n in l,∃ w:X n,P n w) : - ∃ w:∀ n,X n,∀ᶠ n in l,P n (w n) := by - classical - let f n:= if h:∃ w,P n w then h.choose else Classical.choice (inferInstance:Nonempty (X n)) - refine ⟨f,h.mono (fun n hn=>?_)⟩ - unfold f; rw [dite_eq_left hn]; exact hn.choose_spec - -theorem diagonal_gains (l : Filter ℕ) (h : l ≤ atTop) (P : ℕ → ℕ→Prop) - (hp : ∀ k,∀ᶠ n in l,P n k) : - ∃ k:ℕ→ℕ,Tendsto k l atTop∧∀ᶠ n in l,P n (k n) := by - classical - let a (n : ℕ) : Finset ℕ := (Finset.range (n+1)).filter (P n) - let k (n : ℕ) := if h:(a n).Nonempty then (a n).max' h else 0 - have he (n r : ℕ) (hr : r≤n) (hc : P n r) : P n (k n) ∧ r≤k n := by - have hx : r∈a n := mem_filter.mpr ⟨mem_range.mpr (by omega),hc⟩ - unfold k; rw [dite_eq_left ⟨r,hx⟩] - exact ⟨(mem_filter.mp (Finset.max'_mem _ _)).2,Finset.le_max' _ _ hx⟩ - have heq r : ∀ᶠ n in l,P n (k n) ∧ r≤ k n := - (hp r).and ((eventually_ge_atTop r).filter_mono h) |>.mono (fun n ⟨hh,hx⟩=>he n r hx hh) - exact ⟨k,tendsto_atTop.mpr (fun b=> (heq b).mono fun _=> And.right),(heq 0).mono fun _=> And.left⟩ - -theorem slight_inv_stage {f : ℕ→ℕ} {l : Filter ℕ} (hf : Tendsto f l atTop) : - slight l (fun i=> ((f i:ℝ)+1)⁻¹) := by - have h : Tendsto (fun i => (f i:ℝ)+1) l atTop := - tendsto_atTop_add_const_right _ _ (tendsto_natCast_atTop_atTop.comp hf) - intro ε he - exact (h.inv_tendsto_atTop.eventually (gt_mem_nhds he)).mono fun n hn=>hn.le - -theorem trend_sizes (l : Filter ℕ) (h : l ≤ atTop) {M : ℕ} (hM : 1≤ M) : - Tendsto (fun n=> M*n) l atTop ∧ Tendsto (fun n=> ((M*n:ℕ):ℝ)) l atTop := by - have hh : Tendsto (fun n : ℕ=> M*n) atTop atTop := tendsto_atTop.mpr (fun a => - (eventually_ge_atTop a).mono (fun k hk=> le_trans hk (by nlinarith))) - exact ⟨hh.mono_left h, tendsto_natCast_atTop_atTop.comp (hh.mono_left h)⟩ - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ExponentialRates +import Mathlib.Order.Filter.Ultrafilter.Basic + +namespace OAI + +/-! # Ultrafilter Rates -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Real Finset +open scoped Topology + +variable {A B : Type} {l : Filter A} {U : Ultrafilter A} {x y z v a : A → ℝ} + +/-- Upper target thresholds, without claiming nonnegativity. -/ +def slight (l : Filter A) (x : A→ℝ) := ∀ δ:ℝ,0<δ→∀ᶠ n in l,x n≤δ + +theorem slight_gap : + slight (U : Filter A) x ∨ ∃ δ:ℝ,0<δ∧∀ᶠ n in U, δ < x n := by + by_cases h : slight (U : Filter A) x + · exact Or.inl h + right + unfold slight at h + + push Not at h + obtain ⟨δ,hd,h⟩:=h + exact ⟨δ,hd,h⟩ + +/-- At least subexponential mass. -/ +def warm (l : Filter A) (z x : A→ℝ) := + ∀ ε:ℝ,0<ε → ∀ᶠ i in l,bp (-ε * z i) ≤ x i + +namespace warm + +theorem const (hz : Tendsto z l atTop) {a : ℝ} (ha : 0a) := by + intro ε he + exact (((bp_tendsto_zero he).comp hz).eventually (gt_mem_nhds ha)).mono (fun _ h=> h.le) +theorem mono (h : warm l z x) (hg : ∀ᶠ i in l,x i≤ y i) : warm l z y := fun ε he=> + (h ε he).mp (hg.mono fun _ hi h=>h.trans hi) +theorem positive (h : warm l z x) : ∀ᶠ i in l,0 (bp_pos _).trans_le hi) + +theorem mul (h : warm l z x) (hg : warm l z y) : warm l z (fun i=> x i*y i) := by + intro ε he + filter_upwards [h (ε/2) (half_pos he),hg (ε/2) (half_pos he)] with i hi hj + rw [show -ε*z i= -(ε/2)*z i + -(ε/2)*z i from by ring,bp_add] + exact mul_le_mul hi hj (bp_pos _).le ((bp_pos _).le.trans hi) +theorem inv_cap (h : warm l z x) : ExpO l z (fun i=> (x i)⁻¹) := by + intro c hc + filter_upwards [h c hc] with i hi + rw [abs_of_nonneg (inv_nonneg.mpr ((bp_pos _).le.trans hi))] + exact le_trans (inv_anti₀ (bp_pos _) hi) (le_of_eq (by rw [neg_mul,bp_neg,inv_inv])) + +theorem survive (hz : Tendsto z l atTop) (h : warm l z x) (hg : ExpSmall l z y) : + warm l z (fun i=> x i - y i) := by + have he := (hg.mul h.inv_cap).lim hz + refine ((const hz (by norm_num : 0<(1/2:ℝ))).mul h).mono ?_ + filter_upwards [h.positive,he.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1/2))] + with i hi hg + change y i*(x i)⁻¹<1/2 at hg + rw [←div_eq_mul_inv] at hg + linarith only [(div_lt_iff₀ hi).mp hg] +end warm + +namespace ExpSmall +theorem bp_n {c : ℝ} (hc : 0bp (-c*z n)) := + ⟨_,hc,.of_forall (fun _ => (abs_of_pos (bp_pos _)).le)⟩ + +theorem poly (hz : Tendsto z l atTop) (hx : ExpSmall l z x) (k : ℕ) : + ExpSmall l z (fun n=>x n*(z n)^k) := by + refine hx.mul (fun ε he => ?_) + have hp : ∀ᶠ n in l, 1*(z n)^(k:ℝ)< bp (ε*z n) := + hz.eventually (bp_poly_dom he _ _) + filter_upwards [hp,hz.eventually (eventually_ge_atTop 0)] with n hn h + rw [abs_of_nonneg (pow_nonneg h _),←Real.rpow_natCast] + simpa only [one_mul] using hn.le + +end ExpSmall + +theorem taking {X : A→ Type*} [∀ n,Nonempty (X n)] + {P : ∀ n,X n→Prop} (h : ∀ᶠ n in l,∃ w:X n,P n w) : + ∃ w:∀ n,X n,∀ᶠ n in l,P n (w n) := by + classical + let f n:= if h:∃ w,P n w then h.choose else Classical.choice (inferInstance:Nonempty (X n)) + refine ⟨f,h.mono (fun n hn=>?_)⟩ + unfold f; rw [dite_eq_left hn]; exact hn.choose_spec + +theorem diagonal_gains (l : Filter ℕ) (h : l ≤ atTop) (P : ℕ → ℕ→Prop) + (hp : ∀ k,∀ᶠ n in l,P n k) : + ∃ k:ℕ→ℕ,Tendsto k l atTop∧∀ᶠ n in l,P n (k n) := by + classical + let a (n : ℕ) : Finset ℕ := (Finset.range (n+1)).filter (P n) + let k (n : ℕ) := if h:(a n).Nonempty then (a n).max' h else 0 + have he (n r : ℕ) (hr : r≤n) (hc : P n r) : P n (k n) ∧ r≤k n := by + have hx : r∈a n := mem_filter.mpr ⟨mem_range.mpr (by omega),hc⟩ + unfold k; rw [dite_eq_left ⟨r,hx⟩] + exact ⟨(mem_filter.mp (Finset.max'_mem _ _)).2,Finset.le_max' _ _ hx⟩ + have heq r : ∀ᶠ n in l,P n (k n) ∧ r≤ k n := + (hp r).and ((eventually_ge_atTop r).filter_mono h) |>.mono (fun n ⟨hh,hx⟩=>he n r hx hh) + exact ⟨k,tendsto_atTop.mpr (fun b=> (heq b).mono fun _=> And.right),(heq 0).mono fun _=> And.left⟩ + +theorem slight_inv_stage {f : ℕ→ℕ} {l : Filter ℕ} (hf : Tendsto f l atTop) : + slight l (fun i=> ((f i:ℝ)+1)⁻¹) := by + have h : Tendsto (fun i => (f i:ℝ)+1) l atTop := + tendsto_atTop_add_const_right _ _ (tendsto_natCast_atTop_atTop.comp hf) + intro ε he + exact (h.inv_tendsto_atTop.eventually (gt_mem_nhds he)).mono fun n hn=>hn.le + +theorem trend_sizes (l : Filter ℕ) (h : l ≤ atTop) {M : ℕ} (hM : 1≤ M) : + Tendsto (fun n=> M*n) l atTop ∧ Tendsto (fun n=> ((M*n:ℕ):ℝ)) l atTop := by + have hh : Tendsto (fun n : ℕ=> M*n) atTop atTop := tendsto_atTop.mpr (fun a => + (eventually_ge_atTop a).mono (fun k hk=> le_trans hk (by nlinarith))) + exact ⟨hh.mono_left h, tendsto_natCast_atTop_atTop.comp (hh.mono_left h)⟩ + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryCellComparisons.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryCellComparisons.lean index e5d192f4c1bb051144ce6829a9e5e4096f83d279..60454fe253a35f76f751c96df2015ea5f4deea8b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryCellComparisons.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryCellComparisons.lean @@ -1,135 +1,135 @@ -import OAI.Combinatorics.HadwigerCounterexample.CutIntegralBounds -import OAI.Combinatorics.HadwigerCounterexample.ReferenceProductTests - -namespace OAI - -/-! # Unary Cell Comparisons -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module Finset Function Filter -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I J A : Type} [Fintype I] [DecidableEq I] [Fintype J] - -namespace Template -variable (v : Template p I) - -def curtain (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) := - fun x => ind (ownPart (p:=p) v.t q x)*U x -def propel (v : Template p I) (s : Script p I) (m : Mixer p n) := - fun z => ind ((v.draw z).reads s m) - -abbrev Localist (v : Template p I) (N : ℕ) := - ∀ i,Wgt (AtomKey (p:=p) (v.t i) N) -def board (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) - (f : v.Localist N) := - avg unif (fun i=> curtain v q U i * prodW f i) -def shadowed (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) (ε : ℝ) := - ∀ f : v.Localist N,(∀ i j,|f i j|≤1)→ |board v q U f| ≤ ε - -def astonish (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) - (s : Script p I) (m : Mixer p n) (w f : I→Wgt (Knobs p.g n)) (o) := - scene v (propel v s m) (curtain v q U) w f o -def exceeds (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) - (s : Script p I) (m : Mixer p n) (w : I→Wgt (Knobs p.g n)) (ε : ℝ) - (o : UnitType p n N) := - blackout v (propel v s m) (curtain v q U) w ε o - -theorem astonish_val (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) - (s : Script p I) (m : Mixer p n) (w f : I→Wgt (Knobs p.g n)) (o) : - astonish v q U s m w f o= - avg (prodW w) (fun i => ind (earns v s m q o i)*U (resultKey v o i)*prodW f i) := by - unfold astonish earns scene protean curtain propel - simp_rw [ind_and]; exact avg_congr fun i _=>by ring - -structure Paint (v : Template p I) (N : ℕ) where - coeff : ℝ - flies : ∀ i,AtomKey (p:=p) (v.t i) N → Prop -def Paint.cost {v : Template p I} (w : Paint v N) (x : Keys (p:=p) v.t N) := - w.coeff * prodW (fun i j => ind (w.flies i j)) x -def mural (v : Template p I) (w : J → Paint v N) := fun x => ∑ i:J,(w i).cost x -def design (v : Template p I) (w : Wgt (Keys (p:=p) v.t N)) (M : ℝ) (r : ℕ) := - ∃ x:Fin r→Paint v N,w=mural v x∧ ∀ i,|(x i).coeff|≤M - -def patched (v : Template p I) (x : I) - (a : AtomKey (p:=p) (v.t x) N → A) - (B : A → Wgt (Keys (p:=p) (v.beyond x).t N)) := - fun (i:Keys (p:=p) v.t N) => B (a (i x)) ((v.chairK x N i).2) - -omit [DecidableEq I] in -theorem design_mono (v : Template p I) (w : Wgt (Keys (p:=p) v.t N)) - (M : ℝ) (r s : ℕ) (hM : 0 ≤ M) (h : r ≤ s) (hr : design v w M r) : - design v w M s := by - classical - obtain ⟨f,hf,hg⟩ := hr - let g (i : Fin s) : Paint v N := if h:i.valTrue⟩ - let k := Fin.castLE h - have hi i : g (k i)=f i := by unfold g k; simp - refine ⟨g,funext fun x=>?_,fun i=>?_⟩ - · rw [hf] - unfold mural - have h1 : - ∑ i:Fin r, (f i).cost x =∑ i∈ Finset.univ.image k,(g i).cost x := by - rw [Finset.sum_image (Fin.castLE_injective h).injOn] - exact Finset.sum_congr rfl (fun i _ => congrArg (fun t=> t.cost x) (hi i).symm) - rw [h1] - apply Finset.sum_subset (Finset.subset_univ _) - intro i _ hh - have hp : ¬i.val hh (mem_image.mpr ⟨⟨i.val,he⟩,mem_univ _,rfl⟩) - unfold g Paint.cost; simp only [dite_eq_right hp,zero_mul] - unfold g; split - next h => exact hg _ - next h => simpa using hM - -noncomputable def paintJoin (v : Template p I) (x : I) - (d : AtomKey (p:=p) (v.t x) N → Prop) - (p' : Paint (v.beyond x) N) : Paint v N where - coeff := p'.coeff - flies i := if h:i=x then by subst x; exact d else p'.flies (⟨i,h⟩ : Aside x) - -theorem join_cost (v : Template p I) (x : I) (d : AtomKey (p:=p) (v.t x) N → Prop) - (w : Paint (v.beyond x) N) (k) : - (paintJoin v x d w).cost k=ind (d (k x))*w.cost ((v.chairK x N k).2) := by - classical - unfold Paint.cost - rw [chair_split _ _ x] - let f := paintJoin v x d w - have ht : f.flies x=d := by unfold f paintJoin; simp - have hi (i:Aside x) : f.flies i.val=w.flies i := - dite_eq_right i.property - rw [ht] - have hh : prodW (fun i : Aside x => fun j => ind (f.flies i.val j)) - ((v.chairK x N k).2)=prodW (fun i j => ind (w.flies i j)) ((v.chairK x N k).2) := - Finset.prod_congr rfl (fun i _=>congrArg _ (congr_fun (hi i) _)) - change w.coeff* (_ * prodW (fun i : Aside x => fun j => ind (f.flies i.val j)) - ((v.chairK x N k).2))=_ - rw [hh] - ring - -set_option maxHeartbeats 600000 in -theorem design_patch (v : Template p I) (x : I) (r s : ℕ) - (a : AtomKey (p:=p) (v.t x) N → Fin r) - (B : Fin r → Wgt (Keys (p:=p) (v.beyond x).t N)) (M : ℝ) - (h : ∀ i,design (v.beyond x) (B i) M s) : - design v (patched v x a B) M (r*s) := by - classical - choose p' hg hp using h - let g : Fin r × Fin s ≃ Fin (r*s) := Fintype.equivFinOfCardEq (by simp) - let f (i : Fin r × Fin s) := - paintJoin v x (fun j=>a j=i.1) (p' i.1 i.2) - refine ⟨f ∘ g.symm,?_,fun i => hp _ _⟩ - funext i; unfold patched mural - rw [← Equiv.sum_comp g] - simp_rw [Function.comp_apply,Equiv.symm_apply_apply,f,join_cost] - rw [Fintype.sum_prod_type]; simp_rw [← Finset.mul_sum] - rw [Finset.sum_eq_single (a (i x))] - · rw [ind_one (show a (i x)=a (i x) from rfl),one_mul,hg] - rfl - · intro j _ hj; rw [ind_zero (Ne.symm hj),zero_mul] - simp -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CutIntegralBounds +import OAI.Combinatorics.HadwigerCounterexample.ReferenceProductTests + +namespace OAI + +/-! # Unary Cell Comparisons -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Module Finset Function Filter +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I J A : Type} [Fintype I] [DecidableEq I] [Fintype J] + +namespace Template +variable (v : Template p I) + +def curtain (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) := + fun x => ind (ownPart (p:=p) v.t q x)*U x +def propel (v : Template p I) (s : Script p I) (m : Mixer p n) := + fun z => ind ((v.draw z).reads s m) + +abbrev Localist (v : Template p I) (N : ℕ) := + ∀ i,Wgt (AtomKey (p:=p) (v.t i) N) +def board (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) + (f : v.Localist N) := + avg unif (fun i=> curtain v q U i * prodW f i) +def shadowed (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) (ε : ℝ) := + ∀ f : v.Localist N,(∀ i j,|f i j|≤1)→ |board v q U f| ≤ ε + +def astonish (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) + (s : Script p I) (m : Mixer p n) (w f : I→Wgt (Knobs p.g n)) (o) := + scene v (propel v s m) (curtain v q U) w f o +def exceeds (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) + (s : Script p I) (m : Mixer p n) (w : I→Wgt (Knobs p.g n)) (ε : ℝ) + (o : UnitType p n N) := + blackout v (propel v s m) (curtain v q U) w ε o + +theorem astonish_val (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) + (s : Script p I) (m : Mixer p n) (w f : I→Wgt (Knobs p.g n)) (o) : + astonish v q U s m w f o= + avg (prodW w) (fun i => ind (earns v s m q o i)*U (resultKey v o i)*prodW f i) := by + unfold astonish earns scene protean curtain propel + simp_rw [ind_and]; exact avg_congr fun i _=>by ring + +structure Paint (v : Template p I) (N : ℕ) where + coeff : ℝ + flies : ∀ i,AtomKey (p:=p) (v.t i) N → Prop +def Paint.cost {v : Template p I} (w : Paint v N) (x : Keys (p:=p) v.t N) := + w.coeff * prodW (fun i j => ind (w.flies i j)) x +def mural (v : Template p I) (w : J → Paint v N) := fun x => ∑ i:J,(w i).cost x +def design (v : Template p I) (w : Wgt (Keys (p:=p) v.t N)) (M : ℝ) (r : ℕ) := + ∃ x:Fin r→Paint v N,w=mural v x∧ ∀ i,|(x i).coeff|≤M + +def patched (v : Template p I) (x : I) + (a : AtomKey (p:=p) (v.t x) N → A) + (B : A → Wgt (Keys (p:=p) (v.beyond x).t N)) := + fun (i:Keys (p:=p) v.t N) => B (a (i x)) ((v.chairK x N i).2) + +omit [DecidableEq I] in +theorem design_mono (v : Template p I) (w : Wgt (Keys (p:=p) v.t N)) + (M : ℝ) (r s : ℕ) (hM : 0 ≤ M) (h : r ≤ s) (hr : design v w M r) : + design v w M s := by + classical + obtain ⟨f,hf,hg⟩ := hr + let g (i : Fin s) : Paint v N := if h:i.valTrue⟩ + let k := Fin.castLE h + have hi i : g (k i)=f i := by unfold g k; simp + refine ⟨g,funext fun x=>?_,fun i=>?_⟩ + · rw [hf] + unfold mural + have h1 : + ∑ i:Fin r, (f i).cost x =∑ i∈ Finset.univ.image k,(g i).cost x := by + rw [Finset.sum_image (Fin.castLE_injective h).injOn] + exact Finset.sum_congr rfl (fun i _ => congrArg (fun t=> t.cost x) (hi i).symm) + rw [h1] + apply Finset.sum_subset (Finset.subset_univ _) + intro i _ hh + have hp : ¬i.val hh (mem_image.mpr ⟨⟨i.val,he⟩,mem_univ _,rfl⟩) + unfold g Paint.cost; simp only [dite_eq_right hp,zero_mul] + unfold g; split + next h => exact hg _ + next h => simpa using hM + +noncomputable def paintJoin (v : Template p I) (x : I) + (d : AtomKey (p:=p) (v.t x) N → Prop) + (p' : Paint (v.beyond x) N) : Paint v N where + coeff := p'.coeff + flies i := if h:i=x then by subst x; exact d else p'.flies (⟨i,h⟩ : Aside x) + +theorem join_cost (v : Template p I) (x : I) (d : AtomKey (p:=p) (v.t x) N → Prop) + (w : Paint (v.beyond x) N) (k) : + (paintJoin v x d w).cost k=ind (d (k x))*w.cost ((v.chairK x N k).2) := by + classical + unfold Paint.cost + rw [chair_split _ _ x] + let f := paintJoin v x d w + have ht : f.flies x=d := by unfold f paintJoin; simp + have hi (i:Aside x) : f.flies i.val=w.flies i := + dite_eq_right i.property + rw [ht] + have hh : prodW (fun i : Aside x => fun j => ind (f.flies i.val j)) + ((v.chairK x N k).2)=prodW (fun i j => ind (w.flies i j)) ((v.chairK x N k).2) := + Finset.prod_congr rfl (fun i _=>congrArg _ (congr_fun (hi i) _)) + change w.coeff* (_ * prodW (fun i : Aside x => fun j => ind (f.flies i.val j)) + ((v.chairK x N k).2))=_ + rw [hh] + ring + +set_option maxHeartbeats 600000 in +theorem design_patch (v : Template p I) (x : I) (r s : ℕ) + (a : AtomKey (p:=p) (v.t x) N → Fin r) + (B : Fin r → Wgt (Keys (p:=p) (v.beyond x).t N)) (M : ℝ) + (h : ∀ i,design (v.beyond x) (B i) M s) : + design v (patched v x a B) M (r*s) := by + classical + choose p' hg hp using h + let g : Fin r × Fin s ≃ Fin (r*s) := Fintype.equivFinOfCardEq (by simp) + let f (i : Fin r × Fin s) := + paintJoin v x (fun j=>a j=i.1) (p' i.1 i.2) + refine ⟨f ∘ g.symm,?_,fun i => hp _ _⟩ + funext i; unfold patched mural + rw [← Equiv.sum_comp g] + simp_rw [Function.comp_apply,Equiv.symm_apply_apply,f,join_cost] + rw [Fintype.sum_prod_type]; simp_rw [← Finset.mul_sum] + rw [Finset.sum_eq_single (a (i x))] + · rw [ind_one (show a (i x)=a (i x) from rfl),one_mul,hg] + rfl + · intro j _ hj; rw [ind_zero (Ne.symm hj),zero_mul] + simp +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryPositivityBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryPositivityBounds.lean index a17130cf81e3b80c517439e0ad86f9ae99902dab..9db66bbc9787704a3c4c3c8420ab7d55b62da44b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryPositivityBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryPositivityBounds.lean @@ -1,140 +1,140 @@ -import OAI.Combinatorics.HadwigerCounterexample.BasisConditioning - -namespace OAI - -/-! # Unary Positivity Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module LinearMap Function Filter -open scoped BigOperators -variable {p : Shape} {n N : ℕ} -namespace Template -variable (v : Solo p) - -def patrol (m : Mixer p n) (w : Wgt (Knobs p.g n)) - (S : AtomKey (p:=p) (v.t ()) N→Prop) (K : ℕ) (q : F) (x : Orient p n N) := - luminous v m w S K x ∧ - 3/4*pr (lawOmega p N (v.t ()) q) S ≤ pr w (offBeat v S x) - -variable {K s : ℕ} -set_option maxHeartbeats 1200000 in -theorem patrolled (v : Solo p) (M : ℕ) (hM : 1≤M) (hg : Odd p.g) (hj : 1≤p.j) - (z : Digest p.g) (hz : z.feasible (v.t ()) (v.f ())) (hr : 1≤p.r) - (η : ℝ) (hη : 0<η) - (hs : 2*profileA p K ¬ patrol v m w S K q x) ≤ bp (-(1/16:ℝ)*n) := by - classical - let δ := 3/4*η; have hδ : 0<δ := by positivity - let ε := η/4; have hε : 0<ε := by positivity - filter_upwards [radiance_calendar v hs hg δ _ hδ hG, - flat_recital v M hM hj ε hε,eventually_ge_atTop (2*p.r), - pay_nat (a:=1/8) (b:=1/16) 2 (by norm_num)] - with n hn hF hU ha N w q m hm hN S hS - let μ := raw m N - have hμ : IsLaw μ := raw_law m hN - let P := offBeat (n:=n) v S - let T (i : AtomKey (p:=p) (v.t ()) N) := ind (S i) - have hw : IsLaw w := scanLaw p _ _ _ hr hU hz - have he : - carried w (fun x => dialed p (v.t ()) (v.f ()) x=q) := fun i hi => by - unfold w scopedScan; rw [onW_val,ind_zero (show ¬ _ from fun h => - hi (congrArg Digest.sumBit h)),mul_zero,zero_div] - have ht (x) : |T x|≤1 := by rw [abs_of_nonneg (ind_nonneg (S x))]; exact ind_le_one _ - have hx := hF m w q hw he (scopedZ_scan p n _ _ _ hw) hN T ht - have hy := hn N hN m hm w hw (scanned_flow p n (v.t ()) (v.f ()) z) S - let b := pr (lawOmega p N (v.t ()) q) S - let X (x) := ε ≤ |pr w (P x)-b| - let Y (x) := ∃ i, 0 hh.2 ⟨z,h1,h2,h3⟩),hr⟩ - apply (le_trans (pr_mono hμ.nz hi) (pr_or_le hμ.nz)).trans - have h1 : pr μ X≤ bp (-(1/8:ℝ)*n) := le_trans (le_of_eq (by - unfold X P b minorCall offBeat T; simp only [pr]; rfl)) hx - apply (add_le_add h1 hy).trans - have he : (1:ℝ) ≤ profileA p K := by - have hi : 1≤psize p := Fintype.card_pos_iff.mpr ⟨emptySel⟩ - have hP : 0 < profileA p K := by unfold profileA; exact Nat.mul_pos (Nat.mul_pos (by omega) hi) (by omega) - exact_mod_cast (show 1≤profileA p K from hP) - rw [two_mul] at ha - refine le_trans ?_ ha - gcongr; linarith - -def basebeta (p : Shape) (K : ℕ) := - bp (-((K^2:ℕ):ℝ)-1)* scanPrice p - -theorem basebeta_pos (p : Shape) (K : ℕ) : 0 (scan p l t i=z∧ (offBeat v S o) i) ∧ stains v m f i=x) := by - classical - intro l t q u h d hd f hf hx x - let Q := offBeat v S o; let F (j : Knobs p.g n) := scan p l t j=z - let w := spins p n; let R (j : Knobs p.g n) := dialed p l t j=q - let v' := onW w F - have hw := spins_law p n - have hv' := scanLaw (n:=n) p l z t hr hn hz - let Z i := stains v m f i=x - let A := pr u S; let a := pr v' Q - have hA : 0 ≤ A := pr_nonneg (unifOn_sub _).nz - obtain ⟨⟨ha,hh⟩,he⟩ := h - specialize hh d hd f hf hx x - have ht : ∀ i,(F i ∧ Q i)∧Z i → R i := fun i h=> congrArg Digest.sumBit h.1.1 - let B := fun i=> (F i ∧ Q i) ∧ Z i - have hi : pr w B=pr w F*(a * pr (onW v' Q) Z) := by - rw [show B=(fun i => F i ∧ Q i∧Z i) from funext fun i=>propext and_assoc] - rw [pr_of_on hw.nz F]; congr 1 - exact pr_of_on hv'.nz Q Z - have hY : 0 < pr w R := - (scanPrice_pos _).trans_le (dial_fraction p n l t q hr hn ⟨z,hz,rfl⟩) - have hL : (7/8:ℝ)*bp (- (d:ℝ)) ≥ 7/8*bp (- ((K^2:ℕ):ℝ)) := - mul_le_mul_of_nonneg_left (bp_le (by exact_mod_cast neg_le_neg (by exact_mod_cast hd : - (d:ℝ)≤((K^2:ℕ):ℝ)))) (by norm_num) - change _≤pr (onW w R) B - have hR : pr w B≤ pr (onW w R) B := by - rw [pr_on,show (fun x=> R x∧ B x)= B from funext fun i=>propext ⟨And.right,fun h=>⟨ht i h,h⟩⟩] - exact (by - rw [le_div_iff₀ hY] - have hh := (pr_le_tot (p:=R) hw.nz).trans hw.total.le - exact (mul_le_mul_of_nonneg_left hh (pr_nonneg hw.nz)).trans_eq (mul_one _)) - apply le_trans ?_ hR - rw [hi]; unfold basebeta; rw [bp_sub,bp_one] - let K' := bp (-((K^2:ℕ):ℝ)) - have hg : scanPrice p*( (3/4*A)*(7/8*K')) ≤ pr w F*(a * pr (onW v' Q) Z) := - mul_le_mul (scan_fraction l t z hr hn hz) - (mul_le_mul he (le_trans hL hh) (mul_nonneg (by norm_num) (bp_pos _).le) ha.le) - (mul_nonneg (mul_nonneg (by norm_num) hA) (mul_nonneg (by norm_num) (bp_pos _).le)) - (pr_nonneg hw.nz) - refine le_trans ?_ hg - change K' / 2 * _ * _ ≤ _ - nlinarith only [mul_nonneg (mul_nonneg (scanPrice_pos p).le - (show 0≤K' from (bp_pos _).le)) hA] - -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BasisConditioning + +namespace OAI + +/-! # Unary Positivity Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module LinearMap Function Filter +open scoped BigOperators +variable {p : Shape} {n N : ℕ} +namespace Template +variable (v : Solo p) + +def patrol (m : Mixer p n) (w : Wgt (Knobs p.g n)) + (S : AtomKey (p:=p) (v.t ()) N→Prop) (K : ℕ) (q : F) (x : Orient p n N) := + luminous v m w S K x ∧ + 3/4*pr (lawOmega p N (v.t ()) q) S ≤ pr w (offBeat v S x) + +variable {K s : ℕ} +set_option maxHeartbeats 1200000 in +theorem patrolled (v : Solo p) (M : ℕ) (hM : 1≤M) (hg : Odd p.g) (hj : 1≤p.j) + (z : Digest p.g) (hz : z.feasible (v.t ()) (v.f ())) (hr : 1≤p.r) + (η : ℝ) (hη : 0<η) + (hs : 2*profileA p K ¬ patrol v m w S K q x) ≤ bp (-(1/16:ℝ)*n) := by + classical + let δ := 3/4*η; have hδ : 0<δ := by positivity + let ε := η/4; have hε : 0<ε := by positivity + filter_upwards [radiance_calendar v hs hg δ _ hδ hG, + flat_recital v M hM hj ε hε,eventually_ge_atTop (2*p.r), + pay_nat (a:=1/8) (b:=1/16) 2 (by norm_num)] + with n hn hF hU ha N w q m hm hN S hS + let μ := raw m N + have hμ : IsLaw μ := raw_law m hN + let P := offBeat (n:=n) v S + let T (i : AtomKey (p:=p) (v.t ()) N) := ind (S i) + have hw : IsLaw w := scanLaw p _ _ _ hr hU hz + have he : + carried w (fun x => dialed p (v.t ()) (v.f ()) x=q) := fun i hi => by + unfold w scopedScan; rw [onW_val,ind_zero (show ¬ _ from fun h => + hi (congrArg Digest.sumBit h)),mul_zero,zero_div] + have ht (x) : |T x|≤1 := by rw [abs_of_nonneg (ind_nonneg (S x))]; exact ind_le_one _ + have hx := hF m w q hw he (scopedZ_scan p n _ _ _ hw) hN T ht + have hy := hn N hN m hm w hw (scanned_flow p n (v.t ()) (v.f ()) z) S + let b := pr (lawOmega p N (v.t ()) q) S + let X (x) := ε ≤ |pr w (P x)-b| + let Y (x) := ∃ i, 0 hh.2 ⟨z,h1,h2,h3⟩),hr⟩ + apply (le_trans (pr_mono hμ.nz hi) (pr_or_le hμ.nz)).trans + have h1 : pr μ X≤ bp (-(1/8:ℝ)*n) := le_trans (le_of_eq (by + unfold X P b minorCall offBeat T; simp only [pr]; rfl)) hx + apply (add_le_add h1 hy).trans + have he : (1:ℝ) ≤ profileA p K := by + have hi : 1≤psize p := Fintype.card_pos_iff.mpr ⟨emptySel⟩ + have hP : 0 < profileA p K := by unfold profileA; exact Nat.mul_pos (Nat.mul_pos (by omega) hi) (by omega) + exact_mod_cast (show 1≤profileA p K from hP) + rw [two_mul] at ha + refine le_trans ?_ ha + gcongr; linarith + +def basebeta (p : Shape) (K : ℕ) := + bp (-((K^2:ℕ):ℝ)-1)* scanPrice p + +theorem basebeta_pos (p : Shape) (K : ℕ) : 0 (scan p l t i=z∧ (offBeat v S o) i) ∧ stains v m f i=x) := by + classical + intro l t q u h d hd f hf hx x + let Q := offBeat v S o; let F (j : Knobs p.g n) := scan p l t j=z + let w := spins p n; let R (j : Knobs p.g n) := dialed p l t j=q + let v' := onW w F + have hw := spins_law p n + have hv' := scanLaw (n:=n) p l z t hr hn hz + let Z i := stains v m f i=x + let A := pr u S; let a := pr v' Q + have hA : 0 ≤ A := pr_nonneg (unifOn_sub _).nz + obtain ⟨⟨ha,hh⟩,he⟩ := h + specialize hh d hd f hf hx x + have ht : ∀ i,(F i ∧ Q i)∧Z i → R i := fun i h=> congrArg Digest.sumBit h.1.1 + let B := fun i=> (F i ∧ Q i) ∧ Z i + have hi : pr w B=pr w F*(a * pr (onW v' Q) Z) := by + rw [show B=(fun i => F i ∧ Q i∧Z i) from funext fun i=>propext and_assoc] + rw [pr_of_on hw.nz F]; congr 1 + exact pr_of_on hv'.nz Q Z + have hY : 0 < pr w R := + (scanPrice_pos _).trans_le (dial_fraction p n l t q hr hn ⟨z,hz,rfl⟩) + have hL : (7/8:ℝ)*bp (- (d:ℝ)) ≥ 7/8*bp (- ((K^2:ℕ):ℝ)) := + mul_le_mul_of_nonneg_left (bp_le (by exact_mod_cast neg_le_neg (by exact_mod_cast hd : + (d:ℝ)≤((K^2:ℕ):ℝ)))) (by norm_num) + change _≤pr (onW w R) B + have hR : pr w B≤ pr (onW w R) B := by + rw [pr_on,show (fun x=> R x∧ B x)= B from funext fun i=>propext ⟨And.right,fun h=>⟨ht i h,h⟩⟩] + exact (by + rw [le_div_iff₀ hY] + have hh := (pr_le_tot (p:=R) hw.nz).trans hw.total.le + exact (mul_le_mul_of_nonneg_left hh (pr_nonneg hw.nz)).trans_eq (mul_one _)) + apply le_trans ?_ hR + rw [hi]; unfold basebeta; rw [bp_sub,bp_one] + let K' := bp (-((K^2:ℕ):ℝ)) + have hg : scanPrice p*( (3/4*A)*(7/8*K')) ≤ pr w F*(a * pr (onW v' Q) Z) := + mul_le_mul (scan_fraction l t z hr hn hz) + (mul_le_mul he (le_trans hL hh) (mul_nonneg (by norm_num) (bp_pos _).le) ha.le) + (mul_nonneg (mul_nonneg (by norm_num) hA) (mul_nonneg (by norm_num) (bp_pos _).le)) + (pr_nonneg hw.nz) + refine le_trans ?_ hg + change K' / 2 * _ * _ ≤ _ + nlinarith only [mul_nonneg (mul_nonneg (scanPrice_pos p).le + (show 0≤K' from (bp_pos _).le)) hA] + +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryQueryComparison.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryQueryComparison.lean index a069879d319fbe1de53f77d58dd0a20835b972d6..a6c70027f5802a853fa54b57f5206f84f71397aa 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryQueryComparison.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryQueryComparison.lean @@ -1,117 +1,117 @@ -import OAI.Combinatorics.HadwigerCounterexample.BinaryMixingBounds - -namespace OAI - -/-! # Unary Query Comparison -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Matrix Finset Filter Function LinearMap -variable {p : Shape} {n N : ℕ} - -namespace Template - -def solo (p : Shape) (t : Tag p.g) (s : Label p.b) (f : Flavor p.g) : - Template p Unit := ⟨fun _ => true,fun _=>t,fun _ =>s,fun _=>f⟩ - -abbrev Solo (p : Shape) := Template p Unit -variable (v : Solo p) - -def soloeq (N : ℕ) : Keys (p:=p) v.t N ≃ AtomKey (p:=p) (v.t ()) N where - toFun x := x () - invFun x i := i.rec x - left_inv x := by funext i; cases i; rfl - right_inv x := rfl - -theorem soloprice (q : F) : - mapW (lawNu p N v.t (fun _ => q)) (soloeq v N)=lawOmega p N (v.t ()) q := by - have hh : ownPart (p:=p) v.t (fun _=>q) = fun x => ownOne p _ q (soloeq v N x) := by - funext x - apply propext - rw [ownPart_def] - constructor - · intro h; exact h.1 () - intro h; exact ⟨fun i => (by cases i; exact h),fun i j _ _ _ hi => (hi - (Subsingleton.elim i j)).elim⟩ - unfold lawNu; rw [hh]; exact on_equiv .. - -set_option maxHeartbeats 800000 in -theorem solo_data (x : Knobs p.g n) (m : Mixer p n) (q : F) - (hj : 1≤p.j) (h : dialed p (v.t ()) (v.f ()) x=q) : - let k := ownPort (p:=p) v.t - let A := queryLaw v (fun _ => x) (g:=k) - (∀ i,Injective (A i).mulVec)∧ database m A A = ownMap v.t (fun _=>q) := by - classical - intro k A - have ht i : Subsingleton (Port k i) := ⟨fun p q => (own_inj v i) - (Subsingleton.elim _ _)⟩ - let s := v.s (); let l:=v.t (); let f := v.f (); let z := lit f l x - let u := point p s z - have he i (j : Port k i) : - (A i).col j=u := by - unfold A queryLaw u s z f l; rcases j with ⟨⟨a,w⟩,h⟩; cases a; rfl - constructor - · intro i x y h - have := ht i - funext j - let t : Row p n := (emptySel,none) - have hf : A i t j=1 := congr_fun (he i j) t |>.trans (point_base_eval p s z none) - have hh (x) : ((A i) *ᵥ x) t=x j := by - change ∑ j,A i t j*x j=_ - rw [Finset.sum_eq_single j] - · rw [hf,one_mul] - · intro k _ h; exact (h (Subsingleton.elim _ _)).elim - simp - rw [←hh x,←hh y]; exact congr_fun h _ - funext i - ext j t - have h1 := ht i |>.elim j t; subst t - unfold database ownMap - rw [diagonal_apply_eq] - let E := selfM p n m.mixM - have heM : mpair E (mom p s z)=q := (selfM_pair p hj _ (Submodule.subset_span - ⟨_,_,rfl⟩)).trans ((etaScan p l s f x).symm.trans h) - change (pullM (A i) (A i) E) j j=q - - have hh : (pullM (A i) (A i) E) j j=evmat E ((A i).col j) ((A i).col j) := by - rw [pullM_def,Matrix.mul_assoc]; rfl - rw [hh,he,← mpair_outer] - exact heM - -def desc (v : Solo p) (x : Knobs p.g n) (o : Orient p n N) := callOne v () x o -set_option maxHeartbeats 800000 in -theorem solo_read (v : Solo p) (m : Mixer p n) (hN : 2*num (Full p n) x - let A := v.queryLaw z (g:=g) - let T := (v.singleP n).showKey (N:=N) z - let W := scatter v.t N; let Q := soloeq v N - let u := fun x => f (Q (W.symm x)) - have ht (i) : u (T i)=f (v.desc x i) := by - unfold u T W - rw [single_show,Equiv.symm_apply_apply]; rfl - have hL : mapW (lawNu p N v.t (fun _ => q)) W=rackWave (ownMap v.t (fun _ => q)) N := - lawNu_rack .. - obtain ⟨he,he'⟩ := solo_data v x m q hj h - have hR : mapW (raw m N) T=rackStation (ownMap v.t (fun _ => q)) N := by - rw [←he']; exact law_peekR (g:=g) m hN he he - have h1 : avg (lawOmega p N (v.t ()) q) f = avg (rackWave (ownMap v.t (fun _=>q)) N) u := by - rw [←hL,←soloprice,mapW_avg,mapW_avg] - unfold u; simp_rw [Equiv.symm_apply_apply]; rfl - have h2 : avg (raw m N) (f ∘ v.desc x)=avg (rackStation (ownMap v.t (fun _=>q)) N) u := by - rw [←hR,mapW_avg]; simp_rw [ht]; rfl - rw [h2,h1]; exact compare_station _ u (fun i=>hf _) k hk hK -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BinaryMixingBounds + +namespace OAI + +/-! # Unary Query Comparison -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Matrix Finset Filter Function LinearMap +variable {p : Shape} {n N : ℕ} + +namespace Template + +def solo (p : Shape) (t : Tag p.g) (s : Label p.b) (f : Flavor p.g) : + Template p Unit := ⟨fun _ => true,fun _=>t,fun _ =>s,fun _=>f⟩ + +abbrev Solo (p : Shape) := Template p Unit +variable (v : Solo p) + +def soloeq (N : ℕ) : Keys (p:=p) v.t N ≃ AtomKey (p:=p) (v.t ()) N where + toFun x := x () + invFun x i := i.rec x + left_inv x := by funext i; cases i; rfl + right_inv x := rfl + +theorem soloprice (q : F) : + mapW (lawNu p N v.t (fun _ => q)) (soloeq v N)=lawOmega p N (v.t ()) q := by + have hh : ownPart (p:=p) v.t (fun _=>q) = fun x => ownOne p _ q (soloeq v N x) := by + funext x + apply propext + rw [ownPart_def] + constructor + · intro h; exact h.1 () + intro h; exact ⟨fun i => (by cases i; exact h),fun i j _ _ _ hi => (hi + (Subsingleton.elim i j)).elim⟩ + unfold lawNu; rw [hh]; exact on_equiv .. + +set_option maxHeartbeats 800000 in +theorem solo_data (x : Knobs p.g n) (m : Mixer p n) (q : F) + (hj : 1≤p.j) (h : dialed p (v.t ()) (v.f ()) x=q) : + let k := ownPort (p:=p) v.t + let A := queryLaw v (fun _ => x) (g:=k) + (∀ i,Injective (A i).mulVec)∧ database m A A = ownMap v.t (fun _=>q) := by + classical + intro k A + have ht i : Subsingleton (Port k i) := ⟨fun p q => (own_inj v i) + (Subsingleton.elim _ _)⟩ + let s := v.s (); let l:=v.t (); let f := v.f (); let z := lit f l x + let u := point p s z + have he i (j : Port k i) : + (A i).col j=u := by + unfold A queryLaw u s z f l; rcases j with ⟨⟨a,w⟩,h⟩; cases a; rfl + constructor + · intro i x y h + have := ht i + funext j + let t : Row p n := (emptySel,none) + have hf : A i t j=1 := congr_fun (he i j) t |>.trans (point_base_eval p s z none) + have hh (x) : ((A i) *ᵥ x) t=x j := by + change ∑ j,A i t j*x j=_ + rw [Finset.sum_eq_single j] + · rw [hf,one_mul] + · intro k _ h; exact (h (Subsingleton.elim _ _)).elim + simp + rw [←hh x,←hh y]; exact congr_fun h _ + funext i + ext j t + have h1 := ht i |>.elim j t; subst t + unfold database ownMap + rw [diagonal_apply_eq] + let E := selfM p n m.mixM + have heM : mpair E (mom p s z)=q := (selfM_pair p hj _ (Submodule.subset_span + ⟨_,_,rfl⟩)).trans ((etaScan p l s f x).symm.trans h) + change (pullM (A i) (A i) E) j j=q + + have hh : (pullM (A i) (A i) E) j j=evmat E ((A i).col j) ((A i).col j) := by + rw [pullM_def,Matrix.mul_assoc]; rfl + rw [hh,he,← mpair_outer] + exact heM + +def desc (v : Solo p) (x : Knobs p.g n) (o : Orient p n N) := callOne v () x o +set_option maxHeartbeats 800000 in +theorem solo_read (v : Solo p) (m : Mixer p n) (hN : 2*num (Full p n) x + let A := v.queryLaw z (g:=g) + let T := (v.singleP n).showKey (N:=N) z + let W := scatter v.t N; let Q := soloeq v N + let u := fun x => f (Q (W.symm x)) + have ht (i) : u (T i)=f (v.desc x i) := by + unfold u T W + rw [single_show,Equiv.symm_apply_apply]; rfl + have hL : mapW (lawNu p N v.t (fun _ => q)) W=rackWave (ownMap v.t (fun _ => q)) N := + lawNu_rack .. + obtain ⟨he,he'⟩ := solo_data v x m q hj h + have hR : mapW (raw m N) T=rackStation (ownMap v.t (fun _ => q)) N := by + rw [←he']; exact law_peekR (g:=g) m hN he he + have h1 : avg (lawOmega p N (v.t ()) q) f = avg (rackWave (ownMap v.t (fun _=>q)) N) u := by + rw [←hL,←soloprice,mapW_avg,mapW_avg] + unfold u; simp_rw [Equiv.symm_apply_apply]; rfl + have h2 : avg (raw m N) (f ∘ v.desc x)=avg (rackStation (ownMap v.t (fun _=>q)) N) u := by + rw [←hR,mapW_avg]; simp_rw [ht]; rfl + rw [h2,h1]; exact compare_station _ u (fun i=>hf _) k hk hK +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryQueryFrequencies.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryQueryFrequencies.lean index 75d182c16d7b809f340a1037ba69a0d574561145..3c46f5c8160de685813b9344e6fc800699461abb 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryQueryFrequencies.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/UnaryQueryFrequencies.lean @@ -1,98 +1,98 @@ -import OAI.Combinatorics.HadwigerCounterexample.UnaryQueryComparison -import OAI.Combinatorics.HadwigerCounterexample.EmpiricalInformation - -namespace OAI - -/-! # Unary Query Frequencies -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Module Finset Filter Real Function -open scoped BigOperators -variable {p : Shape} {n N : ℕ} -namespace Template - -def minorCall (v : Solo p) (w : Wgt (Knobs p.g n)) - (T : Wgt (AtomKey (p:=p) (v.t ()) N)) (o : Orient p n N) := - avg w (fun i => T (v.desc i o)) - -set_option maxHeartbeats 600000 in -theorem flat_recital (v : Solo p) (M : ℕ) (hM : 1 ≤ M) (hj : 1≤p.j) (ε : ℝ) - (hε : 0<ε) : - ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n) - (w : Wgt (Knobs p.g n)) (q : F), IsLaw w → - carried w (fun x => dialed p (v.t ()) (v.f ()) x=q) → - mapW w (freePart p)=unif → 2*num (Full p n) ε≤|minorCall v w T x - avg (lawOmega p N (v.t ()) q) T|) ≤ - bp (-(1/8:ℝ)*n) := by - classical - let c := ε/2; have hc : 0 h (he i he')) - T hT k (port_limit g) (by linarith only [hl])) hR - exact mul_le_mul_of_nonneg_left hy (hw.nz i) - have heV : - avg μ (fun x => (u x-avg μ u)^2)≤ bp (-(1/4:ℝ)*n) := by - let F (i : Inputs p n Unit) (y : Keys (p:=p) v.t N) := T (y ()) - have ht := hn m (fun i=>w) (fun i=>hw) (fun i=>hZ) hN F (fun i j=>hT _) - have he' : u=fun o : Orient p n N => - avg (prodW (fun _ : Unit => w)) (fun z => - F z (fun i => callOne v i (z i) o)) := by - funext i - let f (x : Knobs p.g n) := T (v.desc x i) - have hz : avg (mapW (draws Unit w) (fun x => x ())) f = _ := - mapW_avg (draws Unit w) _ f - rw [draw_pick hw] at hz - exact hz - rw [he']; exact ht - change pr μ (fun x => ε≤ |u x-b|)≤_ - have heQ x (h : ε≤|u x-b|) : c≤ |u x-avg μ u| := by - have hh := abs_sub_le (u x) (avg μ u) b - unfold c at *; linarith only [h,hh,hi] - refine (pr_mono hμ.nz heQ).trans ((outlier hμ.nz _ _ hc heV).trans ?_) - rw [div_le_iff₀ (by positivity : 0 T (v.desc i o)) + +set_option maxHeartbeats 600000 in +theorem flat_recital (v : Solo p) (M : ℕ) (hM : 1 ≤ M) (hj : 1≤p.j) (ε : ℝ) + (hε : 0<ε) : + ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n) + (w : Wgt (Knobs p.g n)) (q : F), IsLaw w → + carried w (fun x => dialed p (v.t ()) (v.f ()) x=q) → + mapW w (freePart p)=unif → 2*num (Full p n) ε≤|minorCall v w T x - avg (lawOmega p N (v.t ()) q) T|) ≤ + bp (-(1/8:ℝ)*n) := by + classical + let c := ε/2; have hc : 0 h (he i he')) + T hT k (port_limit g) (by linarith only [hl])) hR + exact mul_le_mul_of_nonneg_left hy (hw.nz i) + have heV : + avg μ (fun x => (u x-avg μ u)^2)≤ bp (-(1/4:ℝ)*n) := by + let F (i : Inputs p n Unit) (y : Keys (p:=p) v.t N) := T (y ()) + have ht := hn m (fun i=>w) (fun i=>hw) (fun i=>hZ) hN F (fun i j=>hT _) + have he' : u=fun o : Orient p n N => + avg (prodW (fun _ : Unit => w)) (fun z => + F z (fun i => callOne v i (z i) o)) := by + funext i + let f (x : Knobs p.g n) := T (v.desc x i) + have hz : avg (mapW (draws Unit w) (fun x => x ())) f = _ := + mapW_avg (draws Unit w) _ f + rw [draw_pick hw] at hz + exact hz + rw [he']; exact ht + change pr μ (fun x => ε≤ |u x-b|)≤_ + have heQ x (h : ε≤|u x-b|) : c≤ |u x-avg μ u| := by + have hh := abs_sub_le (u x) (avg μ u) b + unfold c at *; linarith only [h,hh,hi] + refine (pr_mono hμ.nz heQ).trans ((outlier hμ.nz _ _ hc heV).trans ?_) + rw [div_le_iff₀ (by positivity : 0 (dim_mat _ _).trans (by simp) - -def entries (f : Pin p n N) (x : UnitType p n N) : Ledger f.sp := - fun z => (pack (f.sp z))ᵀ * (f.target z)ᵀ * images x (flipZ p z) - -theorem entries_val (f : Pin p n N) {x y : UnitType p n N} (h : f.agree y) - (z) : entries f x z= (pack (f.sp z))ᵀ * actual p y x z := by - have he := Pin.agree_pack.mp h z - unfold entries actual - rw [← transpose_mul,← he,transpose_mul,Matrix.mul_assoc] - -theorem entries_rows (f : Pin p n N) {x y x' y' : UnitType p n N} - (h : f.agree y) (h' : f.agree y') (hg : entries f x=entries f x') : - rowAgree f.sp (actual p y x) (actual p y' x') := by - intro z u hu v - have he : (pack (f.sp z))ᵀ * actual p y x z= (pack (f.sp z))ᵀ * actual p y' x' z := by - rw [←entries_val f h, ←entries_val f h',hg] - obtain ⟨r,rfl⟩ := (pack_mem_iff ..).mp hu - have hE (P : Mat (JointIdx p n) (JointIdx p n)) : - evmat P (pack (f.sp z) *ᵥ r) v=evmat ((pack (f.sp z))ᵀ * P) r v := by - unfold evmat - rw [←Matrix.mulVec_mulVec,dotProduct_transpose_mulVec,dotProduct_comm] - rw [hE,hE,he] - -theorem rowAgree_step {a : Plan p n} {X Y Z} - (h : rowAgree a X Y) (he : rowAgree a Z Y) : - rowAgree a X Z := fun z u hu v => (h z u hu v).trans (he z u hu v).symm - -variable {I : Type} [Fintype I] -namespace Volley -variable (v w : Volley p n I) - -/-- Deterministic realization promise at two orientations. Can be required -only if both accept the specific parameter pair and their keys agree. -/ -def promised (t : Tagging p I) (m : Mixer p n) - (a b : Plan p n) (x y : UnitType p n N) := - v.legal t ∧ w.legal t ∧ v.roleMatch w t ∧ - ∃ Q : Cross p n, v.realized w t m Q ∧ w.realized v t m (reciprocal p Q) ∧ - rowAgree (v.frozen a t) Q (actual p x y) ∧ - rowAgree (w.frozen b t) (reciprocal p Q) (actual p y x) - -private theorem carried_heavy {T : Type} [Fintype T] {w : Wgt T} {p : T→Prop} - (x) (hx : onW w p x ≠ 0) : p x := - Classical.byContradiction fun h => hx (normW_carried (subW_carried w p) x h) - -set_option maxHeartbeats 800000 in -theorem record_hit {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) (u : Keys (p:=p) t N) - (ha : ∀ x, U x → a.agree x ∧ (∀ i,frameLaw m (onSide x i)) ∧ v.keys t x=u) - (hb : ∀ x, V x → b.agree x ∧ (∀ i,frameLaw m (onSide x i)) ∧ w.keys t x=u) - {ζ : ℝ} {q : ℕ} - (h : ∀ x,U x → ∀ y,V 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 * (pr μ U * pr δ V) ≤ pr (pairW μ δ) (fun x => U x.1 ∧ V x.2 ∧ - (rawHoles m).conflict x.1 x.2) + - (hit N*tau N (kslots p I)*L)*(pr μ U+pr δ V) := by - classical - let k := kslots p I - obtain ⟨x0,hx⟩ : - ∃ x0 : UnitType p n N,∀ x,U x → (Pin.make (v.frozen a.sp t) x0).agree x := by - by_cases he : ∃ x,U x - · obtain ⟨x0,hx0⟩ := he - exact ⟨x0,fun x hx => key_pin t (ha x0 hx0).1 (ha x hx).1 - ((ha x0 hx0).2.2.trans (ha x hx).2.2.symm)⟩ - exact ⟨0,fun x h => (he ⟨x,h⟩).elim⟩ - let f := Pin.make (v.frozen a.sp t) x0 - obtain ⟨y0,hy⟩ : - ∃ y0 : UnitType p n N,∀ y,V y → (Pin.make (w.frozen b.sp t) y0).agree y := by - by_cases he : ∃ y,V y - · obtain ⟨y0,hy0⟩ := he - exact ⟨y0,fun y hy => key_pin t (hb y0 hy0).1 (hb y hy).1 - ((hb y0 hy0).2.2.trans (hb y hy).2.2.symm)⟩ - exact ⟨0,fun y h => (he ⟨y,h⟩).elim⟩ - let g := Pin.make (w.frozen b.sp t) y0 - apply prune_pairs μ δ hμ hδ U V (entries g) (entries f) - (fun x => (rawHoles m).conflict x.1 x.2) (hit N) (tau N k) - (bp_pos _).le (bp_pos _) _ _ - · intro i j hi hj - let F := memberC U (entries g) i - let G := memberC V (entries f) j - let α := onW μ F - let β := onW δ G - change tau N k≤pr μ F at hi - change tau N k≤pr δ G at hj - have hL (v : Volley p n I) {a} (h : v.avoids a q) : - planRank (v.frozen a t)=planRank a+k := by - unfold k - rw [← v.key_slots (t:=t) h]; exact (plan_add_rank a (v.keyPlan t)).symm - obtain ⟨hα,hF⟩ := in_clear (f:=f) hz hK hμ hA le_sup_left (hL v hv) - F (fun x h => hx x h.1) hi - obtain ⟨hβ,hG⟩ := in_clear (f:=g) hz hK hδ hB le_sup_left (hL w hw) - G (fun x h => hy x h.1) hj - obtain ⟨x,xX,_⟩ := exists_of_pr_pos hμ.nz (lt_of_lt_of_le (bp_pos _) hi) - obtain ⟨y,yY,_⟩ := exists_of_pr_pos hδ.nz (lt_of_lt_of_le (bp_pos _) hj) - have h1 x (h : α x≠0) : F x := carried_heavy _ h - have h2 y (h : β y≠0) : G y := carried_heavy _ h - obtain ⟨hr,ht,hL,Q,hZ,hI,hQ,hQ'⟩ := h x xX.1 y yY.1 - have he x' (hs : α x'≠0) y' (hs' : β y'≠0) : - rowAgree f.sp (actual p x' y') Q ∧ - rowAgree g.sp (actual p y' x') (reciprocal p Q) := by - have ha := h1 x' hs - have hb := h2 y' hs' - exact ⟨rowAgree_step (entries_rows f (hx x' ha.1) (hx x xX.1) (hb.2.trans yY.2.symm)) hQ, - rowAgree_step (entries_rows g (hy y' hb.1) (hy y yY.1) (ha.2.trans xX.2.symm)) hQ'⟩ - refine (gram_hit Q hα hβ hF hG he hN hT).trans (pr_on_mono (pairW_law hα hβ).nz ?_) - rintro ⟨x,y⟩ hxy heq - obtain ⟨_,hx,hX⟩ := ha x (h1 x (left_ne_zero_of_mul hxy)).1 - obtain ⟨_,hy,hY⟩ := hb y (h2 y (right_ne_zero_of_mul hxy)).1 - have he : scalarBlocks p (actual p x y) = scalarBlocks p Q := congrArg Prod.fst heq - have he' : scalarBlocks p (actual p y x) = scalarBlocks p (reciprocal p Q) := by - rw [← reciprocal_actual x y]; exact congrArg Prod.snd heq - apply v.realized_conflicts w m x y hr ht hx hy (hX.trans hY.symm) hL - · intro i j μ hμ; rw [contract_scalars _ _ he]; exact hZ i j _ hμ - · intro i j μ hμ; rw [contract_scalars _ _ he']; exact hI i j _ hμ - · rw [card_space]; exact hLg - rw [card_space]; exact hLf -end Volley -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.PrimalChannelTests +import OAI.Combinatorics.HadwigerCounterexample.CellPruning + +namespace OAI + +/-! # Unary Records -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix LinearMap Module Submodule Finset +open scoped BigOperators +variable {p : Shape} {n N : ℕ} + +/-- records of x indexed by opposite pin plan signs -/ +abbrev Ledger {p : Shape} {n} (f : Plan p n) := + ∀ z, Mat (Fin (dim (f z))) (JointIdx p n) + +instance fintypeLedger (f : Plan p n) : Fintype (Ledger f) := by + classical + letI (z : Place p) : Fintype (Mat (Fin (dim (f z))) (JointIdx p n)) := inferInstance + exact inferInstance + +theorem ledger_dim (f : Plan p n) : + dim (Ledger f)=planRank f*Fintype.card (JointIdx p n) := by + unfold Ledger dim planRank + rw [finrank_pi_fintype,Finset.sum_mul] + exact Finset.sum_congr rfl fun i _ => (dim_mat _ _).trans (by simp) + +def entries (f : Pin p n N) (x : UnitType p n N) : Ledger f.sp := + fun z => (pack (f.sp z))ᵀ * (f.target z)ᵀ * images x (flipZ p z) + +theorem entries_val (f : Pin p n N) {x y : UnitType p n N} (h : f.agree y) + (z) : entries f x z= (pack (f.sp z))ᵀ * actual p y x z := by + have he := Pin.agree_pack.mp h z + unfold entries actual + rw [← transpose_mul,← he,transpose_mul,Matrix.mul_assoc] + +theorem entries_rows (f : Pin p n N) {x y x' y' : UnitType p n N} + (h : f.agree y) (h' : f.agree y') (hg : entries f x=entries f x') : + rowAgree f.sp (actual p y x) (actual p y' x') := by + intro z u hu v + have he : (pack (f.sp z))ᵀ * actual p y x z= (pack (f.sp z))ᵀ * actual p y' x' z := by + rw [←entries_val f h, ←entries_val f h',hg] + obtain ⟨r,rfl⟩ := (pack_mem_iff ..).mp hu + have hE (P : Mat (JointIdx p n) (JointIdx p n)) : + evmat P (pack (f.sp z) *ᵥ r) v=evmat ((pack (f.sp z))ᵀ * P) r v := by + unfold evmat + rw [←Matrix.mulVec_mulVec,dotProduct_transpose_mulVec,dotProduct_comm] + rw [hE,hE,he] + +theorem rowAgree_step {a : Plan p n} {X Y Z} + (h : rowAgree a X Y) (he : rowAgree a Z Y) : + rowAgree a X Z := fun z u hu v => (h z u hu v).trans (he z u hu v).symm + +variable {I : Type} [Fintype I] +namespace Volley +variable (v w : Volley p n I) + +/-- Deterministic realization promise at two orientations. Can be required +only if both accept the specific parameter pair and their keys agree. -/ +def promised (t : Tagging p I) (m : Mixer p n) + (a b : Plan p n) (x y : UnitType p n N) := + v.legal t ∧ w.legal t ∧ v.roleMatch w t ∧ + ∃ Q : Cross p n, v.realized w t m Q ∧ w.realized v t m (reciprocal p Q) ∧ + rowAgree (v.frozen a t) Q (actual p x y) ∧ + rowAgree (w.frozen b t) (reciprocal p Q) (actual p y x) + +private theorem carried_heavy {T : Type} [Fintype T] {w : Wgt T} {p : T→Prop} + (x) (hx : onW w p x ≠ 0) : p x := + Classical.byContradiction fun h => hx (normW_carried (subW_carried w p) x h) + +set_option maxHeartbeats 800000 in +theorem record_hit {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) (u : Keys (p:=p) t N) + (ha : ∀ x, U x → a.agree x ∧ (∀ i,frameLaw m (onSide x i)) ∧ v.keys t x=u) + (hb : ∀ x, V x → b.agree x ∧ (∀ i,frameLaw m (onSide x i)) ∧ w.keys t x=u) + {ζ : ℝ} {q : ℕ} + (h : ∀ x,U x → ∀ y,V 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 * (pr μ U * pr δ V) ≤ pr (pairW μ δ) (fun x => U x.1 ∧ V x.2 ∧ + (rawHoles m).conflict x.1 x.2) + + (hit N*tau N (kslots p I)*L)*(pr μ U+pr δ V) := by + classical + let k := kslots p I + obtain ⟨x0,hx⟩ : + ∃ x0 : UnitType p n N,∀ x,U x → (Pin.make (v.frozen a.sp t) x0).agree x := by + by_cases he : ∃ x,U x + · obtain ⟨x0,hx0⟩ := he + exact ⟨x0,fun x hx => key_pin t (ha x0 hx0).1 (ha x hx).1 + ((ha x0 hx0).2.2.trans (ha x hx).2.2.symm)⟩ + exact ⟨0,fun x h => (he ⟨x,h⟩).elim⟩ + let f := Pin.make (v.frozen a.sp t) x0 + obtain ⟨y0,hy⟩ : + ∃ y0 : UnitType p n N,∀ y,V y → (Pin.make (w.frozen b.sp t) y0).agree y := by + by_cases he : ∃ y,V y + · obtain ⟨y0,hy0⟩ := he + exact ⟨y0,fun y hy => key_pin t (hb y0 hy0).1 (hb y hy).1 + ((hb y0 hy0).2.2.trans (hb y hy).2.2.symm)⟩ + exact ⟨0,fun y h => (he ⟨y,h⟩).elim⟩ + let g := Pin.make (w.frozen b.sp t) y0 + apply prune_pairs μ δ hμ hδ U V (entries g) (entries f) + (fun x => (rawHoles m).conflict x.1 x.2) (hit N) (tau N k) + (bp_pos _).le (bp_pos _) _ _ + · intro i j hi hj + let F := memberC U (entries g) i + let G := memberC V (entries f) j + let α := onW μ F + let β := onW δ G + change tau N k≤pr μ F at hi + change tau N k≤pr δ G at hj + have hL (v : Volley p n I) {a} (h : v.avoids a q) : + planRank (v.frozen a t)=planRank a+k := by + unfold k + rw [← v.key_slots (t:=t) h]; exact (plan_add_rank a (v.keyPlan t)).symm + obtain ⟨hα,hF⟩ := in_clear (f:=f) hz hK hμ hA le_sup_left (hL v hv) + F (fun x h => hx x h.1) hi + obtain ⟨hβ,hG⟩ := in_clear (f:=g) hz hK hδ hB le_sup_left (hL w hw) + G (fun x h => hy x h.1) hj + obtain ⟨x,xX,_⟩ := exists_of_pr_pos hμ.nz (lt_of_lt_of_le (bp_pos _) hi) + obtain ⟨y,yY,_⟩ := exists_of_pr_pos hδ.nz (lt_of_lt_of_le (bp_pos _) hj) + have h1 x (h : α x≠0) : F x := carried_heavy _ h + have h2 y (h : β y≠0) : G y := carried_heavy _ h + obtain ⟨hr,ht,hL,Q,hZ,hI,hQ,hQ'⟩ := h x xX.1 y yY.1 + have he x' (hs : α x'≠0) y' (hs' : β y'≠0) : + rowAgree f.sp (actual p x' y') Q ∧ + rowAgree g.sp (actual p y' x') (reciprocal p Q) := by + have ha := h1 x' hs + have hb := h2 y' hs' + exact ⟨rowAgree_step (entries_rows f (hx x' ha.1) (hx x xX.1) (hb.2.trans yY.2.symm)) hQ, + rowAgree_step (entries_rows g (hy y' hb.1) (hy y yY.1) (ha.2.trans xX.2.symm)) hQ'⟩ + refine (gram_hit Q hα hβ hF hG he hN hT).trans (pr_on_mono (pairW_law hα hβ).nz ?_) + rintro ⟨x,y⟩ hxy heq + obtain ⟨_,hx,hX⟩ := ha x (h1 x (left_ne_zero_of_mul hxy)).1 + obtain ⟨_,hy,hY⟩ := hb y (h2 y (right_ne_zero_of_mul hxy)).1 + have he : scalarBlocks p (actual p x y) = scalarBlocks p Q := congrArg Prod.fst heq + have he' : scalarBlocks p (actual p y x) = scalarBlocks p (reciprocal p Q) := by + rw [← reciprocal_actual x y]; exact congrArg Prod.snd heq + apply v.realized_conflicts w m x y hr ht hx hy (hX.trans hY.symm) hL + · intro i j μ hμ; rw [contract_scalars _ _ he]; exact hZ i j _ hμ + · intro i j μ hμ; rw [contract_scalars _ _ he']; exact hI i j _ hμ + · rw [card_space]; exact hLg + rw [card_space]; exact hLf +end Volley +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/UnfilteredHistogramEnergy.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/UnfilteredHistogramEnergy.lean index 10a3869cc2bace890812d9e03d3e97dd246b55e4..7c5fc9c7561fabd87e615260b01d22cc655d0b3f 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/UnfilteredHistogramEnergy.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/UnfilteredHistogramEnergy.lean @@ -1,141 +1,141 @@ -import OAI.Combinatorics.HadwigerCounterexample.HistogramEnergyScales - -namespace OAI - -/-! # Unfiltered Histogram Energy -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Real Filter Matrix Function -open scoped BigOperators -variable {I J G : Type} [Fintype I] [Fintype J] [Fintype G] -variable [DecidableEq I] [DecidableEq J] [DecidableEq G] -variable {p : Shape} {n N M : ℕ} -instance rackFintype {I : Type} [Fintype I] [DecidableEq I] (N : ℕ) : Fintype (Rack I N) := inferInstance - -def stamina {B : Type} [Fintype B] - (q : Wgt B) (δ : ℝ) := ∀ i,q i≠0→δ ≤ q i - -theorem stamina_buy {δ : ℝ} (hδ : 0<δ) : ∃ u : ℝ,0≤u ∧ bp (-u) ≤ δ := by - have ht := bp_tendsto_zero (a:=1) zero_lt_one - obtain ⟨u,hu,hb⟩ := ((eventually_ge_atTop (0:ℝ)).and (ht.eventually - (eventually_le_nhds hδ))).exists - exact ⟨u,hu,by simpa using hb⟩ -namespace Template -variable (v : Template p I) - -/-- full query data key function -/ -def resultKey (o : UnitType p n N) (x : Inputs p n I) := - (v.draw x).keys v.t o -def heatMap (o : UnitType p n N) (w : I→Wgt (Knobs p.g n)) := - mapW (prodW w) (v.resultKey o) - -variable {B : Type} [Fintype B] - -set_option maxHeartbeats 1200000 in -theorem roadmap {l : ℕ} {r u E V : ℝ} (v : Template p I) (C : ℝ) - (z : TollBar M C I (KeySlots p v.t) (Ports p) - (globPort p v.t v.aim) n l r u E V) - (hE : 0≤E) (hu : 0 ≤ u) - (m : Mixer p n) (hN : 2*num (Full p n)<↑(M*n)) - (f : Keys (p:=p) v.t (M*n)→ B) - (hB : num B ≤ r) - (h : stamina (mapW unif f) (bp (-u))) - (w : Wgt (UnitType p n (M*n))) (hw : IsLaw w) - (hh : ∀ i,w i ≤ bp (C*↑(M*n))*pairW (raw m (M*n)) (raw m (M*n)) i) - (x : I→Wgt (Knobs p.g n)) (hx : ∀ i,IsLaw (x i)) - (hz : ∀ i,mapW (x i) (freePart p)=unif) : - avg w (fun i => tension (mapW (heatMap v i x) f) (mapW unif f)) ≤ V := by - classical - let N := M*n - let W := UnitType p n N - let D := Keys (p:=p) v.t N - let q := mapW unif f - let X := prodW x - let g := globPort p v.t v.aim - let s := v.doubleP n - have hum : IsLaw (unif : Wgt D) := unif_law - have hq : IsLaw q := mapW_law hum f - let t := num (Fin l)*num I-n - let F (i : W) := f∘v.resultKey i - let Q (x) := draws (Fin l) q x - have h0 (i : D) : unif i≠0 := by rw [unif_apply]; positivity - have h1 (i : D) : q (f i) ≠0 := lsupp_hit hum.nz f i (h0 i) - have h2 (i) (y : Fin l→B) (hF : s.free i) : - mapW w (fun x => F x ∘ i) y≤ bp (E*l)*Q y := by - by_cases hy : mapW w (fun x => F x∘i) y =0 - · rw [hy]; exact mul_nonneg (bp_pos _).le ((draws_law hq).nz _) - let Λ := tied g (Fin l) - let P (j : Fin l) (x : Rack (KeySlots p v.t) N) := f ((scatter v.t N).symm x)=y j - have ht (j : Fin l) : - pr unif (P j)=q (y j) := by - rw [show pr unif (P j) = pr (mapW unif (scatter v.t N).symm) (fun i => f i=y j) from - (mapW_pr unif (scatter v.t N).symm (fun i => f i=y j)).symm, unif_equiv]; rfl - have hr (j : Fin l) : - bp (-u) ≤ pr unif (P j) := by - obtain ⟨o,ho,h'⟩ := lsupp_witness hy - rw [ht, ← congr_fun h' j] - exact h _ (h1 _) - let A := pooled (s.left ∘ i) - let Z := database m A A - have hL := many_frames (N:=N) Λ Z z.frame u hu P hr z.peak - let μ := raw m N - have hk : - mapW (pairW μ μ) (fun x => F x ∘ i) y = - pr (rackStation Z N) (fun x => ∀ j,P j (led j x)) := by - let e (a : Rack (Fin l × KeySlots p v.t) N) := ∀ j,P j (led j a) - let K (o : Forum p n N (Ports p)) := peekR p Λ A A o - have ht : mapW (pairW μ μ) (K ∘ mergeR p) = rackStation Z N := by - rw [← mapW_nested,law_mergeR]; exact law_peekR m hN hF.1 hF.2 - have he (o : W) : e (K (mergeR p o)) ↔ F o ∘ i=y := by - unfold e K Λ P A; simp_rw [peek_pooled,Function.comp_apply] - rw [funext_iff] - have ht (j : Fin l) : - peekR p g (s.left (i j)) (s.left (i j)) (mergeR p o)=scatter v.t N - (v.resultKey o (i j)) := double_show v _ _ - simp_rw [ht,Equiv.symm_apply_apply] - rfl - unfold mapW - change _=pr (rackStation Z N) e - rw [←ht,mapW_pr]; simp_rw [Function.comp_apply,he] - simp_rw [ht] at hL - refine (pr_cap hh _).trans ?_ - change bp _ * (mapW (pairW μ μ) _ _)≤_ - rw [hk] - exact (mul_le_mul_of_nonneg_left hL (bp_pos _).le).trans - (le_trans (le_of_eq (Eq.symm (mul_assoc _ _ _))) (mul_le_mul_of_nonneg_right z.cap - ((draws_law hq).nz y))) - have hv : 0<(l:ℝ) := by exact_mod_cast z.pos - have he := path_energy w X q F hw (prodW_law hx) hq (fun i j => h1 _) u hu h - l (fun i => s.free i) (bp t) - (free_price v n x hx hz g (glob_inj v)) (E*l) (by positivity) (fun i h y => h2 i y h) - unfold heatMap; simp_rw [mapW_nested] - apply le_of_mul_le_mul_left _ hv - apply he.trans - refine le_trans ?_ z.charge - exact add_le_add_left (mul_le_mul_of_nonneg_right hB (log_nonneg (by linarith))) _ - -theorem hist_calendar (v : Template p I) (M : ℕ) (hM : 1≤M) - (C : ℝ) (hC : 0 ≤ C) : - ∃ V : ℝ,∀ r δ : ℝ, 0≤r → 0<δ → - ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n), 2*num (Full p n) tension (mapW (heatMap v i x) f) (mapW unif f)) ≤ V := by - obtain ⟨s,E,V,hs,hE,h⟩ := toll_calendar M hM C hC I _ _ (globPort p v.t v.aim) - refine ⟨V,fun r δ hr hδ => ?_⟩ - obtain ⟨u,hu,hh⟩ := stamina_buy hδ - filter_upwards [h r u hr hu] - with n hn N m hN w hw hW x hx hz B _ hB f hF - exact roadmap v C hn hE hu m hN f hB (fun i hi => hh.trans (hF i hi)) w hw hW x hx hz - -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.HistogramEnergyScales + +namespace OAI + +/-! # Unfiltered Histogram Energy -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Real Filter Matrix Function +open scoped BigOperators +variable {I J G : Type} [Fintype I] [Fintype J] [Fintype G] +variable [DecidableEq I] [DecidableEq J] [DecidableEq G] +variable {p : Shape} {n N M : ℕ} +instance rackFintype {I : Type} [Fintype I] [DecidableEq I] (N : ℕ) : Fintype (Rack I N) := inferInstance + +def stamina {B : Type} [Fintype B] + (q : Wgt B) (δ : ℝ) := ∀ i,q i≠0→δ ≤ q i + +theorem stamina_buy {δ : ℝ} (hδ : 0<δ) : ∃ u : ℝ,0≤u ∧ bp (-u) ≤ δ := by + have ht := bp_tendsto_zero (a:=1) zero_lt_one + obtain ⟨u,hu,hb⟩ := ((eventually_ge_atTop (0:ℝ)).and (ht.eventually + (eventually_le_nhds hδ))).exists + exact ⟨u,hu,by simpa using hb⟩ +namespace Template +variable (v : Template p I) + +/-- full query data key function -/ +def resultKey (o : UnitType p n N) (x : Inputs p n I) := + (v.draw x).keys v.t o +def heatMap (o : UnitType p n N) (w : I→Wgt (Knobs p.g n)) := + mapW (prodW w) (v.resultKey o) + +variable {B : Type} [Fintype B] + +set_option maxHeartbeats 1200000 in +theorem roadmap {l : ℕ} {r u E V : ℝ} (v : Template p I) (C : ℝ) + (z : TollBar M C I (KeySlots p v.t) (Ports p) + (globPort p v.t v.aim) n l r u E V) + (hE : 0≤E) (hu : 0 ≤ u) + (m : Mixer p n) (hN : 2*num (Full p n)<↑(M*n)) + (f : Keys (p:=p) v.t (M*n)→ B) + (hB : num B ≤ r) + (h : stamina (mapW unif f) (bp (-u))) + (w : Wgt (UnitType p n (M*n))) (hw : IsLaw w) + (hh : ∀ i,w i ≤ bp (C*↑(M*n))*pairW (raw m (M*n)) (raw m (M*n)) i) + (x : I→Wgt (Knobs p.g n)) (hx : ∀ i,IsLaw (x i)) + (hz : ∀ i,mapW (x i) (freePart p)=unif) : + avg w (fun i => tension (mapW (heatMap v i x) f) (mapW unif f)) ≤ V := by + classical + let N := M*n + let W := UnitType p n N + let D := Keys (p:=p) v.t N + let q := mapW unif f + let X := prodW x + let g := globPort p v.t v.aim + let s := v.doubleP n + have hum : IsLaw (unif : Wgt D) := unif_law + have hq : IsLaw q := mapW_law hum f + let t := num (Fin l)*num I-n + let F (i : W) := f∘v.resultKey i + let Q (x) := draws (Fin l) q x + have h0 (i : D) : unif i≠0 := by rw [unif_apply]; positivity + have h1 (i : D) : q (f i) ≠0 := lsupp_hit hum.nz f i (h0 i) + have h2 (i) (y : Fin l→B) (hF : s.free i) : + mapW w (fun x => F x ∘ i) y≤ bp (E*l)*Q y := by + by_cases hy : mapW w (fun x => F x∘i) y =0 + · rw [hy]; exact mul_nonneg (bp_pos _).le ((draws_law hq).nz _) + let Λ := tied g (Fin l) + let P (j : Fin l) (x : Rack (KeySlots p v.t) N) := f ((scatter v.t N).symm x)=y j + have ht (j : Fin l) : + pr unif (P j)=q (y j) := by + rw [show pr unif (P j) = pr (mapW unif (scatter v.t N).symm) (fun i => f i=y j) from + (mapW_pr unif (scatter v.t N).symm (fun i => f i=y j)).symm, unif_equiv]; rfl + have hr (j : Fin l) : + bp (-u) ≤ pr unif (P j) := by + obtain ⟨o,ho,h'⟩ := lsupp_witness hy + rw [ht, ← congr_fun h' j] + exact h _ (h1 _) + let A := pooled (s.left ∘ i) + let Z := database m A A + have hL := many_frames (N:=N) Λ Z z.frame u hu P hr z.peak + let μ := raw m N + have hk : + mapW (pairW μ μ) (fun x => F x ∘ i) y = + pr (rackStation Z N) (fun x => ∀ j,P j (led j x)) := by + let e (a : Rack (Fin l × KeySlots p v.t) N) := ∀ j,P j (led j a) + let K (o : Forum p n N (Ports p)) := peekR p Λ A A o + have ht : mapW (pairW μ μ) (K ∘ mergeR p) = rackStation Z N := by + rw [← mapW_nested,law_mergeR]; exact law_peekR m hN hF.1 hF.2 + have he (o : W) : e (K (mergeR p o)) ↔ F o ∘ i=y := by + unfold e K Λ P A; simp_rw [peek_pooled,Function.comp_apply] + rw [funext_iff] + have ht (j : Fin l) : + peekR p g (s.left (i j)) (s.left (i j)) (mergeR p o)=scatter v.t N + (v.resultKey o (i j)) := double_show v _ _ + simp_rw [ht,Equiv.symm_apply_apply] + rfl + unfold mapW + change _=pr (rackStation Z N) e + rw [←ht,mapW_pr]; simp_rw [Function.comp_apply,he] + simp_rw [ht] at hL + refine (pr_cap hh _).trans ?_ + change bp _ * (mapW (pairW μ μ) _ _)≤_ + rw [hk] + exact (mul_le_mul_of_nonneg_left hL (bp_pos _).le).trans + (le_trans (le_of_eq (Eq.symm (mul_assoc _ _ _))) (mul_le_mul_of_nonneg_right z.cap + ((draws_law hq).nz y))) + have hv : 0<(l:ℝ) := by exact_mod_cast z.pos + have he := path_energy w X q F hw (prodW_law hx) hq (fun i j => h1 _) u hu h + l (fun i => s.free i) (bp t) + (free_price v n x hx hz g (glob_inj v)) (E*l) (by positivity) (fun i h y => h2 i y h) + unfold heatMap; simp_rw [mapW_nested] + apply le_of_mul_le_mul_left _ hv + apply he.trans + refine le_trans ?_ z.charge + exact add_le_add_left (mul_le_mul_of_nonneg_right hB (log_nonneg (by linarith))) _ + +theorem hist_calendar (v : Template p I) (M : ℕ) (hM : 1≤M) + (C : ℝ) (hC : 0 ≤ C) : + ∃ V : ℝ,∀ r δ : ℝ, 0≤r → 0<δ → + ∀ᶠ n : ℕ in atTop, let N := M*n; ∀ (m : Mixer p n), 2*num (Full p n) tension (mapW (heatMap v i x) f) (mapW unif f)) ≤ V := by + obtain ⟨s,E,V,hs,hE,h⟩ := toll_calendar M hM C hC I _ _ (globPort p v.t v.aim) + refine ⟨V,fun r δ hr hδ => ?_⟩ + obtain ⟨u,hu,hh⟩ := stamina_buy hδ + filter_upwards [h r u hr hu] + with n hn N m hN w hw hW x hx hz B _ hB f hF + exact roadmap v C hn hE hu m hN f hB (fun i hi => hh.trans (hF i hi)) w hw hW x hx hz + +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/UniformLeafComparisons.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/UniformLeafComparisons.lean index c0c1a4c9bec89eaa8112ff1780e1f999fe922411..a8375590aa5ee03cef1507d38c33acb14098b82c 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/UniformLeafComparisons.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/UniformLeafComparisons.lean @@ -1,93 +1,93 @@ -import OAI.Combinatorics.HadwigerCounterexample.LeafSurrogateExperiments - -namespace OAI - -/-! # Uniform Leaf Comparisons -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Function Matrix Finset -open scoped BigOperators Topology -namespace StatusAnalysis -variable {p:Shape} {M n N s0 K r:ℕ} {q:Format} {d e:Rates} {b:Bool} {b':PreparationParameters} - -namespace Quill -variable (w:Quill p q d b) - (t:Tagging p (Messenger q)) (z: Messenger q→F) -def accounting (m:Mixer p n) (s:Charts p n d) - (μ:Wgt (UnitType p n N)) (r : ℕ) (δ R ε η : ℝ) := - let Q:= w.custom μ s t z m - let ν:= lawNu p N t z - (∀ i,Q i→SubLaw i ∧ lsupp i ν) ∧ roster Q r ε∧smallSet Q ν δ η∧ rosterTail Q ν R η - -set_option maxHeartbeats 900000 in -theorem ownCertificate (M:ℕ) (h:AnalyticParameters p M b' s0) (hw : w.moral t z) - (ε η:ℝ) (he:0<ε) (hη:0<η) : - ∃ (r:ℕ) (δ R:ℝ),0<δ∧0scopedZ_bit p n _ _ _ (hu _)) - (w.billboard (N:=N) s t z m) - let P:=ownPart (p:=p) (N:=N) t z - obtain ⟨hh,_,_,hQ⟩:=ha - have hv : roster (w.custom μ s t z m) r ε∧ smallSet (w.custom μ s t z m) (lawNu p N t z) δ η ∧ - rosterTail (w.custom μ s t z m) (lawNu p N t z) R η := hQ P - refine ⟨fun i hi=>?_,hv⟩ - obtain ⟨x,hp,rfl⟩:= hi - refine ⟨subLaw_sub (hh x hp) P,fun i hi=>?_⟩ - have ht:= density_hung P (subW x P) (subW_carried x P) i - exact left_ne_zero_of_mul (ht.symm ▸ hi) - -structure penny (m:Mixer p n) (s:Charts p n d) (μ:Wgt (UnitType p n N)) - (R η ε:ℝ) (r:ℕ) : Prop where - sales i : w.custom μ s t z m i → SubLaw i∧lsupp i (lawNu p N t z) - roll : roster (w.custom μ s t z m) r ε - tailS : rosterTail (w.custom μ s t z m) (lawNu p N t z) R η - -theorem pennyLarge (R η ε : ℝ) (r:ℕ) (m:Mixer p n) (s:Charts p n d) - (μ:Wgt (UnitType p n N)) (h:w.penny t z m s μ R η ε r) {R' : ℝ} {r':ℕ} - (h1:R≤R') (h2:r≤r') : w.penny t z m s μ R' η ε r' := by - refine ⟨h.sales,?_,fun f hf=>?_⟩ - · obtain ⟨q,hq,hh⟩:= h.roll; exact ⟨q,hq.trans h2,hh⟩ - exact le_trans (pr_mono (h.sales f hf).1.nz (fun i hi=>h1.trans hi)) (h.tailS f hf) - -theorem pennywise (M:ℕ) (h:AnalyticParameters p M b' s0) (hw:w.moral t z) (η:ℝ) (hη:0<η) : - ∃ R:ℝ,0?_⟩ - obtain ⟨r',d',R',hd,hR',he'⟩:= w.ownCertificate t z M h hw ε η he hη - refine ⟨r',?_⟩ - filter_upwards [hV,he'] with n hn ht N m s μ hN hμ hl - obtain ⟨hx,_,_,he⟩:= hn m s μ hN hμ hl - exact ⟨hx,(ht m s μ hN hμ hl).2.1, he⟩ -end Quill - -variable {A B C : Type} [Fintype A] [Fintype B] [Fintype C] -omit [Fintype B] [Fintype C] in -theorem rebate_thick (w : Wgt A) (f : A→B) (g : B→C) (h : Injective g) (p q: Wgt A) : - rebate w p q (g∘f)=rebate w p q f := by - have ht (a : Wgt A) : banner w (g∘f) a = banner w f a := by - funext x; unfold banner cashbook mapW - simp_rw [Function.comp_apply,h.eq_iff] - unfold rebate; rw [ht,ht] -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.LeafSurrogateExperiments + +namespace OAI + +/-! # Uniform Leaf Comparisons -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Function Matrix Finset +open scoped BigOperators Topology +namespace StatusAnalysis +variable {p:Shape} {M n N s0 K r:ℕ} {q:Format} {d e:Rates} {b:Bool} {b':PreparationParameters} + +namespace Quill +variable (w:Quill p q d b) + (t:Tagging p (Messenger q)) (z: Messenger q→F) +def accounting (m:Mixer p n) (s:Charts p n d) + (μ:Wgt (UnitType p n N)) (r : ℕ) (δ R ε η : ℝ) := + let Q:= w.custom μ s t z m + let ν:= lawNu p N t z + (∀ i,Q i→SubLaw i ∧ lsupp i ν) ∧ roster Q r ε∧smallSet Q ν δ η∧ rosterTail Q ν R η + +set_option maxHeartbeats 900000 in +theorem ownCertificate (M:ℕ) (h:AnalyticParameters p M b' s0) (hw : w.moral t z) + (ε η:ℝ) (he:0<ε) (hη:0<η) : + ∃ (r:ℕ) (δ R:ℝ),0<δ∧0scopedZ_bit p n _ _ _ (hu _)) + (w.billboard (N:=N) s t z m) + let P:=ownPart (p:=p) (N:=N) t z + obtain ⟨hh,_,_,hQ⟩:=ha + have hv : roster (w.custom μ s t z m) r ε∧ smallSet (w.custom μ s t z m) (lawNu p N t z) δ η ∧ + rosterTail (w.custom μ s t z m) (lawNu p N t z) R η := hQ P + refine ⟨fun i hi=>?_,hv⟩ + obtain ⟨x,hp,rfl⟩:= hi + refine ⟨subLaw_sub (hh x hp) P,fun i hi=>?_⟩ + have ht:= density_hung P (subW x P) (subW_carried x P) i + exact left_ne_zero_of_mul (ht.symm ▸ hi) + +structure penny (m:Mixer p n) (s:Charts p n d) (μ:Wgt (UnitType p n N)) + (R η ε:ℝ) (r:ℕ) : Prop where + sales i : w.custom μ s t z m i → SubLaw i∧lsupp i (lawNu p N t z) + roll : roster (w.custom μ s t z m) r ε + tailS : rosterTail (w.custom μ s t z m) (lawNu p N t z) R η + +theorem pennyLarge (R η ε : ℝ) (r:ℕ) (m:Mixer p n) (s:Charts p n d) + (μ:Wgt (UnitType p n N)) (h:w.penny t z m s μ R η ε r) {R' : ℝ} {r':ℕ} + (h1:R≤R') (h2:r≤r') : w.penny t z m s μ R' η ε r' := by + refine ⟨h.sales,?_,fun f hf=>?_⟩ + · obtain ⟨q,hq,hh⟩:= h.roll; exact ⟨q,hq.trans h2,hh⟩ + exact le_trans (pr_mono (h.sales f hf).1.nz (fun i hi=>h1.trans hi)) (h.tailS f hf) + +theorem pennywise (M:ℕ) (h:AnalyticParameters p M b' s0) (hw:w.moral t z) (η:ℝ) (hη:0<η) : + ∃ R:ℝ,0?_⟩ + obtain ⟨r',d',R',hd,hR',he'⟩:= w.ownCertificate t z M h hw ε η he hη + refine ⟨r',?_⟩ + filter_upwards [hV,he'] with n hn ht N m s μ hN hμ hl + obtain ⟨hx,_,_,he⟩:= hn m s μ hN hμ hl + exact ⟨hx,(ht m s μ hN hμ hl).2.1, he⟩ +end Quill + +variable {A B C : Type} [Fintype A] [Fintype B] [Fintype C] +omit [Fintype B] [Fintype C] in +theorem rebate_thick (w : Wgt A) (f : A→B) (g : B→C) (h : Injective g) (p q: Wgt A) : + rebate w p q (g∘f)=rebate w p q f := by + have ht (a : Wgt A) : banner w (g∘f) a = banner w f a := by + funext x; unfold banner cashbook mapW + simp_rw [Function.comp_apply,h.eq_iff] + unfold rebate; rw [ht,ht] +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/UniformSideComparisons.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/UniformSideComparisons.lean index 3920aab843543f47cab47d45501e5c40d8410d4d..ef6eddfb266c72160de96cb6d2a1e88528a91672 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/UniformSideComparisons.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/UniformSideComparisons.lean @@ -1,131 +1,131 @@ -import OAI.Combinatorics.HadwigerCounterexample.CommonPartitionRefinement - -namespace OAI - -/-! # Uniform Side Comparisons -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Matrix Function -open scoped BigOperators Topology -open Template -variable {p:Shape} {M n N 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) -variable {b' : PreparationParameters} - -def matchesArea (Y: Silhouette p N r) (o:UnitType p n N) (δ:ℝ) := - ∀ i:Messenger q,(w.allure t z i).close Y (onSide o (parcel b i)) δ -theorem area_mono {o:UnitType p n N} (Y:Silhouette p N r) - {δ ε:ℝ} (h :w.matchesArea t z Y o δ) (he : δ≤ε) : - w.matchesArea t z Y o ε := fun i=> (h i).trans he - -def flunk (Y: Silhouette p N r) (W:Wgt (Keys (p:=p) t N)) (m: Mixer p n) - (δ ε:ℝ) (o : UnitType p n N) := - PreparationParameters.frameSide p m o ∧ matchesArea w t z Y o δ ∧ - ∃ s : Charts p n d, ε< |w.prowl s t z m o W-w.sheen t z o m s Y W| - -private theorem resolve_ready (M:ℕ) (h : AnalyticParameters p M b' s0) - (hw : w.moral t z) (δ : ℝ) (hd:0<δ) : - ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ m : Mixer p n, (2*num (Full p n)<(N:ℝ)) → - binaryGood m → ∀ r:ℕ,∀ Y:Silhouette p N r, ∀ o:UnitType p n N, - PreparationParameters.frameSide p m o → w.matchesArea t z Y o δ → - litFire p o → w.mirrorSpan t z m 0 δ Y o := by - classical - let v:= w.pen t - have ht:=h.enter.first; let a:=(scanPrice p)⁻¹ - have ha : 0fun ht=>h (hw.1 ht) - refine ⟨hW,hp,hv,fun z hz=>(v.resonant m hm o hf hy W hW a ha hC w.script z hz).trans hi, - fun f hf=> (reference_product t z f hf ?_).trans hj⟩ - change _≤(N:ℝ) at hB; linarith only [hB] - -def markedTest (M : ℕ) (b' : PreparationParameters) (s0 n : ℕ) {r} - (X : Silhouette p (M*n) r) (W : Wgt (Keys (p:=p) t (M*n))) (L u ε:ℝ) := - let N:=M*n; ∀ r:ℕ,∀ Y:Silhouette p N r,refines Y X → - ∀ (m : Mixer p n) (U:Wgt (UnitType p n N)), b'.Align s0 p M n m U → - pr U (w.flunk t z Y W m u ε) ≤ L - -set_option maxHeartbeats 1600000 in -theorem sideRelease (M:ℕ) (h : AnalyticParameters p M b' s0) (hw : w.moral t z) (ε:ℝ) (he:0<ε) : - ∃ (l:ℕ) (u c:ℝ),0hM f hf, hh.1⟩ - have hg := bare_bridge w t z m Y o s F (fun i=> finerPigment X Y hy _ (hX _)) - (by linarith only [ht.hG]) ht.hJ hf' (hR m hm.cols hm.rum _ Y o hj hv (not_not.mp hh.2)) W heq - refine not_lt_of_ge (hg.trans ?_) h - have hf : (r:ℝ)*(x*u)≤a := by - have ht : ((r:ℝ)+1)*(x*u) = a := by unfold u; field_simp - rw [←ht]; exact mul_le_mul_of_nonneg_right (by linarith) (by positivity) - unfold x a at * - linarith only [hf,he] - have hU : IsLaw U:=hm.drain.1 - have hT := - h m hm.cols U hm.drain w.script μ hμ (fun i=>scopedZ_bit p n _ _ _ (hμ i)) - have hD' : bp (-(n:ℝ)*n/8) ≤ bp (-c*n) := by - change _ ≤ (n:ℝ) at hD - apply bp_le - nlinarith only [mul_le_mul_of_nonneg_right hD (show 0≤ (n:ℝ) from Nat.cast_nonneg _)] - have hH : pr U Q≤ bp (-c*n) := (hG m hm.cols U hm.drain.2.2.2).trans hD' - change pr U T≤bp (-c*n) at hT - exact ((pr_mono hU.nz hi).trans ((pr_or_le hU.nz).trans (add_le_add hT hH))).trans - (by rw [two_mul] at hQ; exact hQ) - -end Quill -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.CommonPartitionRefinement + +namespace OAI + +/-! # Uniform Side Comparisons -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Matrix Function +open scoped BigOperators Topology +open Template +variable {p:Shape} {M n N 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) +variable {b' : PreparationParameters} + +def matchesArea (Y: Silhouette p N r) (o:UnitType p n N) (δ:ℝ) := + ∀ i:Messenger q,(w.allure t z i).close Y (onSide o (parcel b i)) δ +theorem area_mono {o:UnitType p n N} (Y:Silhouette p N r) + {δ ε:ℝ} (h :w.matchesArea t z Y o δ) (he : δ≤ε) : + w.matchesArea t z Y o ε := fun i=> (h i).trans he + +def flunk (Y: Silhouette p N r) (W:Wgt (Keys (p:=p) t N)) (m: Mixer p n) + (δ ε:ℝ) (o : UnitType p n N) := + PreparationParameters.frameSide p m o ∧ matchesArea w t z Y o δ ∧ + ∃ s : Charts p n d, ε< |w.prowl s t z m o W-w.sheen t z o m s Y W| + +private theorem resolve_ready (M:ℕ) (h : AnalyticParameters p M b' s0) + (hw : w.moral t z) (δ : ℝ) (hd:0<δ) : + ∀ᶠ n : ℕ in atTop, let N:=M*n; ∀ m : Mixer p n, (2*num (Full p n)<(N:ℝ)) → + binaryGood m → ∀ r:ℕ,∀ Y:Silhouette p N r, ∀ o:UnitType p n N, + PreparationParameters.frameSide p m o → w.matchesArea t z Y o δ → + litFire p o → w.mirrorSpan t z m 0 δ Y o := by + classical + let v:= w.pen t + have ht:=h.enter.first; let a:=(scanPrice p)⁻¹ + have ha : 0fun ht=>h (hw.1 ht) + refine ⟨hW,hp,hv,fun z hz=>(v.resonant m hm o hf hy W hW a ha hC w.script z hz).trans hi, + fun f hf=> (reference_product t z f hf ?_).trans hj⟩ + change _≤(N:ℝ) at hB; linarith only [hB] + +def markedTest (M : ℕ) (b' : PreparationParameters) (s0 n : ℕ) {r} + (X : Silhouette p (M*n) r) (W : Wgt (Keys (p:=p) t (M*n))) (L u ε:ℝ) := + let N:=M*n; ∀ r:ℕ,∀ Y:Silhouette p N r,refines Y X → + ∀ (m : Mixer p n) (U:Wgt (UnitType p n N)), b'.Align s0 p M n m U → + pr U (w.flunk t z Y W m u ε) ≤ L + +set_option maxHeartbeats 1600000 in +theorem sideRelease (M:ℕ) (h : AnalyticParameters p M b' s0) (hw : w.moral t z) (ε:ℝ) (he:0<ε) : + ∃ (l:ℕ) (u c:ℝ),0hM f hf, hh.1⟩ + have hg := bare_bridge w t z m Y o s F (fun i=> finerPigment X Y hy _ (hX _)) + (by linarith only [ht.hG]) ht.hJ hf' (hR m hm.cols hm.rum _ Y o hj hv (not_not.mp hh.2)) W heq + refine not_lt_of_ge (hg.trans ?_) h + have hf : (r:ℝ)*(x*u)≤a := by + have ht : ((r:ℝ)+1)*(x*u) = a := by unfold u; field_simp + rw [←ht]; exact mul_le_mul_of_nonneg_right (by linarith) (by positivity) + unfold x a at * + linarith only [hf,he] + have hU : IsLaw U:=hm.drain.1 + have hT := + h m hm.cols U hm.drain w.script μ hμ (fun i=>scopedZ_bit p n _ _ _ (hμ i)) + have hD' : bp (-(n:ℝ)*n/8) ≤ bp (-c*n) := by + change _ ≤ (n:ℝ) at hD + apply bp_le + nlinarith only [mul_le_mul_of_nonneg_right hD (show 0≤ (n:ℝ) from Nat.cast_nonneg _)] + have hH : pr U Q≤ bp (-c*n) := (hG m hm.cols U hm.drain.2.2.2).trans hD' + change pr U T≤bp (-c*n) at hT + exact ((pr_mono hU.nz hi).trans ((pr_or_le hU.nz).trans (add_le_add hT hH))).trans + (by rw [two_mul] at hQ; exact hQ) + +end Quill +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/UniqueStatusCoefficients.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/UniqueStatusCoefficients.lean index 57d5f3627aaa3199a85a408297cbc584b96c00a5..c0ba827ea10aaf818a039acfcd91ccce021b81dc 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/UniqueStatusCoefficients.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/UniqueStatusCoefficients.lean @@ -1,122 +1,122 @@ -import OAI.Combinatorics.HadwigerCounterexample.BinaryStatusComparison - -namespace OAI - -/-! # Unique Status Coefficients -/ - -noncomputable section -namespace HadwigerCounterexample -open Filter Finset Function Matrix Submodule Module LinearMap -open scoped BigOperators -namespace StatusAnalysis -namespace DualAnalysis -variable {p:Shape} {r:ℕ} {d:Rates} - {u:Terrain p r} {s:Gazette p r d} {β δ:ℝ} - -private theorem loose_coeff {n:ℕ} (a b:RhymeSet n) (h:a.coal≠b.coal∨a.headBit≠b.headBit) - (Q S T:F) : - ∃ x:Par n,dotProduct a.coal x.2+a.headBit*x.1+a.gamma*Q+S ≠ - dotProduct b.coal x.2+b.headBit*x.1+b.gamma*Q+T := by - classical - by_contra! he - have h0 := he (0,0) - simp only [dotProduct_zero,mul_zero,add_zero,zero_add] at h0 - obtain ⟨ha,hb⟩ : a.coal=b.coal∧a.headBit=b.headBit :=by - constructor - · funext i - have hh:=he (0,Pi.single i 1) - simp only [dotProduct_single,mul_one,mul_zero,add_zero,add_assoc,h0] at hh - exact add_right_cancel hh - have hh:=he (1,0); simp only [dotProduct_zero,mul_one,zero_add,add_assoc,h0] at hh - exact add_right_cancel hh - simp [ha,hb] at h - -theorem shot_switch (u:Terrain p r) (s:Gazette p r d) (i) (z:Appearance p) - (a:RhymeSet (d i)) (f g:Pulsar p r) - (hw:IsLaw (u z.l z.q)) (hs:∀ j, IsLaw (s i z j)) : - shot u s i z a g ≤ shot u s i z a f+pr (u z.l z.q) (fun j=>f z.l z.q j≠ g z.l z.q j) := by - unfold shot pr; rw [←avg_add] - refine avg_mono hw.nz (fun j=>?_); let T:=s i z j - have hh := disagreement_bound (s i z j) (hs j).nz (a.soot z) - (fun _=>f z.l z.q j) (fun _=>g z.l z.q j) - unfold pr at hh; rw [(hs j).avg_const] at hh; exact hh -set_option maxHeartbeats 1000000 in -theorem unison (hp:3≤p.g) (hu:origami p r u δ) (hs:reports p r u s β δ) - (i : Nodes) {ε e:ℝ} - (a b:RhymeSet (d i)) - (f g:Pulsar p r) (A B : Finset (Label p.b)) (h:(A∪B).card < Fintype.card (Label p.b)) - (hA:praise u s i A a f ε) (hB:praise u s i B b g e) - (hC:a.bit=b.bit) (ht:ε+e<1/2*β) (hβ:0≤β) : - a.coal=b.coal ∧ a.headBit=b.headBit ∧ ∀ l q, pr (u l q) - (fun k=>f l q k+a.gamma*q≠g l q k+b.gamma*q) ≤ ε+e := by - classical - obtain ⟨x,hx⟩:= any_label _ h - let X:= amazes p x - let P l q k (w:Magazine p (d i)) := - a.read q w.2≠ f l q k ∨ b.read q w.2 ≠g l q k - have hX l q : (X l q).apt:=generic_apt p hp _ rfl - have hi l q : - avg (u l q) (fun k=>pr (s i (X l q) k) (P l q k)) ≤ ε+e := by - have h1:=hA (X l q) (fun h=>hx (mem_union_left _ h)) (hX l q) - have h2:=hB (X l q) (fun h=>hx (mem_union_right _ h)) (hX l q) - let t k:=s i (X l q) k - let q1 (k:Fin r) (w:Magazine p (d i)):= a.read q w.2≠ f l q k - let q2 (k:Fin r) (w:Magazine p (d i)):= b.read q w.2≠g l q k - apply (avg_mono (hu.1 l q).nz (fun j=> pr_or_le (p:=q1 j) (q:=q2 j) - (hs.law _ _ (hX ..) j).nz)).trans - rw [avg_add] - exact add_le_add h1 h2 - have ht' (l q k) (w:Magazine p (d i)) (h:¬P l q k w) : - let x:=(w.2.1) - dotProduct a.coal x.2+a.headBit*x.1+a.gamma*q + f l q k = - dotProduct b.coal x.2+b.headBit*x.1+b.gamma*q+g l q k := by - have ha : a.read q w.2=f l q k := not_not.mp (mt Or.inl h) - have hb : b.read q w.2=g l q k := not_not.mp (mt Or.inr h) - let x:=w.2.1 - let V (s:RhymeSet (d i)) := dotProduct s.coal x.2+s.headBit*x.1+s.gamma*q - have hh (s:RhymeSet (d i)) : V s + s.read q w.2=s.bit*(w.2.2+x.1) := by - have hh : s.read q w.2=s.bit*(w.2.2+x.1)+V s := by unfold RhymeSet.read V x; ring - rw [hh,add_left_comm,char_two,add_zero] - change V a+_= V b+_ - rw [←ha, ←hb,hh,hh,hC] - have he : a.coal=b.coal∧a.headBit=b.headBit := by - let l:Tag p.g:= ⟨0,by omega⟩; let Q:=show F from 0 - let R:=X l Q; let S(k:Fin r):= δ≤u l Q k - by_contra! hf - have hb (k) (hk:S k): β ≤ pr (s i R k) (P l Q k) := by - obtain ⟨z,hz⟩:= loose_coeff a b (by tauto) Q (f l Q k) - (g l Q k) - · exact le_trans (hs.generous i _ rfl (hX _ _) k hk z) - (pr_mono (hs.law _ R (hX _ _) k).nz (fun x hx=> not_not.mp - (fun ht=>hz (hx ▸ ht' l Q k x ht)))) - - have hh : 1/2*β ≤ avg (u l Q) (fun k=>pr (s i R k) (P l Q k)) := by - refine (mul_le_mul_of_nonneg_right (hu.2 l Q) hβ).trans ?_ - unfold pr; rw [←avg_mul]; refine avg_mono (hu.1 l Q).nz fun i=> ?_ - change ind (S i) * _ ≤ _ - by_cases h:S i - · rw [ind_one h,one_mul]; exact hb i h - rw [ind_zero h,zero_mul]; exact pr_nonneg (hs.law _ _ (hX _ _) i).nz - exact ht.not_ge (hh.trans (hi l Q)) - refine ⟨he.1,he.2,fun l q=> le_trans ?_ (hi l q)⟩ - refine avg_mono (hu.1 l q).nz fun k=> ?_ - let W:=s i (X l q) k - have hw:=hs.law i _ (hX l q) k - let C:=f l q k+a.gamma*q≠g l q k+b.gamma*q - change ind C ≤ pr W _ - by_cases h:C - · have hh w : P l q k w := by - by_contra hy - have hm:=ht' l q k w hy; dsimp only at hm - rw [he.1,he.2,add_assoc _ (a.gamma*q),add_assoc _ (b.gamma*q)] at hm - exact h (by rw [add_comm _ (a.gamma*q),add_comm _ (b.gamma*q)]; exact add_left_cancel hm) - rw [ind_one h]; simp_rw [funext fun w=>eq_true (hh w),pr_true,show tot W=1 from hw.total]; exact le_rfl - rw [ind_zero h] - exact pr_nonneg hw.nz -end DualAnalysis -end StatusAnalysis -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.BinaryStatusComparison + +namespace OAI + +/-! # Unique Status Coefficients -/ + +noncomputable section +namespace HadwigerCounterexample +open Filter Finset Function Matrix Submodule Module LinearMap +open scoped BigOperators +namespace StatusAnalysis +namespace DualAnalysis +variable {p:Shape} {r:ℕ} {d:Rates} + {u:Terrain p r} {s:Gazette p r d} {β δ:ℝ} + +private theorem loose_coeff {n:ℕ} (a b:RhymeSet n) (h:a.coal≠b.coal∨a.headBit≠b.headBit) + (Q S T:F) : + ∃ x:Par n,dotProduct a.coal x.2+a.headBit*x.1+a.gamma*Q+S ≠ + dotProduct b.coal x.2+b.headBit*x.1+b.gamma*Q+T := by + classical + by_contra! he + have h0 := he (0,0) + simp only [dotProduct_zero,mul_zero,add_zero,zero_add] at h0 + obtain ⟨ha,hb⟩ : a.coal=b.coal∧a.headBit=b.headBit :=by + constructor + · funext i + have hh:=he (0,Pi.single i 1) + simp only [dotProduct_single,mul_one,mul_zero,add_zero,add_assoc,h0] at hh + exact add_right_cancel hh + have hh:=he (1,0); simp only [dotProduct_zero,mul_one,zero_add,add_assoc,h0] at hh + exact add_right_cancel hh + simp [ha,hb] at h + +theorem shot_switch (u:Terrain p r) (s:Gazette p r d) (i) (z:Appearance p) + (a:RhymeSet (d i)) (f g:Pulsar p r) + (hw:IsLaw (u z.l z.q)) (hs:∀ j, IsLaw (s i z j)) : + shot u s i z a g ≤ shot u s i z a f+pr (u z.l z.q) (fun j=>f z.l z.q j≠ g z.l z.q j) := by + unfold shot pr; rw [←avg_add] + refine avg_mono hw.nz (fun j=>?_); let T:=s i z j + have hh := disagreement_bound (s i z j) (hs j).nz (a.soot z) + (fun _=>f z.l z.q j) (fun _=>g z.l z.q j) + unfold pr at hh; rw [(hs j).avg_const] at hh; exact hh +set_option maxHeartbeats 1000000 in +theorem unison (hp:3≤p.g) (hu:origami p r u δ) (hs:reports p r u s β δ) + (i : Nodes) {ε e:ℝ} + (a b:RhymeSet (d i)) + (f g:Pulsar p r) (A B : Finset (Label p.b)) (h:(A∪B).card < Fintype.card (Label p.b)) + (hA:praise u s i A a f ε) (hB:praise u s i B b g e) + (hC:a.bit=b.bit) (ht:ε+e<1/2*β) (hβ:0≤β) : + a.coal=b.coal ∧ a.headBit=b.headBit ∧ ∀ l q, pr (u l q) + (fun k=>f l q k+a.gamma*q≠g l q k+b.gamma*q) ≤ ε+e := by + classical + obtain ⟨x,hx⟩:= any_label _ h + let X:= amazes p x + let P l q k (w:Magazine p (d i)) := + a.read q w.2≠ f l q k ∨ b.read q w.2 ≠g l q k + have hX l q : (X l q).apt:=generic_apt p hp _ rfl + have hi l q : + avg (u l q) (fun k=>pr (s i (X l q) k) (P l q k)) ≤ ε+e := by + have h1:=hA (X l q) (fun h=>hx (mem_union_left _ h)) (hX l q) + have h2:=hB (X l q) (fun h=>hx (mem_union_right _ h)) (hX l q) + let t k:=s i (X l q) k + let q1 (k:Fin r) (w:Magazine p (d i)):= a.read q w.2≠ f l q k + let q2 (k:Fin r) (w:Magazine p (d i)):= b.read q w.2≠g l q k + apply (avg_mono (hu.1 l q).nz (fun j=> pr_or_le (p:=q1 j) (q:=q2 j) + (hs.law _ _ (hX ..) j).nz)).trans + rw [avg_add] + exact add_le_add h1 h2 + have ht' (l q k) (w:Magazine p (d i)) (h:¬P l q k w) : + let x:=(w.2.1) + dotProduct a.coal x.2+a.headBit*x.1+a.gamma*q + f l q k = + dotProduct b.coal x.2+b.headBit*x.1+b.gamma*q+g l q k := by + have ha : a.read q w.2=f l q k := not_not.mp (mt Or.inl h) + have hb : b.read q w.2=g l q k := not_not.mp (mt Or.inr h) + let x:=w.2.1 + let V (s:RhymeSet (d i)) := dotProduct s.coal x.2+s.headBit*x.1+s.gamma*q + have hh (s:RhymeSet (d i)) : V s + s.read q w.2=s.bit*(w.2.2+x.1) := by + have hh : s.read q w.2=s.bit*(w.2.2+x.1)+V s := by unfold RhymeSet.read V x; ring + rw [hh,add_left_comm,char_two,add_zero] + change V a+_= V b+_ + rw [←ha, ←hb,hh,hh,hC] + have he : a.coal=b.coal∧a.headBit=b.headBit := by + let l:Tag p.g:= ⟨0,by omega⟩; let Q:=show F from 0 + let R:=X l Q; let S(k:Fin r):= δ≤u l Q k + by_contra! hf + have hb (k) (hk:S k): β ≤ pr (s i R k) (P l Q k) := by + obtain ⟨z,hz⟩:= loose_coeff a b (by tauto) Q (f l Q k) + (g l Q k) + · exact le_trans (hs.generous i _ rfl (hX _ _) k hk z) + (pr_mono (hs.law _ R (hX _ _) k).nz (fun x hx=> not_not.mp + (fun ht=>hz (hx ▸ ht' l Q k x ht)))) + + have hh : 1/2*β ≤ avg (u l Q) (fun k=>pr (s i R k) (P l Q k)) := by + refine (mul_le_mul_of_nonneg_right (hu.2 l Q) hβ).trans ?_ + unfold pr; rw [←avg_mul]; refine avg_mono (hu.1 l Q).nz fun i=> ?_ + change ind (S i) * _ ≤ _ + by_cases h:S i + · rw [ind_one h,one_mul]; exact hb i h + rw [ind_zero h,zero_mul]; exact pr_nonneg (hs.law _ _ (hX _ _) i).nz + exact ht.not_ge (hh.trans (hi l Q)) + refine ⟨he.1,he.2,fun l q=> le_trans ?_ (hi l q)⟩ + refine avg_mono (hu.1 l q).nz fun k=> ?_ + let W:=s i (X l q) k + have hw:=hs.law i _ (hX l q) k + let C:=f l q k+a.gamma*q≠g l q k+b.gamma*q + change ind C ≤ pr W _ + by_cases h:C + · have hh w : P l q k w := by + by_contra hy + have hm:=ht' l q k w hy; dsimp only at hm + rw [he.1,he.2,add_assoc _ (a.gamma*q),add_assoc _ (b.gamma*q)] at hm + exact h (by rw [add_comm _ (a.gamma*q),add_comm _ (b.gamma*q)]; exact add_left_cancel hm) + rw [ind_one h]; simp_rw [funext fun w=>eq_true (hh w),pr_true,show tot W=1 from hw.total]; exact le_rfl + rw [ind_zero h] + exact pr_nonneg hw.nz +end DualAnalysis +end StatusAnalysis +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/UnseenCrossingFactorization.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/UnseenCrossingFactorization.lean index 65c47aa06690e5e8ff864f911e11c0ba890777ff..2c193241501eaf00f51ae61720f026eeaf45b713 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/UnseenCrossingFactorization.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/UnseenCrossingFactorization.lean @@ -1,96 +1,96 @@ -import OAI.Combinatorics.HadwigerCounterexample.FourCornerMasks - -namespace OAI - -/-! # Unseen Crossing Factorization -/ - -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] [Fintype J] -variable [DecidableEq J] -namespace Template -variable (v : Template p I) - -private def spot (w : v.PackSlot) (A : PlusRack Unit N) := - upliftR (fun _:Unit=>w) A - -omit [Fintype I] in -private theorem spot_else (w : v.PackSlot) (A : PlusRack Unit N) {i : v.PackSlot} (hi : i≠w) (j) : - spot v w A j i=0 := by simp [spot,upliftR,Matrix.mul_apply,embedMat,hi] - -private theorem spot_blind (j : I) (c : Corn) (w : v.PackSlot) (hc : ¬ sees v j c w) - (x : v.PackStack N) (A : PlusRack Unit N) : - yieldK v j c (x+(spot v w A,0)) = yieldK v j c x ∧ - yieldK v j c (x+(0,spot v w A)) = yieldK v j c x := by - classical - have hh {x y : v.PackStack N} - (h : ∀ i,sees v j c i→∀ z,x.1 z i=y.1 z i∧x.2 z i=y.2 z i) : - yieldK v j c x=yieldK v j c y := by - funext i l b z - let k : v.PackSlot := (arm j i c,⟨i,l⟩) - have he : sees v j c k := rfl - change yieldK v j c x k.2.1 k.2.2 b z=yieldK v j c y k.2.1 k.2.2 b z - rw [yield_view _ j c x k he,yield_view _ j c y k he,(h k he z).1,(h k he z).2] - constructor <;> apply hh <;> intro i hi z <;> - simp only [Prod.fst_add,Prod.snd_add,Matrix.add_apply, Matrix.zero_apply, - spot_else v w A (show i≠w from (fun h => hc (h ▸ hi))),add_zero,and_self] - -set_option maxHeartbeats 800000 in -theorem cant_leak (v : Template p I) (j : I) (U : Wgt (Keys (p:=p) v.t N)) - (hU : ∀ i, |U i|≤1) (f : Vec (cantRail v j)) (hf : f≠0) : - |avg unif (fun x=>phasedBy (ledgerM _ f) x * packSecs v j U x)| ≤ bp (-(N:ℝ)/2) := by - classical - obtain ⟨⟨⟨a,b⟩,hab⟩,he⟩ := Function.ne_iff.mp hf - let M := ledgerM _ f - have hh : M a b=1 := by - unfold M ledgerM; simp only [Matrix.of_apply,dite_eq_left hab] - exact (bit_cases _).resolve_left he - let s := Finset.univ.filter (fun c=>sees v j c a) - let t := univ\s - let g (s : Finset Corn) (x : v.PackStack N) := ∏ i∈s,U (yieldK v j i x) - have h0 (s x) : |g s x|≤1 := by unfold g; rw [abs_prod]; exact - (prod_le_prod₀ (fun i _=>abs_nonneg _) (fun i _=>hU _)).trans_eq (by simp) - let A (_ : Unit) := a - let B (_ : Unit) := b - have h1 x (q : PlusRack Unit N) : g s (x+(0,upliftR B q))=g s x := by - apply prod_congr rfl - intro k hk - have ht (h : sees v j k b) := ((cant_mem ..).mp hab).2 ⟨k,(mem_filter.mp hk).2,h⟩ - exact congrArg _ (spot_blind v j k b ht x q).2 - have h2 x (q : PlusRack Unit N) : g t (x+(upliftR A q,0))=g t x := by - apply prod_congr rfl - intro k hk - have ht (h : sees v j k a) := - (mem_sdiff.mp hk).2 (mem_filter.mpr ⟨mem_univ _,h⟩) - exact congrArg _ (spot_blind v j k a ht x q).1 - let r := fun _ : v.PackStack N=> (1:ℝ) - have hx x : phasedBy M x * packSecs v j U x=phasedBy M x * g s x * g t x*r x := by - simp only [r,mul_one,mul_assoc] - unfold g t packSecs; rw [mul_comm (∏ z∈s,_),prod_sdiff (subset_univ s)] - change |avg unif (fun x=> phasedBy M x*_)|≤_ - simp_rw [hx] - have ht := layerLeak M (g s) (g t) r A B (h0 s) (h0 t) h1 h2 (fun _ _ _=>rfl) - have he : M.submatrix A B=1 := by ext i j; cases i; cases j; rw [Matrix.one_apply_eq]; exact hh - simpa only [r,he,Matrix.rank_one,Fintype.card_unit,Nat.cast_one,mul_one,abs_one, - unif_law.avg_const] using ht - -def chairCut (v : Template p I) (j : I) (U : Wgt (Keys (p:=p) v.t N)) (δ : ℝ) := - thinCut unif U (Prod.fst ∘ v.chairK j N) (Prod.snd ∘ v.chairK j N) δ - -theorem global_quart (v : Template p I) (j : I) (U : Wgt (Keys (p:=p) v.t N)) - (hU : ∀ i,|U i|≤1) (δ : ℝ) (h : chairCut v j U δ) : - |avg unif (packSecs v j U)|≤δ := by - classical - let E := v.chairK j N - have ht : mapW unif E=pairW unif unif := by rw [←pair_unif,unif_equiv] - change |avg unif (fun i=>quart E U (v.untwin N i))|≤_ - rw [← mapW_avg,unif_equiv,pair_unif] - exact quart_small E _ _ _ _ ht unif_law unif_law hU δ h -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FourCornerMasks + +namespace OAI + +/-! # Unseen Crossing Factorization -/ + +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] [Fintype J] +variable [DecidableEq J] +namespace Template +variable (v : Template p I) + +private def spot (w : v.PackSlot) (A : PlusRack Unit N) := + upliftR (fun _:Unit=>w) A + +omit [Fintype I] in +private theorem spot_else (w : v.PackSlot) (A : PlusRack Unit N) {i : v.PackSlot} (hi : i≠w) (j) : + spot v w A j i=0 := by simp [spot,upliftR,Matrix.mul_apply,embedMat,hi] + +private theorem spot_blind (j : I) (c : Corn) (w : v.PackSlot) (hc : ¬ sees v j c w) + (x : v.PackStack N) (A : PlusRack Unit N) : + yieldK v j c (x+(spot v w A,0)) = yieldK v j c x ∧ + yieldK v j c (x+(0,spot v w A)) = yieldK v j c x := by + classical + have hh {x y : v.PackStack N} + (h : ∀ i,sees v j c i→∀ z,x.1 z i=y.1 z i∧x.2 z i=y.2 z i) : + yieldK v j c x=yieldK v j c y := by + funext i l b z + let k : v.PackSlot := (arm j i c,⟨i,l⟩) + have he : sees v j c k := rfl + change yieldK v j c x k.2.1 k.2.2 b z=yieldK v j c y k.2.1 k.2.2 b z + rw [yield_view _ j c x k he,yield_view _ j c y k he,(h k he z).1,(h k he z).2] + constructor <;> apply hh <;> intro i hi z <;> + simp only [Prod.fst_add,Prod.snd_add,Matrix.add_apply, Matrix.zero_apply, + spot_else v w A (show i≠w from (fun h => hc (h ▸ hi))),add_zero,and_self] + +set_option maxHeartbeats 800000 in +theorem cant_leak (v : Template p I) (j : I) (U : Wgt (Keys (p:=p) v.t N)) + (hU : ∀ i, |U i|≤1) (f : Vec (cantRail v j)) (hf : f≠0) : + |avg unif (fun x=>phasedBy (ledgerM _ f) x * packSecs v j U x)| ≤ bp (-(N:ℝ)/2) := by + classical + obtain ⟨⟨⟨a,b⟩,hab⟩,he⟩ := Function.ne_iff.mp hf + let M := ledgerM _ f + have hh : M a b=1 := by + unfold M ledgerM; simp only [Matrix.of_apply,dite_eq_left hab] + exact (bit_cases _).resolve_left he + let s := Finset.univ.filter (fun c=>sees v j c a) + let t := univ\s + let g (s : Finset Corn) (x : v.PackStack N) := ∏ i∈s,U (yieldK v j i x) + have h0 (s x) : |g s x|≤1 := by unfold g; rw [abs_prod]; exact + (prod_le_prod₀ (fun i _=>abs_nonneg _) (fun i _=>hU _)).trans_eq (by simp) + let A (_ : Unit) := a + let B (_ : Unit) := b + have h1 x (q : PlusRack Unit N) : g s (x+(0,upliftR B q))=g s x := by + apply prod_congr rfl + intro k hk + have ht (h : sees v j k b) := ((cant_mem ..).mp hab).2 ⟨k,(mem_filter.mp hk).2,h⟩ + exact congrArg _ (spot_blind v j k b ht x q).2 + have h2 x (q : PlusRack Unit N) : g t (x+(upliftR A q,0))=g t x := by + apply prod_congr rfl + intro k hk + have ht (h : sees v j k a) := + (mem_sdiff.mp hk).2 (mem_filter.mpr ⟨mem_univ _,h⟩) + exact congrArg _ (spot_blind v j k a ht x q).1 + let r := fun _ : v.PackStack N=> (1:ℝ) + have hx x : phasedBy M x * packSecs v j U x=phasedBy M x * g s x * g t x*r x := by + simp only [r,mul_one,mul_assoc] + unfold g t packSecs; rw [mul_comm (∏ z∈s,_),prod_sdiff (subset_univ s)] + change |avg unif (fun x=> phasedBy M x*_)|≤_ + simp_rw [hx] + have ht := layerLeak M (g s) (g t) r A B (h0 s) (h0 t) h1 h2 (fun _ _ _=>rfl) + have he : M.submatrix A B=1 := by ext i j; cases i; cases j; rw [Matrix.one_apply_eq]; exact hh + simpa only [r,he,Matrix.rank_one,Fintype.card_unit,Nat.cast_one,mul_one,abs_one, + unif_law.avg_const] using ht + +def chairCut (v : Template p I) (j : I) (U : Wgt (Keys (p:=p) v.t N)) (δ : ℝ) := + thinCut unif U (Prod.fst ∘ v.chairK j N) (Prod.snd ∘ v.chairK j N) δ + +theorem global_quart (v : Template p I) (j : I) (U : Wgt (Keys (p:=p) v.t N)) + (hU : ∀ i,|U i|≤1) (δ : ℝ) (h : chairCut v j U δ) : + |avg unif (packSecs v j U)|≤δ := by + classical + let E := v.chairK j N + have ht : mapW unif E=pairW unif unif := by rw [←pair_unif,unif_equiv] + change |avg unif (fun i=>quart E U (v.untwin N i))|≤_ + rw [← mapW_avg,unif_equiv,pair_unif] + exact quart_small E _ _ _ _ ht unif_law unif_law hU δ h +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/WalshBounds.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/WalshBounds.lean index c078f650019343b2275533ebf825b4050a257d2e..3a8e99264d3d93094cf465ecf9055c5748c4564c 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/WalshBounds.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/WalshBounds.lean @@ -1,175 +1,175 @@ -import OAI.Combinatorics.HadwigerCounterexample.FiniteAffineLaws -import Mathlib.Analysis.Real.Sqrt - -namespace OAI - -/-! # Walsh Bounds -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators - -def wsign (x : F) : ℝ := if x = 0 then 1 else -1 - -@[simp] theorem wsign_zero : wsign 0=1 := by simp [wsign] -@[simp] theorem wsign_one : wsign 1=-1 := by simp [wsign] -theorem wsign_add (x y : F) : wsign (x+y) = wsign x * wsign y := by - rcases bit_cases x with h|h <;> rcases bit_cases y with g|g <;> - simp [h,g,char_two] - -@[simp] theorem wsign_abs (x) : |wsign x|=1 := by rcases bit_cases x with h|h <;> simp [h] - -variable {A B V W : Type} [Fintype A] [Fintype B] - -theorem avg_prod (w f g : Wgt A) : - avg w f * avg w g = avg (pairW w w) (fun x => f x.1*g x.2) := (pairW_separate ..).symm - -theorem avg_CS {w : Wgt A} (h : ∀ x, 0 ≤ w x) (f g : Wgt A) : - (avg w (fun x => f x*g x))^2 ≤ avg w (fun x => f x^2)*avg w (fun x => g x^2) := by - let F (f : Wgt A) (x) := Real.sqrt (w x)*f x - have hg (f : Wgt A) (x) : (F f x)^2=w x*f x^2 := by - unfold F; rw [mul_pow, Real.sq_sqrt (h x)] - have hx (x) : F f x*F g x=w x*(f x*g x) := by - unfold F; rw [mul_mul_mul_comm,← pow_two,Real.sq_sqrt (h _)] - have he := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (F f) (F g) - simp_rw [hg,hx] at he - exact he - -variable [AddCommGroup V] [Module F V] [AddCommGroup W] [Module F W] [Fintype V] [Fintype W] - -/-- Walsh orthogonality via a translation of the uniform measure. -/ -theorem wsign_lin (b : V →ₗ[F] F) : avg unif (fun x => wsign (b x)) = ind (b=0) := by - classical - by_cases h : b = 0 - · simp only [h,LinearMap.zero_apply,wsign_zero] - simpa using unif_law.avg_const _ - obtain ⟨x,hx⟩ : ∃ x, b x=1 := by - by_contra! hg - exact h (LinearMap.ext fun x => (bit_cases _).resolve_right (hg x)) - let E : V ≃ V := ⟨(·+x),(·+x),add_polar x,add_polar x⟩ - have he := avg_bij E unif (fun x => wsign (b x)) - change avg unif (fun z => wsign (b (z+x))) = _ at he - simp_rw [map_add,wsign_add,hx,wsign_one] at he - rw [avg_mul] at he - rw [ind_zero h] - linarith only [he] - -/-- A bilinear signs mean. -/ -theorem wsign_bilin (b : V →ₗ[F] W →ₗ[F] F) : - avg (pairW unif unif) (fun x => wsign (b x.1 x.2)) = bp (-(rk b:ℝ)) := by - classical - rw [pairW_avg] - simp_rw [wsign_lin] - have : Finite (W →ₗ[F] F) := Finite.of_injective _ DFunLike.coe_injective - let := Fintype.ofFinite (W →ₗ[F] F) - change pr unif _ = _ - rw [pr_unif_lin b 0,ind_one (LinearMap.range b).zero_mem,one_mul] - -omit [Fintype V] in -theorem avg_ws (b : V →ₗ[F] W →ₗ[F] F) (x z : V) : - avg unif (fun w => wsign (b x w)*wsign (b z w)) = ind (b x=b z) := by - simp_rw [← wsign_add] - change avg unif (fun w => wsign ((b x+b z) w)) = _ - rw [wsign_lin] - apply congrArg ind - exact propext (by rw [← ZModModule.sub_eq_add,sub_eq_zero]) - -/-- Unnormalized inner mean square identity. -/ -theorem avg_wsq (b : V →ₗ[F] W →ₗ[F] F) (v f : Wgt V) : - avg unif (fun w => (avg v (fun x => f x*wsign (b x w)))^2) = - avg (pairW v v) (fun x => f x.1 * f x.2 * ind (b x.1=b x.2)) := by - simp_rw [pow_two,avg_prod] - rw [avg_avg] - refine avg_congr fun ⟨x,z⟩ _ => ?_ - simp_rw [mul_mul_mul_comm (f x) _ (f z)] - rw [avg_mul',avg_ws] - -private theorem bp_half_le {x a : ℝ} (h : x^2 ≤ bp a) : |x| ≤ bp (a/2) := by - have hh : bp (a/2)^2 = bp a := by rw [pow_two,←bp_add]; congr 1; ring - exact le_of_pow_le_pow_left₀ (show (2:ℕ) ≠ 0 by decide) (bp_pos _).le (by rwa [sq_abs,hh]) - -/-- Correlation with arbitrary bounded unary tests. -/ -theorem walsh_bound (b : V →ₗ[F] W →ₗ[F] F) (f : Wgt V) (g : Wgt W) - (hf : ∀ x, |f x|≤1) (hg : ∀ x, |g x|≤1) : - |avg unif (fun w => g w * avg unif (fun x => f x*wsign (b x w)))| ≤ bp (-(rk b:ℝ)/2) := by - classical - have : Finite (W →ₗ[F] F) := Finite.of_injective _ DFunLike.coe_injective - let := Fintype.ofFinite (W →ₗ[F] F) - apply bp_half_le - let F w := avg unif (fun x => f x*wsign (b x w)) - have h1 : - avg unif (fun w => g w^2) ≤ 1 := unif_law.avg_le (fun x => by - have h := abs_le.mp (hg x); nlinarith [h.1,h.2]) - have h2 : - avg unif (fun w => (F w)^2) ≤ bp (-(rk b:ℝ)) := by - unfold F; rw [avg_wsq] - have hx : avg (pairW unif unif) (fun (x : V × V) => ind (b x.1 = b x.2)) - = bp (-(rk b:ℝ)) := by - rw [pairW_avg] - have hh x : - avg unif (fun z => ind (b x = b z)) = bp (-(rk b:ℝ)) := by - have h' : b x ∈ LinearMap.range b := ⟨x,rfl⟩ - have heq := pr_unif_lin b (b x) - rw [ind_one h',one_mul] at heq - change pr unif _ = _ - simp_rw [eq_comm (a:=b x)] - exact heq - simp_rw [hh] - exact unif_law.avg_const _ - rw [← hx] - refine avg_mono (pairW_law unif_law unif_law).nz fun ⟨x,y⟩ => ?_ - have hh : f x*f y ≤ 1 := by - have hh := mul_le_mul (hf x) (hf y) (abs_nonneg _) (by norm_num : 0 ≤ (1:ℝ)) - rw [← abs_mul,one_mul] at hh - exact (le_abs_self _).trans hh - simpa only [one_mul] using mul_le_mul_of_nonneg_right hh (ind_nonneg (b x=b y)) - apply le_trans (avg_CS unif_law.nz _ F) - exact (mul_le_mul h1 h2 (avg_nonneg unif_law.nz fun _ => sq_nonneg _) (by norm_num)).trans_eq - (one_mul _) - -/-- Min-entropy form, squared. -/ -theorem walsh_mass (b : V →ₗ[F] W →ₗ[F] F) (hb : Function.Injective b) (u : Wgt V) (v : Wgt W) - (f : Wgt V) (g : Wgt W) - (hf : ∀ x, |f x|≤1) (hg : ∀ x, |g x|≤1) (hu : SubLaw u) (hv : SubLaw v) - {p q : ℝ} (hp : ∀ x, u x ≤ p) (hq : ∀ x, v x ≤ q) : - (avg v (fun w => g w * avg u (fun x => f x*wsign (b x w))))^2 ≤ - (Fintype.card W : ℝ)*p*q := by - classical - let F w := avg u (fun x => f x*wsign (b x w)) - have hi {A : Type} [Fintype A] {p : ℝ} (h : 0 ≤ p) (v f : Wgt A) (hw : SubLaw v) - (hh : ∀ x, v x ≤ p) (hg : ∀ x, |f x|≤1) : ∑ x, (v x*f x)^2 ≤ p := by - have hr x : (v x*f x)^2 ≤ v x*p := calc - _ = v x^2*f x^2 := mul_pow _ _ _ - _ ≤ v x^2*1 := by - have he := abs_le.mp (hg x) - apply mul_le_mul_of_nonneg_left _ (sq_nonneg _) - nlinarith [he.1,he.2] - _ ≤ _ := by rw [mul_one,pow_two]; exact mul_le_mul_of_nonneg_left (hh x) (hw.nz x) - exact (Finset.sum_le_sum (fun x _ => hr x)).trans (hw.avg_le h (f:=fun _ => p) (fun _ => le_rfl)) - have hh1 := hi ((hv.nz 0).trans (hq 0)) v g hv hq hg - have hh2 := hi ((hu.nz 0).trans (hp 0)) u f hu hp hf - have heq : avg (pairW u u) (fun x : V×V => f x.1*f x.2*ind (b x.1=b x.2)) = - ∑ x, (u x*f x)^2 := by - rw [pairW_avg]; unfold avg - refine Finset.sum_congr rfl fun x _ => ?_ - have h z : (b x=b z) ↔ x=z := hb.eq_iff - simp [h,ind] - ring - have hW : 0 < (Fintype.card W : ℝ) := by exact_mod_cast Fintype.card_pos - have hh3 : ∑ w, F w^2 ≤ (Fintype.card W : ℝ)*p := by - rw [mul_comm] - apply (div_le_iff₀ hW).mp - calc _ = avg unif (fun w => F w^2) := by simp only [avg,unif_apply,← Finset.mul_sum]; - rw [div_eq_mul_inv,mul_comm] - _ ≤ _ := (avg_wsq b u f).le.trans (heq.le.trans hh2) - calc - _ = (∑ w, (v w*g w)*F w)^2 := by simp only [mul_assoc]; rfl - _ ≤ (∑ w, (v w*g w)^2) * ∑ w, (F w)^2 := Finset.sum_mul_sq_le_sq_mul_sq _ _ _ - _ ≤ _ := by rw [mul_comm _ q]; exact mul_le_mul hh1 hh3 - (Finset.sum_nonneg fun _ _ => sq_nonneg _) ((hv.nz 0).trans (hq 0)) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FiniteAffineLaws +import Mathlib.Analysis.Real.Sqrt + +namespace OAI + +/-! # Walsh Bounds -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators + +def wsign (x : F) : ℝ := if x = 0 then 1 else -1 + +@[simp] theorem wsign_zero : wsign 0=1 := by simp [wsign] +@[simp] theorem wsign_one : wsign 1=-1 := by simp [wsign] +theorem wsign_add (x y : F) : wsign (x+y) = wsign x * wsign y := by + rcases bit_cases x with h|h <;> rcases bit_cases y with g|g <;> + simp [h,g,char_two] + +@[simp] theorem wsign_abs (x) : |wsign x|=1 := by rcases bit_cases x with h|h <;> simp [h] + +variable {A B V W : Type} [Fintype A] [Fintype B] + +theorem avg_prod (w f g : Wgt A) : + avg w f * avg w g = avg (pairW w w) (fun x => f x.1*g x.2) := (pairW_separate ..).symm + +theorem avg_CS {w : Wgt A} (h : ∀ x, 0 ≤ w x) (f g : Wgt A) : + (avg w (fun x => f x*g x))^2 ≤ avg w (fun x => f x^2)*avg w (fun x => g x^2) := by + let F (f : Wgt A) (x) := Real.sqrt (w x)*f x + have hg (f : Wgt A) (x) : (F f x)^2=w x*f x^2 := by + unfold F; rw [mul_pow, Real.sq_sqrt (h x)] + have hx (x) : F f x*F g x=w x*(f x*g x) := by + unfold F; rw [mul_mul_mul_comm,← pow_two,Real.sq_sqrt (h _)] + have he := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (F f) (F g) + simp_rw [hg,hx] at he + exact he + +variable [AddCommGroup V] [Module F V] [AddCommGroup W] [Module F W] [Fintype V] [Fintype W] + +/-- Walsh orthogonality via a translation of the uniform measure. -/ +theorem wsign_lin (b : V →ₗ[F] F) : avg unif (fun x => wsign (b x)) = ind (b=0) := by + classical + by_cases h : b = 0 + · simp only [h,LinearMap.zero_apply,wsign_zero] + simpa using unif_law.avg_const _ + obtain ⟨x,hx⟩ : ∃ x, b x=1 := by + by_contra! hg + exact h (LinearMap.ext fun x => (bit_cases _).resolve_right (hg x)) + let E : V ≃ V := ⟨(·+x),(·+x),add_polar x,add_polar x⟩ + have he := avg_bij E unif (fun x => wsign (b x)) + change avg unif (fun z => wsign (b (z+x))) = _ at he + simp_rw [map_add,wsign_add,hx,wsign_one] at he + rw [avg_mul] at he + rw [ind_zero h] + linarith only [he] + +/-- A bilinear signs mean. -/ +theorem wsign_bilin (b : V →ₗ[F] W →ₗ[F] F) : + avg (pairW unif unif) (fun x => wsign (b x.1 x.2)) = bp (-(rk b:ℝ)) := by + classical + rw [pairW_avg] + simp_rw [wsign_lin] + have : Finite (W →ₗ[F] F) := Finite.of_injective _ DFunLike.coe_injective + let := Fintype.ofFinite (W →ₗ[F] F) + change pr unif _ = _ + rw [pr_unif_lin b 0,ind_one (LinearMap.range b).zero_mem,one_mul] + +omit [Fintype V] in +theorem avg_ws (b : V →ₗ[F] W →ₗ[F] F) (x z : V) : + avg unif (fun w => wsign (b x w)*wsign (b z w)) = ind (b x=b z) := by + simp_rw [← wsign_add] + change avg unif (fun w => wsign ((b x+b z) w)) = _ + rw [wsign_lin] + apply congrArg ind + exact propext (by rw [← ZModModule.sub_eq_add,sub_eq_zero]) + +/-- Unnormalized inner mean square identity. -/ +theorem avg_wsq (b : V →ₗ[F] W →ₗ[F] F) (v f : Wgt V) : + avg unif (fun w => (avg v (fun x => f x*wsign (b x w)))^2) = + avg (pairW v v) (fun x => f x.1 * f x.2 * ind (b x.1=b x.2)) := by + simp_rw [pow_two,avg_prod] + rw [avg_avg] + refine avg_congr fun ⟨x,z⟩ _ => ?_ + simp_rw [mul_mul_mul_comm (f x) _ (f z)] + rw [avg_mul',avg_ws] + +private theorem bp_half_le {x a : ℝ} (h : x^2 ≤ bp a) : |x| ≤ bp (a/2) := by + have hh : bp (a/2)^2 = bp a := by rw [pow_two,←bp_add]; congr 1; ring + exact le_of_pow_le_pow_left₀ (show (2:ℕ) ≠ 0 by decide) (bp_pos _).le (by rwa [sq_abs,hh]) + +/-- Correlation with arbitrary bounded unary tests. -/ +theorem walsh_bound (b : V →ₗ[F] W →ₗ[F] F) (f : Wgt V) (g : Wgt W) + (hf : ∀ x, |f x|≤1) (hg : ∀ x, |g x|≤1) : + |avg unif (fun w => g w * avg unif (fun x => f x*wsign (b x w)))| ≤ bp (-(rk b:ℝ)/2) := by + classical + have : Finite (W →ₗ[F] F) := Finite.of_injective _ DFunLike.coe_injective + let := Fintype.ofFinite (W →ₗ[F] F) + apply bp_half_le + let F w := avg unif (fun x => f x*wsign (b x w)) + have h1 : + avg unif (fun w => g w^2) ≤ 1 := unif_law.avg_le (fun x => by + have h := abs_le.mp (hg x); nlinarith [h.1,h.2]) + have h2 : + avg unif (fun w => (F w)^2) ≤ bp (-(rk b:ℝ)) := by + unfold F; rw [avg_wsq] + have hx : avg (pairW unif unif) (fun (x : V × V) => ind (b x.1 = b x.2)) + = bp (-(rk b:ℝ)) := by + rw [pairW_avg] + have hh x : + avg unif (fun z => ind (b x = b z)) = bp (-(rk b:ℝ)) := by + have h' : b x ∈ LinearMap.range b := ⟨x,rfl⟩ + have heq := pr_unif_lin b (b x) + rw [ind_one h',one_mul] at heq + change pr unif _ = _ + simp_rw [eq_comm (a:=b x)] + exact heq + simp_rw [hh] + exact unif_law.avg_const _ + rw [← hx] + refine avg_mono (pairW_law unif_law unif_law).nz fun ⟨x,y⟩ => ?_ + have hh : f x*f y ≤ 1 := by + have hh := mul_le_mul (hf x) (hf y) (abs_nonneg _) (by norm_num : 0 ≤ (1:ℝ)) + rw [← abs_mul,one_mul] at hh + exact (le_abs_self _).trans hh + simpa only [one_mul] using mul_le_mul_of_nonneg_right hh (ind_nonneg (b x=b y)) + apply le_trans (avg_CS unif_law.nz _ F) + exact (mul_le_mul h1 h2 (avg_nonneg unif_law.nz fun _ => sq_nonneg _) (by norm_num)).trans_eq + (one_mul _) + +/-- Min-entropy form, squared. -/ +theorem walsh_mass (b : V →ₗ[F] W →ₗ[F] F) (hb : Function.Injective b) (u : Wgt V) (v : Wgt W) + (f : Wgt V) (g : Wgt W) + (hf : ∀ x, |f x|≤1) (hg : ∀ x, |g x|≤1) (hu : SubLaw u) (hv : SubLaw v) + {p q : ℝ} (hp : ∀ x, u x ≤ p) (hq : ∀ x, v x ≤ q) : + (avg v (fun w => g w * avg u (fun x => f x*wsign (b x w))))^2 ≤ + (Fintype.card W : ℝ)*p*q := by + classical + let F w := avg u (fun x => f x*wsign (b x w)) + have hi {A : Type} [Fintype A] {p : ℝ} (h : 0 ≤ p) (v f : Wgt A) (hw : SubLaw v) + (hh : ∀ x, v x ≤ p) (hg : ∀ x, |f x|≤1) : ∑ x, (v x*f x)^2 ≤ p := by + have hr x : (v x*f x)^2 ≤ v x*p := calc + _ = v x^2*f x^2 := mul_pow _ _ _ + _ ≤ v x^2*1 := by + have he := abs_le.mp (hg x) + apply mul_le_mul_of_nonneg_left _ (sq_nonneg _) + nlinarith [he.1,he.2] + _ ≤ _ := by rw [mul_one,pow_two]; exact mul_le_mul_of_nonneg_left (hh x) (hw.nz x) + exact (Finset.sum_le_sum (fun x _ => hr x)).trans (hw.avg_le h (f:=fun _ => p) (fun _ => le_rfl)) + have hh1 := hi ((hv.nz 0).trans (hq 0)) v g hv hq hg + have hh2 := hi ((hu.nz 0).trans (hp 0)) u f hu hp hf + have heq : avg (pairW u u) (fun x : V×V => f x.1*f x.2*ind (b x.1=b x.2)) = + ∑ x, (u x*f x)^2 := by + rw [pairW_avg]; unfold avg + refine Finset.sum_congr rfl fun x _ => ?_ + have h z : (b x=b z) ↔ x=z := hb.eq_iff + simp [h,ind] + ring + have hW : 0 < (Fintype.card W : ℝ) := by exact_mod_cast Fintype.card_pos + have hh3 : ∑ w, F w^2 ≤ (Fintype.card W : ℝ)*p := by + rw [mul_comm] + apply (div_le_iff₀ hW).mp + calc _ = avg unif (fun w => F w^2) := by simp only [avg,unif_apply,← Finset.mul_sum]; + rw [div_eq_mul_inv,mul_comm] + _ ≤ _ := (avg_wsq b u f).le.trans (heq.le.trans hh2) + calc + _ = (∑ w, (v w*g w)*F w)^2 := by simp only [mul_assoc]; rfl + _ ≤ (∑ w, (v w*g w)^2) * ∑ w, (F w)^2 := Finset.sum_mul_sq_le_sq_mul_sq _ _ _ + _ ≤ _ := by rw [mul_comm _ q]; exact mul_le_mul hh1 hh3 + (Finset.sum_nonneg fun _ _ => sq_nonneg _) ((hv.nz 0).trans (hq 0)) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/WeakProductComparison.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/WeakProductComparison.lean index 34e28e162614731ce099c0aab1299da76331f758..c58875cffea8937f3584d63f7f5fdad68a884d31 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/WeakProductComparison.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/WeakProductComparison.lean @@ -1,72 +1,72 @@ -import OAI.Combinatorics.HadwigerCounterexample.ProductComparisonScales - -namespace OAI - -/-! # Weak Product Comparison -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix LinearMap Function Filter -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] -namespace Template -variable (v : Template p I) - -theorem shadow_norm (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) - (ε : ℝ) (h : shadowed v q U ε) - (hN : 2*num (I × Toast p)-(N:ℝ)≤ -1) : - let W := netFact (trayPort p v.t) - ∀ f : v.Localist N,(∀ i j,|f i j|≤1) → - |avg (lawNu p N v.t q) (fun x=> U x*prodW f x)| ≤ W*ε := by - classical - intro W f hf - let B := pr unif (ownPart (p:=p) v.t q (N:=N)) - have ht := priceNu v.t q hN - have hW : 0 (U x-T x)*prodW f x)|≤ ε) ∧ - engaged v q (U-T) n C (bp (-c*n)) ε := by - classical - let W:=netFact (trayPort p v.t) - have hW : 0?_,?_⟩ - · have he := shadow_norm v q (U-T) u hQ (by linarith only [hN]) f hf - have hh : W*u≤ ε := by rw [mul_comm]; exact (le_div_iff₀ hW).mp (min_le_right ..) - exact he.trans hh - intro m hN w hw s x hx hz - refine (pr_mono hw.1.nz (fun i hh=>?_)).trans (h m hN w hw s x hx hz) - obtain ⟨f,hf,hg⟩ := hh - exact ⟨f,hf,lt_of_le_of_lt (min_le_left ..) hg⟩ -end Template -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.ProductComparisonScales + +namespace OAI + +/-! # Weak Product Comparison -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix LinearMap Function Filter +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {I : Type} [Fintype I] [DecidableEq I] +namespace Template +variable (v : Template p I) + +theorem shadow_norm (v : Template p I) (q : I→F) (U : Wgt (Keys (p:=p) v.t N)) + (ε : ℝ) (h : shadowed v q U ε) + (hN : 2*num (I × Toast p)-(N:ℝ)≤ -1) : + let W := netFact (trayPort p v.t) + ∀ f : v.Localist N,(∀ i j,|f i j|≤1) → + |avg (lawNu p N v.t q) (fun x=> U x*prodW f x)| ≤ W*ε := by + classical + intro W f hf + let B := pr unif (ownPart (p:=p) v.t q (N:=N)) + have ht := priceNu v.t q hN + have hW : 0 (U x-T x)*prodW f x)|≤ ε) ∧ + engaged v q (U-T) n C (bp (-c*n)) ε := by + classical + let W:=netFact (trayPort p v.t) + have hW : 0?_,?_⟩ + · have he := shadow_norm v q (U-T) u hQ (by linarith only [hN]) f hf + have hh : W*u≤ ε := by rw [mul_comm]; exact (le_div_iff₀ hW).mp (min_le_right ..) + exact he.trans hh + intro m hN w hw s x hx hz + refine (pr_mono hw.1.nz (fun i hh=>?_)).trans (h m hN w hw s x hx hz) + obtain ⟨f,hf,hg⟩ := hh + exact ⟨f,hf,lt_of_le_of_lt (min_le_left ..) hg⟩ +end Template +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/WeightedPartitions.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/WeightedPartitions.lean index ac37bb118ef053b0b26d182a2d154d7ac489f112..23955146ccd2a9defdb592da8cb5b0a8efa7f23b 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/WeightedPartitions.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/WeightedPartitions.lean @@ -1,135 +1,135 @@ -import OAI.Combinatorics.HadwigerCounterexample.FinitePhaseAlternative - -namespace OAI - -/-! # Weighted Partitions -/ - -noncomputable section -namespace HadwigerCounterexample -open scoped BigOperators -open Finset -variable {A : Type} [Fintype A] - -abbrev Tiles (A : Type) := Finset (Finset A) -def inTiles (T : Tiles A) := fun x:A => ∃ i∈ T,x∈i - -def apart (T : Tiles A) := - ∀ x,∀ S∈T, ∀ F∈ T,x∈S→x∈F→ S=F - -def partMass (w : Wgt A) (S : Finset A) := pr w (fun x => x∈S) -def partW (w : Wgt A) (S : Finset A) := onW w (fun x => x∈S) - -def allMass (w : Wgt A) (T : Tiles A) := pr w (inTiles T) -def allW (w : Wgt A) (T : Tiles A) := onW w (inTiles T) - -variable {w : Wgt A} {T : Tiles A} - -theorem issued_sub (w : Wgt A) (hw : ∀ x, 0≤w x) (S R : Finset A) (h : R⊆S) : - partMass w R=partMass w S*partMass (partW w S) R := by - have he : (fun x => x∈ R)=(fun x => x∈S∧x∈R) := by ext; tauto - unfold partMass - exact ((congrArg (pr w) he).trans (pr_of_on hw _ _)) - -theorem issued_law (w : Wgt A) (hw : ∀ x, 0≤w x) - {S R : Finset A} (hp : 0 < partMass w S) (h : R⊆S) - (he : 0 < partMass (partW w S) R) : - 0 < partMass w R ∧ partW w R=partW (partW w S) R := by - refine ⟨by rw [issued_sub w hw S R h]; exact mul_pos hp he,?_⟩ - have ht := on_both w (fun x => x∈S) (fun x => x∈R) hw hp he - unfold partW; rw [ht] - exact congrArg (onW w) (by ext; tauto) - -omit [Fintype A] in -theorem ind_tiles (ht : apart T) (x : A) : - ind (inTiles T x)= ∑ i∈T,ind (x∈i) := by - classical - by_cases hh : inTiles T x - · rw [ind_one hh] - obtain ⟨i,hi,hx⟩ := hh - rw [Finset.sum_eq_single i] - · rw [ind_one hx] - · intro j hj h; exact ind_zero (fun hc => h (ht x j hj i hi hc hx)) - simp [hi] - rw [ind_zero hh] - exact (Finset.sum_eq_zero (fun i hi => ind_zero (fun h => hh ⟨i,hi,h⟩))).symm - -theorem tiles_inter (w : Wgt A) (T : Tiles A) (P : A→Prop) (hT : apart T) : - pr w (fun x => inTiles T x∧P x)= ∑ i∈T,pr w (fun x => x∈i ∧ P x) := by - unfold pr - simp_rw [ind_and, ind_tiles hT,Finset.sum_mul,avg_sum] - -theorem mass_apart (h : apart T) : allMass w T=∑ i∈T,partMass w i := by - simpa only [and_true,allMass,partMass] using tiles_inter w T (fun x => True) h - -def portionW (w : Wgt A) (T : Tiles A) : Wgt T := - fun x => partMass w x.val / allMass w T - -theorem rebuild {T : Tiles A} (hw : ∀ x, 0 ≤ w x) - (hT : apart T) (he : ∀ i ∈ T, 0 < partMass w i) - (h : 0 < allMass w T) : - IsLaw (portionW w T) ∧ allW w T = mixW (portionW w T) (fun i => partW w i.val) := by - classical - constructor - · refine ⟨fun i => div_nonneg (pr_nonneg hw) h.le,?_⟩ - unfold tot portionW - simp_rw [div_eq_mul_inv] - rw [← Finset.sum_mul,Finset.sum_coe_sort,← mass_apart hT,mul_inv_cancel₀ h.ne'] - funext x - rw [allW,onW_val,ind_tiles hT] - unfold mixW avg - have hg (i:T) : - portionW w T i* partW w i.val x = w x*ind (x∈i.val)/allMass w T := by - have hx : pr w (fun x => x∈i.val) ≠ 0 := (he _ i.property).ne' - unfold portionW partW partMass - rw [onW_val]; field_simp - change w x * _ / allMass w T=_ - simp_rw [hg] - simp_rw [div_eq_mul_inv] - rw [← Finset.sum_mul,← Finset.mul_sum, Finset.sum_coe_sort T (fun y => ind (x∈y))] - -/-- Refine on every old tile, with rules allowed to be different on every -tile. Total loss bound relative to the old tiled union. -/ -theorem improve (T : Tiles A) (w : Wgt A) (hw : ∀ x,0 ≤ w x) - (P : A→Prop) (R : Finset A→Finset A→Prop) (hT : apart T) {c : ℝ} - (h : ∀ i∈T,∃ V : Tiles A, apart V ∧ - (∀ S∈V,S ⊆ i ∧ R i S) ∧ - pr (partW w i) (fun x => x∈i∧P x∧¬inTiles V x) ≤ c) : - ∃ V : Tiles A,apart V∧ (∀ S∈V,∃ i∈T,S⊆i ∧ R i S) ∧ - pr w (fun x => inTiles T x ∧ P x ∧ ¬inTiles V x)≤ allMass w T*c := by - classical - have h1 : ∀ i : Finset A, ∃ V : Tiles A,i∈T → apart V ∧ - (∀ S∈V,S ⊆ i ∧ R i S) ∧ - pr (partW w i) (fun x => x∈i∧P x∧¬inTiles V x) ≤ c := by - intro i - by_cases hi : i∈T - · obtain ⟨V,h⟩ := h i hi - exact ⟨V,fun _ => h⟩ - exact ⟨∅,fun h => (hi h).elim⟩ - choose V hV using h1 - let G := T.biUnion V - refine ⟨G,?_,?_,?_⟩ - · intro x S hS W hw hx hx' - obtain ⟨i,hi,hS⟩ := Finset.mem_biUnion.mp hS - obtain ⟨j,hj,hW⟩ := Finset.mem_biUnion.mp hw - obtain rfl := hT x i hi j hj (((hV i hi).2.1 S hS).1 hx) (((hV j hj).2.1 W hW).1 hx') - exact (hV i hi).1 x S hS W hW hx hx' - · rintro S hS - obtain ⟨i,hi,hS⟩ := Finset.mem_biUnion.mp hS - exact ⟨i,hi,(hV i hi).2.1 _ hS⟩ - · rw [mass_apart hT,tiles_inter _ T _ hT, Finset.sum_mul] - refine Finset.sum_le_sum fun i hi => ?_ - have he (x) (hx : inTiles (V i) x) : inTiles G x := by - obtain ⟨S,hS,h⟩ := hx - exact ⟨S,Finset.mem_biUnion.mpr ⟨i,hi,hS⟩,h⟩ - let Z (x : A) := x∈i∧P x∧¬inTiles (V i) x - calc pr w _ - _ ≤ pr w (fun x => x∈i∧ Z x) := - pr_mono hw (fun x h => ⟨h.1,h.1,h.2.1,fun hx => h.2.2 (he _ hx)⟩) - _ = _ := pr_of_on hw (fun x => x∈i) Z - _ ≤ _ := mul_le_mul_of_nonneg_left (hV i hi).2.2 (pr_nonneg hw) - -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.FinitePhaseAlternative + +namespace OAI + +/-! # Weighted Partitions -/ + +noncomputable section +namespace HadwigerCounterexample +open scoped BigOperators +open Finset +variable {A : Type} [Fintype A] + +abbrev Tiles (A : Type) := Finset (Finset A) +def inTiles (T : Tiles A) := fun x:A => ∃ i∈ T,x∈i + +def apart (T : Tiles A) := + ∀ x,∀ S∈T, ∀ F∈ T,x∈S→x∈F→ S=F + +def partMass (w : Wgt A) (S : Finset A) := pr w (fun x => x∈S) +def partW (w : Wgt A) (S : Finset A) := onW w (fun x => x∈S) + +def allMass (w : Wgt A) (T : Tiles A) := pr w (inTiles T) +def allW (w : Wgt A) (T : Tiles A) := onW w (inTiles T) + +variable {w : Wgt A} {T : Tiles A} + +theorem issued_sub (w : Wgt A) (hw : ∀ x, 0≤w x) (S R : Finset A) (h : R⊆S) : + partMass w R=partMass w S*partMass (partW w S) R := by + have he : (fun x => x∈ R)=(fun x => x∈S∧x∈R) := by ext; tauto + unfold partMass + exact ((congrArg (pr w) he).trans (pr_of_on hw _ _)) + +theorem issued_law (w : Wgt A) (hw : ∀ x, 0≤w x) + {S R : Finset A} (hp : 0 < partMass w S) (h : R⊆S) + (he : 0 < partMass (partW w S) R) : + 0 < partMass w R ∧ partW w R=partW (partW w S) R := by + refine ⟨by rw [issued_sub w hw S R h]; exact mul_pos hp he,?_⟩ + have ht := on_both w (fun x => x∈S) (fun x => x∈R) hw hp he + unfold partW; rw [ht] + exact congrArg (onW w) (by ext; tauto) + +omit [Fintype A] in +theorem ind_tiles (ht : apart T) (x : A) : + ind (inTiles T x)= ∑ i∈T,ind (x∈i) := by + classical + by_cases hh : inTiles T x + · rw [ind_one hh] + obtain ⟨i,hi,hx⟩ := hh + rw [Finset.sum_eq_single i] + · rw [ind_one hx] + · intro j hj h; exact ind_zero (fun hc => h (ht x j hj i hi hc hx)) + simp [hi] + rw [ind_zero hh] + exact (Finset.sum_eq_zero (fun i hi => ind_zero (fun h => hh ⟨i,hi,h⟩))).symm + +theorem tiles_inter (w : Wgt A) (T : Tiles A) (P : A→Prop) (hT : apart T) : + pr w (fun x => inTiles T x∧P x)= ∑ i∈T,pr w (fun x => x∈i ∧ P x) := by + unfold pr + simp_rw [ind_and, ind_tiles hT,Finset.sum_mul,avg_sum] + +theorem mass_apart (h : apart T) : allMass w T=∑ i∈T,partMass w i := by + simpa only [and_true,allMass,partMass] using tiles_inter w T (fun x => True) h + +def portionW (w : Wgt A) (T : Tiles A) : Wgt T := + fun x => partMass w x.val / allMass w T + +theorem rebuild {T : Tiles A} (hw : ∀ x, 0 ≤ w x) + (hT : apart T) (he : ∀ i ∈ T, 0 < partMass w i) + (h : 0 < allMass w T) : + IsLaw (portionW w T) ∧ allW w T = mixW (portionW w T) (fun i => partW w i.val) := by + classical + constructor + · refine ⟨fun i => div_nonneg (pr_nonneg hw) h.le,?_⟩ + unfold tot portionW + simp_rw [div_eq_mul_inv] + rw [← Finset.sum_mul,Finset.sum_coe_sort,← mass_apart hT,mul_inv_cancel₀ h.ne'] + funext x + rw [allW,onW_val,ind_tiles hT] + unfold mixW avg + have hg (i:T) : + portionW w T i* partW w i.val x = w x*ind (x∈i.val)/allMass w T := by + have hx : pr w (fun x => x∈i.val) ≠ 0 := (he _ i.property).ne' + unfold portionW partW partMass + rw [onW_val]; field_simp + change w x * _ / allMass w T=_ + simp_rw [hg] + simp_rw [div_eq_mul_inv] + rw [← Finset.sum_mul,← Finset.mul_sum, Finset.sum_coe_sort T (fun y => ind (x∈y))] + +/-- Refine on every old tile, with rules allowed to be different on every +tile. Total loss bound relative to the old tiled union. -/ +theorem improve (T : Tiles A) (w : Wgt A) (hw : ∀ x,0 ≤ w x) + (P : A→Prop) (R : Finset A→Finset A→Prop) (hT : apart T) {c : ℝ} + (h : ∀ i∈T,∃ V : Tiles A, apart V ∧ + (∀ S∈V,S ⊆ i ∧ R i S) ∧ + pr (partW w i) (fun x => x∈i∧P x∧¬inTiles V x) ≤ c) : + ∃ V : Tiles A,apart V∧ (∀ S∈V,∃ i∈T,S⊆i ∧ R i S) ∧ + pr w (fun x => inTiles T x ∧ P x ∧ ¬inTiles V x)≤ allMass w T*c := by + classical + have h1 : ∀ i : Finset A, ∃ V : Tiles A,i∈T → apart V ∧ + (∀ S∈V,S ⊆ i ∧ R i S) ∧ + pr (partW w i) (fun x => x∈i∧P x∧¬inTiles V x) ≤ c := by + intro i + by_cases hi : i∈T + · obtain ⟨V,h⟩ := h i hi + exact ⟨V,fun _ => h⟩ + exact ⟨∅,fun h => (hi h).elim⟩ + choose V hV using h1 + let G := T.biUnion V + refine ⟨G,?_,?_,?_⟩ + · intro x S hS W hw hx hx' + obtain ⟨i,hi,hS⟩ := Finset.mem_biUnion.mp hS + obtain ⟨j,hj,hW⟩ := Finset.mem_biUnion.mp hw + obtain rfl := hT x i hi j hj (((hV i hi).2.1 S hS).1 hx) (((hV j hj).2.1 W hW).1 hx') + exact (hV i hi).1 x S hS W hW hx hx' + · rintro S hS + obtain ⟨i,hi,hS⟩ := Finset.mem_biUnion.mp hS + exact ⟨i,hi,(hV i hi).2.1 _ hS⟩ + · rw [mass_apart hT,tiles_inter _ T _ hT, Finset.sum_mul] + refine Finset.sum_le_sum fun i hi => ?_ + have he (x) (hx : inTiles (V i) x) : inTiles G x := by + obtain ⟨S,hS,h⟩ := hx + exact ⟨S,Finset.mem_biUnion.mpr ⟨i,hi,hS⟩,h⟩ + let Z (x : A) := x∈i∧P x∧¬inTiles (V i) x + calc pr w _ + _ ≤ pr w (fun x => x∈i∧ Z x) := + pr_mono hw (fun x h => ⟨h.1,h.1,h.2.1,fun hx => h.2.2 (he _ hx)⟩) + _ = _ := pr_of_on hw (fun x => x∈i) Z + _ ≤ _ := mul_le_mul_of_nonneg_left (hV i hi).2.2 (pr_nonneg hw) + +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ZeroDiscrepancyLemma.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ZeroDiscrepancyLemma.lean index c26153cac90a483c0299eec6c0bc140e0738121f..233c1f185197e6193a42973144c3f25a9a2cfea9 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ZeroDiscrepancyLemma.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ZeroDiscrepancyLemma.lean @@ -1,126 +1,126 @@ -import OAI.Combinatorics.HadwigerCounterexample.OppositePredictions - -namespace OAI - -/-! # Zero Discrepancy Lemma -/ - -noncomputable section -namespace HadwigerCounterexample -open Matrix Finset Function Filter Real -open scoped BigOperators -variable {p : Shape} {n N : ℕ} {A B : Type} [Fintype A] [Fintype B] - -theorem weighted_some [Nonempty B] {w : Wgt A} (h : IsLaw w) (f : B → A→Prop) - (he : ∀ i,w i≠0 → ∃ j,f j i) : - ∃ j,(num B)⁻¹ ≤ pr w (f j) := by - classical - have hi : pr w (fun _=> True) ≤ pr w (fun i=>∃ j,f j i) := pr_mono_support w h.nz - (fun i hi _=> he i hi) - have hx := hi.trans (pr_exists_le h.nz f) - rw [pr_true,h.total] at hx - by_contra! hh - have ht : ∑ i:B,pr w (f i)<∑ i:B,(num B)⁻¹ := by - obtain ⟨i⟩ := (inferInstance:Nonempty B) - exact Finset.sum_lt_sum (fun i _=> (hh i).le) ⟨i,mem_univ _,hh i⟩ - have hb : (num B:ℝ)≠0 := by unfold num; positivity - simp only [sum_const, card_univ,nsmul_eq_mul] at ht - change ∑ i:B,pr w _ sparse_rep (hy i).1 - (show 4*totalRank (v i)h i - have hh := (card_le_card hz).trans (hL b); rw [card_univ] at hh; omega - have hx : 0by - obtain ⟨hd,v,H,hZ,hT,hV⟩:=h x hx - obtain ⟨s,E,hE,t,hQ⟩:= unit_screen p K D q B hD hg hB m x hg' hj v α he - (fun i=>(hZ i).2) hd hT H (fun i=>(hZ i).1) g ε hV - exact ⟨(s,E,t),hE,hQ⟩) - let E := i.2.1; let t := i.2.2 - let z := onW w (S i) - have hi' := ((inv_pos_of_pos hp).trans_le hi) - have hZ : IsLaw z := on_law hw.nz hi' - let v := mapW z (fun x=>onSide x t) - have hv (x) : v x ≤ num V*L*raw m N x := by - have hx (i) : z i≤num V*w i := (on_mon hw.nz (inv_pos_of_pos hp) hi i).trans_eq - (by rw [inv_inv]) - exact (mapW_cap hx (fun x=>onSide x t) _).trans - (le_trans (mul_le_mul_of_nonneg_left (hk t x) hp.le) (le_of_eq (by ring))) - have hB : E.card ≤ q := by - obtain ⟨x,hx,_⟩:=exists_of_pr_pos hw.nz hi' - exact hx.1 - apply hn m hN E (le_trans hs (by gcongr)) i.1 (g t) v (mapW_law hZ _) hv - have hp : carried z (S i) := normW_carried (subW_carried w _) - have hb : carried v (fun y => screen p y i.1 E (screenRank p K) (g t) ε) := - mapW_carried hp (fun x hx=> hx.2) - exact fun i hi=>not_not.mp fun h=>hi (hb i h) -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.OppositePredictions + +namespace OAI + +/-! # Zero Discrepancy Lemma -/ + +noncomputable section +namespace HadwigerCounterexample +open Matrix Finset Function Filter Real +open scoped BigOperators +variable {p : Shape} {n N : ℕ} {A B : Type} [Fintype A] [Fintype B] + +theorem weighted_some [Nonempty B] {w : Wgt A} (h : IsLaw w) (f : B → A→Prop) + (he : ∀ i,w i≠0 → ∃ j,f j i) : + ∃ j,(num B)⁻¹ ≤ pr w (f j) := by + classical + have hi : pr w (fun _=> True) ≤ pr w (fun i=>∃ j,f j i) := pr_mono_support w h.nz + (fun i hi _=> he i hi) + have hx := hi.trans (pr_exists_le h.nz f) + rw [pr_true,h.total] at hx + by_contra! hh + have ht : ∑ i:B,pr w (f i)<∑ i:B,(num B)⁻¹ := by + obtain ⟨i⟩ := (inferInstance:Nonempty B) + exact Finset.sum_lt_sum (fun i _=> (hh i).le) ⟨i,mem_univ _,hh i⟩ + have hb : (num B:ℝ)≠0 := by unfold num; positivity + simp only [sum_const, card_univ,nsmul_eq_mul] at ht + change ∑ i:B,pr w _ sparse_rep (hy i).1 + (show 4*totalRank (v i)h i + have hh := (card_le_card hz).trans (hL b); rw [card_univ] at hh; omega + have hx : 0by + obtain ⟨hd,v,H,hZ,hT,hV⟩:=h x hx + obtain ⟨s,E,hE,t,hQ⟩:= unit_screen p K D q B hD hg hB m x hg' hj v α he + (fun i=>(hZ i).2) hd hT H (fun i=>(hZ i).1) g ε hV + exact ⟨(s,E,t),hE,hQ⟩) + let E := i.2.1; let t := i.2.2 + let z := onW w (S i) + have hi' := ((inv_pos_of_pos hp).trans_le hi) + have hZ : IsLaw z := on_law hw.nz hi' + let v := mapW z (fun x=>onSide x t) + have hv (x) : v x ≤ num V*L*raw m N x := by + have hx (i) : z i≤num V*w i := (on_mon hw.nz (inv_pos_of_pos hp) hi i).trans_eq + (by rw [inv_inv]) + exact (mapW_cap hx (fun x=>onSide x t) _).trans + (le_trans (mul_le_mul_of_nonneg_left (hk t x) hp.le) (le_of_eq (by ring))) + have hB : E.card ≤ q := by + obtain ⟨x,hx,_⟩:=exists_of_pr_pos hw.nz hi' + exact hx.1 + apply hn m hN E (le_trans hs (by gcongr)) i.1 (g t) v (mapW_law hZ _) hv + have hp : carried z (S i) := normW_carried (subW_carried w _) + have hb : carried v (fun y => screen p y i.1 E (screenRank p K) (g t) ε) := + mapW_carried hp (fun x hx=> hx.2) + exact fun i hi=>not_not.mp fun h=>hi (hb i h) +end HadwigerCounterexample + +end + +end OAI diff --git a/lean/OAI/Combinatorics/HadwigerCounterexample/ZeroDiscrepancyPrediction.lean b/lean/OAI/Combinatorics/HadwigerCounterexample/ZeroDiscrepancyPrediction.lean index 25c93b5aa41e8beeecb1b2346a66e22549ec5c7e..cd43219199263f29922197bcd34fc4e7246a6e89 100644 --- a/lean/OAI/Combinatorics/HadwigerCounterexample/ZeroDiscrepancyPrediction.lean +++ b/lean/OAI/Combinatorics/HadwigerCounterexample/ZeroDiscrepancyPrediction.lean @@ -1,124 +1,124 @@ -import OAI.Combinatorics.HadwigerCounterexample.NumericalGramPrescriptions - -namespace OAI - -/-! # Zero Discrepancy Prediction -/ - -noncomputable section -namespace HadwigerCounterexample -open Finset Matrix Module LinearMap Submodule Function -open scoped BigOperators -variable {p : Shape} {n N : ℕ} -def zoomset (p : Shape) (w : Tag p.g →Moment p n) := - Finset.univ.filter (fun i => etab p n Block.S (w i)≠0) - -theorem zoom_le (w : Tag p.g → Moment p n) : (zoomset p w).card≤ (nonzeroTags w).card := by - apply Finset.card_le_card - intro i hi - exact (mem_nonzeroTags i w).mpr (fun he => (mem_filter.mp hi).2 (by rw [he,map_zero])) - -def screenRank (p : Shape) (K : ℕ) := (p.g-1)*(p.h+2*p.J*K) -def screen (p : Shape) (i : Orient p n N) (s : Label p.b) (E : Finset (Tag p.g)) (r : ℕ) - (g : Augur p N) (δ : ℝ) := - ∃ w : Pdual p n, - (∀ l f,pr (spins p n) (mismatch p g w l s f i) ≤ δ)∧ - ∀ l : Tag p.g, - ∃ M:Moment p n,M.rank ≤ r ∧ ∀ x : Knobs p.g n, - let f:= creed p E - let v:=spring p l s f x - w (useAtom p l s f x)=dialed p l f x+evmat M v v - -set_option maxHeartbeats 600000 in -theorem coreRole (p : Shape) (w : Tag p.g→Moment p n) (hw : ∀ t,w t∈Wtag p n t) - (α : F) (hg : Odd p.g) (h : parityW w+α=1) (l s x) : - let f:= creed p (zoomset p w) - let M:=useAtom p l s f x - T0 p n (cut p n w) M + α*role p n M=dialed p l f x := by - classical - intro f M - let U:=cut p n w - let Q:= scan p l f x - have h1 : Q (.inr ())=0 := by simp [Q,f,scan,creed,Flavor.keeps,asBlock,Block.S] - have hq : role p n M=dialed p l f x := by - rw [role_scan] - change Q.diagO=Q.sumBit; unfold Digest.sumBit; rw [h1,add_zero] - let E:=zoomset p w - have hh t : sharedT p n t M=0 := by rw [sharedT_scan p hg]; change Q _+(if l=t then Q _ else 0)=_ - ; rw [h1]; simp - have he t (ht : t∈ E) : roleT p n t M=0 := by - rw [roleT_scan p] - refine sum_eq_zero fun i _ => ?_ - have hv : ¬ f.keeps l (Block.O i t) := fun hx=> (mem_filter.mp hx.2).2 ht - unfold scan; exact ite_eq_right hv - have hl t (hE : t∉E) : - role p n U+sharedT p n t U+α=1 := by - have hz : etab p n Block.S (w t)=0 := not_ne_iff.mp (fun hg=>hE (mem_filter.mpr ⟨mem_univ _,hg⟩)) - unfold U - rw [role_cut p w hw,sharedT_cut p hg t,hz,add_zero,← Finset.sum_add_distrib] - exact h - rw [T0_val]; change role _ _ U* _ + _ + _ = _ - simp_rw [hh,mul_zero,zero_add] - rw [←hq] - let r := role p n U - have hm : role p n M=∑ t, roleT p n t M := by unfold role; rw [LinearMap.sum_apply] - rw [hm,mul_sum,mul_sum,←sum_add_distrib,←sum_add_distrib] - refine Finset.sum_congr rfl fun t _=>?_ - by_cases ht : t∈E - · rw [he t ht]; ring - rw [← add_mul,←add_mul,hl t ht,one_mul] - -theorem inner_gem (p : Shape) (x : UnitType p n N) (i : Bool) (t : Tag p.g) : - ∃ M : Moment p n,M.rank ≤ (p.g-1)*p.h ∧ ∀ (s z), - innerP p x i (atom p t s z)=mpair M (mom p s z) := by - classical - let A:=onSide x i; let B:=onSide x (!i) - let P (e : Comp p.g) := channel (B e).2*(channel (B e).1)ᵀ - let Z (e : Comp p.g) := liftM (primary (A e).1)ᵀ (primary (A e).2)ᵀ (P e) - let M := ∑ i:TagStar t,Z i.val - have ht i : (Z i).rank ≤ p.h := (rank_lift_le ..).trans ((Matrix.rank_mul_le_left ..).trans - ((Matrix.rank_le_card_width (channel (B i).2)).trans_eq (by simp))) - refine ⟨M,(mrk_sum_le ..).trans ((Finset.sum_le_sum (fun i _=>ht i.val)).trans_eq ?_),?_⟩ - · simp only [sum_const,card_univ,nsmul_eq_mul,Nat.cast_id,card_star] - intro s z - change (∑ i:Comp p.g, mpair (P i) (liftM (primary (A i).1) (primary (A i).2) (atom p t s z i))) - =_ - let Q:= mom p s z - have he i : - mpair (P i) (liftM (primary (A i).1) (primary (A i).2) (atom p t s z i)) = - if inc i t then mpair (Z i) Q else 0 := by - rw [mpair_liftM,atom_def]; by_cases ht:inc i t <;> simp only [ht,ite_false,ite_true,map_zero]; rfl - simp_rw [he] - unfold M; rw [←Finset.sum_filter,mpair_sum]; exact Finset.sum_subtype _ (by simp) _ - -theorem zero_screen (p : Shape) (x : UnitType p n N) (i : Bool) (s : Label p.b) - (m : Mixer p n) (α : F) (hg : Odd p.g) - (w : Tag p.g→Moment p n) (hw : ∀ i,w i∈ Wtag p n i) (h : parityW w+α=1) - (K : ℕ) (hk : totalRank (cut p n w) ≤ K) (g : Augur p N) - (δ : ℝ) (L : Finset (Label p.b)) (hs : s∉ L) - (hz : postulates p (onSide x i) g (yoke p m x i (cut p n w) α) L δ) : - screen p (onSide x i) s (zoomset p w) (screenRank p K) g δ := by - classical - let a := cut p n w; let f:=creed p (zoomset p w) - refine ⟨_,hz s hs,fun l=>?_⟩ - obtain ⟨M,hM,ht⟩:=inner_gem p x i l - refine ⟨M+qmix m a l,le_trans (mrk_add_le ..) ?_,fun y=>?_⟩ - · refine (Nat.add_le_add hM (qmix_rank ..)).trans ?_ - unfold screenRank; change _+p.J*(p.g-1)*(2*totalRank a)≤_ - exact le_trans (Nat.add_le_add_left (Nat.mul_le_mul_left (p.J*(p.g-1)) - (Nat.mul_le_mul_left 2 hk)) _) (le_of_eq (by ring)) - let A:=useAtom p l s f y - let z:=lit f l y; let T:=mom p s z - have h0 : (Tsym m a+α • role p n) A= dialed p l f y+mpair (qmix m a l) T := by - have hh : Tmix m a A=mpair (qmix m a l) T := Tmix_atom .. - change T0 p n a A + Tmix m a A + α * role p n A=_ - rw [hh,add_right_comm] - exact congrArg (·+_) (coreRole p w hw α hg h l s y) - change innerP p x i A + (Tsym m a + α • role p n) A = dialed p l f y+_ - rw [show innerP p x i A=mpair M T from ht s z,h0, ←mpair_outer,mpair_add] - change mpair M T+(dialed p l f y + _) = dialed p l f y+(mpair M T+_) - rw [add_left_comm]; rfl -end HadwigerCounterexample - -end - -end OAI +import OAI.Combinatorics.HadwigerCounterexample.NumericalGramPrescriptions + +namespace OAI + +/-! # Zero Discrepancy Prediction -/ + +noncomputable section +namespace HadwigerCounterexample +open Finset Matrix Module LinearMap Submodule Function +open scoped BigOperators +variable {p : Shape} {n N : ℕ} +def zoomset (p : Shape) (w : Tag p.g →Moment p n) := + Finset.univ.filter (fun i => etab p n Block.S (w i)≠0) + +theorem zoom_le (w : Tag p.g → Moment p n) : (zoomset p w).card≤ (nonzeroTags w).card := by + apply Finset.card_le_card + intro i hi + exact (mem_nonzeroTags i w).mpr (fun he => (mem_filter.mp hi).2 (by rw [he,map_zero])) + +def screenRank (p : Shape) (K : ℕ) := (p.g-1)*(p.h+2*p.J*K) +def screen (p : Shape) (i : Orient p n N) (s : Label p.b) (E : Finset (Tag p.g)) (r : ℕ) + (g : Augur p N) (δ : ℝ) := + ∃ w : Pdual p n, + (∀ l f,pr (spins p n) (mismatch p g w l s f i) ≤ δ)∧ + ∀ l : Tag p.g, + ∃ M:Moment p n,M.rank ≤ r ∧ ∀ x : Knobs p.g n, + let f:= creed p E + let v:=spring p l s f x + w (useAtom p l s f x)=dialed p l f x+evmat M v v + +set_option maxHeartbeats 600000 in +theorem coreRole (p : Shape) (w : Tag p.g→Moment p n) (hw : ∀ t,w t∈Wtag p n t) + (α : F) (hg : Odd p.g) (h : parityW w+α=1) (l s x) : + let f:= creed p (zoomset p w) + let M:=useAtom p l s f x + T0 p n (cut p n w) M + α*role p n M=dialed p l f x := by + classical + intro f M + let U:=cut p n w + let Q:= scan p l f x + have h1 : Q (.inr ())=0 := by simp [Q,f,scan,creed,Flavor.keeps,asBlock,Block.S] + have hq : role p n M=dialed p l f x := by + rw [role_scan] + change Q.diagO=Q.sumBit; unfold Digest.sumBit; rw [h1,add_zero] + let E:=zoomset p w + have hh t : sharedT p n t M=0 := by rw [sharedT_scan p hg]; change Q _+(if l=t then Q _ else 0)=_ + ; rw [h1]; simp + have he t (ht : t∈ E) : roleT p n t M=0 := by + rw [roleT_scan p] + refine sum_eq_zero fun i _ => ?_ + have hv : ¬ f.keeps l (Block.O i t) := fun hx=> (mem_filter.mp hx.2).2 ht + unfold scan; exact ite_eq_right hv + have hl t (hE : t∉E) : + role p n U+sharedT p n t U+α=1 := by + have hz : etab p n Block.S (w t)=0 := not_ne_iff.mp (fun hg=>hE (mem_filter.mpr ⟨mem_univ _,hg⟩)) + unfold U + rw [role_cut p w hw,sharedT_cut p hg t,hz,add_zero,← Finset.sum_add_distrib] + exact h + rw [T0_val]; change role _ _ U* _ + _ + _ = _ + simp_rw [hh,mul_zero,zero_add] + rw [←hq] + let r := role p n U + have hm : role p n M=∑ t, roleT p n t M := by unfold role; rw [LinearMap.sum_apply] + rw [hm,mul_sum,mul_sum,←sum_add_distrib,←sum_add_distrib] + refine Finset.sum_congr rfl fun t _=>?_ + by_cases ht : t∈E + · rw [he t ht]; ring + rw [← add_mul,←add_mul,hl t ht,one_mul] + +theorem inner_gem (p : Shape) (x : UnitType p n N) (i : Bool) (t : Tag p.g) : + ∃ M : Moment p n,M.rank ≤ (p.g-1)*p.h ∧ ∀ (s z), + innerP p x i (atom p t s z)=mpair M (mom p s z) := by + classical + let A:=onSide x i; let B:=onSide x (!i) + let P (e : Comp p.g) := channel (B e).2*(channel (B e).1)ᵀ + let Z (e : Comp p.g) := liftM (primary (A e).1)ᵀ (primary (A e).2)ᵀ (P e) + let M := ∑ i:TagStar t,Z i.val + have ht i : (Z i).rank ≤ p.h := (rank_lift_le ..).trans ((Matrix.rank_mul_le_left ..).trans + ((Matrix.rank_le_card_width (channel (B i).2)).trans_eq (by simp))) + refine ⟨M,(mrk_sum_le ..).trans ((Finset.sum_le_sum (fun i _=>ht i.val)).trans_eq ?_),?_⟩ + · simp only [sum_const,card_univ,nsmul_eq_mul,Nat.cast_id,card_star] + intro s z + change (∑ i:Comp p.g, mpair (P i) (liftM (primary (A i).1) (primary (A i).2) (atom p t s z i))) + =_ + let Q:= mom p s z + have he i : + mpair (P i) (liftM (primary (A i).1) (primary (A i).2) (atom p t s z i)) = + if inc i t then mpair (Z i) Q else 0 := by + rw [mpair_liftM,atom_def]; by_cases ht:inc i t <;> simp only [ht,ite_false,ite_true,map_zero]; rfl + simp_rw [he] + unfold M; rw [←Finset.sum_filter,mpair_sum]; exact Finset.sum_subtype _ (by simp) _ + +theorem zero_screen (p : Shape) (x : UnitType p n N) (i : Bool) (s : Label p.b) + (m : Mixer p n) (α : F) (hg : Odd p.g) + (w : Tag p.g→Moment p n) (hw : ∀ i,w i∈ Wtag p n i) (h : parityW w+α=1) + (K : ℕ) (hk : totalRank (cut p n w) ≤ K) (g : Augur p N) + (δ : ℝ) (L : Finset (Label p.b)) (hs : s∉ L) + (hz : postulates p (onSide x i) g (yoke p m x i (cut p n w) α) L δ) : + screen p (onSide x i) s (zoomset p w) (screenRank p K) g δ := by + classical + let a := cut p n w; let f:=creed p (zoomset p w) + refine ⟨_,hz s hs,fun l=>?_⟩ + obtain ⟨M,hM,ht⟩:=inner_gem p x i l + refine ⟨M+qmix m a l,le_trans (mrk_add_le ..) ?_,fun y=>?_⟩ + · refine (Nat.add_le_add hM (qmix_rank ..)).trans ?_ + unfold screenRank; change _+p.J*(p.g-1)*(2*totalRank a)≤_ + exact le_trans (Nat.add_le_add_left (Nat.mul_le_mul_left (p.J*(p.g-1)) + (Nat.mul_le_mul_left 2 hk)) _) (le_of_eq (by ring)) + let A:=useAtom p l s f y + let z:=lit f l y; let T:=mom p s z + have h0 : (Tsym m a+α • role p n) A= dialed p l f y+mpair (qmix m a l) T := by + have hh : Tmix m a A=mpair (qmix m a l) T := Tmix_atom .. + change T0 p n a A + Tmix m a A + α * role p n A=_ + rw [hh,add_right_comm] + exact congrArg (·+_) (coreRole p w hw α hg h l s y) + change innerP p x i A + (Tsym m a + α • role p n) A = dialed p l f y+_ + rw [show innerP p x i A=mpair M T from ht s z,h0, ←mpair_outer,mpair_add] + change mpair M T+(dialed p l f y + _) = dialed p l f y+(mpair M T+_) + rw [add_left_comm]; rfl +end HadwigerCounterexample + +end + +end OAI